MessageHandler.c 580 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "define.h"
  24. #include "SystemLogMessage.h"
  25. //#include "config.h"
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <stdlib.h>
  29. /*for sendfile()*/
  30. #include <sys/sendfile.h>
  31. /*for O_RDONLY*/
  32. #include <fcntl.h>
  33. #include "sqlite3.h"
  34. #include <arpa/inet.h>
  35. //#define _GNU_SOURCE
  36. #include <time.h>
  37. #include "MessageHandler.h"
  38. #include <assert.h>
  39. #include <pthread.h>
  40. #include <mcheck.h>
  41. #define PASS 1
  42. #define FAIL -1
  43. #define FALSE 0
  44. #define TRUE 1 // Option 1
  45. //ChargePointMaxProfile
  46. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  47. //TxDefaultProfile
  48. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  49. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  50. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  51. //TxProfile
  52. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  53. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  54. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  55. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  56. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  57. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  58. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  59. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  60. struct StatusCodeData *ShmStatusCodeData;
  61. struct PsuData *ShmPsuData ;
  62. struct OCPP16Data *ShmOCPP16Data;
  63. // define Macro
  64. #define SystemLogMessage
  65. // OCPP Message Type
  66. #define MESSAGE_TYPE_CALL 2
  67. #define MESSAGE_TYPE_CALLRESULT 3
  68. #define MESSAGE_TYPE_CALLERROR 4
  69. //
  70. #define server_cycle_Status 120
  71. #define MACROSTR(k) #k
  72. //ConfigurationMaxKeys
  73. #define GetConfigurationMaxKeysNUM 43
  74. //char guid[37];
  75. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  76. char queuedata[2600]={0};
  77. //===============================
  78. // Configuration: unknownkey
  79. //===============================
  80. static char unknownkey[10][20]={0};
  81. static int UnknownKeynum = 0;
  82. //===============================
  83. // Gun Total Numbers
  84. //===============================
  85. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  86. static int gunTotalNumber=0;
  87. //===============================
  88. // Local List Version
  89. //===============================
  90. static int localversion=0;
  91. static char idTagAuthorization[32]={0};
  92. //===============================
  93. // OCPP Path
  94. //===============================
  95. extern char OcppPath[160];
  96. extern char OcppProtocol[10];
  97. extern char OcppHost[50];
  98. extern char OcppTempPath[50];
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP StartTransaction transactionId variables
  115. //===============================
  116. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  117. //===============================
  118. // OCPP other variables
  119. //===============================
  120. int isUpdateRequest = FALSE;
  121. static int HeartBeatWaitTime = 10;
  122. static int FirstHeartBeat = 0;
  123. static int FirmwareStatusNotificationStatus = 3; // Idle
  124. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  125. static char CurrentChargingProfileScheduleStr[30]={0};
  126. //========================================
  127. // OCPP status/previous related variables
  128. //========================================
  129. static int GunStatusInterval = 10;
  130. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  131. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  132. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  133. static int GbPreviousSystemStatus[GB_QUANTITY];
  134. static int AcPreviousSystemStatus[AC_QUANTITY];
  135. int TransactionMessageAttemptsValue = 0;
  136. int TransactionMessageRetryIntervalValue = 0;
  137. static struct OCPPAuthLocalElemet
  138. {
  139. int listVersionInt;
  140. char idTagstr[20];
  141. char parentIdTag[20];
  142. char expiryDate[30];
  143. char idTagstatus[16];
  144. }idTagQuery;
  145. //=============================================
  146. // OCPP HeartBeat Response Not Receive Counts
  147. //============================================
  148. static int HeartBeatWithNOResponse = 0;
  149. static int HeartBeatCount = 0;
  150. extern struct lws *wsi_client;
  151. extern struct lws_context *context;
  152. extern unsigned char SendBuffer[4096];
  153. extern int SendBufLen;
  154. extern char *random_uuid( char buf[37] );
  155. extern void split(char **arr, char *str, const char *del);
  156. extern pthread_mutex_t mutex1;
  157. extern struct Charger_Info Charger;
  158. extern sqlite3 *db;
  159. int TransactionMessageAttemptsGet(void);
  160. int TransactionMessageRetryIntervalGet(void);
  161. int GetOcppConnStatus(void);
  162. void SetOcppConnStatus(uint8_t status);
  163. int updateSetting(char *key, char *value);
  164. int setKeyValue(char *key, char *value);
  165. void OCPP_get_TableAuthlocalAllData(void);
  166. void processUnkownKey(void);
  167. struct StructOCPPMeterValue
  168. {
  169. unsigned char TimeStamp[28];
  170. struct StructSampledValue SampledValue[10];
  171. };
  172. struct ClientTime
  173. {
  174. unsigned int Heartbeat;
  175. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  176. unsigned int StartTransaction;
  177. unsigned int StopTransaction;
  178. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  179. }clientTime;
  180. typedef union
  181. {
  182. //Operations Initiated by Central System
  183. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  184. struct
  185. {
  186. //CsMsgValue[0]
  187. unsigned char StatusNotificationReq :1; //bit 0,
  188. unsigned char StatusNotificationConf :1; //bit 0,
  189. unsigned char :6; //bit 2~7
  190. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  191. }CpinitiateMsg;
  192. CpinitiateMsg cpinitateMsg;
  193. //==========================================
  194. // Init all Enumeration & Mapping String
  195. //==========================================
  196. /*ChargePointErrorCode*/
  197. typedef enum {
  198. ConnectorLockFailure,
  199. EVCommunicationError,
  200. GroundFailure,
  201. HighTemperature,
  202. InternalError,
  203. LocalListConflict,
  204. NoError,
  205. OtherError,
  206. OverCurrentFailure,
  207. OverVoltage,
  208. PowerMeterFailure,
  209. PowerSwitchFailure,
  210. ReaderFailure,
  211. ResetFailure,
  212. UnderVoltage,
  213. WeakSignal
  214. } ChargePointErrorCode;
  215. #if 0
  216. static char *ChargePointErrorCodeStr[] = {
  217. MACROSTR(ConnectorLockFailure),
  218. MACROSTR(EVCommunicationError),
  219. MACROSTR(GroundFailure),
  220. MACROSTR(HighTemperature),
  221. MACROSTR(InternalError),
  222. MACROSTR(LocalListConflict),
  223. MACROSTR(NoError),
  224. MACROSTR(OtherError),
  225. MACROSTR(OverCurrentFailure),
  226. MACROSTR(OverVoltage),
  227. MACROSTR(PowerMeterFailure),
  228. MACROSTR(PowerSwitchFailure),
  229. MACROSTR(ReaderFailure),
  230. MACROSTR(ResetFailure),
  231. MACROSTR(UnderVoltage),
  232. MACROSTR(WeakSignal)
  233. };
  234. #endif
  235. /*ChargePointStatus*/
  236. typedef enum {
  237. Available =0,
  238. Preparing,
  239. Charging,
  240. SuspendedEVSE,
  241. SuspendedEV,
  242. Finishing,
  243. Reserved,
  244. Unavailable,
  245. Faulted
  246. } ChargePointStatus;
  247. static char * ChargePointStatusStr[] = {
  248. MACROSTR(Available),
  249. MACROSTR(Preparing),
  250. MACROSTR(Charging),
  251. MACROSTR(SuspendedEVSE),
  252. MACROSTR(SuspendedEV),
  253. MACROSTR(Finishing),
  254. MACROSTR(Reserved),
  255. MACROSTR(Unavailable),
  256. MACROSTR(Faulted)
  257. };
  258. /*AvailabilityType*/
  259. typedef enum {
  260. RegistrationStatus_Accepted,
  261. RegistrationStatus_Pending,
  262. RegistrationStatus_Rejected
  263. } RegistrationStatus;
  264. static char *RegistrationStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Pending),
  267. MACROSTR(Rejected)
  268. };
  269. /*AvailabilityType*/
  270. typedef enum {
  271. Inoperative,
  272. Operative
  273. } AvailabilityType;
  274. static char *AvailabilityTypeStr[] = {
  275. MACROSTR(Inoperative),
  276. MACROSTR(Operative)
  277. };
  278. /*AvailabilityStatus*/
  279. typedef enum {
  280. Accepted,
  281. Rejected,
  282. Scheduled
  283. } AvailabilityStatus;
  284. static char *AvailabilityStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected),
  287. MACROSTR(Scheduled)
  288. };
  289. /*ConfigurationStatus*/
  290. typedef enum {
  291. ConfigurationStatus_Accepted,
  292. ConfigurationStatus_Rejected,
  293. RebootRequired,
  294. NotSupported
  295. } ConfigurationStatus;
  296. static char *ConfigurationStatusStr[] = {
  297. MACROSTR(Accepted),
  298. MACROSTR(Rejected),
  299. MACROSTR(RebootRequired),
  300. MACROSTR(NotSupported)
  301. };
  302. /*ClearCacheStatus*/
  303. typedef enum {
  304. ClearCacheStatus_Accepted,
  305. ClearCacheStatus_Rejected
  306. } ClearCacheStatus;
  307. static char *ClearCacheStatusStr[] = {
  308. MACROSTR(Accepted),
  309. MACROSTR(Rejected)
  310. };
  311. /*ChargingProfilePurposeType*/
  312. typedef enum {
  313. ChargePointMaxProfile,
  314. TxDefaultProfile,
  315. TxProfile
  316. } ChargingProfilePurposeType;
  317. static char *ChargingProfilePurposeTypeStr[] = {
  318. MACROSTR(ChargePointMaxProfile),
  319. MACROSTR(TxDefaultProfile),
  320. MACROSTR(TxProfile)
  321. };
  322. /*ChargingProfileStatus*/
  323. typedef enum {
  324. ChargingProfileStatus_Accepted,
  325. ChargingProfileStatus_Rejected,
  326. ChargingProfileStatus_NotSupported
  327. } ChargingProfileStatus;
  328. static char *ChargingProfileStatusStr[] = {
  329. MACROSTR(Accepted),
  330. MACROSTR(Rejected),
  331. MACROSTR(NotSupported)
  332. };
  333. /*ClearChargingProfileStatus*/
  334. typedef enum {
  335. ClearChargingProfileStatus_Accepted,
  336. ClearChargingProfileStatus_Unknown
  337. } ClearChargingProfileStatus;
  338. static char *ClearChargingProfileStatusStr[] = {
  339. MACROSTR(Accepted),
  340. MACROSTR(Unknown)
  341. };
  342. /*GetCompositeScheduleStatus*/
  343. typedef enum {
  344. GetCompositeScheduleStatus_Accepted,
  345. GetCompositeScheduleStatus_Rejected
  346. } GetCompositeScheduleStatus;
  347. static char *GetCompositeScheduleStatusStr[] = {
  348. MACROSTR(Accepted),
  349. MACROSTR(Rejected)
  350. };
  351. /*ChargingRateUnitType*/
  352. typedef enum {
  353. ChargingRateUnitType_W,
  354. ChargingRateUnitType_A
  355. } ChargingRateUnitType;
  356. /*AuthorizationStatus*/
  357. typedef enum {
  358. AuthorizationStatus_Accepted ,
  359. AuthorizationStatus_Blocked ,
  360. AuthorizationStatus_Expired ,
  361. AuthorizationStatus_Invalid ,
  362. AuthorizationStatus_ConcurrentTx
  363. } AuthorizationStatus;
  364. /*UpdateType*/
  365. typedef enum {
  366. Differential ,
  367. Full
  368. } UpdateType;
  369. static char *UpdateTypeStr[] = {
  370. MACROSTR(Differential),
  371. MACROSTR(Full)
  372. };
  373. /*UpdateStatus*/
  374. typedef enum {
  375. UpdateStatus_Accepted ,
  376. UpdateStatus_Failed ,
  377. UpdateStatus_NotSupported ,
  378. UpdateStatus_VersionMismatch
  379. } UpdateStatus;
  380. static char *UpdateStatusStr[] = {
  381. MACROSTR(Accepted),
  382. MACROSTR(Failed),
  383. MACROSTR(NotSupported),
  384. MACROSTR(VersionMismatch)
  385. };
  386. /*RemoteStartStopStatus*/
  387. typedef enum {
  388. RemoteStartStopStatus_Accepted,
  389. RemoteStartStopStatus_Rejected
  390. } RemoteStartStopStatus;
  391. static char *RemoteStartStopStatusStr[] = {
  392. MACROSTR(Accepted),
  393. MACROSTR(Rejected)
  394. };
  395. /*ReservationStatus*/
  396. typedef enum {
  397. ReservationStatus_Accepted,
  398. ReservationStatus_Faulted,
  399. ReservationStatus_Occupied,
  400. ReservationStatus_Rejected,
  401. ReservationStatus_Unavailable
  402. } ReservationStatus;
  403. static char *ReservationStatusStr[] = {
  404. MACROSTR(Accepted),
  405. MACROSTR(Faulted),
  406. MACROSTR(Occupied),
  407. MACROSTR(Rejected),
  408. MACROSTR(Unavailable)
  409. };
  410. /*ResetType*/
  411. typedef enum {
  412. Hard,
  413. Soft
  414. } ResetType;
  415. static char *ResetTypeStr[] = {
  416. MACROSTR(Hard),
  417. MACROSTR(Soft)
  418. };
  419. /*ResetStatus*/
  420. typedef enum {
  421. ResetStatus_Accepted,
  422. ResetStatus_Rejected
  423. } ResetStatus;
  424. static char *ResetStatusStr[] = {
  425. MACROSTR(Accepted),
  426. MACROSTR(Rejected)
  427. };
  428. /*DiagnosticsStatus*/
  429. typedef enum {
  430. DiagnosticsStatus_Idle,
  431. DiagnosticsStatus_Uploaded,
  432. DiagnosticsStatus_UploadFailed,
  433. DiagnosticsStatus_Uploading
  434. } DiagnosticsStatus;
  435. static char * DiagnosticsStatusStr[] = {
  436. MACROSTR(Idle),
  437. MACROSTR(Uploaded),
  438. MACROSTR(UploadFailed),
  439. MACROSTR(Uploading)
  440. };
  441. /*FirmwareStatus*/
  442. typedef enum {
  443. FirmwareStatus_Downloaded,
  444. FirmwareStatus_DownloadFailed,
  445. FirmwareStatus_Downloading,
  446. FirmwareStatus_Idle,
  447. FirmwareStatus_InstallationFailed,
  448. FirmwareStatus_Installing,
  449. FirmwareStatus_Installed
  450. } FirmwareStatus;
  451. static char * FirmwareStatusStr[] = {
  452. MACROSTR(Downloaded),
  453. MACROSTR(DownloadFailed),
  454. MACROSTR(Downloading),
  455. MACROSTR(Idle),
  456. MACROSTR(InstallationFailed),
  457. MACROSTR(Installing),
  458. MACROSTR(Installed)
  459. };
  460. /*MessageTrigger*/
  461. typedef enum {
  462. BootNotification,
  463. DiagnosticsStatusNotification,
  464. FirmwareStatusNotification,
  465. Heartbeat,
  466. MeterValues,
  467. StatusNotification
  468. } MessageTrigger;
  469. static char * MessageTriggerStr[] = {
  470. MACROSTR(BootNotification),
  471. MACROSTR(DiagnosticsStatusNotification),
  472. MACROSTR(FirmwareStatusNotification),
  473. MACROSTR(Heartbeat),
  474. MACROSTR(MeterValues),
  475. MACROSTR(StatusNotification)
  476. };
  477. /*TriggerMessageStatus*/
  478. typedef enum {
  479. TriggerMessageStatus_Accepted ,
  480. TriggerMessageStatus_Rejected ,
  481. TriggerMessageStatus_NotImplemented
  482. } TriggerMessageStatus;
  483. static char * TriggerMessageStatusStr[] = {
  484. MACROSTR(Accepted),
  485. MACROSTR(Rejected),
  486. MACROSTR(NotImplemented)
  487. };
  488. /*UnlockStatus*/
  489. typedef enum {
  490. Unlocked,
  491. UnlockFailed,
  492. UnlockStatus_NotSupported
  493. } UnlockStatus;
  494. static char * UnlockStatusStr[] = {
  495. MACROSTR(Unlocked),
  496. MACROSTR(UnlockFailed),
  497. MACROSTR(NotSupported)
  498. };
  499. /*StopTransactionReason*/
  500. typedef enum {
  501. EmergencyStop,
  502. EVDisconnected,
  503. HardReset,
  504. Local,
  505. Other,
  506. PowerLoss,
  507. Reboot,
  508. Remote,
  509. SoftReset,
  510. UnlockCommand,
  511. DeAuthorized
  512. } StopTransactionReason;
  513. #if 0
  514. static char * StopTransactionReasonStr[] = {
  515. MACROSTR(EmergencyStop),
  516. MACROSTR(EVDisconnected),
  517. MACROSTR(HardReset),
  518. MACROSTR(Local),
  519. MACROSTR(Other),
  520. MACROSTR(PowerLoss),
  521. MACROSTR(Reboot),
  522. MACROSTR(Remote),
  523. MACROSTR(SoftReset),
  524. MACROSTR(UnlockCommand),
  525. MACROSTR(DeAuthorized)
  526. };
  527. #endif
  528. /*CancelReservationStatus*/
  529. typedef enum {
  530. CancelReservationStatus_Accepted,
  531. CancelReservationStatus_Rejected
  532. } CancelReservationStatus;
  533. static char * CancelReservationStatusStr[] = {
  534. MACROSTR(Accepted),
  535. MACROSTR(Rejected)
  536. };
  537. /*ReadingContext*/
  538. typedef enum {
  539. ReadingContext_Interruption_Begin,
  540. ReadingContext_Interruption_End,
  541. ReadingContext_Other,
  542. ReadingContext_Sample_Clock,
  543. ReadingContext_Sample_Periodic ,
  544. ReadingContext_Transaction_Begin ,
  545. ReadingContext_Transaction_End,
  546. ReadingContext_Trigger
  547. } ReadingContext;
  548. static char * ReadingContextStr[] = {
  549. MACROSTR(Interruption.Begin),
  550. MACROSTR(Interruption.End),
  551. MACROSTR(Other),
  552. MACROSTR(Sample.Clock),
  553. MACROSTR(Sample.Periodic),
  554. MACROSTR(Transaction.Begin),
  555. MACROSTR(Transaction.End),
  556. MACROSTR(Trigger)
  557. };
  558. /*ValueFormat*/
  559. typedef enum {
  560. Raw,
  561. SignedData
  562. } ValueFormat;
  563. static char * ValueFormatStr[] = {
  564. MACROSTR(Raw),
  565. MACROSTR(SignedData)
  566. };
  567. /*Measurand*/
  568. typedef enum {
  569. Current_Export ,
  570. Current_Import,
  571. Current_Offered,
  572. Energy_Active_Export_Register,
  573. Energy_Active_Import_Register,
  574. Energy_Reactive_Export_Register,
  575. Energy_Reactive_Import_Register,
  576. Energy_Active_Export_Interval,
  577. Energy_Active_Import_Interval,
  578. Energy_Reactive_Export_Interval,
  579. Energy_Reactive_Import_Interval,
  580. Frequency,
  581. Power_Active_Export ,
  582. Power_Active_Import,
  583. Power_Factor,
  584. Power_Offered,
  585. Power_Reactive_Export,
  586. Power_Reactive_Import,
  587. RPM,
  588. SoC,
  589. Temperature ,
  590. Voltage
  591. } Measurand;
  592. static char * MeasurandStr[] = {
  593. MACROSTR(Current.Export),
  594. MACROSTR(Current.Import),
  595. MACROSTR(Current.Offered),
  596. MACROSTR(Energy.Active.Export.Register),
  597. MACROSTR(Energy.Active.Import.Register),
  598. MACROSTR(Energy.Reactive.Export.Register),
  599. MACROSTR(Energy.Reactive.Import.Register),
  600. MACROSTR(Energy.Active.Export.Interval),
  601. MACROSTR(Energy.Active.Import.Interval),
  602. MACROSTR(Energy.Reactive.Export.Interval),
  603. MACROSTR(Energy.Reactive.Import.Interval),
  604. MACROSTR(Frequency),
  605. MACROSTR(Power.Active.Export),
  606. MACROSTR(Power.Active.Import),
  607. MACROSTR(Power.Factor),
  608. MACROSTR(Power.Offered),
  609. MACROSTR(Power.Reactive.ExportMACROSTR),
  610. MACROSTR(Power.Reactive.Import),
  611. MACROSTR(RPM),
  612. MACROSTR(SoC),
  613. MACROSTR(Temperature),
  614. MACROSTR(Voltage)
  615. };
  616. /*Location*/
  617. typedef enum {
  618. Location_Body,
  619. Location_Cable,
  620. Location_EV,
  621. Location_Inlet ,
  622. Location_Outlet
  623. } Location;
  624. static char * LocationStr[] = {
  625. MACROSTR(Body),
  626. MACROSTR(Cable),
  627. MACROSTR(EV),
  628. MACROSTR(Inlet),
  629. MACROSTR(Outlet)
  630. };
  631. /*Phase*/
  632. typedef enum {
  633. L1,
  634. L2,
  635. L3,
  636. N,
  637. L1_N,
  638. L2_N,
  639. L3_N,
  640. L1_L2,
  641. L2_L3,
  642. L3_L1
  643. } Phase;
  644. static char * PhaseStr[] = {
  645. MACROSTR(L1),
  646. MACROSTR(L2),
  647. MACROSTR(L3),
  648. MACROSTR(N),
  649. MACROSTR(L1-N),
  650. MACROSTR(L2-N),
  651. MACROSTR(L3-N),
  652. MACROSTR(L1-L2),
  653. MACROSTR(L2-L3),
  654. MACROSTR(L3-L1)
  655. };
  656. /*UnitOfMeasure*/
  657. typedef enum {
  658. UnitOfMeasure_Wh,
  659. UnitOfMeasure_kWh ,
  660. UnitOfMeasure_varh ,
  661. UnitOfMeasure_kvarh ,
  662. UnitOfMeasure_W ,
  663. UnitOfMeasure_kW ,
  664. UnitOfMeasure_VA ,
  665. UnitOfMeasure_kVA ,
  666. UnitOfMeasure_var ,
  667. UnitOfMeasure_kvar ,
  668. UnitOfMeasure_A ,
  669. UnitOfMeasure_V ,
  670. UnitOfMeasure_Celsius ,
  671. UnitOfMeasure_Fahrenheit ,
  672. UnitOfMeasure_K ,
  673. UnitOfMeasure_Percent
  674. } UnitOfMeasure;
  675. static char * UnitOfMeasureStr[] = {
  676. MACROSTR(Wh),
  677. MACROSTR(kWh),
  678. MACROSTR(varh),
  679. MACROSTR(kvarh),
  680. MACROSTR(W),
  681. MACROSTR(kW),
  682. MACROSTR(VA),
  683. MACROSTR(kVA),
  684. MACROSTR(var),
  685. MACROSTR(kvar),
  686. MACROSTR(A),
  687. MACROSTR(V),
  688. MACROSTR(Celsius),
  689. MACROSTR(Fahrenheit),
  690. MACROSTR(K),
  691. MACROSTR(Percent)
  692. };
  693. #if 0
  694. /*Configuration enum*/
  695. enum CoreProfile {
  696. AllowOfflineTxForUnknownId=0,
  697. AuthorizationCacheEnabled,
  698. AuthorizeRemoteTxRequests,
  699. BlinkRepeat,
  700. ClockAlignedDataInterval,
  701. ConnectionTimeOut,
  702. GetConfigurationMaxKeys,
  703. HeartbeatInterval,
  704. LightIntensity,
  705. LocalAuthorizeOffline,
  706. LocalPreAuthorize,
  707. MaxEnergyOnInvalidId,
  708. MeterValuesAlignedData,
  709. MeterValuesAlignedDataMaxLength,
  710. MeterValuesSampledData,
  711. MeterValuesSampledDataMaxLength,
  712. MeterValueSampleInterval,
  713. MinimumStatusDuration,
  714. NumberOfConnectors,
  715. ResetRetries,
  716. ConnectorPhaseRotation,
  717. ConnectorPhaseRotationMaxLength,
  718. StopTransactionOnEVSideDisconnect,
  719. StopTransactionOnInvalidId,
  720. StopTxnAlignedData,
  721. StopTxnAlignedDataMaxLength,
  722. StopTxnSampledData,
  723. StopTxnSampledDataMaxLength,
  724. SupportedFeatureProfiles,
  725. SupportedFeatureProfilesMaxLength,
  726. TransactionMessageAttempts,
  727. TransactionMessageRetryInterval,
  728. UnlockConnectorOnEVSideDisconnect,
  729. WebSocketPingInterval,
  730. _CoreProfile_CNT
  731. };
  732. #endif
  733. enum LocalAuthListManagementProfile{
  734. LocalAuthListEnabled=0,
  735. LocalAuthListMaxLength,
  736. SendLocalListMaxLength,
  737. _LocalAuthListManagementProfile_CNT
  738. };
  739. enum ReservationProfile{
  740. ReserveConnectorZeroSupported
  741. };
  742. enum SmartChargingProfile{
  743. ChargeProfileMaxStackLevel,
  744. ChargingScheduleAllowedChargingRateUnit,
  745. ChargingScheduleMaxPeriods,
  746. ConnectorSwitch3to1PhaseSupported,
  747. MaxChargingProfilesInstalled
  748. };
  749. enum ChargerSystemStatus{
  750. ChargerSystemStatus_Booting,
  751. ChargerSystemStatus_Idle,
  752. ChargerSystemStatus_Authorizing,
  753. ChargerSystemStatus_Preparing,
  754. ChargerSystemStatus_Charging,
  755. ChargerSystemStatus_Terminating,
  756. ChargerSystemStatus_Alarm,
  757. ChargerSystemStatus_Fault
  758. };
  759. enum GetConfigurationKey {
  760. GetConfiguration_AllowOfflineTxForUnknownId=0,
  761. GetConfiguration_AuthorizationCacheEnabled,
  762. GetConfiguration_AuthorizeRemoteTxRequests,
  763. GetConfiguration_BlinkRepeat,
  764. GetConfiguration_ClockAlignedDataInterval,
  765. GetConfiguration_ConnectionTimeOut,
  766. GetConfiguration_GetConfigurationMaxKeys,
  767. GetConfiguration_HeartbeatInterval,
  768. GetConfiguration_LightIntensity,
  769. GetConfiguration_LocalAuthorizeOffline,
  770. GetConfiguration_LocalPreAuthorize,
  771. GetConfiguration_MaxEnergyOnInvalidId,
  772. GetConfiguration_MeterValuesAlignedData,
  773. GetConfiguration_MeterValuesAlignedDataMaxLength,
  774. GetConfiguration_MeterValuesSampledData,
  775. GetConfiguration_MeterValuesSampledDataMaxLength,
  776. GetConfiguration_MeterValueSampleInterval,
  777. GetConfiguration_MinimumStatusDuration,
  778. GetConfiguration_NumberOfConnectors,
  779. GetConfiguration_ResetRetries,
  780. GetConfiguration_ConnectorPhaseRotation,
  781. GetConfiguration_ConnectorPhaseRotationMaxLength,
  782. GetConfiguration_StopTransactionOnEVSideDisconnect,
  783. GetConfiguration_StopTransactionOnInvalidId,
  784. GetConfiguration_StopTxnAlignedData,
  785. GetConfiguration_StopTxnAlignedDataMaxLength,
  786. GetConfiguration_StopTxnSampledData,
  787. GetConfiguration_StopTxnSampledDataMaxLength,
  788. GetConfiguration_SupportedFeatureProfiles,
  789. GetConfiguration_SupportedFeatureProfilesMaxLength,
  790. GetConfiguration_TransactionMessageAttempts,
  791. GetConfiguration_TransactionMessageRetryInterval,
  792. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  793. GetConfiguration_WebSocketPingInterval,
  794. GetConfiguration_LocalAuthListEnabled,
  795. GetConfiguration_LocalAuthListMaxLength,
  796. GetConfiguration_SendLocalListMaxLength,
  797. GetConfiguration_ReserveConnectorZeroSupported,
  798. GetConfiguration_ChargeProfileMaxStackLevel,
  799. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  800. GetConfiguration_ChargingScheduleMaxPeriods,
  801. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  802. GetConfiguration_MaxChargingProfilesInstalled,
  803. };
  804. //GetConfiguration Array
  805. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  806. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  807. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  808. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  809. //==========================================
  810. // Init all share memory
  811. //==========================================
  812. int InitShareMemory()
  813. {
  814. int result = PASS;
  815. int MeterSMId;
  816. //creat ShmSysConfigAndInfo
  817. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  818. {
  819. #ifdef SystemLogMessage
  820. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  821. #endif
  822. result = FAIL;
  823. }
  824. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  825. {
  826. #ifdef SystemLogMessage
  827. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  828. #endif
  829. result = FAIL;
  830. }
  831. else
  832. {}
  833. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  834. {
  835. #ifdef SystemLogMessage
  836. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  837. #endif
  838. result = FAIL;
  839. }
  840. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  841. {
  842. #ifdef SystemLogMessage
  843. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  844. #endif
  845. result = FAIL;
  846. }
  847. else
  848. {}
  849. //creat ShmPsuData
  850. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmget ShmPsuData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  858. {
  859. #ifdef SystemLogMessage
  860. DEBUG_ERROR("shmat ShmPsuData NG\n");
  861. #endif
  862. result = FAIL;
  863. }
  864. else
  865. {}
  866. //creat ShmOCPP16Data
  867. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  871. #endif
  872. result = FAIL;
  873. }
  874. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  875. {
  876. #ifdef SystemLogMessage
  877. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  878. #endif
  879. result = FAIL;
  880. }
  881. else
  882. {}
  883. /****************************** For Initial Settings************************************************/
  884. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  885. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  886. {
  887. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  888. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  889. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  890. }
  891. // Charger PRE_SYS_MODE
  892. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  893. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  894. clientTime.Heartbeat=time((time_t*)NULL);
  895. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  896. {
  897. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  898. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  899. }
  900. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  901. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  902. // allocate Configuration memory address
  903. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  904. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  905. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  908. {
  909. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  910. DEBUG_INFO("DC ...\n");
  911. }
  912. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  913. {
  914. SystemInitial = AC_QUANTITY;
  915. DEBUG_INFO("AC ...\n");
  916. }
  917. //Status Setting
  918. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  919. {
  920. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  921. }
  922. for (int index = 0; index < CCS_QUANTITY; index++)
  923. {
  924. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  925. }
  926. for (int index = 0; index < GB_QUANTITY; index++)
  927. {
  928. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  929. }
  930. for (int index = 0; index < AC_QUANTITY; index++)
  931. {
  932. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  933. }
  934. return result;
  935. }
  936. int ProcessShareMemory()
  937. {
  938. if(InitShareMemory() == FAIL)
  939. {
  940. #ifdef SystemLogMessage
  941. DEBUG_ERROR("InitShareMemory NG\n");
  942. #endif
  943. if(ShmStatusCodeData!=NULL)
  944. {
  945. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  946. }
  947. sleep(5);
  948. return FAIL;
  949. }
  950. return PASS;
  951. }
  952. //---------------------------------------------
  953. // new:
  954. // enum SYSTEM_STATUS
  955. // {
  956. // SYS_MODE_BOOTING = 0,
  957. // SYS_MODE_IDLE = 1,
  958. // SYS_MODE_AUTHORIZING = 2,
  959. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  960. // SYS_MODE_REASSIGN = 4,
  961. // SYS_MODE_PREPARING = 5,
  962. // SYS_MODE_PREPARE_FOR_EV = 6,
  963. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  964. // SYS_MODE_CHARGING = 8,
  965. // SYS_MODE_TERMINATING = 9,
  966. // SYS_MODE_COMPLETE = 10,
  967. // SYS_MODE_ALARM = 11,
  968. // SYS_MODE_FAULT = 12,
  969. // SYS_MODE_RESERVATION = 13,
  970. // SYS_MODE_BOOKING = 14,
  971. // SYS_MODE_MAINTAIN = 15,
  972. // SYS_MODE_DEBUG = 16,
  973. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  974. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  975. // SYS_MODE_UPDATE = 19
  976. // };
  977. //
  978. //
  979. //-----------------------------------------
  980. void CheckSystemValue(void)
  981. {
  982. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  983. int IdleModeCnt = 0;
  984. char filenmae[100]={0};
  985. char str[100]={0};
  986. //===============================
  987. // send Heartbeat
  988. //===============================
  989. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  990. {
  991. printf("Heartbeat !!!\n");
  992. //parameter for test
  993. sendHeartbeatRequest(0);
  994. //==============================================
  995. // Reset Waiting Time
  996. //==============================================
  997. clientTime.Heartbeat=time((time_t*)NULL);
  998. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  999. }
  1000. //==============================================
  1001. // Update firmware request
  1002. //==============================================
  1003. if(isUpdateRequest == TRUE )
  1004. {
  1005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1006. {
  1007. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1008. {
  1009. //check SystemStatus
  1010. /*************************DC*******************************/
  1011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1012. {
  1013. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1014. {
  1015. IdleModeCnt = IdleModeCnt + 1;
  1016. }
  1017. }
  1018. for (int index = 0; index < CCS_QUANTITY; index++)
  1019. {
  1020. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1021. {
  1022. IdleModeCnt = IdleModeCnt + 1;
  1023. }
  1024. }
  1025. for (int index = 0; index < GB_QUANTITY; index++)
  1026. {
  1027. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1028. {
  1029. IdleModeCnt = IdleModeCnt + 1;
  1030. }
  1031. }
  1032. }
  1033. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1034. {
  1035. isUpdateRequest = FALSE;
  1036. }
  1037. }
  1038. else
  1039. {
  1040. /*************************AC*******************************/
  1041. for (int index = 0; index < AC_QUANTITY; index++)
  1042. {
  1043. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1044. {
  1045. IdleModeCnt = IdleModeCnt + 1;
  1046. }
  1047. }
  1048. if(IdleModeCnt == AC_QUANTITY)
  1049. {
  1050. isUpdateRequest = FALSE;
  1051. }
  1052. }
  1053. }
  1054. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1055. {
  1056. //===============================
  1057. // CSU Trigger Reset Conf
  1058. //===============================
  1059. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1060. {
  1061. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1062. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1063. {
  1064. server_sign = FALSE;
  1065. }
  1066. }
  1067. //===============================
  1068. // CSU Trigger Authorize Request
  1069. //===============================
  1070. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1071. {
  1072. //if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1073. //{
  1074. sendAuthorizeRequest(0);
  1075. authorizeRetryTimes = authorizeRetryTimes + 1;
  1076. // authenrequest = TRUE
  1077. if(authorizeRetryTimes < 3)
  1078. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1079. //}
  1080. }
  1081. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1082. {
  1083. authorizeRetryTimes = 0;
  1084. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1085. server_sign = FALSE;
  1086. }
  1087. else if((server_sign == FALSE) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  1088. {
  1089. sendAuthorizeRequest(0);
  1090. }
  1091. //===============================
  1092. // CSU Trigger Smart Charging Profilw
  1093. //===============================
  1094. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1095. {
  1096. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1097. GetChargingProfileRequest(gun_index);
  1098. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1099. }
  1100. //==============================================
  1101. // Charger start transaction
  1102. //==============================================
  1103. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1104. {
  1105. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1106. sendStartTransactionRequest(gun_index);
  1107. clientTime.StartTransaction = time((time_t*)NULL);
  1108. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1109. }
  1110. //==============================================
  1111. // Charger stop transaction
  1112. //==============================================
  1113. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1114. {
  1115. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1116. sendStopTransactionRequest(gun_index);
  1117. clientTime.StopTransaction = time((time_t*)NULL);
  1118. }
  1119. //==============================================
  1120. // Charger status report
  1121. //==============================================
  1122. /* Check Mode Change */
  1123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1124. {
  1125. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1126. {
  1127. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1128. {
  1129. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1130. {
  1131. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1132. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1133. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1134. statusModeChage[gun_index] = TRUE;
  1135. }
  1136. }
  1137. }
  1138. for (int index = 0; index < CCS_QUANTITY; index++)
  1139. {
  1140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1141. {
  1142. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1143. {
  1144. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1145. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1146. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1147. statusModeChage[gun_index] = TRUE;
  1148. }
  1149. }
  1150. }
  1151. for (int index = 0; index < GB_QUANTITY; index++)
  1152. {
  1153. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1154. {
  1155. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1156. {
  1157. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1158. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. else //AC
  1166. {
  1167. for (int index = 0; index < AC_QUANTITY; index++)
  1168. {
  1169. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1170. {
  1171. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1172. {
  1173. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1174. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1175. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1176. statusModeChage[gun_index] = TRUE;
  1177. }
  1178. }
  1179. }// END OF FOR
  1180. }// END OF ELSE
  1181. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1182. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1183. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1184. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1185. {
  1186. if(SystemInitial != 0)
  1187. SystemInitial = SystemInitial -1;
  1188. sendStatusNotificationRequest(gun_index);
  1189. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1190. statusModeChage[gun_index] = FALSE;
  1191. }
  1192. //==============================================
  1193. // Meter report
  1194. //==============================================
  1195. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1196. {
  1197. //check Transaction active
  1198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1199. {
  1200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1201. {
  1202. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1203. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1204. {
  1205. meterValueSend[gun_index] =1;
  1206. }
  1207. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1208. {
  1209. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1210. if((access(filenmae,F_OK))!=-1)
  1211. {
  1212. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1213. sprintf(str,"rm -f %s",filenmae);
  1214. system(str);
  1215. }
  1216. }
  1217. }// End for CHAdeMO
  1218. for (int index = 0; index < CCS_QUANTITY; index++)
  1219. {
  1220. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1221. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1222. {
  1223. meterValueSend[gun_index] =1;
  1224. }
  1225. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1226. {
  1227. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1228. if((access(filenmae,F_OK))!=-1)
  1229. {
  1230. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1231. sprintf(str,"rm -f %s",filenmae);
  1232. system(str);
  1233. }
  1234. }
  1235. } // End for CCS
  1236. for (int index = 0; index < GB_QUANTITY; index++)
  1237. {
  1238. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1239. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1240. {
  1241. meterValueSend[gun_index] =1;
  1242. }
  1243. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1244. {
  1245. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1246. if((access(filenmae,F_OK))!=-1)
  1247. {
  1248. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1249. sprintf(str,"rm -f %s",filenmae);
  1250. system(str);
  1251. }
  1252. }
  1253. }// End for GB
  1254. }
  1255. else
  1256. {
  1257. for (int index = 0; index < AC_QUANTITY; index++)
  1258. {
  1259. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1260. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1261. {
  1262. meterValueSend[gun_index] =1;
  1263. }
  1264. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1265. {
  1266. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1267. if((access(filenmae,F_OK))!=-1)
  1268. {
  1269. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1270. sprintf(str,"rm -f %s",filenmae);
  1271. system(str);
  1272. }
  1273. }
  1274. }//End for AC
  1275. }//END OF ELSE
  1276. // sleep(1);
  1277. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1278. if(meterValueSend[gun_index] == 1)
  1279. sendMeterValuesRequest(gun_index);
  1280. }
  1281. //==============================================
  1282. // Check Connector reserved
  1283. //==============================================
  1284. //===============================
  1285. // Check if Reserve is expired
  1286. //===============================
  1287. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1288. {
  1289. double diff_t;
  1290. struct tm tp;
  1291. // current time
  1292. time_t t = time(NULL);
  1293. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1294. tp.tm_isdst = -1;
  1295. time_t utc = mktime(&tp);
  1296. diff_t = difftime(utc, t);
  1297. if(diff_t <= 0)
  1298. {
  1299. DEBUG_INFO("reserve expired !!! \n");
  1300. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1301. }
  1302. }//END OF Check if Reserve is expired
  1303. //==========================================
  1304. // csu trigger FirmwareStatusNotificationReq
  1305. //==========================================
  1306. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1307. {
  1308. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1309. }
  1310. //==========================================
  1311. // csu trigger CancelReservationConf
  1312. //==========================================
  1313. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1314. {
  1315. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1316. }
  1317. //==========================================
  1318. // csu trigger ChangeAvailabilityConf
  1319. //==========================================
  1320. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1321. {
  1322. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1323. }
  1324. //==========================================
  1325. // csu trigger UnlockConnectorConf
  1326. //==========================================
  1327. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1328. {
  1329. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1330. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1331. }
  1332. //==========================================
  1333. // csu trigger ReserveNowConf
  1334. //==========================================
  1335. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1336. {
  1337. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1338. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1339. }
  1340. //==========================================
  1341. // csu trigger DataTransferReq
  1342. //==========================================
  1343. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1344. {
  1345. sendDataTransferRequest(gun_index);
  1346. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1347. }
  1348. }
  1349. }
  1350. //==========================================
  1351. // send request routine
  1352. //==========================================
  1353. int sendAuthorizeRequest(int gun_index)
  1354. {
  1355. mtrace();
  1356. int result = FAIL;
  1357. char message[100]={0};
  1358. char guid[37];
  1359. char tempdata[65]={0};
  1360. DEBUG_INFO("sendAuthorizeRequest \n");
  1361. //Local Authorize
  1362. if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1363. {
  1364. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1365. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1366. {
  1367. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1368. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1369. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1370. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1371. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1372. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1373. authorizeRetryTimes = 0;
  1374. return result;
  1375. }
  1376. else
  1377. {
  1378. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1379. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1380. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1381. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1382. result = PASS;
  1383. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1384. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1385. authorizeRetryTimes = 0;
  1386. return result;
  1387. }
  1388. }
  1389. //initailize struct Authorize
  1390. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1391. //get data from shared memory
  1392. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1393. random_uuid(guid);
  1394. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1395. LWS_Send(message);
  1396. sprintf(tempdata, "Authorize,%d", gun_index);
  1397. if(hashmap_operation(0, guid, tempdata) == 1)
  1398. {
  1399. result = PASS;
  1400. DEBUG_ERROR("Authorize mapItem pass\n");
  1401. }
  1402. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1403. return result;
  1404. }
  1405. int sendBootNotificationRequest(void)
  1406. {
  1407. mtrace();
  1408. int result = FAIL;
  1409. char message[500]={0}, payload[700]={0};
  1410. char guid[37]={0};
  1411. char tempdata[65]={0};
  1412. int IsGunCharging = FALSE;
  1413. //check Transaction active
  1414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1415. {
  1416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1417. {
  1418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1419. {
  1420. IsGunCharging = TRUE;
  1421. }
  1422. }
  1423. for (int index = 0; index < CCS_QUANTITY; index++)
  1424. {
  1425. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1426. {
  1427. IsGunCharging = TRUE;
  1428. }
  1429. }
  1430. for (int index = 0; index < GB_QUANTITY; index++)
  1431. {
  1432. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1433. {
  1434. IsGunCharging = TRUE;
  1435. }
  1436. }
  1437. }
  1438. else
  1439. {
  1440. for (int index = 0; index < AC_QUANTITY; index++)
  1441. {
  1442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1443. {
  1444. IsGunCharging = TRUE;
  1445. }
  1446. }
  1447. }
  1448. if(IsGunCharging == TRUE)
  1449. {
  1450. server_sign = TRUE;
  1451. return result;
  1452. }
  1453. // Fill BootNotification fields
  1454. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1455. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1456. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1457. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1458. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1459. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1460. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1461. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1462. ShmOCPP16Data->ChargeBoxId
  1463. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1464. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1465. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1466. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1467. ,ShmOCPP16Data->BootNotification.CpIccid
  1468. ,ShmOCPP16Data->BootNotification.CpImsi
  1469. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1470. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1471. random_uuid(guid);
  1472. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1473. LWS_Send(message);
  1474. sprintf(tempdata, "BootNotification,0");
  1475. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1476. {
  1477. result = PASS;
  1478. }
  1479. memset(queuedata, 0, sizeof(queuedata));
  1480. strcpy(queuedata,message);
  1481. HeartBeatCount = 0;
  1482. return result;
  1483. }
  1484. int sendDataTransferRequest(int gun_index)
  1485. {
  1486. mtrace();
  1487. char message[1000]={0};
  1488. char guid[37]={0};
  1489. char tempdata[65]={0};
  1490. int result = FAIL;
  1491. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1492. random_uuid(guid);
  1493. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1494. MESSAGE_TYPE_CALL,
  1495. guid,
  1496. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1497. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1498. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1499. LWS_Send(message);
  1500. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1501. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1502. {
  1503. result = PASS;
  1504. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1505. }
  1506. return result;
  1507. }
  1508. int sendDiagnosticsStatusNotificationRequest(char *status)
  1509. {
  1510. mtrace();
  1511. int result = FAIL;
  1512. char message[110]={0};
  1513. char guid[37]={0};
  1514. char tempdata[65]={0};
  1515. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1516. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1517. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1518. random_uuid(guid);
  1519. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1520. LWS_Send(message);
  1521. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1522. if(hashmap_operation(0, guid, tempdata) == 1)
  1523. {
  1524. result = PASS;
  1525. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1526. }
  1527. //#ifdef SystemLogMessage
  1528. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1529. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1530. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1531. //#endif
  1532. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1533. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1534. //record status
  1535. if(strcmp(status,"Idle")==0)
  1536. {
  1537. DiagnosticsStatusNotificationStatus = 0;
  1538. }
  1539. else if(strcmp(status,"Uploaded")==0)
  1540. {
  1541. DiagnosticsStatusNotificationStatus = 1;
  1542. }
  1543. else if(strcmp(status,"UploadFailed")==0)
  1544. {
  1545. DiagnosticsStatusNotificationStatus = 2;
  1546. }
  1547. else if(strcmp(status,"Uploading")==0)
  1548. {
  1549. DiagnosticsStatusNotificationStatus = 3;
  1550. }
  1551. return result;
  1552. }
  1553. int sendFirmwareStatusNotificationRequest(char *status)
  1554. {
  1555. mtrace();
  1556. int result = FAIL;
  1557. char message[110]={0};
  1558. char guid[37]={0};
  1559. char tempdata[65]={0};
  1560. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1561. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1562. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1563. random_uuid(guid);
  1564. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1565. LWS_Send(message);
  1566. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1567. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1568. {
  1569. result = PASS;
  1570. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1571. }
  1572. //#ifdef SystemLogMessage
  1573. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1574. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1575. //#endif
  1576. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1577. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1578. //record status
  1579. if(strcmp(status,"Downloaded")==0)
  1580. {
  1581. FirmwareStatusNotificationStatus = 0;
  1582. }
  1583. else if(strcmp(status,"DownloadFailed")==0)
  1584. {
  1585. FirmwareStatusNotificationStatus = 1;
  1586. }
  1587. else if(strcmp(status,"Downloading")==0)
  1588. {
  1589. FirmwareStatusNotificationStatus = 2;
  1590. }
  1591. else if(strcmp(status,"Idle")==0)
  1592. {
  1593. FirmwareStatusNotificationStatus = 3;
  1594. }
  1595. else if(strcmp(status,"InstallationFailed")==0)
  1596. {
  1597. FirmwareStatusNotificationStatus = 4;
  1598. }
  1599. else if(strcmp(status,"Installing")==0)
  1600. {
  1601. FirmwareStatusNotificationStatus = 5;
  1602. }
  1603. else if(strcmp(status,"Installed")==0)
  1604. {
  1605. FirmwareStatusNotificationStatus = 6;
  1606. }
  1607. return result;
  1608. }
  1609. int sendHeartbeatRequest(int gun_index)
  1610. {
  1611. mtrace();
  1612. int result = FAIL;
  1613. char message[80]={0};
  1614. char guid[37]={0};
  1615. char tempdata[65]={0};
  1616. random_uuid(guid);
  1617. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1618. , MESSAGE_TYPE_CALL
  1619. , guid );
  1620. LWS_Send(message);
  1621. sprintf(tempdata, "Heartbeat,%d", 0);
  1622. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1623. {
  1624. result = PASS;
  1625. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1626. }
  1627. return result;
  1628. }
  1629. int sendStartTransactionRequest(int gun_index)
  1630. {
  1631. mtrace();
  1632. int result = FAIL;
  1633. char message[250]={0};
  1634. char guid[37]={0};
  1635. struct timeval tmnow;
  1636. struct tm *tm;
  1637. char buf[28];//, usec_buf[6];
  1638. char tempdata[65]={0};
  1639. DEBUG_INFO("sendStartTransactionRequest...");
  1640. gettimeofday(&tmnow, NULL);
  1641. time_t t;
  1642. t = time(NULL);
  1643. /*UTC time and date*/
  1644. tm = gmtime(&t);
  1645. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1646. #if 0 // remove temporally
  1647. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1648. strcat(buf,".");
  1649. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1650. strcat(buf,usec_buf);
  1651. #endif
  1652. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1653. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1654. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1656. {
  1657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1658. {
  1659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1660. {
  1661. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1662. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1663. }
  1664. }
  1665. for (int index = 0; index < CCS_QUANTITY; index++)
  1666. {
  1667. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1668. {
  1669. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1670. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1671. }
  1672. }
  1673. for (int index = 0; index < GB_QUANTITY; index++)
  1674. {
  1675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1676. {
  1677. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1678. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1679. }
  1680. }
  1681. }
  1682. else
  1683. {
  1684. for (int index = 0; index < AC_QUANTITY; index++)
  1685. {
  1686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1687. {
  1688. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1689. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1690. }
  1691. }
  1692. }//END OF ELSE
  1693. random_uuid(guid);
  1694. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1695. , MESSAGE_TYPE_CALL
  1696. , guid
  1697. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1698. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1699. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1700. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1701. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1702. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1703. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1704. {
  1705. result = PASS;
  1706. }
  1707. strcpy(queuedata, message);
  1708. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1709. LWS_Send(message);
  1710. #if 0
  1711. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1712. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1713. {
  1714. result = PASS;
  1715. }
  1716. strcpy(queuedata, message);
  1717. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1718. #endif
  1719. //#ifdef SystemLogMessage
  1720. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1721. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1722. //#endif
  1723. return result;
  1724. }
  1725. int sendStatusNotificationRequest(int gun_index)
  1726. {
  1727. mtrace();
  1728. int result = FAIL;
  1729. char message[600]={0};
  1730. char guid[37];
  1731. int currentStatus = 0;
  1732. struct timeval tmnow;
  1733. struct tm *tm;
  1734. char buf[28];//, usec_buf[6];
  1735. char tempdata[65]={0};
  1736. gettimeofday(&tmnow, NULL);
  1737. time_t t;
  1738. t = time(NULL);
  1739. /*UTC time and date*/
  1740. tm = gmtime(&t);
  1741. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1742. #if 0 // remove temporally
  1743. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1744. strcat(buf,".");
  1745. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1746. strcat(buf,usec_buf);
  1747. #endif
  1748. printf("%s",buf);
  1749. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1750. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1751. // it's option
  1752. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1753. /*
  1754. enum _SYSTEM_STATUS
  1755. {
  1756. S_BOOTING = 0,
  1757. S_IDLE, = 1
  1758. S_AUTHORIZING, =2
  1759. S_REASSIGN_CHECK, =3
  1760. S_REASSIGN, =4
  1761. S_PRECHARGE, =5
  1762. S_PREPARING_FOR_EV, =6
  1763. S_PREPARING_FOR_EVSE, =7
  1764. S_CHARGING, =8
  1765. S_TERMINATING, =9
  1766. S_COMPLETE, =10
  1767. S_ALARM, =11
  1768. S_FAULT =12
  1769. }
  1770. */
  1771. //check Transaction active
  1772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1773. {
  1774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1775. {
  1776. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1777. {
  1778. currentStatus = 0; //OCPP Status: Available
  1779. }
  1780. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1781. {
  1782. currentStatus = 1; //OCPP Status: Preparing
  1783. }
  1784. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1785. {
  1786. currentStatus = 2; //OCPP Status: Charging
  1787. }
  1788. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1789. {
  1790. currentStatus = 5; //OCPP Status: Finishing
  1791. }
  1792. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1793. {
  1794. currentStatus = 4; //OCPP Status: SuspendedEV
  1795. }
  1796. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) // ---> Unavailable
  1797. {
  1798. currentStatus = 7; //OCPP Status: Unavailable
  1799. }
  1800. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1801. {
  1802. currentStatus = 8; //OCPP Status: Faulted
  1803. }
  1804. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1805. {
  1806. currentStatus = 6; //OCPP Status: Reserved
  1807. }
  1808. }//end of for CHAdeMO_QUANTITY
  1809. for (int index = 0; index < CCS_QUANTITY; index++)
  1810. {
  1811. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1812. {
  1813. currentStatus = 0; //OCPP Status: Available
  1814. }
  1815. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1816. {
  1817. currentStatus = 1; //OCPP Status: Preparing
  1818. }
  1819. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1820. {
  1821. currentStatus = 2; //OCPP Status: Charging
  1822. }
  1823. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1824. {
  1825. currentStatus = 5; //OCPP Status: Finishing
  1826. }
  1827. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM ,S_TERMINATING ---> SuspendedEV
  1828. {
  1829. currentStatus = 4; //OCPP Status: SuspendedEV
  1830. }
  1831. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1832. {
  1833. currentStatus = 7; //OCPP Status : Unavailable
  1834. }
  1835. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1836. {
  1837. currentStatus = 8; //OCPP Status: Faulted
  1838. }
  1839. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1840. {
  1841. currentStatus = 6; //OCPP Status: Reserved
  1842. }
  1843. }
  1844. for (int index = 0; index < GB_QUANTITY; index++)
  1845. {
  1846. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1847. {
  1848. currentStatus = 0; //OCPP Status: Available
  1849. }
  1850. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1851. {
  1852. currentStatus = 1; //OCPP Status: Preparing
  1853. }
  1854. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1855. {
  1856. currentStatus = 2; //OCPP Status: Charging
  1857. }
  1858. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1859. {
  1860. currentStatus = 5; //OCPP Status: Finishing
  1861. }
  1862. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM , S_TERMINATING ---> SuspendedEV
  1863. {
  1864. currentStatus = 4; //OCPP Status: SuspendedEV
  1865. }
  1866. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1867. {
  1868. currentStatus = 7; //OCPP Status: Unavailable
  1869. }
  1870. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1871. {
  1872. currentStatus = 8; //OCPP Status: Faulted
  1873. }
  1874. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1875. {
  1876. currentStatus = 6; //OCPP Status: Reserved
  1877. }
  1878. }
  1879. }
  1880. else
  1881. {
  1882. for (int index = 0; index < AC_QUANTITY; index++)
  1883. {
  1884. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1885. {
  1886. currentStatus = 0; //OCPP Status: Available
  1887. }
  1888. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1889. {
  1890. currentStatus = 1; //OCPP Status: Preparing
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1893. {
  1894. currentStatus = 2; //OCPP Status: Charging
  1895. }
  1896. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1897. {
  1898. currentStatus = 5; //OCPP Status: Finishing
  1899. }
  1900. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1901. {
  1902. currentStatus = 4; //OCPP Status: SuspendedEV
  1903. }
  1904. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1905. {
  1906. currentStatus = 7; //OCPP Status: Unavailable
  1907. }
  1908. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1909. {
  1910. currentStatus = 8; //OCPP Status: Faulted
  1911. }
  1912. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1913. {
  1914. currentStatus = 6; //OCPP Status: Reserved
  1915. }
  1916. }//end of for AC_QUANTITY
  1917. }//END OF ELSE
  1918. //it's option
  1919. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1920. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1921. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1922. random_uuid(guid);
  1923. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1924. , MESSAGE_TYPE_CALL
  1925. , guid
  1926. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1927. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1928. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1929. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1930. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1931. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1932. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1933. LWS_Send(message);
  1934. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1935. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1936. {
  1937. //DEBUG_ERROR("statusNotification mapitem pass");
  1938. result = PASS;
  1939. }
  1940. return result;
  1941. }
  1942. int sendStopTransactionRequest(int gun_index)
  1943. {
  1944. mtrace();
  1945. int result = FAIL;
  1946. //char message[1500]={0};
  1947. char guid[37]={0};
  1948. char tempdata[65]={0};
  1949. //int idx_sample=0;
  1950. DEBUG_ERROR("sendStopTransactionRequest \n");
  1951. memset(queuedata, 0, sizeof(queuedata));
  1952. //ENERGY_ACTIVE_IMPORT_REGISTER
  1953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1954. {
  1955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1956. {
  1957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1958. {
  1959. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1960. }
  1961. }// END OF CHAdeMO_QUANTITY
  1962. for (int index = 0; index < CCS_QUANTITY; index++)
  1963. {
  1964. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1965. {
  1966. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1967. }
  1968. }// END OF CCS_QUANTITY
  1969. for (int index = 0; index < GB_QUANTITY; index++)
  1970. {
  1971. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1972. {
  1973. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1974. }
  1975. }// END OF GB_QUANTITY
  1976. }
  1977. else
  1978. {
  1979. for (int index = 0; index < AC_QUANTITY; index++)
  1980. {
  1981. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1982. {
  1983. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1984. }
  1985. }// END OF AC_QUANTITY
  1986. }//END OF ELSE
  1987. //Stop Transaction Time
  1988. struct timeval tmnow;
  1989. struct tm *tm;
  1990. char buf[28];//, usec_buf[6];
  1991. gettimeofday(&tmnow, NULL);
  1992. time_t t;
  1993. t = time(NULL);
  1994. /*UTC time and date*/
  1995. tm = gmtime(&t);
  1996. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  1998. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  1999. random_uuid(guid);
  2000. /***********************************transactionData******************************************************/
  2001. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2003. //=================================
  2004. // Transaction_Begin
  2005. //=================================
  2006. // Energy.Active.Export.Interval
  2007. //idx_sample=0;
  2008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Export_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2013. {
  2014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2015. }
  2016. else
  2017. {
  2018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2019. }
  2020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2022. //=================================
  2023. // Transaction_End
  2024. //=================================
  2025. //Current.Export
  2026. //idx_sample=1;
  2027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2028. {
  2029. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2030. {
  2031. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2032. {
  2033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2034. }
  2035. }
  2036. for (int index = 0; index < CCS_QUANTITY; index++)
  2037. {
  2038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2039. {
  2040. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2041. }
  2042. }
  2043. for (int index = 0; index < GB_QUANTITY; index++)
  2044. {
  2045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2046. {
  2047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2048. }
  2049. }
  2050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2051. }
  2052. else
  2053. {
  2054. for (int index = 0; index < AC_QUANTITY; index++)
  2055. {
  2056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2057. {
  2058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2059. }
  2060. }
  2061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2062. }// END FOR AC ELSE
  2063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2066. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2069. //Energy.Active.Export.Interval
  2070. //idx_sample=2;
  2071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2072. {
  2073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2074. {
  2075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2076. {
  2077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2078. }
  2079. }
  2080. for (int index = 0; index < CCS_QUANTITY; index++)
  2081. {
  2082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2083. {
  2084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2085. }
  2086. }
  2087. for (int index = 0; index < GB_QUANTITY; index++)
  2088. {
  2089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2090. {
  2091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2092. }
  2093. }
  2094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2095. }
  2096. else
  2097. {
  2098. for (int index = 0; index < AC_QUANTITY; index++)
  2099. {
  2100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2101. {
  2102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2103. }
  2104. }
  2105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2106. }// END FOR AC ELSE
  2107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2110. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2113. //Power.Active.Export
  2114. //idx_sample=3;
  2115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2116. {
  2117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2118. {
  2119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2120. {
  2121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2122. }
  2123. }
  2124. for (int index = 0; index < CCS_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2127. {
  2128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2129. }
  2130. }
  2131. for (int index = 0; index < GB_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2134. {
  2135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2136. }
  2137. }
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2139. }
  2140. else
  2141. {
  2142. for (int index = 0; index < AC_QUANTITY; index++)
  2143. {
  2144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2145. {
  2146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2147. }
  2148. }
  2149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2150. }// END FOR AC ELSE
  2151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2154. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2157. //Voltage
  2158. //idx_sample=4;
  2159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2160. {
  2161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2162. {
  2163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2164. {
  2165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2166. }
  2167. }
  2168. for (int index = 0; index < CCS_QUANTITY; index++)
  2169. {
  2170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2171. {
  2172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2173. }
  2174. }
  2175. for (int index = 0; index < GB_QUANTITY; index++)
  2176. {
  2177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2178. {
  2179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2180. }
  2181. }
  2182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2183. }
  2184. else
  2185. {
  2186. for (int index = 0; index < AC_QUANTITY; index++)
  2187. {
  2188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2189. {
  2190. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2191. }
  2192. }
  2193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2194. }// END FOR AC ELSE
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2198. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2201. //SoC
  2202. //idx_sample=5;
  2203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2204. {
  2205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2206. {
  2207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2208. {
  2209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2210. }
  2211. }
  2212. for (int index = 0; index < CCS_QUANTITY; index++)
  2213. {
  2214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2215. {
  2216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2217. }
  2218. }
  2219. for (int index = 0; index < GB_QUANTITY; index++)
  2220. {
  2221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2222. {
  2223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2224. }
  2225. }
  2226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2232. } // END FOR DC CASE
  2233. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2234. {
  2235. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2236. ,MESSAGE_TYPE_CALL
  2237. ,guid
  2238. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2239. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2240. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2241. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2242. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2243. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2244. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2245. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2246. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2248. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2249. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2257. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2258. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2259. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2260. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2261. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2262. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2263. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2264. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2265. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2266. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2268. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2269. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2286. );
  2287. }
  2288. else
  2289. {
  2290. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2291. ,MESSAGE_TYPE_CALL
  2292. ,guid
  2293. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2294. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2295. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2298. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2334. );
  2335. }
  2336. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2337. if(hashmap_operation(0, guid, tempdata) == 1)
  2338. {
  2339. result = PASS;
  2340. DEBUG_INFO("StopTransaction mapitem pass\n");
  2341. }
  2342. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2343. LWS_Send(queuedata);
  2344. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2345. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2346. {
  2347. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2348. }
  2349. #if 0
  2350. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2351. if(hashmap_operation(0, guid, tempdata) == 1)
  2352. {
  2353. result = PASS;
  2354. DEBUG_INFO("StopTransaction mapitem pass\n");
  2355. }
  2356. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2357. #endif
  2358. //for test
  2359. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2360. return result;
  2361. }
  2362. int sendMeterValuesRequest(int gun_index)
  2363. {
  2364. mtrace();
  2365. int result = FAIL;
  2366. // char message[1500]={0};
  2367. char guid[37]={0};
  2368. //int idx_sample=0;
  2369. //int length = 0;
  2370. char tempdata[65]={0};
  2371. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2372. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2373. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2374. {
  2375. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2376. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2377. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2378. return result;
  2379. }
  2380. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2381. {
  2382. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2383. }
  2384. memset(queuedata, 0, sizeof(queuedata));
  2385. //set value
  2386. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2387. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2388. random_uuid(guid);
  2389. //UTC Date time
  2390. struct timeval tmnow;
  2391. struct tm *tm;
  2392. char buf[28];//, usec_buf[6];
  2393. gettimeofday(&tmnow, NULL);
  2394. time_t t;
  2395. t = time(NULL);
  2396. /*UTC time and date*/
  2397. tm = gmtime(&t);
  2398. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2400. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2401. //idx_sample=0;
  2402. //********************************(1)Current.Export************************************************/
  2403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2404. {
  2405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2406. {
  2407. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2408. {
  2409. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2410. }
  2411. }
  2412. for (int index = 0; index < CCS_QUANTITY; index++)
  2413. {
  2414. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2415. {
  2416. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2417. }
  2418. }
  2419. for (int index = 0; index < GB_QUANTITY; index++)
  2420. {
  2421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2422. {
  2423. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2424. }
  2425. }
  2426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2427. }
  2428. else
  2429. {
  2430. for (int index = 0; index < AC_QUANTITY; index++)
  2431. {
  2432. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2433. {
  2434. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2435. }
  2436. }
  2437. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2438. }// END FOR AC ELSE
  2439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2441. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2442. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2445. //idx_sample=1;
  2446. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2448. {
  2449. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2450. {
  2451. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2452. {
  2453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2454. }
  2455. }
  2456. for (int index = 0; index < CCS_QUANTITY; index++)
  2457. {
  2458. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2459. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2460. {
  2461. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2462. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2463. }
  2464. }
  2465. for (int index = 0; index < GB_QUANTITY; index++)
  2466. {
  2467. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2468. {
  2469. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2470. }
  2471. }
  2472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2473. }
  2474. else
  2475. {
  2476. for (int index = 0; index < AC_QUANTITY; index++)
  2477. {
  2478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2479. {
  2480. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2481. }
  2482. }
  2483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2484. }//END FOR AC ELSE
  2485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2488. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2491. //idx_sample=2;
  2492. //********************************(4)Power.Active.Export************************************************/
  2493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2494. {
  2495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2496. {
  2497. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2498. {
  2499. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2500. }
  2501. }
  2502. for (int index = 0; index < CCS_QUANTITY; index++)
  2503. {
  2504. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2505. {
  2506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2507. }
  2508. }
  2509. for (int index = 0; index < GB_QUANTITY; index++)
  2510. {
  2511. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2512. {
  2513. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2514. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2515. }
  2516. }
  2517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2518. }
  2519. else
  2520. {
  2521. for (int index = 0; index < AC_QUANTITY; index++)
  2522. {
  2523. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2524. {
  2525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2526. }
  2527. }
  2528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2529. }// END FOR AC ELSE
  2530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2533. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2536. //idx_sample=3;
  2537. //***********************************************(5)VOLTAGE******************************************************/
  2538. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2539. {
  2540. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2541. {
  2542. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2543. {
  2544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2545. }
  2546. }
  2547. for (int index = 0; index < CCS_QUANTITY; index++)
  2548. {
  2549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2550. {
  2551. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2552. }
  2553. }
  2554. for (int index = 0; index < GB_QUANTITY; index++)
  2555. {
  2556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2557. {
  2558. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2559. }
  2560. }
  2561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2562. }
  2563. else
  2564. {
  2565. for (int index = 0; index < AC_QUANTITY; index++)
  2566. {
  2567. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2568. {
  2569. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2570. }
  2571. }
  2572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2573. }//END FOR AC ELSE
  2574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2577. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2581. {
  2582. //idx_sample=4;
  2583. //sampledValue = NULL;
  2584. //***********************************************(6)SOC******************************************************/
  2585. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2586. {
  2587. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2588. {
  2589. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2590. }
  2591. }
  2592. for (int index = 0; index < CCS_QUANTITY; index++)
  2593. {
  2594. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2595. {
  2596. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2597. }
  2598. }
  2599. for (int index = 0; index < GB_QUANTITY; index++)
  2600. {
  2601. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2602. {
  2603. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2604. }
  2605. }
  2606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2612. }
  2613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2614. {
  2615. 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\"}]}]}]"
  2616. ,MESSAGE_TYPE_CALL
  2617. ,guid
  2618. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2619. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2620. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2656. );
  2657. }
  2658. else
  2659. {
  2660. 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\"}]}]}]"
  2661. ,MESSAGE_TYPE_CALL
  2662. ,guid
  2663. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2664. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2665. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2694. );
  2695. }
  2696. // Put request guid to hash map
  2697. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2698. 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*/)
  2699. {
  2700. result = PASS;
  2701. DEBUG_INFO("MeterValues mapitem pass\n");
  2702. }
  2703. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2704. LWS_Send(queuedata);
  2705. #if 0
  2706. // Put request guid to hash map
  2707. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2708. 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*/)
  2709. {
  2710. result = PASS;
  2711. DEBUG_INFO("MeterValues mapitem pass\n");
  2712. }
  2713. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2714. #endif
  2715. return result;
  2716. }
  2717. //==========================================
  2718. // send confirm routine
  2719. //==========================================
  2720. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2721. {
  2722. mtrace();
  2723. int result = FAIL;
  2724. char message[100]={0};
  2725. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2726. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2727. LWS_Send(message);
  2728. result = TRUE;
  2729. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2730. return result;
  2731. }
  2732. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2733. {
  2734. mtrace();
  2735. int result = FAIL;
  2736. char message[100]={0};
  2737. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2738. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2739. LWS_Send(message);
  2740. result = TRUE;
  2741. return result;
  2742. }
  2743. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2744. {
  2745. mtrace();
  2746. int result = FAIL;
  2747. char message[100]={0};
  2748. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2749. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2750. LWS_Send(message);
  2751. result = TRUE;
  2752. return result;
  2753. }
  2754. int sendClearCacheConfirmation(char *uuid,char *payload)
  2755. {
  2756. mtrace();
  2757. int result = FAIL;
  2758. char message[500]={0};
  2759. // int count = 0;
  2760. // int gun_index = 0;
  2761. // char guid[37];
  2762. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2763. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2764. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2765. LWS_Send(message);
  2766. return result;
  2767. }
  2768. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2769. {
  2770. mtrace();
  2771. int result = FAIL;
  2772. char message[500]={0};
  2773. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2774. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2775. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2776. LWS_Send(message);
  2777. return result;
  2778. }
  2779. int sendDataTransferConfirmation(char *uuid,char *payload)
  2780. {
  2781. mtrace();
  2782. char statusStr[20]={0};
  2783. char dataStr[10]={0};
  2784. char sstr[20]={0};
  2785. int c = 0;
  2786. char *loc;
  2787. int result = FAIL;
  2788. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2789. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2790. /**********************status**************************/
  2791. loc = strstr(payload, "status");
  2792. memset(sstr ,0, sizeof(sstr) );
  2793. c = 0;
  2794. while (loc[3+strlen("status")+c] != '\"')
  2795. {
  2796. sstr[c] = loc[3+strlen("status")+c];
  2797. c++;
  2798. }
  2799. sstr[c] = '\0';
  2800. strcpy(statusStr, sstr);
  2801. /**********************data**************************/
  2802. loc = strstr(payload, "data");
  2803. memset(sstr ,0, sizeof(sstr) );
  2804. c = 0;
  2805. while (loc[3+strlen("data")+c] != '\"')
  2806. {
  2807. sstr[c] = loc[3+strlen("data")+c];
  2808. c++;
  2809. }
  2810. sstr[c] = '\0';
  2811. strcpy(dataStr, sstr);
  2812. return result;
  2813. }
  2814. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2815. {
  2816. mtrace();
  2817. int result = FAIL;
  2818. char message[1000]={0};
  2819. double diff_f = 0.0;
  2820. int diff_i = 0;
  2821. int diffSeconds = 0;
  2822. struct tm tp;
  2823. int TimeZero = FALSE;
  2824. int CompositeScheduleIndex = 0;
  2825. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2826. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2827. {
  2828. TimeZero = TRUE;
  2829. }
  2830. else
  2831. {
  2832. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2833. }
  2834. if(TimeZero == FALSE)
  2835. {
  2836. tp.tm_isdst = -1;
  2837. time_t utc = mktime(&tp);
  2838. time_t t = time(NULL);
  2839. diff_f = difftime(t, utc);
  2840. diff_i = (int)diff_f;
  2841. diffSeconds = diff_i % 86400;//86400 seconds/day
  2842. }
  2843. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2844. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2845. #if 0 //remove temporally
  2846. 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}"
  2847. ,MESSAGE_TYPE_CALLRESULT
  2848. ,uuid
  2849. ,payload
  2850. ,connectorIdInt
  2851. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2852. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2853. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2854. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2855. #endif
  2856. if(nPeriod == 0)
  2857. {
  2858. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2859. ,MESSAGE_TYPE_CALLRESULT
  2860. ,uuid
  2861. ,payload
  2862. ,connectorIdInt
  2863. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2864. }
  2865. else
  2866. {
  2867. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2868. ,MESSAGE_TYPE_CALLRESULT
  2869. ,uuid
  2870. ,payload
  2871. ,connectorIdInt
  2872. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2873. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2874. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2875. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2876. int len = nPeriod;
  2877. //Last Period StartPriod is less than diffSeconds
  2878. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2879. {
  2880. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2881. , 0
  2882. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2883. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2884. }
  2885. else
  2886. {
  2887. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2888. {
  2889. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2890. {
  2891. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2892. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2893. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2894. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2895. }
  2896. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2897. {
  2898. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2899. , (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*/))
  2900. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2901. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2902. }
  2903. }
  2904. }
  2905. sprintf(message + strlen(message), "]}}]");
  2906. }
  2907. LWS_Send(message);
  2908. result = TRUE;
  2909. return result;
  2910. }
  2911. int sendGetConfigurationConfirmation(char *uuid)
  2912. {
  2913. mtrace();
  2914. int result = FAIL;
  2915. int MaxKeySupported = 0;
  2916. int sentConfigurationNumber= 0;
  2917. int sentunConfigurationNumber= 0;
  2918. char message[4000]={0};
  2919. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2920. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2921. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2922. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  2923. ,MESSAGE_TYPE_CALLRESULT
  2924. ,uuid );
  2925. //configuration key
  2926. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2927. {
  2928. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2929. {
  2930. if (sentConfigurationNumber == 0)
  2931. {
  2932. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  2933. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2934. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2935. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2936. }
  2937. else
  2938. {
  2939. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2940. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2941. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2942. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2943. }
  2944. sentConfigurationNumber = sentConfigurationNumber + 1;
  2945. }
  2946. }
  2947. sprintf(message + strlen(message), "]");
  2948. if(UnknownKeynum != 0)
  2949. {
  2950. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2951. //unkown key
  2952. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2953. {
  2954. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2955. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2956. if(sentunConfigurationNumber == 0)
  2957. {
  2958. sprintf(message + strlen(message), "\"%s\""
  2959. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2960. }
  2961. else
  2962. {
  2963. sprintf(message + strlen(message), ",\"%s\""
  2964. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2965. }
  2966. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  2967. }
  2968. sprintf(message + strlen(message), "]");
  2969. }
  2970. sprintf(message + strlen(message), "} ]");
  2971. LWS_Send(message);
  2972. return result;
  2973. }
  2974. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2975. {
  2976. mtrace();
  2977. int result = FAIL;
  2978. char message[400]={0};
  2979. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  2980. if(strcmp(payload,"")==0)
  2981. {
  2982. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  2983. }
  2984. else
  2985. {
  2986. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  2987. }
  2988. LWS_Send(message);
  2989. result = TRUE;
  2990. return result;
  2991. }
  2992. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2993. {
  2994. mtrace();
  2995. int result = FAIL;
  2996. char message[80]={0};
  2997. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  2998. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  2999. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3000. LWS_Send(message);
  3001. result = TRUE;
  3002. return result;
  3003. }
  3004. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3005. {
  3006. mtrace();
  3007. int result = FAIL;
  3008. char message[80]={0};
  3009. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3010. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3011. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3012. LWS_Send(message);
  3013. result = TRUE;
  3014. return result;
  3015. }
  3016. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3017. {
  3018. mtrace();
  3019. int result = FAIL;
  3020. char message[80]={0};
  3021. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3022. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3023. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3024. LWS_Send(message);
  3025. result = TRUE;
  3026. return result;
  3027. }
  3028. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3029. {
  3030. mtrace();
  3031. int result = FAIL;
  3032. char message[80]={0};
  3033. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3034. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3035. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3036. LWS_Send(message);
  3037. result = TRUE;
  3038. return result;
  3039. }
  3040. int sendResetConfirmation(char *uuid,char *payload)
  3041. {
  3042. mtrace();
  3043. int result = FAIL;
  3044. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3045. char message[80]={0};
  3046. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3047. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3048. LWS_Send(message);
  3049. result = TRUE;
  3050. return result;
  3051. }
  3052. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3053. {
  3054. mtrace();
  3055. int result = FAIL;
  3056. char message[500]={0};
  3057. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3058. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3059. LWS_Send(message);
  3060. result = TRUE;
  3061. return result;
  3062. }
  3063. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3064. {
  3065. mtrace();
  3066. int result = FAIL;
  3067. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3068. char message[80]={0};
  3069. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3070. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3071. LWS_Send(message);
  3072. result = TRUE;
  3073. return result;
  3074. }
  3075. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3076. {
  3077. mtrace();
  3078. int result = FAIL;
  3079. char message[80]={0};
  3080. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3081. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3082. LWS_Send(message);
  3083. result = TRUE;
  3084. return result;
  3085. }
  3086. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3087. {
  3088. mtrace();
  3089. int result = FAIL;
  3090. char message[80]={0};
  3091. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3092. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3093. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3094. LWS_Send(message);
  3095. result = TRUE;
  3096. return result;
  3097. }
  3098. int sendUpdateFirmwareConfirmation(char *uuid)
  3099. {
  3100. mtrace();
  3101. int result = FAIL;
  3102. char message[60]={0};
  3103. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3104. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3105. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3106. LWS_Send(message);
  3107. result = TRUE;
  3108. return result;
  3109. }
  3110. //==========================================
  3111. // send CallError routine
  3112. //==========================================
  3113. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3114. {
  3115. mtrace();
  3116. //int result = FAIL;
  3117. char message[220]={0};
  3118. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3119. #ifdef SystemLogMessage
  3120. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3121. uniqueId, action, errorCode, errorDescription);
  3122. #endif
  3123. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3124. LWS_Send(message);
  3125. //result = TRUE;
  3126. }
  3127. //==========================================
  3128. // Handle server request routine Start
  3129. //==========================================
  3130. #define GUN_NUM 1
  3131. int handleCancelReservationRequest(char *uuid, char *payload)
  3132. {
  3133. mtrace();
  3134. int result = FAIL;
  3135. int gunNO = 0;
  3136. int reservationIdInt =0;
  3137. char comfirmstr[20];
  3138. int c = 0;
  3139. char *loc;
  3140. char sstr[100]={0};
  3141. DEBUG_INFO("handle CancelReservationRequest\n");
  3142. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3143. c = 0;
  3144. loc = strstr(payload, "reservationId");
  3145. memset(sstr ,0, sizeof(sstr) );
  3146. while (loc[strlen("reservationId")+2+c] != '}')
  3147. {
  3148. sstr[c] = loc[strlen("reservationId")+2+c];
  3149. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3150. c++;
  3151. }
  3152. sstr[c] = '\0';
  3153. reservationIdInt = atoi(sstr);
  3154. memset(comfirmstr, 0, sizeof comfirmstr);
  3155. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3156. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3157. //check Transaction active
  3158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3159. {
  3160. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3161. {
  3162. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3163. {
  3164. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3165. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3166. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3167. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3168. goto end;
  3169. }
  3170. }
  3171. for (int index = 0; index < CCS_QUANTITY; index++)
  3172. {
  3173. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3174. {
  3175. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3176. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3177. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3178. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3179. goto end;
  3180. }
  3181. }
  3182. for (int index = 0; index < GB_QUANTITY; index++)
  3183. {
  3184. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3185. {
  3186. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3187. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3188. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3189. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3190. goto end;
  3191. }
  3192. }
  3193. }
  3194. else
  3195. {
  3196. for (int index = 0; index < AC_QUANTITY; index++)
  3197. {
  3198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3199. {
  3200. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3201. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3202. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3203. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3204. goto end;
  3205. }
  3206. }
  3207. }// END FOR AC ELSE
  3208. //The reservationId does NOT match the reservationId
  3209. sendCancelReservationConfirmation(uuid, comfirmstr);
  3210. end:
  3211. // Fill in ocpp packet uuid
  3212. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3213. return result;
  3214. }
  3215. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3216. {
  3217. mtrace();
  3218. int result = FAIL;
  3219. int gunIndex = 0;
  3220. char sstr[90]={0};
  3221. char typeStr[16]={0};
  3222. char comfirmstr[20];
  3223. int specificId = FALSE;
  3224. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3225. char *loc;
  3226. //int intervalInt = 0;
  3227. int c = 0;
  3228. /*** connectorId ****/
  3229. c = 0;
  3230. loc = strstr(payload, "connectorId");
  3231. memset(sstr ,0, sizeof(sstr) );
  3232. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3233. {
  3234. sstr[c] = loc[strlen("connectorId")+2+c];
  3235. c++;
  3236. }
  3237. sstr[c] = '\0';
  3238. gunIndex = atoi(sstr);
  3239. /***type ****/
  3240. loc = strstr(payload, "type");
  3241. memset(sstr ,0, sizeof(sstr) );
  3242. c = 0;
  3243. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3244. {
  3245. sstr[c] = loc[3+strlen("type")+c];
  3246. c++;
  3247. }
  3248. sstr[c] = '\0';
  3249. strcpy(typeStr, sstr);
  3250. if(gunIndex != 0)
  3251. {
  3252. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3253. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3254. }
  3255. else
  3256. {
  3257. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3258. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3259. }
  3260. memset(comfirmstr, 0, sizeof comfirmstr);
  3261. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3262. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3263. {
  3264. specificId = TRUE;
  3265. }
  3266. if(specificId == FALSE)
  3267. goto end;
  3268. if(gunIndex != 0)
  3269. {
  3270. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3271. }
  3272. else
  3273. {
  3274. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3275. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3276. }
  3277. /*
  3278. enum SYSTEM_STATUS
  3279. {
  3280. SYS_MODE_BOOTING = 0,
  3281. SYS_MODE_IDLE = 1,
  3282. SYS_MODE_AUTHORIZING = 2,
  3283. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3284. SYS_MODE_REASSIGN = 4,
  3285. SYS_MODE_PREPARING = 5,
  3286. SYS_MODE_PREPARE_FOR_EV = 6,
  3287. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3288. SYS_MODE_CHARGING = 8,
  3289. SYS_MODE_TERMINATING = 9,
  3290. SYS_MODE_COMPLETE = 10,
  3291. SYS_MODE_ALARM = 11,
  3292. SYS_MODE_FAULT = 12,
  3293. SYS_MODE_RESERVATION = 13,
  3294. SYS_MODE_BOOKING = 14,
  3295. SYS_MODE_MAINTAIN = 15,
  3296. SYS_MODE_DEBUG = 16,
  3297. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3298. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3299. SYS_MODE_UPDATE = 19
  3300. };
  3301. */
  3302. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3303. {
  3304. //check Transaction active
  3305. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3306. {
  3307. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3308. {
  3309. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3310. {
  3311. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3312. {
  3313. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3314. }
  3315. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3316. {
  3317. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3318. }
  3319. else
  3320. {
  3321. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3322. }
  3323. goto end;
  3324. }
  3325. }//END FOR CHAdeMO_QUANTITY
  3326. for (int index = 0; index < CCS_QUANTITY; index++)
  3327. {
  3328. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3329. {
  3330. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3331. {
  3332. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3333. }
  3334. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3335. {
  3336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3337. }
  3338. else
  3339. {
  3340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3341. }
  3342. goto end;
  3343. }
  3344. }//END FOR CCS_QUANTITY
  3345. for (int index = 0; index < GB_QUANTITY; index++)
  3346. {
  3347. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3348. {
  3349. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3350. {
  3351. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3352. }
  3353. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3354. {
  3355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3356. }
  3357. else
  3358. {
  3359. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3360. }
  3361. goto end;
  3362. }
  3363. }// END FOR GB_QUANTITY
  3364. }
  3365. else
  3366. {
  3367. for (int index = 0; index < AC_QUANTITY; index++)
  3368. {
  3369. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3370. {
  3371. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3372. {
  3373. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3374. }
  3375. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3376. {
  3377. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3378. }
  3379. else
  3380. {
  3381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3382. }
  3383. goto end;
  3384. }
  3385. }//END FOR AC_QUANTITY
  3386. }// END FOR AC ELSE
  3387. }//END FOR AvailabilityTypeStr[Inoperative]
  3388. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3389. {
  3390. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3391. //check Transaction active
  3392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3393. {
  3394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3395. {
  3396. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3397. {
  3398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3399. goto end;
  3400. }
  3401. }//END FOR CHAdeMO_QUANTITY
  3402. for (int index = 0; index < CCS_QUANTITY; index++)
  3403. {
  3404. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3405. {
  3406. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3407. goto end;
  3408. }
  3409. }//END FOR CCS_QUANTITY
  3410. for (int index = 0; index < GB_QUANTITY; index++)
  3411. {
  3412. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3413. {
  3414. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3416. goto end;
  3417. }
  3418. }// END FOR GB_QUANTITY
  3419. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3420. }
  3421. else
  3422. {
  3423. for (int index = 0; index < AC_QUANTITY; index++)
  3424. {
  3425. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3426. {
  3427. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3428. goto end;
  3429. }
  3430. }//END FOR CHAdeMO_QUANTITY
  3431. }//END FOR AC ELSE
  3432. }//END FOR AvailabilityTypeStr[Operative]
  3433. end:
  3434. if(gunIndex != 0)
  3435. {
  3436. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3437. }
  3438. else
  3439. {
  3440. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3441. }
  3442. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3443. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3444. return result;
  3445. }
  3446. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3447. {
  3448. mtrace();
  3449. int result = FAIL;
  3450. char sstr[100]={0};
  3451. char keystr[40]={0};
  3452. char valuestr[100]={0};
  3453. char *loc;
  3454. int c = 0;
  3455. char comfirmstr[20]={0};
  3456. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3457. /***key ****/
  3458. loc = strstr(payload, "key");
  3459. memset(sstr ,0, sizeof(sstr) );
  3460. c = 0;
  3461. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3462. {
  3463. sstr[c] = loc[3+strlen("key")+c];
  3464. c++;
  3465. }
  3466. sstr[c] = '\0';
  3467. strcpy(keystr, sstr);
  3468. //DEBUG_INFO( "keystr=%s\n",keystr);
  3469. /***value ****/
  3470. loc = strstr(payload, "value");
  3471. memset(sstr ,0, sizeof(sstr) );
  3472. c = 0;
  3473. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3474. {
  3475. sstr[c] = loc[3+strlen("value")+c];
  3476. c++;
  3477. }
  3478. sstr[c] = '\0';
  3479. strcpy(valuestr, sstr);
  3480. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3481. if((uuid==NULL) || (payload ==NULL) )
  3482. {
  3483. #ifdef Debug
  3484. DEBUG_INFO("payload is null\n");
  3485. #endif
  3486. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3487. }
  3488. else
  3489. {
  3490. int status = setKeyValue(keystr, valuestr);
  3491. switch(status)
  3492. {
  3493. case ConfigurationStatus_Accepted:
  3494. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3495. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3496. StoreConfigurationTable();
  3497. break;
  3498. case ConfigurationStatus_Rejected:
  3499. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3500. break;
  3501. case RebootRequired:
  3502. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3503. StoreConfigurationTable();
  3504. break;
  3505. case NotSupported:
  3506. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3507. break;
  3508. default:
  3509. break;
  3510. }
  3511. }
  3512. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3513. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3514. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3515. return result;
  3516. }
  3517. int handleClearCacheRequest(char *uuid, char *payload)
  3518. {
  3519. mtrace();
  3520. int result = FAIL;
  3521. char comfirmstr[20];
  3522. int fd;
  3523. char rmFileCmd[100]={0};
  3524. struct stat stats;
  3525. DEBUG_INFO("handle ClearCacheRequest\n");
  3526. stat("/Storage/OCPP", &stats);
  3527. // Check for directory existence
  3528. if (S_ISDIR(stats.st_mode) == 1)
  3529. {
  3530. //DEBUG_ERROR("\n OCPP directory exist \n");
  3531. }
  3532. else
  3533. {
  3534. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3535. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3536. system(rmFileCmd);
  3537. }
  3538. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3539. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3540. {
  3541. DEBUG_INFO("AuthorizationCache file exist.\n");
  3542. }
  3543. else
  3544. {
  3545. DEBUG_INFO("AuthorizationCache file not exist\n");
  3546. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3547. if(log == NULL)
  3548. {
  3549. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3550. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3551. goto end;
  3552. }
  3553. else
  3554. {
  3555. fclose(log);
  3556. }
  3557. }
  3558. fd = open(AuthorizationCache_JSON,O_RDWR);
  3559. if(fd < 0)
  3560. {
  3561. DEBUG_INFO("open AuthorizationCache file failed\n");
  3562. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3563. }
  3564. else
  3565. {
  3566. DEBUG_INFO("open AuthorizationCache file successful\n");
  3567. //* 清空? 件 */
  3568. ftruncate(fd,0);
  3569. //* ? 新设置? 件? 移??*/
  3570. lseek(fd,0,SEEK_SET);
  3571. close(fd);
  3572. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3573. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3574. }
  3575. end:
  3576. sendClearCacheConfirmation(uuid, comfirmstr);
  3577. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3578. return result;
  3579. }
  3580. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3581. {
  3582. mtrace();
  3583. int result = FAIL;
  3584. int resultRename;
  3585. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3586. char chargingProfilePurposeStr[26]={0};
  3587. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3588. char tempchargingProfilePurposeStr[26]={0};
  3589. char sstr[160]={0};//sstr[200]={ 0 };
  3590. char str[100]={0};
  3591. int c = 0;
  3592. //int i = 0;
  3593. //char * pch;
  3594. char *loc;
  3595. char fname[200];
  3596. char comfirmstr[20]={0};
  3597. char word[1000]={0};
  3598. int clearflag = FALSE;
  3599. int chargingProfileIdIsNULL = FALSE;
  3600. int connectorIsNULL = FALSE;
  3601. int chargingProfilePurposeIsNULL = FALSE;
  3602. int stackLevelIsNULL = FALSE;
  3603. int GotoEnd = FALSE;
  3604. FILE *fptr1, *fptr2;
  3605. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json";
  3606. int n_chargingProfile=0;
  3607. char sLineWord[1060]={0};
  3608. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3609. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3610. //***id ****/
  3611. c = 0;
  3612. loc = strstr(payload, "id");
  3613. memset(sstr ,0, sizeof(sstr) );
  3614. if(loc == NULL)
  3615. {
  3616. chargingProfileIdIsNULL = TRUE;
  3617. }
  3618. else
  3619. {
  3620. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3621. {
  3622. sstr[c] = loc[strlen("id")+2+c];
  3623. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3624. c++;
  3625. }
  3626. sstr[c] = '\0';
  3627. chargingProfileIdInt = atoi(sstr);
  3628. }
  3629. //***connectorId ****/
  3630. c=0;
  3631. loc = strstr(payload, "connectorId");
  3632. memset(sstr ,0, sizeof(sstr) );
  3633. if(loc == NULL)
  3634. {
  3635. connectorIsNULL = TRUE;
  3636. }
  3637. else
  3638. {
  3639. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3640. {
  3641. sstr[c] = loc[strlen("connectorId")+2+c];
  3642. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3643. c++;
  3644. }
  3645. sstr[c] = '\0';
  3646. connectorIdInt = atoi(sstr);
  3647. }
  3648. //***chargingProfilePurpose ****/
  3649. loc = strstr(payload, "chargingProfilePurpose");
  3650. memset(sstr ,0, sizeof(sstr) );
  3651. c = 0;
  3652. if(loc == NULL)
  3653. {
  3654. chargingProfilePurposeIsNULL = TRUE;
  3655. }
  3656. else
  3657. {
  3658. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3659. {
  3660. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3661. c++;
  3662. }
  3663. sstr[c] = '\0';
  3664. strcpy(chargingProfilePurposeStr, sstr);
  3665. }
  3666. //***stackLevel ****/
  3667. c=0;
  3668. loc = strstr(payload, "stackLevel");
  3669. memset(sstr ,0, sizeof(sstr) );
  3670. if(loc == NULL)
  3671. {
  3672. stackLevelIsNULL = TRUE;
  3673. }
  3674. else
  3675. {
  3676. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3677. {
  3678. sstr[c] = loc[strlen("stackLevel")+2+c];
  3679. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3680. c++;
  3681. }
  3682. sstr[c] = '\0';
  3683. stackLevelInt = atoi(sstr);
  3684. }
  3685. if(connectorIsNULL == FALSE)
  3686. {
  3687. switch(connectorIdInt)
  3688. {
  3689. case 0:
  3690. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3691. {
  3692. strcpy(fname, ChargePointMaxProfile_JSON);
  3693. }
  3694. else
  3695. {
  3696. strcpy(fname, TxDefaultProfile_0_JSON);
  3697. }
  3698. break;
  3699. case 1:
  3700. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3701. {
  3702. strcpy(fname, TxDefaultProfile_1_JSON);
  3703. }
  3704. // else
  3705. // {
  3706. // strcpy(fname, TxProfile_1_JSON);
  3707. // }
  3708. break;
  3709. case 2:
  3710. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3711. {
  3712. strcpy(fname, TxDefaultProfile_2_JSON);
  3713. }
  3714. // else
  3715. // {
  3716. // strcpy(fname, TxProfile_2_JSON);
  3717. // }
  3718. break;
  3719. default:
  3720. strcpy(fname, ChargePointMaxProfile_JSON );
  3721. break;
  3722. }
  3723. }
  3724. else
  3725. {
  3726. strcpy(fname, ChargePointMaxProfile_JSON );
  3727. }
  3728. fptr1 = fopen(fname, "r");
  3729. if (!fptr1)
  3730. {
  3731. //file not exist
  3732. DEBUG_INFO("Unable to open the input file!!\n");
  3733. fptr1 = fopen(fname, "w+");
  3734. }
  3735. fclose(fptr1);
  3736. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3737. {
  3738. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3739. goto end;
  3740. }
  3741. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3742. {
  3743. //clear file in C
  3744. sprintf(str,"rm -f %s",fname);
  3745. system(str);
  3746. // clear temp file
  3747. sprintf(str,"rm -f %s",temp);
  3748. system(str);
  3749. #if 0
  3750. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3751. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3752. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3753. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3754. fclose(fopen(TxProfile_1_JSON, "w"));
  3755. fclose(fopen(TxProfile_2_JSON, "w"));
  3756. #endif
  3757. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3758. goto end;
  3759. }
  3760. else
  3761. {
  3762. fptr1 = fopen(fname, "r");
  3763. fptr2 = fopen(temp, "w+");
  3764. while(fscanf(fptr1, "%s", word) != EOF)
  3765. {
  3766. //DEBUG_INFO("word=%s\n",word);
  3767. if(strcmp(word, "chargingProfileId") == 0)
  3768. {
  3769. n_chargingProfile = n_chargingProfile + 1;
  3770. DEBUG_INFO("chargingProfileId Found\n");
  3771. }
  3772. }
  3773. rewind(fptr1);
  3774. //search Charging Profile Element
  3775. //int i= 0;
  3776. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3777. {
  3778. //*************************tempconnectorIdInt*********************************/
  3779. loc = strstr(sLineWord, "connectorId");
  3780. c = 0;
  3781. memset(sstr ,0, sizeof(sstr) );
  3782. while (loc[strlen("connectorId")+2+c] != ',')
  3783. {
  3784. sstr[c] = loc[strlen("connectorId")+2+c];
  3785. c++;
  3786. }
  3787. sstr[c] = '\0';
  3788. tempconnectorIdInt = atoi(sstr);
  3789. //chargingProfileId
  3790. c = 0;
  3791. loc = strstr(sLineWord, "chargingProfileId");
  3792. memset(sstr ,0, sizeof(sstr) );
  3793. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3794. {
  3795. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3796. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3797. c++;
  3798. }
  3799. sstr[c] = '\0';
  3800. tempchargingProfileIdInt = atoi(sstr);
  3801. //stackLevel
  3802. c = 0;
  3803. loc = strstr(sLineWord, "stackLevel");
  3804. memset(sstr ,0, sizeof(sstr) );
  3805. while (loc[strlen("stackLevel")+2+c] != ',')
  3806. {
  3807. sstr[c] = loc[strlen("stackLevel")+2+c];
  3808. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3809. c++;
  3810. }
  3811. sstr[c] = '\0';
  3812. tempstackLevelInt = atoi(sstr);
  3813. c = 0;
  3814. loc = strstr(sLineWord, "chargingProfilePurpose");
  3815. memset(sstr ,0, sizeof(sstr) );
  3816. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3817. {
  3818. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3819. c++;
  3820. }
  3821. sstr[c] = '\0';
  3822. strcpy(tempchargingProfilePurposeStr, sstr);
  3823. if(chargingProfileIdIsNULL == FALSE)
  3824. {
  3825. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3826. {
  3827. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3828. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3829. clearflag = TRUE;
  3830. continue;
  3831. }
  3832. else
  3833. {
  3834. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3835. //json_object_array_add(newHeatMap, jsonitem);
  3836. fprintf(fptr2, sLineWord);//writing data into file
  3837. }
  3838. }
  3839. else
  3840. {
  3841. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3842. {
  3843. if(stackLevelIsNULL == TRUE)//((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3844. {
  3845. fclose(fptr1);
  3846. fclose(fptr2);
  3847. sprintf(str,"rm -f %s",fname);
  3848. system(str);
  3849. // clear temp file
  3850. sprintf(str,"rm -f %s",temp);
  3851. system(str);
  3852. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3853. clearflag = TRUE;
  3854. GotoEnd = TRUE;
  3855. break;
  3856. }
  3857. else if((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt))
  3858. {
  3859. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3860. clearflag = TRUE;
  3861. continue;
  3862. }
  3863. }
  3864. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3865. {
  3866. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3867. {
  3868. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3869. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3870. {
  3871. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3872. clearflag = TRUE;
  3873. continue;
  3874. }
  3875. }
  3876. }
  3877. else
  3878. {
  3879. //json_object_array_add(newHeatMap, jsonitem);
  3880. fprintf(fptr2, sLineWord);//writing data into file
  3881. }
  3882. }
  3883. memset(sLineWord, 0, sizeof sLineWord);
  3884. }
  3885. if((clearflag == FALSE) && (GotoEnd == TRUE))
  3886. {
  3887. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3888. sprintf(str,"rm -f %s",temp);
  3889. system(str);
  3890. goto end;
  3891. }
  3892. else
  3893. {
  3894. goto end;
  3895. }
  3896. fclose(fptr1);
  3897. fclose(fptr2);
  3898. sprintf(str,"rm -f %s",fname);
  3899. system(str);
  3900. resultRename = rename(temp, fname);
  3901. if(resultRename == 0)
  3902. {
  3903. DEBUG_INFO("File ChargingProfile renamed successfully");
  3904. }
  3905. else
  3906. {
  3907. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3908. }
  3909. }
  3910. end:
  3911. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3912. return result;
  3913. }
  3914. int handleDataTransferRequest(char *uuid, char *payload)
  3915. {
  3916. mtrace();
  3917. int result = FAIL;
  3918. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3919. char tempvendorId[255]={0};
  3920. char tempmessageId[50]={0};
  3921. char tempdata[50]={0};
  3922. char sstr[160]={0};//sstr[200]={ 0 };
  3923. char message[80]={0};
  3924. int c = 0;
  3925. char *loc;
  3926. DEBUG_INFO("handle DataTransferRequest\n");
  3927. if((uuid != NULL) && (payload != NULL))
  3928. {
  3929. //===============================
  3930. // vendorId
  3931. //===============================
  3932. c = 0;
  3933. loc = strstr(payload, "vendorId");
  3934. while (loc[strlen("vendorId")+3+c] != '\"')
  3935. {
  3936. sstr[c] = loc[strlen("vendorId")+3+c];
  3937. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3938. c++;
  3939. }
  3940. sstr[c] = '\0';
  3941. strcpy(tempvendorId,sstr);
  3942. //===============================
  3943. // messageId
  3944. //===============================
  3945. memset(sstr ,0, sizeof(sstr) );
  3946. c = 0;
  3947. loc = strstr(payload, "messageId");
  3948. while (loc[strlen("messageId")+3+c] != '\"')
  3949. {
  3950. sstr[c] = loc[strlen("messageId")+3+c];
  3951. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3952. c++;
  3953. }
  3954. sstr[c] = '\0';
  3955. strcpy(tempmessageId,sstr);
  3956. //===============================
  3957. // data
  3958. //===============================
  3959. memset(sstr ,0, sizeof(sstr) );
  3960. c = 0;
  3961. loc = strstr(payload, "data");
  3962. printf("loc=%s\n",loc);
  3963. while (loc[strlen("data")+3+c] != '\"')
  3964. {
  3965. sstr[c] = loc[strlen("data")+3+c];
  3966. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3967. c++;
  3968. }
  3969. sstr[c] = '\0';
  3970. strcpy(tempdata,sstr);
  3971. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  3972. }
  3973. else
  3974. {
  3975. char guid[37]={0};
  3976. random_uuid(guid);
  3977. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  3978. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  3979. }
  3980. LWS_Send(message);
  3981. return result;
  3982. }
  3983. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3984. {
  3985. mtrace();
  3986. int result = FAIL;
  3987. int connectorIdInt, durationInt;
  3988. char chargingRateUnitStr[4]={0};
  3989. //int tempconnectorIdInt,
  3990. int tempdurationInt;
  3991. float tempminChargingRateFloat = 0.0;
  3992. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  3993. int tempStartPeriodInt=0;
  3994. float tempLimitInt=0.0;//0.1;
  3995. int tempNumberPhasesInt=0;
  3996. char fname[200];
  3997. char comfirmstr[20];
  3998. //float totallimit =0.0;
  3999. float MinChargingRate =0.0;
  4000. //double diff_t;
  4001. //struct tm tp;
  4002. FILE *fptr1;
  4003. int c = 0;
  4004. //int i = 0;
  4005. char * pch;
  4006. char *loc;
  4007. char sstr[200]={ 0 };
  4008. int n_chargingProfile = 0;
  4009. int n_SchedulePeriods = 0;
  4010. char SchedulePeriodList[10][200]={0};
  4011. char sLineWord[800]={0};
  4012. //int n_periods = 0;
  4013. char word[1000]={0};
  4014. int confirmPeriods = 0;
  4015. struct StructProfile ChargePointMaxProfile;
  4016. struct StructProfile TxDefaultProfile;
  4017. struct StructProfile TxProfile;
  4018. struct StructProfile TxDefaultProfiletemp[2]={0};
  4019. int TxDefaultProfileFileIsNull=FALSE;
  4020. int ChargePointMaxProfileIsNull=FALSE;
  4021. int TxProfileIsNull=FALSE;
  4022. int CompositeSceduleIndex = 0;
  4023. char ChargePointMaxProfileScheduleStr[30]={0};
  4024. char TxDefaultProfileScheduleStr[30]={0};
  4025. char TxProfileScheduleStr[30]={0};
  4026. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4027. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4028. memset(&TxProfile,0,sizeof(struct StructProfile));
  4029. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4030. c=0;
  4031. loc = strstr(payload, "connectorId");
  4032. memset(sstr ,0, sizeof(sstr) );
  4033. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4034. {
  4035. sstr[c] = loc[strlen("connectorId")+2+c];
  4036. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4037. c++;
  4038. }
  4039. sstr[c] = '\0';
  4040. connectorIdInt = atoi(sstr);
  4041. c=0;
  4042. loc = strstr(payload, "duration");
  4043. memset(sstr ,0, sizeof(sstr) );
  4044. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4045. {
  4046. sstr[c] = loc[strlen("duration")+2+c];
  4047. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4048. c++;
  4049. }
  4050. sstr[c] = '\0';
  4051. durationInt = atoi(sstr);
  4052. c = 0;
  4053. loc = strstr(payload, "chargingRateUnit");
  4054. memset(sstr ,0, sizeof(sstr) );
  4055. if(loc == NULL)
  4056. {
  4057. }
  4058. else
  4059. {
  4060. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4061. {
  4062. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4063. c++;
  4064. }
  4065. sstr[c] = '\0';
  4066. strcpy(chargingRateUnitStr, sstr);
  4067. }
  4068. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4069. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4070. if(connectorIdInt==0) // connectorId is 0
  4071. {
  4072. //******************************ChargePointMaxProfile*****************************************************/
  4073. strcpy(fname, ChargePointMaxProfile_JSON );
  4074. char word[30]={0};
  4075. char sLineWord[1060]={0};
  4076. int n_chargingProfile=0;
  4077. ChargePointMaxProfileIsNull=TRUE;
  4078. if((access(fname,F_OK))!=-1)
  4079. {
  4080. fptr1 = fopen(fname, "r");
  4081. int c;
  4082. c = fgetc(fptr1);
  4083. //DEBUG_INFO("c:%d\n",c);
  4084. rewind(fptr1);
  4085. if(c == EOF)
  4086. {
  4087. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4088. ChargePointMaxProfileIsNull=TRUE;
  4089. fclose(fptr1);
  4090. }
  4091. else
  4092. {
  4093. ChargePointMaxProfileIsNull=FALSE;
  4094. while(fscanf(fptr1, "%s", word) != EOF)
  4095. {
  4096. if(strcmp(word, "chargingProfileId") == 0)
  4097. {
  4098. n_chargingProfile = n_chargingProfile + 1;
  4099. printf("Found\n");
  4100. }
  4101. }
  4102. rewind(fptr1);
  4103. //search Charging Profile Element
  4104. int i= 0;
  4105. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4106. #if 0
  4107. /***********connectorId****************/
  4108. c = 0;
  4109. loc = strstr(sLineWord, "connectorId");
  4110. // printf("loc=%s\n",loc);
  4111. memset(sstr ,0, sizeof(sstr) );
  4112. while (loc[strlen("connectorId")+2+c] != ',')
  4113. {
  4114. sstr[c] = loc[strlen("connectorId")+2+c];
  4115. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4116. c++;
  4117. }
  4118. sstr[c] = '\0';
  4119. tempconnectorIdInt = atoi(sstr);
  4120. #endif
  4121. //***********validFrom**************/
  4122. c = 0;
  4123. loc = strstr(sLineWord, "validFrom");
  4124. //DEBUG_INFO("loc=%s\n",loc);
  4125. memset(sstr ,0, sizeof(sstr) );
  4126. if(loc != NULL)
  4127. {
  4128. while (loc[3+strlen("validFrom")+c] != '\"')
  4129. {
  4130. sstr[c] = loc[3+strlen("validFrom")+c];
  4131. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4132. c++;
  4133. }
  4134. sstr[c] = '\0';
  4135. DEBUG_INFO("validFrom=%s\n",sstr);
  4136. strcpy(tempvalidFromStr,sstr);
  4137. }
  4138. else
  4139. {
  4140. strcpy(tempvalidFromStr,"");
  4141. }
  4142. //**********startSchedule**********/
  4143. c = 0;
  4144. loc = strstr(sLineWord, "startSchedule");
  4145. //DEBUG_INFO("loc=%s\n",loc);
  4146. memset(sstr ,0, sizeof(sstr) );
  4147. while (loc[3+strlen("startSchedule")+c] != '\"')
  4148. {
  4149. sstr[c] = loc[3+strlen("startSchedule")+c];
  4150. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4151. c++;
  4152. }
  4153. sstr[c] = '\0';
  4154. strcpy(tempstartScheduleStr, sstr);
  4155. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4156. //**********chargingRateUnit**********/
  4157. c = 0;
  4158. loc = strstr(sLineWord, "chargingRateUnit");
  4159. memset(sstr ,0, sizeof(sstr) );
  4160. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4161. {
  4162. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4163. c++;
  4164. }
  4165. sstr[c] = '\0';
  4166. strcpy(tempchargingRateUnitStr, sstr);
  4167. //**********minChargingRate*******/
  4168. c = 0;
  4169. loc = strstr(sLineWord, "minChargingRate");
  4170. //printf("loc=%s\n",loc);
  4171. if(loc != NULL)
  4172. {
  4173. memset(sstr ,0, sizeof(sstr) );
  4174. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4175. {
  4176. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4177. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4178. c++;
  4179. }
  4180. sstr[c] = '\0';
  4181. tempminChargingRateFloat = atof(sstr);
  4182. }
  4183. else
  4184. {
  4185. tempminChargingRateFloat = 0.0;
  4186. }
  4187. //
  4188. #if 0
  4189. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4190. tp.tm_isdst = -1;
  4191. time_t utc = mktime(&tp);
  4192. // current time
  4193. time_t t = time(NULL);
  4194. #endif
  4195. //diff_t = difftime(t, utc);
  4196. //parsing strings to words
  4197. i = 0;
  4198. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4199. loc = loc+3+strlen("chargingSchedulePeriod");
  4200. pch = strtok(loc ,"{");
  4201. while (pch != NULL)
  4202. {
  4203. strcpy(SchedulePeriodList[i], pch);
  4204. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4205. //printf ("%s\n",pch);
  4206. pch = strtok (NULL, "{");
  4207. i = i + 1;
  4208. }
  4209. n_SchedulePeriods = i;
  4210. for(int i=0;i<n_SchedulePeriods;i++)
  4211. {
  4212. //*************startPeriod****************/
  4213. c = 0;
  4214. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4215. memset(sstr ,0, sizeof(sstr) );
  4216. while (loc[strlen("startPeriod")+2+c] != ',')
  4217. {
  4218. sstr[c] = loc[strlen("startPeriod")+2+c];
  4219. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4220. c++;
  4221. }
  4222. sstr[c] = '\0';
  4223. tempStartPeriodInt = atoi(sstr);
  4224. //*************limit****************/
  4225. c = 0;
  4226. loc = strstr(SchedulePeriodList[i], "limit");
  4227. memset(sstr ,0, sizeof(sstr) );
  4228. while (loc[strlen("limit")+2+c] != ',')
  4229. {
  4230. sstr[c] = loc[strlen("limit")+2+c];
  4231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4232. c++;
  4233. }
  4234. sstr[c] = '\0';
  4235. tempLimitInt = atof(sstr);
  4236. //*************numberPhases****************/
  4237. c = 0;
  4238. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4239. memset(sstr ,0, sizeof(sstr) );
  4240. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4241. {
  4242. sstr[c] = loc[strlen("numberPhases")+2+c];
  4243. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4244. c++;
  4245. }
  4246. sstr[c] = '\0';
  4247. tempNumberPhasesInt = atoi(sstr);
  4248. ChargePointMaxProfile.Duration = durationInt;
  4249. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4250. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4251. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4252. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4253. }
  4254. if(MinChargingRate < tempminChargingRateFloat)
  4255. MinChargingRate = tempminChargingRateFloat;
  4256. }
  4257. }// End of file ChargingProfile
  4258. } //THE END OF ACCESS ChargePointMaxProfile
  4259. //******************************TxDefaultProfile***********************************************/
  4260. strcpy(fname, TxDefaultProfile_0_JSON);
  4261. memset(word, 0, 30);
  4262. memset(sLineWord, 0, 1060);
  4263. //char word[30]={0};
  4264. //char sLineWord[1060]={0};
  4265. n_chargingProfile=0;
  4266. TxDefaultProfileFileIsNull=TRUE;
  4267. if((access(fname,F_OK))!=-1)
  4268. {
  4269. fptr1 = fopen(fname, "r");
  4270. c = 0;
  4271. c = fgetc(fptr1);
  4272. //DEBUG_INFO("c:%d\n",c);
  4273. rewind(fptr1);
  4274. if(c == EOF)
  4275. {
  4276. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4277. TxDefaultProfileFileIsNull=TRUE;
  4278. fclose(fptr1);
  4279. }
  4280. else
  4281. {
  4282. TxDefaultProfileFileIsNull=FALSE;
  4283. while(fscanf(fptr1, "%s", word) != EOF)
  4284. {
  4285. if(strcmp(word, "chargingProfileId") == 0)
  4286. {
  4287. n_chargingProfile = n_chargingProfile + 1;
  4288. printf("Found\n");
  4289. }
  4290. }
  4291. rewind(fptr1);
  4292. //search Charging Profile Element
  4293. int i= 0;
  4294. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4295. #if 0
  4296. /***********connectorId****************/
  4297. c = 0;
  4298. loc = strstr(sLineWord, "connectorId");
  4299. // printf("loc=%s\n",loc);
  4300. memset(sstr ,0, sizeof(sstr) );
  4301. while (loc[strlen("connectorId")+2+c] != ',')
  4302. {
  4303. sstr[c] = loc[strlen("connectorId")+2+c];
  4304. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4305. c++;
  4306. }
  4307. sstr[c] = '\0';
  4308. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4309. tempconnectorIdInt = atoi(sstr);
  4310. #endif
  4311. //***********validFrom**************/
  4312. c = 0;
  4313. loc = strstr(sLineWord, "validFrom");
  4314. //DEBUG_INFO("loc=%s\n",loc);
  4315. memset(sstr ,0, sizeof(sstr) );
  4316. if(loc != NULL)
  4317. {
  4318. while (loc[3+strlen("validFrom")+c] != '\"')
  4319. {
  4320. sstr[c] = loc[3+strlen("validFrom")+c];
  4321. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4322. c++;
  4323. }
  4324. sstr[c] = '\0';
  4325. DEBUG_INFO("validFrom=%s\n",sstr);
  4326. strcpy(tempvalidFromStr,sstr);
  4327. }
  4328. else
  4329. {
  4330. strcpy(tempvalidFromStr,"");
  4331. }
  4332. //**********startSchedule**********/
  4333. c = 0;
  4334. loc = strstr(sLineWord, "startSchedule");
  4335. //DEBUG_INFO("loc=%s\n",loc);
  4336. memset(sstr ,0, sizeof(sstr) );
  4337. while (loc[3+strlen("startSchedule")+c] != '\"')
  4338. {
  4339. sstr[c] = loc[3+strlen("startSchedule")+c];
  4340. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4341. c++;
  4342. }
  4343. sstr[c] = '\0';
  4344. strcpy(tempstartScheduleStr, sstr);
  4345. strcpy(TxDefaultProfileScheduleStr, sstr);
  4346. DEBUG_INFO(" debug 3-1\n");
  4347. //**********chargingRateUnit**********/
  4348. c = 0;
  4349. loc = strstr(sLineWord, "chargingRateUnit");
  4350. memset(sstr ,0, sizeof(sstr) );
  4351. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4352. {
  4353. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4354. c++;
  4355. }
  4356. sstr[c] = '\0';
  4357. strcpy(tempchargingRateUnitStr, sstr);
  4358. //**********minChargingRate*******/
  4359. c = 0;
  4360. loc = strstr(sLineWord, "minChargingRate");
  4361. //printf("loc=%s\n",loc);
  4362. if(loc != NULL)
  4363. {
  4364. memset(sstr ,0, sizeof(sstr) );
  4365. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4366. {
  4367. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4369. c++;
  4370. }
  4371. sstr[c] = '\0';
  4372. tempminChargingRateFloat = atof(sstr);
  4373. }
  4374. else
  4375. {
  4376. tempminChargingRateFloat = 0.0;
  4377. }
  4378. #if 0
  4379. //
  4380. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4381. tp.tm_isdst = -1;
  4382. time_t utc = mktime(&tp);
  4383. // current time
  4384. time_t t = time(NULL);
  4385. //diff_t = difftime(t, utc);
  4386. #endif
  4387. //parsing strings to words
  4388. i = 0;
  4389. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4390. loc = loc+3+strlen("chargingSchedulePeriod");
  4391. pch = strtok(loc ,"{");
  4392. while (pch != NULL)
  4393. {
  4394. strcpy(SchedulePeriodList[i], pch);
  4395. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4396. //printf ("%s\n",pch);
  4397. pch = strtok (NULL, "{");
  4398. i = i + 1;
  4399. }
  4400. n_SchedulePeriods = i;
  4401. for(int i=0;i<n_SchedulePeriods;i++)
  4402. {
  4403. //*************startPeriod****************/
  4404. c = 0;
  4405. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4406. memset(sstr ,0, sizeof(sstr) );
  4407. while (loc[strlen("startPeriod")+2+c] != ',')
  4408. {
  4409. sstr[c] = loc[strlen("startPeriod")+2+c];
  4410. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4411. c++;
  4412. }
  4413. sstr[c] = '\0';
  4414. tempStartPeriodInt = atoi(sstr);
  4415. //*************limit****************/
  4416. c = 0;
  4417. loc = strstr(SchedulePeriodList[i], "limit");
  4418. memset(sstr ,0, sizeof(sstr) );
  4419. while (loc[strlen("limit")+2+c] != ',')
  4420. {
  4421. sstr[c] = loc[strlen("limit")+2+c];
  4422. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4423. c++;
  4424. }
  4425. sstr[c] = '\0';
  4426. tempLimitInt = atof(sstr);
  4427. //*************numberPhases****************/
  4428. c = 0;
  4429. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4430. memset(sstr ,0, sizeof(sstr) );
  4431. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4432. {
  4433. sstr[c] = loc[strlen("numberPhases")+2+c];
  4434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4435. c++;
  4436. }
  4437. sstr[c] = '\0';
  4438. tempNumberPhasesInt = atoi(sstr);
  4439. TxDefaultProfile.Duration = durationInt;
  4440. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4441. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4442. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4443. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4444. }
  4445. if(MinChargingRate < tempminChargingRateFloat)
  4446. MinChargingRate = tempminChargingRateFloat;
  4447. }
  4448. }
  4449. }// the end of ACCESS TxDefaultProfile
  4450. // Composite Schedule
  4451. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4452. {
  4453. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4454. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4455. {
  4456. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4457. {
  4458. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4459. }
  4460. else
  4461. {
  4462. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4463. }
  4464. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4465. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4466. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4467. }
  4468. }
  4469. //* Define temporary variables */
  4470. struct tm *gtime;
  4471. time_t now;
  4472. char buf[28];
  4473. /* Read the current system time */
  4474. time(&now);
  4475. /* Convert the system time to GMT (now UTC) */
  4476. gtime = gmtime(&now);
  4477. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4478. // make .conf
  4479. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4480. //MaxChargingProfilesInstalled is 10
  4481. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4482. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4483. //nPeriod = 1;
  4484. if(chargingRateUnitStr[0] != 0)
  4485. {
  4486. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4487. }
  4488. else
  4489. {
  4490. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4491. }
  4492. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4493. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4494. confirmPeriods = 1;
  4495. }
  4496. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4497. {
  4498. //*****************************ChargePointMaxProfile******************************************/
  4499. strcpy(fname, ChargePointMaxProfile_JSON);
  4500. ChargePointMaxProfileIsNull=TRUE;
  4501. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4502. {
  4503. fptr1 = fopen(fname, "r");
  4504. int c;
  4505. c = fgetc(fptr1);
  4506. //DEBUG_INFO("c:%d\n",c);
  4507. rewind(fptr1);
  4508. if(c == EOF)
  4509. {
  4510. DEBUG_INFO("\n End of file reached.");
  4511. ChargePointMaxProfileIsNull=TRUE;
  4512. fclose(fptr1);
  4513. }
  4514. else
  4515. {
  4516. ChargePointMaxProfileIsNull=FALSE;
  4517. while(fscanf(fptr1, "%s", word) != EOF)
  4518. {
  4519. if(strcmp(word, "chargingProfileId") == 0)
  4520. {
  4521. n_chargingProfile = n_chargingProfile + 1;
  4522. }
  4523. }
  4524. rewind(fptr1);
  4525. //search Charging Profile Element
  4526. int i = 0;
  4527. int j = 0;
  4528. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4529. #if 0
  4530. /***********connectorId****************/
  4531. c = 0;
  4532. loc = strstr(sLineWord, "connectorId");
  4533. memset(sstr ,0, sizeof(sstr) );
  4534. while (loc[strlen("connectorId")+2+c] != ',')
  4535. {
  4536. sstr[c] = loc[strlen("connectorId")+2+c];
  4537. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4538. c++;
  4539. }
  4540. sstr[c] = '\0';
  4541. tempconnectorIdInt = atoi(sstr);
  4542. #endif
  4543. //***********validFrom**************/
  4544. c = 0;
  4545. loc = strstr(sLineWord, "validFrom");
  4546. if(loc != NULL)
  4547. {
  4548. memset(sstr ,0, sizeof(sstr) );
  4549. while (loc[3+strlen("validFrom")+c] != '\"')
  4550. {
  4551. sstr[c] = loc[3+strlen("validFrom")+c];
  4552. c++;
  4553. }
  4554. sstr[c] = '\0';
  4555. strcpy(tempvalidFromStr,sstr);
  4556. }
  4557. else
  4558. {
  4559. strcpy(tempvalidFromStr,"");
  4560. }
  4561. //***********validFrom**************/
  4562. c = 0;
  4563. loc = strstr(sLineWord, "duration");
  4564. if(loc != NULL)
  4565. {
  4566. memset(sstr ,0, sizeof(sstr) );
  4567. while (loc[2+strlen("duration")+c] != ',')
  4568. {
  4569. sstr[c] = loc[2+strlen("duration")+c];
  4570. c++;
  4571. }
  4572. sstr[c] = '\0';
  4573. tempdurationInt = atoi(sstr);
  4574. }
  4575. else
  4576. {
  4577. tempdurationInt = 0;
  4578. }
  4579. //**********startSchedule**********/
  4580. c = 0;
  4581. loc = strstr(sLineWord, "startSchedule");
  4582. memset(sstr ,0, sizeof(sstr) );
  4583. while (loc[3+strlen("startSchedule")+c] != '\"')
  4584. {
  4585. sstr[c] = loc[3+strlen("startSchedule")+c];
  4586. c++;
  4587. }
  4588. sstr[c] = '\0';
  4589. strcpy(tempstartScheduleStr, sstr);
  4590. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4591. //**********chargingRateUnit**********/
  4592. c = 0;
  4593. loc = strstr(sLineWord, "chargingRateUnit");
  4594. memset(sstr ,0, sizeof(sstr) );
  4595. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4596. {
  4597. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4598. c++;
  4599. }
  4600. sstr[c] = '\0';
  4601. strcpy(tempchargingRateUnitStr, sstr);
  4602. //**********minChargingRate*******/
  4603. c = 0;
  4604. loc = strstr(sLineWord, "minChargingRate");
  4605. if(loc != NULL)
  4606. {
  4607. memset(sstr ,0, sizeof(sstr) );
  4608. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4609. {
  4610. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4611. c++;
  4612. }
  4613. sstr[c] = '\0';
  4614. tempminChargingRateFloat = atof(sstr);
  4615. }
  4616. else
  4617. {
  4618. tempminChargingRateFloat = 0.0;
  4619. }
  4620. #if 0
  4621. //
  4622. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4623. tp.tm_isdst = -1;
  4624. time_t utc = mktime(&tp);
  4625. time_t t = time(NULL);
  4626. //diff_t = difftime(t, utc);
  4627. #endif
  4628. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4629. //DEBUG_INFO(" debug 5 -1\n");
  4630. //parsing strings to words
  4631. i = 0;
  4632. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4633. loc = loc+3+strlen("chargingSchedulePeriod");
  4634. pch = strtok(loc ,"{");
  4635. while (pch != NULL)
  4636. {
  4637. strcpy(SchedulePeriodList[i], pch);
  4638. pch = strtok (NULL, "{");
  4639. i = i + 1;
  4640. }
  4641. n_SchedulePeriods = i;
  4642. for(int i=0;i<n_SchedulePeriods;i++)
  4643. {
  4644. //*************startPeriod****************/
  4645. c = 0;
  4646. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4647. memset(sstr ,0, sizeof(sstr) );
  4648. while (loc[strlen("startPeriod")+2+c] != ',')
  4649. {
  4650. sstr[c] = loc[strlen("startPeriod")+2+c];
  4651. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4652. c++;
  4653. }
  4654. sstr[c] = '\0';
  4655. tempStartPeriodInt = atoi(sstr);
  4656. //*************limit****************/
  4657. c = 0;
  4658. loc = strstr(SchedulePeriodList[i], "limit");
  4659. memset(sstr ,0, sizeof(sstr) );
  4660. while (loc[strlen("limit")+2+c] != ',')
  4661. {
  4662. sstr[c] = loc[strlen("limit")+2+c];
  4663. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4664. c++;
  4665. }
  4666. sstr[c] = '\0';
  4667. tempLimitInt = atof(sstr);
  4668. //*************numberPhases****************/
  4669. c = 0;
  4670. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4671. memset(sstr ,0, sizeof(sstr) );
  4672. while (loc[strlen("numberPhases")+2+c] != '}')
  4673. {
  4674. sstr[c] = loc[strlen("numberPhases")+2+c];
  4675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4676. c++;
  4677. }
  4678. sstr[c] = '\0';
  4679. tempNumberPhasesInt = atoi(sstr);
  4680. if(j == 0)
  4681. {
  4682. ChargePointMaxProfile.Duration = tempdurationInt;
  4683. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4684. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4685. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4686. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4687. }
  4688. }
  4689. if(MinChargingRate < tempminChargingRateFloat)
  4690. {
  4691. MinChargingRate = tempminChargingRateFloat;
  4692. }
  4693. if(confirmPeriods < n_SchedulePeriods)
  4694. {
  4695. confirmPeriods = n_SchedulePeriods;
  4696. }
  4697. j = j + 1;
  4698. }
  4699. fclose(fptr1);
  4700. }
  4701. }// the end of access file ChargePointMaxProfile
  4702. //****************************TxDefaultProfile************************************************/
  4703. switch(connectorIdInt)
  4704. {
  4705. case 0:
  4706. break;
  4707. case 1:
  4708. strcpy(fname, TxDefaultProfile_1_JSON );
  4709. break;
  4710. case 2:
  4711. strcpy(fname, TxDefaultProfile_2_JSON );
  4712. break;
  4713. default:
  4714. strcpy(fname, TxDefaultProfile_1_JSON );
  4715. break;
  4716. }
  4717. TxDefaultProfileFileIsNull=TRUE;
  4718. if((access(fname,F_OK))!=-1)
  4719. {
  4720. fptr1 = fopen(fname, "r");
  4721. c = 0;
  4722. c = fgetc(fptr1);
  4723. //DEBUG_INFO("c:%d\n",c);
  4724. rewind(fptr1);
  4725. if(c == EOF)
  4726. {
  4727. DEBUG_INFO("\n End of file reached.");
  4728. TxDefaultProfileFileIsNull=TRUE;
  4729. fclose(fptr1);
  4730. }
  4731. else
  4732. {
  4733. TxDefaultProfileFileIsNull=FALSE;
  4734. while(fscanf(fptr1, "%s", word) != EOF)
  4735. {
  4736. if(strcmp(word, "chargingProfileId") == 0)
  4737. {
  4738. n_chargingProfile = n_chargingProfile + 1;
  4739. }
  4740. }
  4741. rewind(fptr1);
  4742. //search Charging Profile Element
  4743. int i = 0;
  4744. int j = 0;
  4745. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4746. //DEBUG_INFO(" 1-1\n");
  4747. #if 0
  4748. /***********connectorId****************/
  4749. c = 0;
  4750. loc = strstr(sLineWord, "connectorId");
  4751. memset(sstr ,0, sizeof(sstr) );
  4752. while (loc[strlen("connectorId")+2+c] != ',')
  4753. {
  4754. sstr[c] = loc[strlen("connectorId")+2+c];
  4755. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4756. c++;
  4757. }
  4758. sstr[c] = '\0';
  4759. tempconnectorIdInt = atoi(sstr);
  4760. #endif
  4761. //***********validFrom**************/
  4762. c = 0;
  4763. loc = strstr(sLineWord, "validFrom");
  4764. if(loc != NULL)
  4765. {
  4766. memset(sstr ,0, sizeof(sstr) );
  4767. while (loc[3+strlen("validFrom")+c] != '\"')
  4768. {
  4769. sstr[c] = loc[3+strlen("validFrom")+c];
  4770. c++;
  4771. }
  4772. sstr[c] = '\0';
  4773. strcpy(tempvalidFromStr,sstr);
  4774. }
  4775. else
  4776. {
  4777. strcpy(tempvalidFromStr,"");
  4778. }
  4779. //***********validFrom**************/
  4780. c = 0;
  4781. loc = strstr(sLineWord, "duration");
  4782. if(loc != NULL)
  4783. {
  4784. memset(sstr ,0, sizeof(sstr) );
  4785. while (loc[2+strlen("duration")+c] != ',')
  4786. {
  4787. sstr[c] = loc[2+strlen("duration")+c];
  4788. c++;
  4789. }
  4790. sstr[c] = '\0';
  4791. tempdurationInt = atoi(sstr);
  4792. }
  4793. else
  4794. {
  4795. tempdurationInt = 0;
  4796. }
  4797. //**********startSchedule**********/
  4798. c = 0;
  4799. loc = strstr(sLineWord, "startSchedule");
  4800. memset(sstr ,0, sizeof(sstr) );
  4801. while (loc[3+strlen("startSchedule")+c] != '\"')
  4802. {
  4803. sstr[c] = loc[3+strlen("startSchedule")+c];
  4804. c++;
  4805. }
  4806. sstr[c] = '\0';
  4807. strcpy(tempstartScheduleStr, sstr);
  4808. strcpy(TxDefaultProfileScheduleStr, sstr);
  4809. //**********chargingRateUnit**********/
  4810. c = 0;
  4811. loc = strstr(sLineWord, "chargingRateUnit");
  4812. memset(sstr ,0, sizeof(sstr) );
  4813. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4814. {
  4815. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4816. c++;
  4817. }
  4818. sstr[c] = '\0';
  4819. strcpy(tempchargingRateUnitStr, sstr);
  4820. //**********minChargingRate*******/
  4821. c = 0;
  4822. loc = strstr(sLineWord, "minChargingRate");
  4823. if(loc != NULL)
  4824. {
  4825. memset(sstr ,0, sizeof(sstr) );
  4826. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4827. {
  4828. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4829. c++;
  4830. }
  4831. sstr[c] = '\0';
  4832. tempminChargingRateFloat = atof(sstr);
  4833. }
  4834. else
  4835. {
  4836. tempminChargingRateFloat = 0.0;
  4837. }
  4838. #if 0
  4839. //
  4840. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4841. tp.tm_isdst = -1;
  4842. time_t utc = mktime(&tp);
  4843. time_t t = time(NULL);
  4844. //diff_t = difftime(t, utc);
  4845. #endif
  4846. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4847. //parsing strings to words
  4848. i = 0;
  4849. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4850. loc = loc+3+strlen("chargingSchedulePeriod");
  4851. pch = strtok(loc ,"{");
  4852. while (pch != NULL)
  4853. {
  4854. strcpy(SchedulePeriodList[i], pch);
  4855. pch = strtok (NULL, "{");
  4856. i = i + 1;
  4857. }
  4858. n_SchedulePeriods = i;
  4859. for(int i=0;i<n_SchedulePeriods;i++)
  4860. {
  4861. //*************startPeriod****************/
  4862. c = 0;
  4863. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4864. memset(sstr ,0, sizeof(sstr) );
  4865. while (loc[strlen("startPeriod")+2+c] != ',')
  4866. {
  4867. sstr[c] = loc[strlen("startPeriod")+2+c];
  4868. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4869. c++;
  4870. }
  4871. sstr[c] = '\0';
  4872. tempStartPeriodInt = atoi(sstr);
  4873. //*************limit****************/
  4874. c = 0;
  4875. loc = strstr(SchedulePeriodList[i], "limit");
  4876. memset(sstr ,0, sizeof(sstr) );
  4877. while (loc[strlen("limit")+2+c] != ',')
  4878. {
  4879. sstr[c] = loc[strlen("limit")+2+c];
  4880. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4881. c++;
  4882. }
  4883. sstr[c] = '\0';
  4884. tempLimitInt = atof(sstr);
  4885. //*************numberPhases****************/
  4886. c = 0;
  4887. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4888. memset(sstr ,0, sizeof(sstr) );
  4889. while (loc[strlen("numberPhases")+2+c] != '}')
  4890. {
  4891. sstr[c] = loc[strlen("numberPhases")+2+c];
  4892. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4893. c++;
  4894. }
  4895. sstr[c] = '\0';
  4896. tempNumberPhasesInt = atoi(sstr);
  4897. if(j == 0)
  4898. {
  4899. TxDefaultProfile.Duration = tempdurationInt;
  4900. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4901. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4902. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4903. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4904. }
  4905. else
  4906. {
  4907. //other stack level charging Profile
  4908. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4909. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4910. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4911. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4912. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4913. }
  4914. }
  4915. if(MinChargingRate < tempminChargingRateFloat)
  4916. MinChargingRate = tempminChargingRateFloat;
  4917. if(confirmPeriods < n_SchedulePeriods)
  4918. confirmPeriods = n_SchedulePeriods;
  4919. j = j + 1;
  4920. //DEBUG_INFO(" 1-2\n");
  4921. }
  4922. fclose(fptr1);
  4923. //Stacking Charging Profiles
  4924. for(int l=0; l <(j-1) ;l++)
  4925. {
  4926. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4927. {
  4928. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4929. {
  4930. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4931. {
  4932. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4933. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4934. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4935. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4936. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4937. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4938. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4939. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4940. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4941. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4942. }
  4943. else
  4944. {
  4945. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4946. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4947. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4948. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4949. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4950. }
  4951. }
  4952. }
  4953. }
  4954. //end of Stacking Charging Profiles
  4955. }
  4956. }// the end of ACCESS TxDefaultProfile
  4957. //****************************TxProfile************************************************/
  4958. switch(connectorIdInt)
  4959. {
  4960. case 0:
  4961. break;
  4962. case 1:
  4963. strcpy(fname, TxProfile_1_JSON );
  4964. break;
  4965. case 2:
  4966. strcpy(fname, TxProfile_2_JSON );
  4967. break;
  4968. default:
  4969. strcpy(fname, TxProfile_1_JSON );
  4970. break;
  4971. }
  4972. TxProfileIsNull=TRUE;
  4973. if((access(fname,F_OK))!=-1)
  4974. {
  4975. fptr1 = fopen(fname, "r");
  4976. c = 0;
  4977. c = fgetc(fptr1);
  4978. //DEBUG_INFO("c:%d\n",c);
  4979. rewind(fptr1);
  4980. if(c == EOF)
  4981. {
  4982. DEBUG_INFO("\n End of file reached.");
  4983. TxProfileIsNull=TRUE;
  4984. fclose(fptr1);
  4985. }
  4986. else
  4987. {
  4988. TxProfileIsNull=FALSE;
  4989. while(fscanf(fptr1, "%s", word) != EOF)
  4990. {
  4991. if(strcmp(word, "chargingProfileId") == 0)
  4992. {
  4993. n_chargingProfile = n_chargingProfile + 1;
  4994. }
  4995. }
  4996. rewind(fptr1);
  4997. //search Charging Profile Element
  4998. int i= 0;
  4999. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5000. #if 0
  5001. /***********connectorId****************/
  5002. c = 0;
  5003. loc = strstr(sLineWord, "connectorId");
  5004. memset(sstr ,0, sizeof(sstr) );
  5005. while (loc[strlen("connectorId")+2+c] != ',')
  5006. {
  5007. sstr[c] = loc[strlen("connectorId")+2+c];
  5008. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5009. c++;
  5010. }
  5011. sstr[c] = '\0';
  5012. tempconnectorIdInt = atoi(sstr);
  5013. #endif
  5014. //***********validFrom**************/
  5015. c = 0;
  5016. loc = strstr(sLineWord, "validFrom");
  5017. if(loc != NULL)
  5018. {
  5019. memset(sstr ,0, sizeof(sstr) );
  5020. while (loc[3+strlen("validFrom")+c] != '\"')
  5021. {
  5022. sstr[c] = loc[3+strlen("validFrom")+c];
  5023. c++;
  5024. }
  5025. sstr[c] = '\0';
  5026. strcpy(tempvalidFromStr,sstr);
  5027. }
  5028. else
  5029. {
  5030. strcpy(tempvalidFromStr,"");
  5031. }
  5032. //**********startSchedule**********/
  5033. c = 0;
  5034. loc = strstr(sLineWord, "startSchedule");
  5035. memset(sstr ,0, sizeof(sstr) );
  5036. while (loc[3+strlen("startSchedule")+c] != '\"')
  5037. {
  5038. sstr[c] = loc[3+strlen("startSchedule")+c];
  5039. c++;
  5040. }
  5041. sstr[c] = '\0';
  5042. strcpy(tempstartScheduleStr, sstr);
  5043. strcpy(TxProfileScheduleStr, sstr);
  5044. //**********chargingRateUnit**********/
  5045. c = 0;
  5046. loc = strstr(sLineWord, "chargingRateUnit");
  5047. memset(sstr ,0, sizeof(sstr) );
  5048. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5049. {
  5050. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5051. c++;
  5052. }
  5053. sstr[c] = '\0';
  5054. strcpy(tempchargingRateUnitStr, sstr);
  5055. //**********minChargingRate*******/
  5056. c = 0;
  5057. loc = strstr(sLineWord, "minChargingRate");
  5058. if(loc != NULL)
  5059. {
  5060. memset(sstr ,0, sizeof(sstr) );
  5061. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5062. {
  5063. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5064. c++;
  5065. }
  5066. sstr[c] = '\0';
  5067. tempminChargingRateFloat = atof(sstr);
  5068. }
  5069. else
  5070. {
  5071. tempminChargingRateFloat = 0.0;
  5072. }
  5073. #if 0
  5074. //
  5075. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5076. tp.tm_isdst = -1;
  5077. time_t utc = mktime(&tp);
  5078. time_t t = time(NULL);
  5079. //diff_t = difftime(t, utc);
  5080. #endif
  5081. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5082. //parsing strings to words
  5083. i = 0;
  5084. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5085. loc = loc+3+strlen("chargingSchedulePeriod");
  5086. pch = strtok(loc ,"{");
  5087. while (pch != NULL)
  5088. {
  5089. strcpy(SchedulePeriodList[i], pch);
  5090. pch = strtok (NULL, "{");
  5091. i = i + 1;
  5092. }
  5093. n_SchedulePeriods = i;
  5094. for(int i=0;i<n_SchedulePeriods;i++)
  5095. {
  5096. //*************startPeriod****************/
  5097. c = 0;
  5098. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5099. memset(sstr ,0, sizeof(sstr) );
  5100. while (loc[strlen("startPeriod")+2+c] != ',')
  5101. {
  5102. sstr[c] = loc[strlen("startPeriod")+2+c];
  5103. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5104. c++;
  5105. }
  5106. sstr[c] = '\0';
  5107. tempStartPeriodInt = atoi(sstr);
  5108. //*************limit****************/
  5109. c = 0;
  5110. loc = strstr(SchedulePeriodList[i], "limit");
  5111. memset(sstr ,0, sizeof(sstr) );
  5112. while (loc[strlen("limit")+2+c] != ',')
  5113. {
  5114. sstr[c] = loc[strlen("limit")+2+c];
  5115. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5116. c++;
  5117. }
  5118. sstr[c] = '\0';
  5119. tempLimitInt = atof(sstr);
  5120. //*************numberPhases****************/
  5121. c = 0;
  5122. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5123. memset(sstr ,0, sizeof(sstr) );
  5124. while (loc[strlen("numberPhases")+2+c] != '}')
  5125. {
  5126. sstr[c] = loc[strlen("numberPhases")+2+c];
  5127. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5128. c++;
  5129. }
  5130. sstr[c] = '\0';
  5131. tempNumberPhasesInt = atoi(sstr);
  5132. TxProfile.Duration = durationInt;
  5133. TxProfile.TotalPeriod = n_SchedulePeriods;
  5134. TxProfile.Period[i].Limit = tempLimitInt;
  5135. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5136. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5137. }
  5138. if(MinChargingRate < tempminChargingRateFloat)
  5139. MinChargingRate = tempminChargingRateFloat;
  5140. if(confirmPeriods < n_SchedulePeriods)
  5141. confirmPeriods = n_SchedulePeriods;
  5142. }
  5143. fclose(fptr1);
  5144. }
  5145. }// the end of ACCESS TxProfile
  5146. //CompositeSchedule
  5147. int period=0;
  5148. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5149. {
  5150. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5151. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5152. {
  5153. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5154. {
  5155. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5156. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5157. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5158. period = period + 1;
  5159. }
  5160. else
  5161. {
  5162. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5163. {
  5164. }
  5165. else
  5166. {
  5167. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5168. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5169. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5170. period = period + 1;
  5171. }
  5172. }
  5173. }
  5174. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5175. {
  5176. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5177. {
  5178. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5179. {
  5180. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5181. }
  5182. else
  5183. {
  5184. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5185. }
  5186. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5187. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5188. period = period + 1;
  5189. }
  5190. }
  5191. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5192. {
  5193. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5194. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5195. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5196. period = period + 1;
  5197. }
  5198. }
  5199. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5200. {
  5201. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5202. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5203. {
  5204. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5205. {
  5206. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5207. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5208. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5209. period = period + 1;
  5210. }
  5211. else
  5212. {
  5213. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5214. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5215. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5216. period = period + 1;
  5217. }
  5218. }
  5219. }
  5220. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5221. {
  5222. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5223. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5224. {
  5225. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5226. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5227. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5228. period = period + 1;
  5229. }
  5230. }
  5231. confirmPeriods = period;
  5232. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5233. //* Define temporary variables */
  5234. struct tm *gtime;
  5235. time_t now;
  5236. char buf[28];
  5237. //* Read the current system time */
  5238. time(&now);
  5239. //* Convert the system time to GMT (now UTC) */
  5240. gtime = gmtime(&now);
  5241. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5242. // make .conf
  5243. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5244. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5245. //DEBUG_INFO(" debug 11\n");
  5246. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5247. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5248. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5249. }
  5250. else
  5251. {
  5252. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5253. }
  5254. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5255. return result;
  5256. }
  5257. int handleGetConfigurationRequest(char *uuid, char *payload)
  5258. {
  5259. mtrace();
  5260. int result = FAIL;
  5261. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5262. //struct json_object *jsonitem;
  5263. int MaxKeySupported = 0;
  5264. int n_keys = 0;
  5265. char requestKey[43][50]={0};
  5266. char search[]="[";
  5267. char sstr[500]={ 0 };
  5268. //int pos;
  5269. int l, c = 0;
  5270. int i = 0;
  5271. char *delim = "\",\"";
  5272. char * pch;
  5273. char *loc = strstr(payload, search);
  5274. //********************* Parsing String ***********************************/
  5275. if(loc == NULL) {
  5276. DEBUG_INFO("no key match in Configuration \n");
  5277. }
  5278. else {
  5279. //pos = loc - payload;
  5280. l = strlen(loc)-4;
  5281. while (c < l)
  5282. {
  5283. sstr[c] = loc[c+2];
  5284. c++;
  5285. }
  5286. sstr[c] = '\0';
  5287. //parsing strings to words
  5288. pch = strtok(sstr,delim);
  5289. if(pch == NULL)
  5290. {
  5291. strcpy(requestKey[0], sstr);
  5292. }
  5293. else
  5294. {
  5295. while (pch != NULL)
  5296. {
  5297. strcpy(requestKey[i], pch);
  5298. pch = strtok (NULL, delim);
  5299. i = i + 1;
  5300. }
  5301. n_keys = i;
  5302. }
  5303. }
  5304. UnknownKeynum = 0;
  5305. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5306. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5307. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5308. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5309. if(n_keys != 0)
  5310. {
  5311. for(int i=0;i<n_keys;i++)
  5312. {
  5313. getKeyValue(requestKey[i]);
  5314. //json_object_put(jsonitem);
  5315. }
  5316. }
  5317. else
  5318. {
  5319. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5320. getKeyValue("");
  5321. }
  5322. processUnkownKey();
  5323. sendGetConfigurationConfirmation(uuid);
  5324. return result;
  5325. }
  5326. static char fnamePlusPath[100]={0};
  5327. static char fnamePWithNoPath[60]={0};
  5328. void checkUploadLog(void)
  5329. {
  5330. FILE *fp;
  5331. /* Open the command for reading. */
  5332. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5333. if (fp == NULL) {
  5334. printf("Failed to run command\n" );
  5335. exit(1);
  5336. }
  5337. int ftppathlen = 0;
  5338. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5339. int i = 0;
  5340. /* Read the output a line at a time - output it. */
  5341. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5342. if(i==0)
  5343. {
  5344. ftppathlen = strlen(fnamePlusPath);
  5345. printf("%s\n", fnamePlusPath);
  5346. fnamePlusPath[ftppathlen]='\0';
  5347. break;
  5348. }
  5349. i= i+1;
  5350. }
  5351. /* close */
  5352. pclose(fp);
  5353. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5354. {
  5355. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5356. {
  5357. fnamePlusPath[k]='\0';
  5358. }
  5359. }
  5360. i=1;
  5361. //char fname[60]={0};
  5362. while(i < ftppathlen)
  5363. {
  5364. int len=ftppathlen-i;
  5365. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5366. {
  5367. printf("compare '/' all right\n");
  5368. break;
  5369. }
  5370. i=i+1;
  5371. }
  5372. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5373. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5374. fnamePWithNoPath[i+1] = '\0';
  5375. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5376. {
  5377. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5378. {
  5379. fnamePWithNoPath[j]='\0';
  5380. }
  5381. }
  5382. FILE* fp1 = fopen(fnamePlusPath, "r");
  5383. if (fp1)
  5384. {
  5385. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5386. // file exists
  5387. fclose(fp1);
  5388. }
  5389. else
  5390. {
  5391. // file doesn't exist
  5392. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5393. }
  5394. }
  5395. static char GetDiagnosticspayloadData[300]={0};
  5396. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5397. {
  5398. mtrace();
  5399. int result = FAIL;
  5400. pthread_t t; // pthread 變數
  5401. system("exec /root/logPackTools 'log' 6");
  5402. #if 0
  5403. //char buffer [128];
  5404. time (&rawtime);
  5405. //printf("%ld\n", rawtime);
  5406. timeinfo = localtime (&rawtime);
  5407. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5408. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5409. if((access(fnamePlusPath,F_OK))!=-1)
  5410. {
  5411. DEBUG_INFO("fnamePlusPath exist.\n");
  5412. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5413. }
  5414. else
  5415. {
  5416. DEBUG_INFO("fnamePlusPath not exist!\n");
  5417. }
  5418. #endif
  5419. checkUploadLog();
  5420. memset(GetDiagnosticspayloadData, 0, 300);
  5421. strcpy(GetDiagnosticspayloadData, payload);
  5422. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5423. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5424. return result;
  5425. }
  5426. void* GetDiagnosticsProcess(void* data)
  5427. {
  5428. pthread_detach(pthread_self());
  5429. mtrace();
  5430. int retriesInt=0, retryIntervalInt=0;
  5431. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5432. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5433. 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};
  5434. int port=0;
  5435. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5436. int c = 0;
  5437. char *loc;
  5438. int isSuccess = FALSE;
  5439. char ftpbuf[200]={0};
  5440. //char temp[100]={0};
  5441. char * pch;
  5442. // [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"}]
  5443. char str[300]={ 0 };
  5444. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5445. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5446. DEBUG_INFO("GetDiagnosticsProcess\n");
  5447. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5448. //****************location*******************/
  5449. c = 0;
  5450. memset(sstr ,0, sizeof(sstr) );
  5451. loc = strstr(str, "location");
  5452. while (loc[3+strlen("location")+c] != '\"')
  5453. {
  5454. sstr[c] = loc[3+strlen("location")+c];
  5455. c++;
  5456. }
  5457. sstr[c] = '\0';
  5458. strcpy(locationstr,sstr);
  5459. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5460. if(strcmp(locationstr,"")==0)
  5461. {
  5462. DEBUG_INFO("location is <Empty>!\n");
  5463. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5464. goto end;
  5465. }
  5466. //****************retries*******************/
  5467. c = 0;
  5468. loc = strstr(str, "retries");
  5469. if(loc == NULL)
  5470. {
  5471. retriesIsNULL = TRUE;
  5472. }
  5473. else
  5474. {
  5475. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5476. {
  5477. sstr[c] = loc[strlen("retries")+2+c];
  5478. c++;
  5479. }
  5480. sstr[c] = '\0';
  5481. retriesInt = atoi(sstr);
  5482. }
  5483. if(retriesIsNULL == TRUE)
  5484. {
  5485. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5486. }
  5487. //****************retryInterval*******************/
  5488. c = 0;
  5489. loc = strstr(str, "retryInterval");
  5490. if(loc == NULL)
  5491. {
  5492. retryIntervalIsNULL = TRUE;
  5493. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5494. }
  5495. else
  5496. {
  5497. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5498. {
  5499. sstr[c] = loc[strlen("retryInterval")+2+c];
  5500. c++;
  5501. }
  5502. sstr[c] = '\0';
  5503. retryIntervalInt = atoi(sstr);
  5504. }
  5505. //****************startTime*******************/
  5506. c = 0;
  5507. memset(sstr ,0, sizeof(sstr) );
  5508. loc = strstr(str, "startTime");
  5509. if(loc == NULL)
  5510. {
  5511. startTimeIsNULL = TRUE;
  5512. }
  5513. else
  5514. {
  5515. while (loc[3+strlen("startTime")+c] != '\"')
  5516. {
  5517. sstr[c] = loc[3+strlen("startTime")+c];
  5518. c++;
  5519. }
  5520. sstr[c] = '\0';
  5521. strcpy(startTimestr,sstr);
  5522. }
  5523. //****************stopTime*******************/
  5524. c = 0;
  5525. memset(sstr ,0, sizeof(sstr) );
  5526. loc = strstr(str, "stopTime");
  5527. if(loc == NULL)
  5528. {
  5529. stopTimeIsNULL = TRUE;
  5530. }
  5531. else
  5532. {
  5533. while (loc[3+strlen("stopTime")+c] != '\"')
  5534. {
  5535. sstr[c] = loc[3+strlen("stopTime")+c];
  5536. c++;
  5537. }
  5538. sstr[c] = '\0';
  5539. strcpy(stopTimestr,sstr);
  5540. }
  5541. memset(protocol, 0, sizeof(protocol));
  5542. memset(user, 0, sizeof(user) );
  5543. memset(password, 0, sizeof(password));
  5544. memset(host, 0, sizeof(host));
  5545. memset(path, 0, sizeof(path));
  5546. memset(ftppath, 0, sizeof(ftppath));
  5547. memset(host1, 0, sizeof(host1));
  5548. memset(path1, 0, sizeof(path1));
  5549. /*location: ftp://user:password@host:port/path*/
  5550. #if 0
  5551. time_t rawtime;
  5552. struct tm * timeinfo;
  5553. //char buffer [128];
  5554. time (&rawtime);
  5555. //printf("%ld\n", rawtime);
  5556. timeinfo = localtime (&rawtime);
  5557. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5558. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5559. #endif
  5560. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5561. if((access(fnamePlusPath,F_OK))!=-1)
  5562. {
  5563. DEBUG_INFO("fnamePlusPath exist.\n");
  5564. }
  5565. else
  5566. {
  5567. DEBUG_INFO("fnamePlusPath not exist!\n");
  5568. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5569. goto end;
  5570. }
  5571. pch=strchr(locationstr,'@');
  5572. if(pch==NULL)
  5573. {
  5574. sscanf(locationstr,
  5575. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5576. protocol, host, &port, path);
  5577. strcpy(user,"anonymous");
  5578. strcpy(password,"");
  5579. }
  5580. else
  5581. {
  5582. //DEBUG_INFO("pch=%s\n", pch);
  5583. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5584. protocol, user, password, host, &port, path);
  5585. }
  5586. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5587. {
  5588. DEBUG_INFO("protocol is not ftp/http ! \n");
  5589. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5590. goto end;
  5591. }
  5592. if(strncmp(locationstr,"http", 4) == 0)
  5593. {
  5594. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  5595. sprintf(ftppath,"/%s", path);
  5596. do{
  5597. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5598. sleep(retryIntervalInt);
  5599. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5600. if(!isSuccess)
  5601. {
  5602. DEBUG_INFO("Diagnostics fail.\n");
  5603. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5604. }
  5605. else
  5606. {
  5607. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5608. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5609. }
  5610. }
  5611. else
  5612. {
  5613. sscanf(host,"%[^/]%s",host1, path1);
  5614. sprintf(ftppath,"%s", path1);
  5615. int ftppathlen=strlen(ftppath);
  5616. int i=1;
  5617. char filenametemp[50];
  5618. while(i < ftppathlen)
  5619. {
  5620. int len=ftppathlen-i;
  5621. if(ftppath[len]== 47) // '/' ascll code: 47
  5622. {
  5623. DEBUG_INFO("find '/' all right\n");
  5624. break;
  5625. }
  5626. i=i+1;
  5627. }
  5628. memset(filenametemp, 0, sizeof(filenametemp));
  5629. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5630. filenametemp[i+1] = 0;
  5631. memset(ftpbuf, 0, sizeof(ftpbuf));
  5632. if(port == 0)
  5633. port = 21;
  5634. do{
  5635. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5636. sleep(retryIntervalInt);
  5637. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5638. if(!isSuccess)
  5639. {
  5640. DEBUG_INFO("Diagnostics fail.\n");
  5641. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5642. }
  5643. else
  5644. {
  5645. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5646. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5647. }
  5648. }
  5649. end:
  5650. DiagnosticsStatusNotificationStatus = 0; //Idle
  5651. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5652. }
  5653. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5654. {
  5655. mtrace();
  5656. int result = FAIL;
  5657. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5658. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5659. {
  5660. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5661. localversion = -1;
  5662. }
  5663. else
  5664. {
  5665. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5666. OCPP_getListVerion();
  5667. }
  5668. //from db.OCPP_getListVerion
  5669. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5670. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5671. sendGetLocalListVersionConfirmation(uuid,"");
  5672. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5673. return result;
  5674. }
  5675. int handleRemoteStartRequest(char *uuid, char *payload)
  5676. {
  5677. mtrace();
  5678. int result = FAIL;
  5679. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5680. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5681. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5682. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5683. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5684. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5685. int chargingSchedulePeriodCount = 0;
  5686. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5687. int c = 0;
  5688. char *loc;
  5689. char comfirmstr[20]={0};
  5690. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5691. if(server_pending == TRUE)
  5692. {
  5693. return 0;
  5694. }
  5695. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5696. //**********connectorId****************/
  5697. c = 0;
  5698. memset(sstr ,0, sizeof(sstr) );
  5699. loc = strstr(payload, "connectorId");
  5700. if(loc == NULL)
  5701. {
  5702. connectorIdIsNULL = TRUE;
  5703. }
  5704. else
  5705. {
  5706. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5707. {
  5708. sstr[c] = loc[strlen("connectorId")+2+c];
  5709. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5710. c++;
  5711. }
  5712. sstr[c] = '\0';
  5713. connectorIdInt = atoi(sstr);
  5714. }
  5715. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  5716. {
  5717. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5718. goto end;
  5719. }
  5720. //****************idTag*******************/
  5721. c = 0;
  5722. memset(sstr ,0, sizeof(sstr) );
  5723. loc = strstr(payload, "idTag");
  5724. while (loc[3+strlen("idTag")+c] != '\"')
  5725. {
  5726. sstr[c] = loc[3+strlen("idTag")+c];
  5727. c++;
  5728. }
  5729. sstr[c] = '\0';
  5730. strcpy(idTagstr,sstr);
  5731. //****************chargingProfile*******************/
  5732. c = 0;
  5733. memset(sstr ,0, sizeof(sstr) );
  5734. loc = strstr(payload, "chargingProfile");
  5735. if(loc == NULL)
  5736. {
  5737. chargingProfileIsNULL = TRUE;
  5738. }
  5739. else
  5740. {
  5741. //****************chargingProfileId*******************/
  5742. c=0;
  5743. loc = strstr(payload, "chargingProfileId");
  5744. memset(sstr ,0, sizeof(sstr) );
  5745. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5746. {
  5747. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5748. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5749. c++;
  5750. }
  5751. sstr[c] = '\0';
  5752. chargingProfileIdInt = atoi(sstr);
  5753. //****************transactionId*******************/
  5754. loc = strstr(payload, "transactionId");
  5755. if(loc == NULL)
  5756. {
  5757. transactionIdIsNULL = TRUE;
  5758. }
  5759. else
  5760. {
  5761. c=0;
  5762. memset(sstr ,0, sizeof(sstr) );
  5763. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5764. {
  5765. sstr[c] = loc[strlen("transactionId")+2+c];
  5766. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5767. c++;
  5768. }
  5769. sstr[c] = '\0';
  5770. transactionIdInt = atoi(sstr);
  5771. }
  5772. //****************stackLevel*******************/
  5773. c=0;
  5774. loc = strstr(payload, "stackLevel");
  5775. memset(sstr ,0, sizeof(sstr) );
  5776. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5777. {
  5778. sstr[c] = loc[strlen("stackLevel")+2+c];
  5779. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5780. c++;
  5781. }
  5782. sstr[c] = '\0';
  5783. stackLevelInt = atoi(sstr);
  5784. //****************chargingProfilePurpose*******************/
  5785. c = 0;
  5786. memset(sstr ,0, sizeof(sstr) );
  5787. loc = strstr(payload, "chargingProfilePurpose");
  5788. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5789. {
  5790. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5791. c++;
  5792. }
  5793. sstr[c] = '\0';
  5794. strcpy(chargingProfilePurposestr,sstr);
  5795. //****************chargingProfileKind*******************/
  5796. c = 0;
  5797. memset(sstr ,0, sizeof(sstr) );
  5798. loc = strstr(payload, "chargingProfileKind");
  5799. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5800. {
  5801. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5802. c++;
  5803. }
  5804. sstr[c] = '\0';
  5805. strcpy(chargingProfileKindstr,sstr);
  5806. //****************recurrencyKind*******************/
  5807. loc = strstr(payload, "recurrencyKind");
  5808. if(loc == NULL)
  5809. {
  5810. recurrencyKindIsNULL = TRUE;
  5811. }
  5812. else
  5813. {
  5814. c = 0;
  5815. memset(sstr ,0, sizeof(sstr) );
  5816. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5817. {
  5818. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5819. c++;
  5820. }
  5821. sstr[c] = '\0';
  5822. strcpy(recurrencyKindstr,sstr);
  5823. }
  5824. //****************validFrom*******************/
  5825. loc = strstr(payload, "validFrom");
  5826. if(loc == NULL)
  5827. {
  5828. validFromIsNULL = TRUE;
  5829. }
  5830. else
  5831. {
  5832. c = 0;
  5833. memset(sstr ,0, sizeof(sstr) );
  5834. while (loc[3+strlen("validFrom")+c] != '\"')
  5835. {
  5836. sstr[c] = loc[3+strlen("validFrom")+c];
  5837. c++;
  5838. }
  5839. sstr[c] = '\0';
  5840. strcpy(validFromstr,sstr);
  5841. }
  5842. //****************validTo*******************/
  5843. loc = strstr(payload, "validTo");
  5844. if(loc == NULL)
  5845. {
  5846. validToIsNULL = TRUE;
  5847. }
  5848. else
  5849. {
  5850. c = 0;
  5851. memset(sstr ,0, sizeof(sstr) );
  5852. while (loc[3+strlen("validTo")+c] != '\"')
  5853. {
  5854. sstr[c] = loc[3+strlen("validTo")+c];
  5855. c++;
  5856. }
  5857. sstr[c] = '\0';
  5858. strcpy(validTostr,sstr);
  5859. }
  5860. //****************chargingSchedule*******************/
  5861. loc = strstr(payload, "chargingSchedule");
  5862. if(loc != NULL)
  5863. {
  5864. //****************duration*******************/
  5865. loc = strstr(payload, "duration");
  5866. if(loc == NULL)
  5867. {
  5868. durationIsNULL = TRUE;
  5869. }
  5870. else
  5871. {
  5872. c=0;
  5873. memset(sstr ,0, sizeof(sstr) );
  5874. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5875. {
  5876. sstr[c] = loc[strlen("duration")+2+c];
  5877. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5878. c++;
  5879. }
  5880. sstr[c] = '\0';
  5881. durationInt = atoi(sstr);
  5882. }
  5883. //****************startSchedule******************/
  5884. loc = strstr(payload, "startSchedule");
  5885. if(loc == NULL)
  5886. {
  5887. startScheduleIsNULL = TRUE;
  5888. }
  5889. else
  5890. {
  5891. c = 0;
  5892. memset(sstr ,0, sizeof(sstr) );
  5893. while (loc[3+strlen("startSchedule")+c] != '\"')
  5894. {
  5895. sstr[c] = loc[3+strlen("startSchedule")+c];
  5896. c++;
  5897. }
  5898. sstr[c] = '\0';
  5899. strcpy(startSchedulestr,sstr);
  5900. }
  5901. //****************chargingRateUnit*******************/
  5902. c = 0;
  5903. memset(sstr ,0, sizeof(sstr) );
  5904. loc = strstr(payload, "chargingRateUnit");
  5905. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5906. {
  5907. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5908. c++;
  5909. }
  5910. sstr[c] = '\0';
  5911. strcpy(chargingRateUnitstr,sstr);
  5912. //****************minChargingRate*******************/
  5913. loc = strstr(payload, "minChargingRate");
  5914. if(loc == NULL)
  5915. {
  5916. minChargingRateIsNULL = TRUE;
  5917. }
  5918. else
  5919. {
  5920. c=0;
  5921. memset(sstr ,0, sizeof(sstr) );
  5922. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5923. {
  5924. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5925. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5926. c++;
  5927. }
  5928. sstr[c] = '\0';
  5929. minChargingRateflaot = atof(sstr);
  5930. }
  5931. //****************chargingSchedulePeriod count*******************/
  5932. int what_len = strlen("startPeriod");
  5933. char *where = payload;
  5934. while ((where = strstr(where, "startPeriod"))) {
  5935. where += what_len;
  5936. chargingSchedulePeriodCount++;
  5937. }
  5938. where = payload;
  5939. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5940. {
  5941. //****************startPeriod*******************/
  5942. c=0;
  5943. loc = strstr(where, "startPeriod");
  5944. memset(sstr ,0, sizeof(sstr) );
  5945. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5946. {
  5947. sstr[c] = loc[strlen("startPeriod")+2+c];
  5948. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5949. c++;
  5950. }
  5951. sstr[c] = '\0';
  5952. startPeriodInt[periodNums] = atoi(sstr);
  5953. //****************limit*******************/
  5954. c=0;
  5955. loc = strstr(where, "limit");
  5956. memset(sstr ,0, sizeof(sstr) );
  5957. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5958. {
  5959. sstr[c] = loc[strlen("limit")+2+c];
  5960. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5961. c++;
  5962. }
  5963. sstr[c] = '\0';
  5964. limitflaot[periodNums] = atof(sstr);
  5965. //****************numberPhases*******************/
  5966. loc = strstr(where, "numberPhases");
  5967. if(loc == NULL)
  5968. {
  5969. numberPhasesIsNULL = TRUE;
  5970. }
  5971. else
  5972. {
  5973. c=0;
  5974. memset(sstr ,0, sizeof(sstr) );
  5975. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5976. {
  5977. sstr[c] = loc[strlen("numberPhases")+2+c];
  5978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5979. c++;
  5980. }
  5981. sstr[c] = '\0';
  5982. numberPhasesInt[periodNums] = atoi(sstr);
  5983. }
  5984. where = loc;
  5985. }
  5986. }
  5987. }
  5988. /*
  5989. enum _SYSTEM_STATUS
  5990. {
  5991. S_BOOTING = 0,
  5992. S_IDLE, = 1
  5993. S_AUTHORIZING, =2
  5994. S_REASSIGN_CHECK, =3
  5995. S_REASSIGN, =4
  5996. S_PRECHARGE, =5
  5997. S_PREPARING_FOR_EV, =6
  5998. S_PREPARING_FOR_EVSE, =7
  5999. S_CHARGING, =8
  6000. S_TERMINATING, =9
  6001. S_COMPLETE, =10
  6002. S_ALARM, =11
  6003. S_FAULT =12
  6004. }
  6005. */
  6006. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6007. {
  6008. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6009. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6010. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6011. //check Transaction active
  6012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6013. {
  6014. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6017. {
  6018. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6019. {
  6020. //Reserved
  6021. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6022. }
  6023. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6024. {
  6025. //Reserved
  6026. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6027. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6028. goto end;
  6029. }
  6030. else
  6031. {
  6032. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6033. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6034. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6035. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6036. {
  6037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6038. goto end;
  6039. }
  6040. }//END FOR ELSE
  6041. }
  6042. }// END FOR CHAdeMO_QUANTITY
  6043. for (int index = 0; index < CCS_QUANTITY; index++)
  6044. {
  6045. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6046. {
  6047. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6048. {
  6049. //Reserved
  6050. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6051. }
  6052. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6053. {
  6054. //Reserved
  6055. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6056. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6057. goto end;
  6058. }
  6059. else
  6060. {
  6061. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6062. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6063. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6064. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6065. {
  6066. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6067. goto end;
  6068. }
  6069. }// END FOR ELSE
  6070. }
  6071. }// END FOR CCS_QUANTITY
  6072. for (int index = 0; index < GB_QUANTITY; index++)
  6073. {
  6074. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6075. {
  6076. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6077. {
  6078. //Reserved
  6079. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6080. }
  6081. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6082. {
  6083. //Reserved
  6084. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6086. goto end;
  6087. }
  6088. else
  6089. {
  6090. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6091. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6092. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6093. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6094. {
  6095. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6096. goto end;
  6097. }
  6098. }// END FOR ELSE
  6099. }
  6100. } // END FOR GB_QUANTITY
  6101. }
  6102. else
  6103. {
  6104. for (int index = 0; index < AC_QUANTITY; index++)
  6105. {
  6106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6107. {
  6108. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6109. {
  6110. //Reserved
  6111. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6112. }
  6113. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6114. {
  6115. //Reserved
  6116. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6117. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6118. goto end;
  6119. }
  6120. else
  6121. {
  6122. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6123. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6124. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6125. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6126. {
  6127. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6128. goto end;
  6129. }
  6130. }//END FOR ELSE
  6131. }
  6132. }// END FOR AC_QUANTITY
  6133. }
  6134. if(chargingProfileIsNULL == FALSE)
  6135. {
  6136. //ChargingProfile
  6137. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6138. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6139. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6140. if(recurrencyKindIsNULL == FALSE) //OPTION
  6141. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6142. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6143. if(transactionIdIsNULL == FALSE) // OPTION
  6144. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6145. if(validFromIsNULL == FALSE) // OPTION
  6146. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6147. if(validToIsNULL == FALSE) //OPTION
  6148. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6149. //ChargingSchedule
  6150. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6151. if(durationIsNULL == FALSE) //OPTION
  6152. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6153. if(minChargingRateIsNULL == FALSE) //OPTION
  6154. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6155. if(startScheduleIsNULL == FALSE) //OPTION
  6156. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6157. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6158. {
  6159. //ChargingSchedulePeriod
  6160. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6161. if(numberPhasesIsNULL == FALSE)
  6162. {
  6163. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6164. }
  6165. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6166. }
  6167. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6168. {
  6169. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6170. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6171. //memset idTag
  6172. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6173. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6174. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6175. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6176. }
  6177. else
  6178. {
  6179. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6180. }
  6181. }
  6182. else
  6183. {
  6184. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6185. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6186. //memset idTag
  6187. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6188. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6189. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6190. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6191. }
  6192. }
  6193. else
  6194. {
  6195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6196. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6197. }
  6198. end:
  6199. if(connectorIdIsNULL == FALSE)
  6200. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6201. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6202. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6203. //OCPP send RemoteStartConfirmation by first.
  6204. sendRemoteStartConfirmation(uuid, comfirmstr);
  6205. return result;
  6206. }
  6207. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6208. {
  6209. mtrace();
  6210. int result = FAIL;
  6211. int match = FALSE;
  6212. int GunNO = 0;
  6213. int transactionIdInt=0;
  6214. int transactionIdIsNULL= FALSE;
  6215. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6216. int c = 0;
  6217. char *loc;
  6218. char comfirmstr[20];
  6219. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6220. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6221. if(server_pending == TRUE)
  6222. {
  6223. return 0;
  6224. }
  6225. c=0;
  6226. loc = strstr(payload, "transactionId");
  6227. if(loc == NULL)
  6228. {
  6229. transactionIdIsNULL= TRUE;
  6230. }
  6231. else
  6232. {
  6233. memset(sstr ,0, sizeof(sstr) );
  6234. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6235. {
  6236. sstr[c] = loc[strlen("transactionId")+2+c];
  6237. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6238. c++;
  6239. }
  6240. sstr[c] = '\0';
  6241. transactionIdInt = atoi(sstr);
  6242. }
  6243. if(transactionIdIsNULL == FALSE)
  6244. {
  6245. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6246. {
  6247. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6248. {
  6249. //check Transaction active
  6250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6251. {
  6252. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6253. {
  6254. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6255. {
  6256. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6257. {
  6258. match = TRUE;
  6259. GunNO = gun_index;
  6260. }
  6261. }
  6262. }// END FOR CHAdeMO_QUANTITY
  6263. for (int index = 0; index < CCS_QUANTITY; index++)
  6264. {
  6265. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6266. {
  6267. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6268. {
  6269. match = TRUE;
  6270. GunNO = gun_index;
  6271. }
  6272. }
  6273. }// END FOR CCS_QUANTITY
  6274. for (int index = 0; index < GB_QUANTITY; index++)
  6275. {
  6276. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6277. {
  6278. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6279. {
  6280. match = TRUE;
  6281. GunNO = gun_index;
  6282. }
  6283. }
  6284. }// END FOR GB_QUANTITY
  6285. }
  6286. else
  6287. {
  6288. for (int index = 0; index < AC_QUANTITY; index++)
  6289. {
  6290. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6291. {
  6292. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6293. {
  6294. match = TRUE;
  6295. GunNO = gun_index;
  6296. }
  6297. }
  6298. }// END FOR CHAdeMO_QUANTITY
  6299. }// END FOR AC ELSE
  6300. }// CHECK IF ResponseTransactionId == transactionIdInt
  6301. }//END FOR
  6302. if( match == TRUE)
  6303. {
  6304. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6305. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6306. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6307. }
  6308. else
  6309. {
  6310. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6311. }
  6312. }
  6313. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6314. return result;
  6315. }
  6316. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6317. {
  6318. mtrace();
  6319. int result = FAIL;
  6320. int connectorIdInt=0, reservationIdInt=0;
  6321. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6322. char comfirmstr[20]={0};
  6323. char sstr[180]={ 0 };
  6324. int c = 0;
  6325. char *loc;
  6326. //char *ptr;
  6327. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6328. //***(1)connectorId ****/
  6329. c=0;
  6330. loc = strstr(payload, "connectorId");
  6331. memset(sstr ,0, sizeof(sstr) );
  6332. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6333. {
  6334. sstr[c] = loc[strlen("connectorId")+2+c];
  6335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6336. c++;
  6337. }
  6338. sstr[c] = '\0';
  6339. connectorIdInt = atoi(sstr);
  6340. //***(2)expiryDate ****/
  6341. loc = strstr(payload, "expiryDate");
  6342. memset(sstr ,0, sizeof(sstr) );
  6343. c = 0;
  6344. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6345. {
  6346. sstr[c] = loc[3+strlen("expiryDate")+c];
  6347. c++;
  6348. }
  6349. sstr[c] = '\0';
  6350. strcpy(expiryDatestr, sstr);
  6351. //***(3)idTag ****/
  6352. loc = strstr(payload, "idTag");
  6353. memset(sstr ,0, sizeof(sstr) );
  6354. c = 0;
  6355. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6356. {
  6357. sstr[c] = loc[3+strlen("idTag")+c];
  6358. c++;
  6359. }
  6360. sstr[c] = '\0';
  6361. strcpy(idTagstr, sstr);
  6362. //***(4)parentIdTag ****/
  6363. loc = strstr(payload, "parentIdTag");
  6364. memset(sstr ,0, sizeof(sstr) );
  6365. c = 0;
  6366. if(loc == NULL)
  6367. {
  6368. strcpy(parentIdTagstr, "");
  6369. }
  6370. else
  6371. {
  6372. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6373. {
  6374. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6375. c++;
  6376. }
  6377. sstr[c] = '\0';
  6378. strcpy(parentIdTagstr, sstr);
  6379. }
  6380. //***(5)reservationId ****/
  6381. c=0;
  6382. loc = strstr(payload, "reservationId");
  6383. memset(sstr ,0, sizeof(sstr) );
  6384. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6385. {
  6386. sstr[c] = loc[strlen("reservationId")+2+c];
  6387. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6388. c++;
  6389. }
  6390. sstr[c] = '\0';
  6391. reservationIdInt = atoi(sstr);
  6392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6393. /*
  6394. enum SYSTEM_STATUS
  6395. {
  6396. SYS_MODE_BOOTING = 0,
  6397. SYS_MODE_IDLE = 1,
  6398. SYS_MODE_AUTHORIZING = 2,
  6399. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6400. SYS_MODE_REASSIGN = 4,
  6401. SYS_MODE_PREPARING = 5,
  6402. SYS_MODE_PREPARE_FOR_EV = 6,
  6403. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6404. SYS_MODE_CHARGING = 8,
  6405. SYS_MODE_TERMINATING = 9,
  6406. SYS_MODE_COMPLETE = 10,
  6407. SYS_MODE_ALARM = 11,
  6408. SYS_MODE_FAULT = 12,
  6409. SYS_MODE_RESERVATION = 13,
  6410. SYS_MODE_BOOKING = 14,
  6411. SYS_MODE_MAINTAIN = 15,
  6412. SYS_MODE_DEBUG = 16,
  6413. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6414. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6415. SYS_MODE_UPDATE = 19
  6416. };
  6417. */
  6418. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6419. {
  6420. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6421. goto end;
  6422. }
  6423. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6424. {
  6425. //check Transaction active
  6426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6427. {
  6428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6429. {
  6430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6431. {
  6432. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6433. {
  6434. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6435. {
  6436. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6437. {
  6438. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6440. }
  6441. 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'))
  6442. {
  6443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6444. }
  6445. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6446. {
  6447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6448. }
  6449. else
  6450. {
  6451. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6452. }
  6453. }
  6454. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6455. {
  6456. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6457. }
  6458. }
  6459. else
  6460. {
  6461. //replace reservation
  6462. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6464. }
  6465. }
  6466. } // END FOR CHAdeMO_QUANTITY
  6467. for (int index = 0; index < CCS_QUANTITY; index++)
  6468. {
  6469. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6470. {
  6471. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6472. {
  6473. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6474. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6475. {
  6476. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6477. {
  6478. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6480. }
  6481. 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'))
  6482. {
  6483. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6484. }
  6485. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6486. {
  6487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6488. }
  6489. else
  6490. {
  6491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6492. }
  6493. }
  6494. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6495. {
  6496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6497. }
  6498. }
  6499. else
  6500. {
  6501. //replace reservation
  6502. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6503. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6504. }
  6505. }
  6506. } // END FOR CCS_QUANTITY
  6507. for (int index = 0; index < GB_QUANTITY; index++)
  6508. {
  6509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6510. {
  6511. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6512. {
  6513. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6514. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6515. {
  6516. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6517. {
  6518. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6519. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6520. }
  6521. 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'))
  6522. {
  6523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6524. }
  6525. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6526. {
  6527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6528. }
  6529. else
  6530. {
  6531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6532. }
  6533. }
  6534. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6535. {
  6536. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6537. }
  6538. }
  6539. else
  6540. {
  6541. //replace reservation
  6542. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6544. }
  6545. }
  6546. }// END FOR GB_QUANTITY
  6547. }
  6548. else
  6549. {
  6550. for (int index = 0; index < AC_QUANTITY; index++)
  6551. {
  6552. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6553. {
  6554. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6555. {
  6556. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6557. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6558. {
  6559. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6560. {
  6561. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6562. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6563. }
  6564. 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'))
  6565. {
  6566. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6567. }
  6568. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6569. {
  6570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6571. }
  6572. else
  6573. {
  6574. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6575. }
  6576. }
  6577. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6578. {
  6579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6580. }
  6581. }
  6582. else
  6583. {
  6584. //replace reservation
  6585. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6587. }
  6588. }
  6589. } // END FOR AC_QUANTITY
  6590. }//END FOR AC ELSE
  6591. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6592. }
  6593. else if(connectorIdInt == 0)
  6594. {
  6595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6596. {
  6597. //check Transaction active
  6598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6599. {
  6600. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6601. {
  6602. 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'))
  6603. {
  6604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6605. goto end;
  6606. }
  6607. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6608. {
  6609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6610. goto end;
  6611. }
  6612. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6613. {
  6614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6615. goto end;
  6616. }
  6617. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6618. {
  6619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6620. goto end;
  6621. }
  6622. }
  6623. }// END FOR CHAdeMO_QUANTITY
  6624. for (int index = 0; index < CCS_QUANTITY; index++)
  6625. {
  6626. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6627. {
  6628. 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'))
  6629. {
  6630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6631. }
  6632. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6633. {
  6634. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6635. }
  6636. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6637. {
  6638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6639. }
  6640. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6641. {
  6642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6643. }
  6644. }
  6645. } // END FOR CCS_QUANTITY
  6646. for (int index = 0; index < GB_QUANTITY; index++)
  6647. {
  6648. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6649. {
  6650. 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'))
  6651. {
  6652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6653. }
  6654. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6655. {
  6656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6657. }
  6658. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6659. {
  6660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6661. }
  6662. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6663. {
  6664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6665. }
  6666. }
  6667. } // END FOR GB_QUANTITY
  6668. }
  6669. else
  6670. {
  6671. for (int index = 0; index < AC_QUANTITY; index++)
  6672. {
  6673. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6674. {
  6675. 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'))
  6676. {
  6677. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6678. goto end;
  6679. }
  6680. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6681. {
  6682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6683. goto end;
  6684. }
  6685. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6686. {
  6687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6688. goto end;
  6689. }
  6690. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6691. {
  6692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6693. goto end;
  6694. }
  6695. }
  6696. }// END FOR AC_QUANTITY
  6697. }
  6698. //The connectorId is 0
  6699. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6701. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6702. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6703. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6704. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6705. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6706. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6707. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6708. result = TRUE;
  6709. return result;
  6710. }
  6711. else
  6712. {
  6713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6714. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6715. }
  6716. if(strcmp(comfirmstr,"Accepted") == 0)
  6717. {
  6718. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6719. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6720. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6721. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6722. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6723. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6724. result = TRUE;
  6725. return result;
  6726. }
  6727. end:
  6728. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6729. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6730. return result;
  6731. }
  6732. int handleResetRequest(char *uuid, char *payload)
  6733. {
  6734. mtrace();
  6735. int result = FAIL;
  6736. char sstr[10]={0};
  6737. char typestr[10]={0};
  6738. char comfirmstr[20]={0};
  6739. int c = 0;
  6740. char *loc;
  6741. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6742. DEBUG_INFO("handleResetRequest ...\n");
  6743. loc = strstr(payload, "type");
  6744. memset(sstr ,0, sizeof(sstr) );
  6745. c = 0;
  6746. while (loc[3+strlen("type")+c] != '\"')
  6747. {
  6748. sstr[c] = loc[3+strlen("type")+c];
  6749. c++;
  6750. }
  6751. sstr[c] = '\0';
  6752. strcpy(typestr,sstr);
  6753. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6754. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6755. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6756. {
  6757. //check Transaction active
  6758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6759. {
  6760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6761. {
  6762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6763. {
  6764. //0: unplug, 1: Plug-in
  6765. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6766. }
  6767. }
  6768. for (int index = 0; index < CCS_QUANTITY; index++)
  6769. {
  6770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6771. {
  6772. //0: unplug, 1: Plug-in
  6773. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6774. }
  6775. }
  6776. for (int index = 0; index < GB_QUANTITY; index++)
  6777. {
  6778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6779. {
  6780. //0: unplug, 1: Plug-in
  6781. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6782. }
  6783. }
  6784. }
  6785. else
  6786. {
  6787. for (int index = 0; index < AC_QUANTITY; index++)
  6788. {
  6789. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6790. {
  6791. //0: unplug, 1: Plug-in
  6792. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6793. }
  6794. }
  6795. }// END FOR AC ELSE
  6796. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6797. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6798. result = TRUE;
  6799. return result;
  6800. }
  6801. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6802. {
  6803. //check Transaction active
  6804. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6805. {
  6806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6807. {
  6808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6809. {
  6810. //0: unplug, 1: Plug-in
  6811. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6812. }
  6813. }
  6814. for (int index = 0; index < CCS_QUANTITY; index++)
  6815. {
  6816. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6817. {
  6818. //0: unplug, 1: Plug-in
  6819. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6820. }
  6821. }
  6822. for (int index = 0; index < GB_QUANTITY; index++)
  6823. {
  6824. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6825. {
  6826. //0: unplug, 1: Plug-in
  6827. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6828. }
  6829. }
  6830. }
  6831. else
  6832. {
  6833. for (int index = 0; index < AC_QUANTITY; index++)
  6834. {
  6835. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6836. {
  6837. //0: unplug, 1: Plug-in
  6838. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6839. }
  6840. }
  6841. }// END FOR AC ELSE
  6842. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6843. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6844. result = TRUE;
  6845. return result;
  6846. }
  6847. else
  6848. {
  6849. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6850. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6851. goto errorend;
  6852. }
  6853. errorend:
  6854. sendResetConfirmation(uuid, comfirmstr);
  6855. return result;
  6856. }
  6857. int handleSendLocalListRequest(char *uuid, char *payload)
  6858. {
  6859. mtrace();
  6860. int result = FAIL;
  6861. int listVersionInt;
  6862. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6863. char listsearch[]="listVersion";
  6864. char updateTypesearch[]="updateType";
  6865. char localAuthorizationListsearch[]="localAuthorizationList";
  6866. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6867. char CardList[500][160]={0};
  6868. char updateTypestr[15]={0};
  6869. char idTagstr[20]={0};
  6870. char parentIdTag[20]={0};
  6871. char expiryDate[30]={0};
  6872. char idTagstatus[16]={0};
  6873. int c = 0;
  6874. int i = 0;
  6875. char *delim1 = "}";
  6876. char * pch;
  6877. char *loc;
  6878. //char *ptr;
  6879. char comfirmstr[20];
  6880. //int n_localAuthorizations = 0;
  6881. int checkState_Faulted = FALSE;
  6882. DEBUG_INFO("handleSendLocalListRequest\n");
  6883. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6884. {
  6885. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6886. goto end;
  6887. }
  6888. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6889. {
  6890. //check Charge Point state
  6891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6892. {
  6893. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6894. {
  6895. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6896. }
  6897. }
  6898. for (int index = 0; index < CCS_QUANTITY; index++)
  6899. {
  6900. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6901. {
  6902. checkState_Faulted = TRUE; //OCPP Status
  6903. }
  6904. }
  6905. for (int index = 0; index < GB_QUANTITY; index++)
  6906. {
  6907. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6908. {
  6909. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6910. }
  6911. }
  6912. }
  6913. else
  6914. {
  6915. //check Charge Point state
  6916. for (int index = 0; index < AC_QUANTITY; index++)
  6917. {
  6918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6919. {
  6920. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6921. }
  6922. }
  6923. }// END FOR AC ELSE
  6924. if(checkState_Faulted == TRUE)
  6925. {
  6926. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6927. goto end;
  6928. }
  6929. //listVersion
  6930. c = 0;
  6931. loc = strstr(payload, listsearch);
  6932. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  6933. {
  6934. sstr[c] = loc[strlen("listVersion")+2+c];
  6935. c++;
  6936. }
  6937. sstr[c] = '\0';
  6938. listVersionInt = atoi(sstr);
  6939. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6940. //updateType
  6941. loc = strstr(payload, updateTypesearch);
  6942. c = 0;
  6943. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6944. {
  6945. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6946. c++;
  6947. }
  6948. sstr[c] = '\0';
  6949. strcpy(updateTypestr, sstr);
  6950. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6951. //localAuthorizationList
  6952. memset(sstr ,0, sizeof(sstr) );
  6953. loc = strstr(payload, localAuthorizationListsearch);
  6954. if(loc != NULL) // localAuthorizationList is not NULL
  6955. {
  6956. //Check UpdateType
  6957. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6958. {
  6959. //Local list full update
  6960. printf("Local list full update.\n");
  6961. OCPP_cleanLocalList();
  6962. }
  6963. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6964. {
  6965. //Local list different update
  6966. printf("Local list different update.\n");
  6967. OCPP_getListVerion();
  6968. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6969. {
  6970. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6971. goto end;
  6972. }
  6973. }
  6974. else
  6975. {
  6976. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6977. goto end;
  6978. }
  6979. c = 0;
  6980. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6981. {
  6982. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6983. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6984. c++;
  6985. }
  6986. sstr[c] = '\0';
  6987. //DEBUG_INFO("sstr=%s\n", sstr);
  6988. //parsing strings to words
  6989. i = 0;
  6990. pch = strtok(sstr,delim1);
  6991. while (pch != NULL)
  6992. {
  6993. strcpy(CardList[i], pch);
  6994. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  6995. pch = strtok (NULL, delim1);
  6996. i = i + 1;
  6997. }
  6998. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  6999. //local Authorizations List Numbers
  7000. //n_localAuthorizations = i;
  7001. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7002. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7003. c= 0;
  7004. while(c < i)
  7005. {
  7006. //Search "IdToken"
  7007. memset(sstr ,0, sizeof(sstr) );
  7008. loc = strstr(CardList[c], "idTag");
  7009. int j = 0;
  7010. while (loc[3+strlen("idTag")+j] != '\"')
  7011. {
  7012. sstr[j] = loc[3+strlen("idTag")+j];
  7013. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7014. j++;
  7015. }
  7016. sstr[j] = '\0';
  7017. strcpy(idTagstr, sstr);
  7018. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7019. //Search "expiryDate"
  7020. memset(sstr ,0, sizeof(sstr) );
  7021. loc = strstr(CardList[c], "expiryDate");
  7022. j = 0;
  7023. if(loc != NULL)
  7024. {
  7025. while (loc[3+strlen("expiryDate")+j] != '\"')
  7026. {
  7027. sstr[j] = loc[3+strlen("expiryDate")+j];
  7028. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7029. j++;
  7030. }
  7031. sstr[j] = '\0';
  7032. strcpy(expiryDate, sstr);
  7033. }
  7034. else
  7035. {
  7036. strcpy(expiryDate, "");
  7037. }
  7038. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7039. //Search "parentIdTag"
  7040. memset(sstr ,0, sizeof(sstr) );
  7041. loc = strstr(CardList[c], "parentIdTag");
  7042. j = 0;
  7043. if(loc != NULL)
  7044. {
  7045. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7046. {
  7047. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7048. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7049. j++;
  7050. }
  7051. sstr[j] = '\0';
  7052. strcpy(parentIdTag, sstr);
  7053. }
  7054. else
  7055. {
  7056. strcpy(parentIdTag, "");
  7057. }
  7058. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7059. //Search "status"
  7060. memset(sstr ,0, sizeof(sstr) );
  7061. loc = strstr(CardList[c], "status");
  7062. j = 0;
  7063. while (loc[3+strlen("status")+j] != '\"')
  7064. {
  7065. sstr[j] = loc[3+strlen("status")+j];
  7066. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7067. j++;
  7068. }
  7069. sstr[j] = '\0';
  7070. strcpy(idTagstatus, sstr);
  7071. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7072. OCPP_getIdTag(idTagstr);
  7073. //OCPP_getIdTag("test"); For Test
  7074. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7075. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7076. {
  7077. //Local list full update
  7078. DEBUG_INFO("Local list full update.\n");
  7079. // update list
  7080. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7081. OCPP_get_TableAuthlocalAllData();
  7082. }
  7083. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7084. {
  7085. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7086. {
  7087. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7088. }
  7089. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7090. {
  7091. OCPP_deleteIdTag(idTagstr);
  7092. }
  7093. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7094. {
  7095. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7096. }
  7097. }
  7098. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7099. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7100. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7101. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7102. c++;
  7103. }
  7104. }
  7105. else
  7106. {
  7107. //Check UpdateType
  7108. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7109. {
  7110. //Local list full update
  7111. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7112. OCPP_cleanLocalList();
  7113. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7114. goto end;
  7115. }
  7116. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7117. {
  7118. //Local list different update
  7119. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7120. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7121. goto end;
  7122. }
  7123. }
  7124. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7125. end:
  7126. sendSendLocalListConfirmation(uuid, comfirmstr);
  7127. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7128. return result;
  7129. }
  7130. #define MAX 200
  7131. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7132. {
  7133. mtrace();
  7134. int result = FAIL;
  7135. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7136. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7137. char chargingProfilePurposeStr[30]={0};
  7138. char chargingProfileKindStr[16]={0};
  7139. char recurrencyKindStr[10]={0};
  7140. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7141. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7142. int chargingSchedulePeriodCount = 0;
  7143. //int updateflag = FALSE;
  7144. char comfirmstr[20]={0};
  7145. int meet= FALSE;
  7146. char sstr[10]={0};
  7147. int c = 0;
  7148. char *loc;
  7149. FILE *fptr1;//, *fptr2;
  7150. //int lno=0;//, linectr = 0;
  7151. //int modifyflag = FALSE;
  7152. char filename[MAX]={0};
  7153. char tempfile[] = "/Storage/OCPP/temp.json";
  7154. //int resultRename=0;
  7155. char rmFileCmd[50]={0};
  7156. char tempchargingProfilePurposeStr[30]={0};
  7157. //[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}}}]
  7158. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7159. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7160. //*********************connectorId***************************/
  7161. loc = strstr(payload, "connectorId");
  7162. c = 0;
  7163. memset(sstr ,0, sizeof(sstr) );
  7164. while (loc[strlen("connectorId")+2+c] != ',')
  7165. {
  7166. sstr[c] = loc[strlen("connectorId")+2+c];
  7167. c++;
  7168. }
  7169. sstr[c] = '\0';
  7170. connectorIdInt = atoi(sstr);
  7171. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7172. {
  7173. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7174. }
  7175. else
  7176. {
  7177. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7178. }
  7179. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7180. //*********************chargingProfileId***************************/
  7181. loc = strstr(payload, "chargingProfileId");
  7182. c = 0;
  7183. memset(sstr ,0, sizeof(sstr) );
  7184. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7185. {
  7186. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7187. c++;
  7188. }
  7189. sstr[c] = '\0';
  7190. chargingProfileIdInt = atoi(sstr);
  7191. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7192. {
  7193. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7194. }
  7195. else
  7196. {
  7197. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7198. }
  7199. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7200. //*********************transactionId***************************/
  7201. loc = strstr(payload, "transactionId");
  7202. if(loc != NULL)
  7203. {
  7204. c = 0;
  7205. memset(sstr ,0, sizeof(sstr) );
  7206. while (loc[strlen("transactionId")+2+c] != ',')
  7207. {
  7208. sstr[c] = loc[strlen("transactionId")+2+c];
  7209. c++;
  7210. }
  7211. sstr[c] = '\0';
  7212. transactionIdInt = atoi(sstr);
  7213. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7214. {
  7215. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7216. }
  7217. else
  7218. {
  7219. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7220. }
  7221. }
  7222. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7223. //*********************stackLevel***************************/
  7224. loc = strstr(payload, "stackLevel");
  7225. c = 0;
  7226. memset(sstr ,0, sizeof(sstr) );
  7227. while (loc[strlen("stackLevel")+2+c] != ',')
  7228. {
  7229. sstr[c] = loc[strlen("stackLevel")+2+c];
  7230. c++;
  7231. }
  7232. sstr[c] = '\0';
  7233. stackLevelInt = atoi(sstr);
  7234. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7235. {
  7236. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7237. }
  7238. else
  7239. {
  7240. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7241. }
  7242. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7243. //*********************chargingProfilePurpose***************************/
  7244. loc = strstr(payload, "chargingProfilePurpose");
  7245. c = 0;
  7246. memset(sstr ,0, sizeof(sstr) );
  7247. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7248. {
  7249. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7250. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7251. c++;
  7252. }
  7253. sstr[c] = '\0';
  7254. strcpy(chargingProfilePurposeStr,sstr);
  7255. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7256. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7257. {
  7258. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7259. }
  7260. else
  7261. {
  7262. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7263. }
  7264. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7265. //*********************chargingProfileKind***************************/
  7266. loc = strstr(payload, "chargingProfileKind");
  7267. c = 0;
  7268. memset(sstr ,0, sizeof(sstr) );
  7269. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7270. {
  7271. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7272. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7273. c++;
  7274. }
  7275. sstr[c] = '\0';
  7276. strcpy(chargingProfileKindStr,sstr);
  7277. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7278. {
  7279. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7280. }
  7281. else
  7282. {
  7283. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7284. }
  7285. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7286. //*********************recurrencyKind***************************/
  7287. loc = strstr(payload, "recurrencyKind");
  7288. if(loc != NULL)
  7289. {
  7290. c = 0;
  7291. memset(sstr ,0, sizeof(sstr) );
  7292. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7293. {
  7294. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7295. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7296. c++;
  7297. }
  7298. sstr[c] = '\0';
  7299. strcpy(recurrencyKindStr,sstr);
  7300. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7301. {
  7302. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7303. }
  7304. else
  7305. {
  7306. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7307. }
  7308. }
  7309. else
  7310. {
  7311. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7312. {
  7313. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7314. }
  7315. else
  7316. {
  7317. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7318. }
  7319. }
  7320. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7321. //*********************validFrom***************************/
  7322. loc = strstr(payload, "validFrom");
  7323. if(loc != NULL)
  7324. {
  7325. c = 0;
  7326. memset(sstr ,0, sizeof(sstr) );
  7327. while (loc[3+strlen("validFrom")+c] != '\"')
  7328. {
  7329. sstr[c] = loc[3+strlen("validFrom")+c];
  7330. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7331. c++;
  7332. }
  7333. sstr[c] = '\0';
  7334. strcpy(validFromStr,sstr);
  7335. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7336. {
  7337. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7338. }
  7339. else
  7340. {
  7341. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7342. }
  7343. }
  7344. else
  7345. {
  7346. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7347. {
  7348. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7349. }
  7350. else
  7351. {
  7352. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7353. }
  7354. }
  7355. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7356. //*********************validTo***************************/
  7357. loc = strstr(payload, "validTo");
  7358. if(loc != NULL)
  7359. {
  7360. c = 0;
  7361. memset(sstr ,0, sizeof(sstr) );
  7362. while (loc[3+strlen("validTo")+c] != '\"')
  7363. {
  7364. sstr[c] = loc[3+strlen("validTo")+c];
  7365. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7366. c++;
  7367. }
  7368. sstr[c] = '\0';
  7369. strcpy(validToStr,sstr);
  7370. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7371. {
  7372. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7373. }
  7374. else
  7375. {
  7376. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7377. }
  7378. }
  7379. else
  7380. {
  7381. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7382. {
  7383. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7384. }
  7385. else
  7386. {
  7387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7388. }
  7389. }
  7390. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7391. //*********************duration***************************/
  7392. loc = strstr(payload, "duration");
  7393. if(loc != NULL)
  7394. {
  7395. c = 0;
  7396. memset(sstr ,0, sizeof(sstr) );
  7397. while (loc[strlen("duration")+2+c] != ',')
  7398. {
  7399. sstr[c] = loc[strlen("duration")+2+c];
  7400. c++;
  7401. }
  7402. sstr[c] = '\0';
  7403. durationInt = atoi(sstr);
  7404. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7405. {
  7406. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7407. }
  7408. else
  7409. {
  7410. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7411. }
  7412. }
  7413. else
  7414. {
  7415. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7416. {
  7417. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7418. }
  7419. else
  7420. {
  7421. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7422. }
  7423. }
  7424. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7425. //*********************startSchedule***************************/
  7426. loc = strstr(payload, "startSchedule");
  7427. if(loc != NULL)
  7428. {
  7429. c = 0;
  7430. memset(sstr ,0, sizeof(sstr) );
  7431. while (loc[3+strlen("startSchedule")+c] != '\"')
  7432. {
  7433. sstr[c] = loc[3+strlen("startSchedule")+c];
  7434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7435. c++;
  7436. }
  7437. sstr[c] = '\0';
  7438. strcpy(startScheduleStr,sstr);
  7439. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7440. {
  7441. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7442. }
  7443. else
  7444. {
  7445. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7446. }
  7447. }
  7448. else
  7449. {
  7450. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7451. {
  7452. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7453. }
  7454. else
  7455. {
  7456. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7457. }
  7458. }
  7459. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7460. //*********************chargingRateUnit***************************/
  7461. loc = strstr(payload, "chargingRateUnit");
  7462. if(loc != NULL)
  7463. {
  7464. c = 0;
  7465. memset(sstr ,0, sizeof(sstr) );
  7466. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7467. {
  7468. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7469. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7470. c++;
  7471. }
  7472. sstr[c] = '\0';
  7473. strcpy(chargingRateUnitStr,sstr);
  7474. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7475. {
  7476. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7477. }
  7478. else
  7479. {
  7480. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7481. }
  7482. }
  7483. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7484. //****************chargingSchedulePeriod count start*******************/
  7485. int what_len = strlen("startPeriod");
  7486. char tempChargingProfile[1000]={0};
  7487. strcpy(tempChargingProfile,(const char*)payload);
  7488. char *where = tempChargingProfile;
  7489. if (what_len)
  7490. {
  7491. while ((where = strstr(where, "startPeriod"))) {
  7492. where += what_len;
  7493. chargingSchedulePeriodCount++;
  7494. }
  7495. }
  7496. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7497. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7498. //where = payload;
  7499. int templength = 0;
  7500. //int searchstart = 0;
  7501. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7502. {
  7503. //****************startPeriod*******************/
  7504. c=0;
  7505. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7506. memset(sstr ,0, sizeof(sstr) );
  7507. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7508. {
  7509. sstr[c] = loc[strlen("startPeriod")+2+c];
  7510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7511. c++;
  7512. }
  7513. sstr[c] = '\0';
  7514. startPeriodInt[periodNums] = atoi(sstr);
  7515. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7516. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7517. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7518. {
  7519. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7520. }
  7521. else
  7522. {
  7523. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7524. }
  7525. templength = strlen("startPeriod")+2+c;
  7526. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7527. //****************limit*******************/
  7528. c=0;
  7529. loc = strstr(tempChargingProfile + templength, "limit");
  7530. memset(sstr ,0, sizeof(sstr) );
  7531. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7532. {
  7533. sstr[c] = loc[strlen("limit")+2+c];
  7534. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7535. c++;
  7536. }
  7537. sstr[c] = '\0';
  7538. limitflaot[periodNums] = atof(sstr);
  7539. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7540. {
  7541. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7542. }
  7543. else
  7544. {
  7545. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7546. }
  7547. templength = templength + strlen("limit")+2+c;
  7548. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7549. //****************numberPhases*******************/
  7550. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7551. if(loc != NULL)
  7552. {
  7553. c=0;
  7554. memset(sstr ,0, sizeof(sstr) );
  7555. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7556. {
  7557. sstr[c] = loc[strlen("numberPhases")+2+c];
  7558. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7559. c++;
  7560. }
  7561. sstr[c] = '\0';
  7562. numberPhasesInt[periodNums] = atoi(sstr);
  7563. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7564. {
  7565. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7566. }
  7567. else
  7568. {
  7569. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7570. }
  7571. templength = templength + strlen("numberPhases")+2+c;
  7572. }
  7573. //where = loc;
  7574. }
  7575. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7576. //****************chargingSchedulePeriod count end*******************/
  7577. //*********************minChargingRate***************************/
  7578. loc = strstr(payload, "minChargingRate");
  7579. if(loc != NULL)
  7580. {
  7581. c = 0;
  7582. memset(sstr ,0, sizeof(sstr) );
  7583. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7584. {
  7585. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7586. c++;
  7587. }
  7588. sstr[c] = '\0';
  7589. minChargingRateFloat = atof(sstr);
  7590. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7591. {
  7592. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7593. }
  7594. else
  7595. {
  7596. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7597. }
  7598. }
  7599. else
  7600. {
  7601. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7602. {
  7603. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7604. }
  7605. else
  7606. {
  7607. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7608. }
  7609. }
  7610. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7611. {
  7612. //printf("set chargingProfile 1-2\n");
  7613. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7614. if(connectorIdInt != 0)
  7615. {
  7616. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7617. goto end;
  7618. }
  7619. strcpy(filename, ChargePointMaxProfile_JSON );
  7620. fptr1 = fopen(filename, "r");
  7621. if (!fptr1)
  7622. {
  7623. //file not exist
  7624. DEBUG_INFO("Unable to open the input file!!\n");
  7625. fptr1 = fopen(filename, "w+");
  7626. }
  7627. fclose(fptr1);
  7628. }
  7629. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7630. {
  7631. //printf("set chargingProfile 1-3\n");
  7632. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7633. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7634. {
  7635. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7636. goto end;
  7637. }
  7638. switch(connectorIdInt)
  7639. {
  7640. case 0:
  7641. strcpy(filename, TxDefaultProfile_0_JSON );
  7642. break;
  7643. case 1:
  7644. strcpy(filename, TxDefaultProfile_1_JSON );
  7645. break;
  7646. case 2:
  7647. strcpy(filename, TxDefaultProfile_2_JSON );
  7648. break;
  7649. default:
  7650. strcpy(filename, TxDefaultProfile_0_JSON );
  7651. break;
  7652. }
  7653. fptr1 = fopen(filename, "r");
  7654. if (!fptr1)
  7655. {
  7656. //file not exist
  7657. //DEBUG_INFO("Unable to open the input file!!\n");
  7658. fptr1 = fopen(filename, "w+");
  7659. }
  7660. fclose(fptr1);
  7661. }
  7662. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7663. {
  7664. //printf("set chargingProfile 1-4\n");
  7665. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7666. //check Transaction active
  7667. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7668. {
  7669. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7670. {
  7671. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7672. {
  7673. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7674. {
  7675. meet = TRUE;
  7676. break;
  7677. }
  7678. }
  7679. }
  7680. }
  7681. for (int index = 0; index < CCS_QUANTITY; index++)
  7682. {
  7683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7684. {
  7685. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7686. {
  7687. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7688. {
  7689. meet = TRUE;
  7690. break;
  7691. }
  7692. }
  7693. }
  7694. }
  7695. for (int index = 0; index < GB_QUANTITY; index++)
  7696. {
  7697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7698. {
  7699. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7700. {
  7701. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7702. {
  7703. meet = TRUE;
  7704. break;
  7705. }
  7706. }
  7707. }
  7708. }
  7709. if(meet == FALSE)
  7710. {
  7711. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7712. goto end;
  7713. }
  7714. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7715. {
  7716. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7717. goto end;
  7718. }
  7719. switch(connectorIdInt)
  7720. {
  7721. case 0:
  7722. break;
  7723. case 1:
  7724. strcpy(filename, TxProfile_1_JSON);
  7725. break;
  7726. case 2:
  7727. strcpy(filename, TxProfile_2_JSON);
  7728. break;
  7729. default:
  7730. strcpy(filename, TxProfile_1_JSON);
  7731. break;
  7732. }
  7733. fptr1 = fopen(filename, "r");
  7734. if (!fptr1)
  7735. {
  7736. //file not exist
  7737. DEBUG_INFO("Unable to open the input file!!\n");
  7738. fptr1 = fopen(filename, "w+");
  7739. }
  7740. fclose(fptr1);
  7741. }
  7742. //**********************************Write to File********************************************************/
  7743. FILE *infile;
  7744. FILE *outfile;
  7745. // open file for writing
  7746. infile = fopen (filename, "r");
  7747. outfile = fopen (tempfile, "w");
  7748. int d =0;
  7749. d = fgetc(infile);
  7750. //DEBUG_INFO("d:%d\n",d);
  7751. rewind(infile);
  7752. //*检测到文件结束标识返回1,否则返回0。*/
  7753. if(d == EOF)
  7754. {
  7755. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7756. fprintf(outfile,"%s\n",payload);
  7757. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7758. fclose(infile);
  7759. fclose(outfile);
  7760. sprintf(rmFileCmd,"rm -f %s",filename);
  7761. system(rmFileCmd);
  7762. rename(tempfile, filename);
  7763. #if 0
  7764. resultRename = rename(tempfile, filename);
  7765. if(resultRename == 0)
  7766. {
  7767. DEBUG_INFO("File chargingProfile renamed successfully");
  7768. }
  7769. else
  7770. {
  7771. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7772. }
  7773. #endif
  7774. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7775. //system(rmFileCmd);
  7776. }
  7777. else
  7778. {
  7779. char buf[1000]={0};
  7780. int ChargingProfileAdded = FALSE;
  7781. while (fgets(buf, sizeof(buf), infile) != NULL)
  7782. {
  7783. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7784. //*************************tempconnectorIdInt*********************************/
  7785. loc = strstr(buf, "connectorId");
  7786. c = 0;
  7787. memset(sstr ,0, sizeof(sstr) );
  7788. while (loc[strlen("connectorId")+2+c] != ',')
  7789. {
  7790. sstr[c] = loc[strlen("connectorId")+2+c];
  7791. c++;
  7792. }
  7793. sstr[c] = '\0';
  7794. tempconnectorIdInt = atoi(sstr);
  7795. //*************************tempchargingProfileIdInt*********************************/
  7796. loc = strstr(buf, "chargingProfileId");
  7797. c = 0;
  7798. memset(sstr ,0, sizeof(sstr) );
  7799. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7800. {
  7801. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7802. c++;
  7803. }
  7804. sstr[c] = '\0';
  7805. tempchargingProfileIdInt = atoi(sstr);
  7806. //*************************tempstackLevelInt*********************************/
  7807. loc = strstr(buf, "stackLevel");
  7808. c = 0;
  7809. memset(sstr ,0, sizeof(sstr) );
  7810. while (loc[strlen("stackLevel")+2+c] != ',')
  7811. {
  7812. sstr[c] = loc[strlen("stackLevel")+2+c];
  7813. c++;
  7814. }
  7815. sstr[c] = '\0';
  7816. tempstackLevelInt = atoi(sstr);
  7817. //*************************tempchargingProfilePurposeStr*********************************/
  7818. loc = strstr(payload, "chargingProfilePurpose");
  7819. c = 0;
  7820. memset(sstr ,0, sizeof(sstr) );
  7821. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7822. {
  7823. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7824. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7825. c++;
  7826. }
  7827. sstr[c] = '\0';
  7828. strcpy(tempchargingProfilePurposeStr,sstr);
  7829. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7830. {
  7831. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7832. {
  7833. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7834. if(ChargingProfileAdded == FALSE)
  7835. {
  7836. fprintf(outfile,"%s\n",payload);
  7837. ChargingProfileAdded = TRUE;
  7838. }
  7839. }
  7840. else
  7841. {
  7842. if(tempstackLevelInt < stackLevelInt)
  7843. {
  7844. if(ChargingProfileAdded == FALSE)
  7845. {
  7846. fprintf(outfile,"%s\n",payload);
  7847. ChargingProfileAdded = TRUE;
  7848. fprintf(outfile,"%s\n",buf);
  7849. }
  7850. else
  7851. {
  7852. fprintf(outfile,"%s\n",buf);
  7853. }
  7854. }
  7855. else
  7856. {
  7857. if(ChargingProfileAdded == FALSE)
  7858. {
  7859. fprintf(outfile,"%s\n",buf);
  7860. fprintf(outfile,"%s\n",payload);
  7861. ChargingProfileAdded = TRUE;
  7862. }
  7863. else
  7864. {
  7865. fprintf(outfile,"%s\n",buf);
  7866. }
  7867. }
  7868. }
  7869. }
  7870. else
  7871. {
  7872. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7873. {
  7874. if(ChargingProfileAdded == FALSE)
  7875. {
  7876. fprintf(outfile,"%s\n",payload);
  7877. ChargingProfileAdded = TRUE;
  7878. fprintf(outfile,"%s\n",buf);
  7879. }
  7880. else
  7881. {
  7882. fprintf(outfile,"%s\n",buf);
  7883. }
  7884. }
  7885. else if(tempstackLevelInt < stackLevelInt)
  7886. {
  7887. if(ChargingProfileAdded == FALSE)
  7888. {
  7889. fprintf(outfile,"%s\n",payload);
  7890. ChargingProfileAdded = TRUE;
  7891. fprintf(outfile,"%s\n",buf);
  7892. }
  7893. else
  7894. {
  7895. fprintf(outfile,"%s\n",buf);
  7896. }
  7897. }
  7898. else
  7899. {
  7900. if(ChargingProfileAdded == FALSE)
  7901. {
  7902. fprintf(outfile,"%s\n",buf);
  7903. fprintf(outfile,"%s\n",payload);
  7904. ChargingProfileAdded = TRUE;
  7905. }
  7906. else
  7907. {
  7908. fprintf(outfile,"%s\n",buf);
  7909. }
  7910. }
  7911. }
  7912. } // end of while loop
  7913. fclose(infile);
  7914. fclose(outfile);
  7915. sprintf(rmFileCmd,"rm -f %s",filename);
  7916. system(rmFileCmd);
  7917. rename(tempfile, filename);
  7918. #if 0
  7919. resultRename = rename(tempfile, filename);
  7920. if(resultRename == 0)
  7921. {
  7922. DEBUG_INFO("File chargingProfile renamed successfully");
  7923. }
  7924. else
  7925. {
  7926. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7927. }
  7928. #endif
  7929. result = TRUE;
  7930. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7931. }
  7932. end:
  7933. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7934. return result;
  7935. return result;
  7936. }
  7937. int handleTriggerMessageRequest(char *uuid, char *payload)
  7938. {
  7939. mtrace();
  7940. int result = FAIL;
  7941. int connectorIdIsNULL = FALSE;
  7942. int connectorIdInt =0;
  7943. char sstr[40]={0};
  7944. char requestedMessagestr[40]={0};
  7945. char comfirmstr[20]={0};
  7946. int c = 0;
  7947. char *loc;
  7948. DEBUG_INFO("handleTriggerMessageRequest\n");
  7949. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7950. c = 0;
  7951. loc = strstr(payload, "requestedMessage");
  7952. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7953. {
  7954. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7955. c++;
  7956. }
  7957. sstr[c] = '\0';
  7958. strcpy(requestedMessagestr, sstr);
  7959. c = 0;
  7960. loc = strstr(payload, "connectorId");
  7961. if(loc == NULL)
  7962. {
  7963. connectorIdIsNULL = TRUE;
  7964. }
  7965. else
  7966. {
  7967. memset(sstr ,0, sizeof(sstr) );
  7968. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7969. {
  7970. sstr[c] = loc[strlen("connectorId")+2+c];
  7971. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7972. c++;
  7973. }
  7974. sstr[c] = '\0';
  7975. connectorIdInt = atoi(sstr);
  7976. }
  7977. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7978. {
  7979. //connectorIdInt = json_object_get_int(connectorId);
  7980. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7981. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7982. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7983. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7984. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7985. }
  7986. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7987. {
  7988. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7989. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7990. return TRUE;
  7991. }
  7992. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7993. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7994. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7995. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7996. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7997. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7998. {
  7999. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8000. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8001. return TRUE;
  8002. }
  8003. else
  8004. {
  8005. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8006. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8007. }
  8008. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8009. {
  8010. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8011. {
  8012. FirmwareStatusNotificationStatus = 3;
  8013. }
  8014. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8015. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8016. }
  8017. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8018. {
  8019. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8020. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8021. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8022. }
  8023. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8024. {
  8025. sendBootNotificationRequest();
  8026. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8027. }
  8028. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8029. {
  8030. sendHeartbeatRequest(connectorIdInt);
  8031. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8032. }
  8033. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8034. {
  8035. if(connectorIdIsNULL == FALSE)
  8036. {
  8037. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8038. {
  8039. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8040. sendMeterValuesRequest(connectorIdInt -1);
  8041. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8042. }
  8043. }
  8044. else
  8045. {
  8046. for(int idx=0;idx< gunTotalNumber;idx++)
  8047. {
  8048. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8049. sendMeterValuesRequest(idx);
  8050. }
  8051. }
  8052. }
  8053. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8054. {
  8055. if(connectorIdIsNULL == FALSE)
  8056. {
  8057. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8058. {
  8059. sendStatusNotificationRequest(connectorIdInt -1);
  8060. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8061. }
  8062. }
  8063. else
  8064. {
  8065. for(int idx=0;idx< gunTotalNumber;idx++)
  8066. sendStatusNotificationRequest(idx);
  8067. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8068. }
  8069. }
  8070. return result;
  8071. }
  8072. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8073. {
  8074. mtrace();
  8075. int result = FAIL;
  8076. char sstr[6]={0};
  8077. int connectorIdInt =0;
  8078. char comfirmstr[20]={0};
  8079. int c = 0;
  8080. char *loc;
  8081. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8082. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8083. c = 0;
  8084. loc = strstr(payload, "connectorId");
  8085. memset(sstr ,0, sizeof(sstr) );
  8086. while (loc[strlen("connectorId")+2+c] != '}')
  8087. {
  8088. sstr[c] = loc[strlen("connectorId")+2+c];
  8089. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8090. c++;
  8091. }
  8092. sstr[c] = '\0';
  8093. connectorIdInt = atoi(sstr);
  8094. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8095. if(gunTotalNumber == 0)
  8096. {
  8097. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8098. goto end;
  8099. }
  8100. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8101. {
  8102. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8103. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8104. goto end;
  8105. }
  8106. else
  8107. {
  8108. //check Transaction active
  8109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8110. {
  8111. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8112. {
  8113. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8114. {
  8115. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8116. }
  8117. }
  8118. for (int index = 0; index < CCS_QUANTITY; index++)
  8119. {
  8120. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8121. {
  8122. //stop Transaction
  8123. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8124. }
  8125. }
  8126. for (int index = 0; index < GB_QUANTITY; index++)
  8127. {
  8128. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8129. {
  8130. //stop Transaction
  8131. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8132. }
  8133. }
  8134. }
  8135. else
  8136. {
  8137. for (int index = 0; index < AC_QUANTITY; index++)
  8138. {
  8139. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8140. {
  8141. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8142. }
  8143. }
  8144. }// END FOR AC ELSE
  8145. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8146. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8147. result = TRUE;
  8148. return result;
  8149. }
  8150. end:
  8151. //json_object_put(obj); --- remove temporally
  8152. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8153. return result;
  8154. }
  8155. static char UpdateFirmwarepayloadData[300]={0};
  8156. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8157. {
  8158. mtrace();
  8159. int result = FAIL;
  8160. pthread_t t;
  8161. sendUpdateFirmwareConfirmation(uuid);
  8162. memset(UpdateFirmwarepayloadData, 0, 300);
  8163. strcpy(UpdateFirmwarepayloadData, payload);
  8164. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8165. ////pthread_join(t, NULL); //
  8166. //pthread_detach(t);
  8167. //sendUpdateFirmwareConfirmation(uuid);
  8168. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8169. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8170. return result;
  8171. }
  8172. void *UpdateFirmwareProcess(void *data)
  8173. {
  8174. pthread_detach(pthread_self());
  8175. mtrace();
  8176. int retriesInt =0, retryIntervalInt=0;
  8177. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8178. int port=0;
  8179. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8180. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8181. //char comfirmstr[20];
  8182. int isSuccess = 0;
  8183. char ftpbuf[200];
  8184. char temp[100];
  8185. char * pch;
  8186. int retriesISNULL=FALSE;
  8187. int retryInterval=FALSE;
  8188. int c = 0;
  8189. //int i = 0;
  8190. char *loc;
  8191. char sstr[300]={ 0 };
  8192. char str[300]={ 0 };
  8193. //char *str = (char*) data; // ? ?輸入資 ?
  8194. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8195. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8196. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8197. //***************location **************/
  8198. loc = strstr(str, "location");
  8199. memset(sstr ,0, sizeof(sstr) );
  8200. c = 0;
  8201. while (loc[3+strlen("location")+c] != '\"')
  8202. {
  8203. sstr[c] = loc[3+strlen("location")+c];
  8204. c++;
  8205. }
  8206. sstr[c] = '\0';
  8207. strcpy(locationstr, sstr);
  8208. //***************retries**************/
  8209. c = 0;
  8210. loc = strstr(str, "retries");
  8211. if(loc == NULL)
  8212. {
  8213. retriesISNULL=TRUE;
  8214. }
  8215. else
  8216. {
  8217. memset(sstr ,0, sizeof(sstr) );
  8218. while (loc[strlen("retries")+2+c] != ',')
  8219. {
  8220. sstr[c] = loc[strlen("retries")+2+c];
  8221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8222. c++;
  8223. }
  8224. sstr[c] = '\0';
  8225. }
  8226. if(retriesISNULL == FALSE)
  8227. {
  8228. retriesInt = atoi(sstr);
  8229. }
  8230. //***************retrieveDate **************/
  8231. loc = strstr(str, "retrieveDate");
  8232. memset(sstr ,0, sizeof(sstr) );
  8233. c = 0;
  8234. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8235. {
  8236. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8237. c++;
  8238. }
  8239. sstr[c] = '\0';
  8240. strcpy(retrieveDatestr, sstr);
  8241. //***************retryInterval **************/
  8242. c = 0;
  8243. loc = strstr(str, "retryInterval");
  8244. memset(sstr ,0, sizeof(sstr) );
  8245. if(loc == NULL)
  8246. {
  8247. retryInterval=TRUE;
  8248. }
  8249. else
  8250. {
  8251. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8252. {
  8253. sstr[c] = loc[strlen("retryInterval")+2+c];
  8254. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8255. c++;
  8256. }
  8257. sstr[c] = '\0';
  8258. }
  8259. if(retryInterval==FALSE)
  8260. {
  8261. retryIntervalInt = atoi(sstr);
  8262. }
  8263. memset(ftppath, 0, sizeof(ftppath));
  8264. memset(path, 0, sizeof(path));
  8265. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8266. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8267. if(strncmp(locationstr,"http", 4) == 0)
  8268. {
  8269. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8270. protocol, host, path);
  8271. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8272. // protocol, user, password, host, path);
  8273. sprintf(ftppath,"/%s", path);
  8274. //DEBUG_INFO("protocol =%s\n",protocol);
  8275. //DEBUG_INFO("host =%s\n",host);
  8276. //DEBUG_INFO("path =%s\n",path);
  8277. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8278. int ftppathlen=strlen(ftppath);
  8279. int i=1;
  8280. char filenametemp[50];
  8281. while(i < ftppathlen)
  8282. {
  8283. int len=ftppathlen-i;
  8284. if(ftppath[len]== 47) // '/' ascll code: 47
  8285. {
  8286. DEBUG_INFO("compare '/' all right\n");
  8287. break;
  8288. }
  8289. i=i+1;
  8290. }
  8291. memset(filenametemp, 0, sizeof(filenametemp));
  8292. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8293. filenametemp[i+1] = 0;
  8294. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8295. do{
  8296. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8297. sleep(retryIntervalInt);
  8298. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8299. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8300. if(!isSuccess)
  8301. {
  8302. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8303. }
  8304. else
  8305. {
  8306. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8307. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8308. isUpdateRequest = TRUE;
  8309. }
  8310. }
  8311. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8312. {
  8313. memset(ftpbuf, 0, sizeof(ftpbuf));
  8314. memset(temp, 0, sizeof(temp));
  8315. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8316. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8317. int ftppathlen=strlen(ftpbuf);
  8318. int i=1;
  8319. char filenametemp[50];
  8320. while(i < ftppathlen)
  8321. {
  8322. int len=ftppathlen-i;
  8323. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8324. {
  8325. DEBUG_INFO(" compare '/' all right\n");
  8326. break;
  8327. }
  8328. i=i+1;
  8329. }
  8330. memset(filenametemp, 0, sizeof(filenametemp));
  8331. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8332. filenametemp[i+1] = 0;
  8333. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8334. pch=strchr(temp,'@');
  8335. if(pch==NULL)
  8336. {
  8337. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8338. protocol, host, &port, path);
  8339. strcpy(user,"anonymous");
  8340. strcpy(password,"");
  8341. }
  8342. else
  8343. {
  8344. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8345. protocol, user, password, host, &port, path);
  8346. }
  8347. sscanf(host,"%[^/]%s",host1, path1);
  8348. sprintf(ftppath,"%s", path1);
  8349. //DEBUG_INFO("protocol =%s\n",protocol);
  8350. //DEBUG_INFO("user =%s\n",user);
  8351. //DEBUG_INFO("password =%s\n",password);
  8352. //DEBUG_INFO("host1 =%s\n",host1);
  8353. //DEBUG_INFO("port =%d\n",port);
  8354. //DEBUG_INFO("path1 =%s\n",path1);
  8355. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8356. //ftpFile(host, user, password, port, ftppath, fname);
  8357. //download firmware pthred
  8358. if(port == 0)
  8359. {
  8360. port = 21;
  8361. }
  8362. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8363. do{
  8364. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8365. sleep(retryIntervalInt);
  8366. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8367. if(!isSuccess)
  8368. {
  8369. //BulldogUtil.sleepMs(interval*1000);
  8370. DEBUG_INFO("Update firmware request and download file fail.\n");
  8371. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8372. }
  8373. else
  8374. {
  8375. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8376. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8377. isUpdateRequest = TRUE;
  8378. }
  8379. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8380. }
  8381. else
  8382. {
  8383. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8384. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8385. }
  8386. pthread_exit(NULL);
  8387. }
  8388. //==========================================
  8389. // Handle server response routine
  8390. //==========================================
  8391. void handleAuthorizeResponse(char *payload, int gun_index)
  8392. {
  8393. mtrace();
  8394. char expiryDatestr[30]={0};
  8395. char parentIdTagstr[20]={0};
  8396. char statusstr[20]={0};
  8397. char expiryDatestrtemp[30]={0};
  8398. char parentIdTagstrtemp[20]={0};
  8399. char IdTagstrtemp[20]={0};
  8400. char statusstrtemp[20]={0};
  8401. int expiryDateISNULL=FALSE;
  8402. int parentIdTagISNULL=FALSE;
  8403. char sstr[160]={ 0 };
  8404. char* filename = AuthorizationCache_JSON;
  8405. char tempfile[] = "/Storage/OCPP/temp.json";
  8406. int c = 0;
  8407. char *loc;
  8408. int resultRename=0;
  8409. int responseIdTagInfoAsZero= 0;
  8410. char rmFileCmd[50]={0};
  8411. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8412. //***********expiryDate*************/
  8413. loc = strstr(payload, "expiryDate");
  8414. memset(sstr ,0, sizeof(sstr) );
  8415. c = 0;
  8416. if(loc == NULL)
  8417. {
  8418. expiryDateISNULL = TRUE;
  8419. }
  8420. else
  8421. {
  8422. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8423. {
  8424. sstr[c] = loc[3+strlen("expiryDate")+c];
  8425. c++;
  8426. }
  8427. sstr[c] = '\0';
  8428. strcpy(expiryDatestr, sstr);
  8429. }
  8430. //***********parentIdTag*************/
  8431. loc = strstr(payload, "parentIdTag");
  8432. memset(sstr ,0, sizeof(sstr) );
  8433. c = 0;
  8434. if(loc == NULL)
  8435. {
  8436. parentIdTagISNULL = TRUE;
  8437. }
  8438. else
  8439. {
  8440. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8441. {
  8442. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8443. c++;
  8444. }
  8445. sstr[c] = '\0';
  8446. strcpy(parentIdTagstr, sstr);
  8447. }
  8448. //***********status*************/
  8449. loc = strstr(payload, "status");
  8450. memset(sstr ,0, sizeof(sstr) );
  8451. c = 0;
  8452. while (loc[3+strlen("status")+c] != '\"')
  8453. {
  8454. sstr[c] = loc[3+strlen("status")+c];
  8455. c++;
  8456. }
  8457. sstr[c] = '\0';
  8458. strcpy(statusstr, sstr);
  8459. if(expiryDateISNULL == FALSE)
  8460. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8461. if(parentIdTagISNULL == FALSE)
  8462. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8463. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8464. //Update idTag information to authorization cache if supproted
  8465. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8466. {
  8467. if((access(filename,F_OK))!=-1)
  8468. {
  8469. printf("AuthorizationCache exist.\n");
  8470. }
  8471. else
  8472. {
  8473. printf("AuthorizationCache not exist\n");
  8474. FILE *log = fopen(filename, "w+");
  8475. if(log == NULL)
  8476. {
  8477. printf("log is NULL\n");
  8478. goto out;
  8479. }
  8480. else
  8481. {
  8482. fclose(log);
  8483. }
  8484. }
  8485. FILE *infile;
  8486. FILE *outfile;
  8487. // open file for writing
  8488. infile = fopen (filename, "r");
  8489. outfile = fopen (tempfile, "w");
  8490. //*检测到文件结束标识返回1,否则返回0。*/
  8491. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8492. int c;
  8493. c = fgetc(infile);
  8494. //DEBUG_INFO("c:%d\n",c);
  8495. rewind(infile);
  8496. if(c == EOF)
  8497. {
  8498. DEBUG_INFO("Orignal File is NULL\n");
  8499. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8500. {
  8501. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8502. }
  8503. else
  8504. {
  8505. strcpy(expiryDatestrtemp, "");
  8506. }
  8507. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8508. {
  8509. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8510. }
  8511. else
  8512. {
  8513. //write Authorize IdTag
  8514. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8515. }
  8516. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8517. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8518. fclose(infile);
  8519. fclose(outfile);
  8520. sprintf(rmFileCmd,"rm -f %s",filename);
  8521. system(rmFileCmd);
  8522. resultRename = rename(tempfile, filename);
  8523. if(resultRename == 0)
  8524. {
  8525. printf("File renamed successfully");
  8526. }
  8527. else
  8528. {
  8529. printf("Error: unable to rename the file");
  8530. }
  8531. }
  8532. else
  8533. {
  8534. char buf[160]={0};
  8535. while (fgets(buf, sizeof(buf), infile) != NULL)
  8536. {
  8537. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8538. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8539. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8540. memset(statusstr, 0, sizeof(statusstrtemp));
  8541. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8542. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8543. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8544. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8545. //------------------IdTag-----------------------
  8546. loc = strstr(buf, "idTag");
  8547. memset(sstr ,0, sizeof(sstr) );
  8548. c = 0;
  8549. while (loc[3+strlen("idTag")+c] != '\"')
  8550. {
  8551. sstr[c] = loc[3+strlen("idTag")+c];
  8552. c++;
  8553. }
  8554. sstr[c] = '\0';
  8555. strcpy(IdTagstrtemp,sstr);
  8556. //*********************expiryDate***************/
  8557. loc = strstr(buf, "expiryDate");
  8558. memset(sstr ,0, sizeof(sstr) );
  8559. c = 0;
  8560. while (loc[3+strlen("expiryDate")+c] != '\"')
  8561. {
  8562. sstr[c] = loc[3+strlen("expiryDate")+c];
  8563. c++;
  8564. }
  8565. sstr[c] = '\0';
  8566. strcpy(expiryDatestr,sstr);
  8567. //*********************parentIdTag***************/
  8568. loc = strstr(buf, "parentIdTag");
  8569. memset(sstr ,0, sizeof(sstr) );
  8570. c = 0;
  8571. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8572. {
  8573. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8574. c++;
  8575. }
  8576. sstr[c] = '\0';
  8577. strcpy(parentIdTagstr,sstr);
  8578. //*********************status***************/
  8579. loc = strstr(buf, "status");
  8580. memset(sstr ,0, sizeof(sstr) );
  8581. c = 0;
  8582. while (loc[3+strlen("status")+c] != '\"')
  8583. {
  8584. sstr[c] = loc[3+strlen("status")+c];
  8585. c++;
  8586. }
  8587. sstr[c] = '\0';
  8588. strcpy(statusstr,sstr);
  8589. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8590. {
  8591. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8592. responseIdTagInfoAsZero = 1;
  8593. }
  8594. else
  8595. {
  8596. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8597. }
  8598. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8599. {
  8600. //modify item
  8601. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8602. {
  8603. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8604. }
  8605. else
  8606. {
  8607. strcpy(expiryDatestrtemp, "");
  8608. }
  8609. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8610. {
  8611. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8612. }
  8613. else
  8614. {
  8615. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8616. }
  8617. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8618. }
  8619. else
  8620. {
  8621. //wrie original item
  8622. strcpy(expiryDatestrtemp, expiryDatestr);
  8623. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8624. strcpy(statusstrtemp, statusstr);
  8625. }
  8626. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8627. }
  8628. fclose(infile);
  8629. fclose(outfile);
  8630. sprintf(rmFileCmd,"rm -f %s",filename);
  8631. system(rmFileCmd);
  8632. resultRename = rename(tempfile, filename);
  8633. if(resultRename == 0)
  8634. {
  8635. DEBUG_INFO("File renamed successfully");
  8636. }
  8637. else
  8638. {
  8639. DEBUG_INFO("Error: unable to rename the file");
  8640. }
  8641. }
  8642. }
  8643. out:
  8644. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8645. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8646. authorizeRetryTimes = 0;
  8647. }
  8648. void handleBootNotificationResponse(char *payload, int gun_index)
  8649. {
  8650. mtrace();
  8651. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8652. char statusStr[12]={0};
  8653. char currentTimeStr[30]={0};
  8654. char *loc;
  8655. int intervalInt = 0;
  8656. int c = 0;
  8657. //double diff_t;
  8658. struct tm tp;
  8659. char buf[28]={0};
  8660. char timebuf[50]={0};
  8661. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8662. //*** interval ****/
  8663. c = 0;
  8664. loc = strstr(payload, "interval");
  8665. //printf("loc=%s\n",loc);
  8666. memset(sstr ,0, sizeof(sstr) );
  8667. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8668. {
  8669. sstr[c] = loc[strlen("interval")+2+c];
  8670. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8671. c++;
  8672. }
  8673. sstr[c] = '\0';
  8674. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8675. intervalInt = atoi(sstr);
  8676. //***status ****/
  8677. loc = strstr(payload, "status");
  8678. memset(sstr ,0, sizeof(sstr) );
  8679. c = 0;
  8680. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8681. {
  8682. sstr[c] = loc[3+strlen("status")+c];
  8683. c++;
  8684. }
  8685. sstr[c] = '\0';
  8686. strcpy(statusStr, sstr);
  8687. //***currentTime ****/
  8688. loc = strstr(payload, "currentTime");
  8689. //printf("loc=%s\n",loc);
  8690. memset(sstr ,0, sizeof(sstr) );
  8691. c = 0;
  8692. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8693. {
  8694. sstr[c] = loc[3+strlen("currentTime")+c];
  8695. c++;
  8696. }
  8697. sstr[c] = '\0';
  8698. strcpy(currentTimeStr, sstr);
  8699. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8700. HeartBeatWaitTime = BootNotificationInterval;
  8701. clientTime.Heartbeat=time((time_t*)NULL);
  8702. //write back to ShmOCPP16Data->BootNotification
  8703. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8704. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8705. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8706. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8707. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8708. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8709. {
  8710. server_sign = TRUE;
  8711. server_pending =FALSE;
  8712. }
  8713. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8714. {
  8715. server_pending = TRUE;
  8716. }
  8717. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8718. tp.tm_isdst = -1;
  8719. //time_t utc = mktime(&tp);
  8720. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8721. memset(timebuf, 0, sizeof timebuf);
  8722. sprintf(timebuf,"date -s '%s'",buf);
  8723. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8724. system(timebuf);
  8725. //==============================================
  8726. // RTC sync
  8727. //==============================================
  8728. system("/sbin/hwclock -w --systohc");
  8729. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8730. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8731. }
  8732. void handleDataTransferResponse(char *payload, int gun_index)
  8733. {
  8734. char sstr[160]={0};//sstr[200]={ 0 };
  8735. int c = 0;
  8736. char *loc;
  8737. DEBUG_INFO("handleDataTransferResponse ...\n");
  8738. loc = strstr(payload, "status");
  8739. printf("loc=%s\n",loc);
  8740. c = 0;
  8741. while (loc[3+strlen("status")+c] != '\"')
  8742. {
  8743. sstr[c] = loc[3+strlen("status")+c];
  8744. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8745. c++;
  8746. }
  8747. sstr[c] = '\0';
  8748. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8749. }
  8750. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8751. {
  8752. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8753. //struct json_object *obj;
  8754. // obj = json_tokener_parse(payload);
  8755. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8756. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8757. //No fields are defined.
  8758. }
  8759. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8760. {
  8761. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8762. //struct json_object *obj;
  8763. // obj = json_tokener_parse(payload);
  8764. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8765. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8766. //No fields are defined.
  8767. }
  8768. void handleHeartbeatResponse(char *payload, int gun_index)
  8769. {
  8770. mtrace();
  8771. //double diff_t;
  8772. struct tm tp;
  8773. char buf[28]={0};
  8774. char timebuf[50]={0};
  8775. char sstr[30]={ 0 };
  8776. int c = 0;
  8777. char *loc;
  8778. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8779. if((HeartBeatCount%360) == 0)
  8780. {
  8781. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8782. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8783. }
  8784. HeartBeatCount = HeartBeatCount + 1;
  8785. c = 0;
  8786. loc = strstr(payload, "currentTime");
  8787. memset(sstr ,0, sizeof(sstr) );
  8788. while (loc[3+strlen("currentTime")+c] != '\"')
  8789. {
  8790. sstr[c] = loc[3+strlen("currentTime")+c];
  8791. c++;
  8792. }
  8793. sstr[c] = '\0';
  8794. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8795. // #ifdef SystemLogMessage
  8796. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8797. // #endif
  8798. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8799. tp.tm_isdst = -1;
  8800. //time_t utc = mktime(&tp);
  8801. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8802. memset(timebuf, 0, sizeof timebuf);
  8803. sprintf(timebuf,"date -s '%s'",buf);
  8804. system(timebuf);
  8805. //==============================================
  8806. // RTC sync
  8807. //==============================================
  8808. system("/sbin/hwclock -w --systohc");
  8809. if(FirstHeartBeat == 0)
  8810. {
  8811. FirstHeartBeat = 1;
  8812. }
  8813. HeartBeatWithNOResponse = 0;
  8814. }
  8815. void handleMeterValuesResponse(char *payload, int gun_index)
  8816. {
  8817. mtrace();
  8818. //struct json_object *obj;
  8819. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8820. //No fields are defined.
  8821. }
  8822. void handleStartTransactionResponse(char *payload, int gun_index)
  8823. {
  8824. mtrace();
  8825. char sstr[28]={ 0 };
  8826. int c = 0;
  8827. char *loc;
  8828. int transactionIdInt = 0;
  8829. FILE *outfile;
  8830. char data[100]={0};
  8831. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8832. DEBUG_INFO("handleStartTransactionResponse\n");
  8833. //****************expiryDate********************/
  8834. loc = strstr(payload, "expiryDate");
  8835. if(loc == NULL)
  8836. {
  8837. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8838. }
  8839. else
  8840. {
  8841. c = 0;
  8842. memset(sstr ,0, sizeof(sstr) );
  8843. while (loc[3+strlen("expiryDate")+c] != '\"')
  8844. {
  8845. sstr[c] = loc[3+strlen("expiryDate")+c];
  8846. c++;
  8847. }
  8848. sstr[c] = '\0';
  8849. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8850. }
  8851. //****************parentIdTag********************/
  8852. loc = strstr(payload, "parentIdTag");
  8853. if(loc == NULL)
  8854. {
  8855. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8856. }
  8857. else
  8858. {
  8859. c = 0;
  8860. memset(sstr ,0, sizeof(sstr) );
  8861. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8862. {
  8863. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8864. c++;
  8865. }
  8866. sstr[c] = '\0';
  8867. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8868. }
  8869. //****************status********************/
  8870. loc = strstr(payload, "status");
  8871. if(loc == NULL)
  8872. {
  8873. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8874. }
  8875. else
  8876. {
  8877. c = 0;
  8878. memset(sstr ,0, sizeof(sstr) );
  8879. while (loc[3+strlen("status")+c] != '\"')
  8880. {
  8881. sstr[c] = loc[3+strlen("status")+c];
  8882. c++;
  8883. }
  8884. sstr[c] = '\0';
  8885. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8886. }
  8887. //****************transactionId********************/
  8888. c=0;
  8889. loc = strstr(payload, "transactionId");
  8890. memset(sstr ,0, sizeof(sstr) );
  8891. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8892. {
  8893. sstr[c] = loc[strlen("transactionId")+2+c];
  8894. c++;
  8895. }
  8896. sstr[c] = '\0';
  8897. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8898. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8899. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8900. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8901. //-----------Start : write to the Queue TransactionId file -----------------//
  8902. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  8903. {
  8904. //DEBUG_INFO("QueueTransactionId exist.\n");
  8905. }
  8906. else
  8907. {
  8908. //DEBUG_INFO("QueueTransactionId not exist\n");
  8909. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  8910. if(log == NULL)
  8911. {
  8912. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  8913. return ;
  8914. }
  8915. else
  8916. {
  8917. fclose(log);
  8918. }
  8919. }
  8920. // open file for writing
  8921. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  8922. //DEBUG_INFO("data=%s\n",data);
  8923. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  8924. fputs(data, outfile);
  8925. //fputs("\n", outfile);
  8926. fclose (outfile);
  8927. //-------------End: write to the Queue TransactionId file------------------------------------------//
  8928. TransactionId[gun_index] = transactionIdInt;
  8929. //DEBUG_INFO("gun_index: %d\n", gun_index);
  8930. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8931. #ifdef SystemLogMessage
  8932. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8933. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8934. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8935. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8936. #endif
  8937. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8938. {
  8939. //add Charging Record
  8940. SettingChargingRecord(gun_index, transactionIdInt);
  8941. }
  8942. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8943. }
  8944. void handleStatusNotificationResponse(char *payload, int gun_index)
  8945. {
  8946. mtrace();
  8947. printf("handleStatusNotificationResponse\n");
  8948. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8949. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8950. }
  8951. void handleStopTransactionnResponse(char *payload, int gun_index)
  8952. {
  8953. mtrace();
  8954. char sstr[30]={ 0 };
  8955. int c = 0;
  8956. char *loc;
  8957. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8958. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8959. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8960. loc = strstr(payload, "idTagInfo");
  8961. //***********************idTagInfo************************/
  8962. if(loc != NULL)
  8963. {
  8964. //***********************expiryDate************************/
  8965. loc = strstr(payload, "expiryDate");
  8966. if(loc != NULL)
  8967. {
  8968. memset(sstr ,0, sizeof(sstr) );
  8969. c = 0;
  8970. while (loc[3+strlen("expiryDate")+c] != '\"')
  8971. {
  8972. sstr[c] = loc[3+strlen("expiryDate")+c];
  8973. c++;
  8974. }
  8975. sstr[c] = '\0';
  8976. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8977. }
  8978. //***********************parentIdTag************************/
  8979. loc = strstr(payload, "parentIdTag");
  8980. if(loc != NULL)
  8981. {
  8982. memset(sstr ,0, sizeof(sstr) );
  8983. c = 0;
  8984. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8985. {
  8986. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8987. c++;
  8988. }
  8989. sstr[c] = '\0';
  8990. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8991. }
  8992. //***********************status************************/
  8993. loc = strstr(payload, "status");
  8994. memset(sstr ,0, sizeof(sstr) );
  8995. c = 0;
  8996. while (loc[3+strlen("status")+c] != '\"')
  8997. {
  8998. sstr[c] = loc[3+strlen("status")+c];
  8999. c++;
  9000. }
  9001. sstr[c] = '\0';
  9002. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9003. }
  9004. #ifdef SystemLogMessage
  9005. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9006. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9007. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9008. #endif
  9009. }
  9010. //==========================================
  9011. // Handle Error routine
  9012. //==========================================
  9013. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9014. {
  9015. mtrace();
  9016. #ifdef SystemLogMessage
  9017. DEBUG_INFO("errorCode: %s\n", errorCode);
  9018. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9019. DEBUG_INFO("errorDetails: %s\n", payload);
  9020. #endif
  9021. }
  9022. //===============================================
  9023. // Common routine
  9024. //===============================================
  9025. int initialConfigurationTable(void)
  9026. {
  9027. FILE *fp;
  9028. FILE *outfile;
  9029. char str[200]={0};
  9030. char sstr[100]={0};
  9031. int c = 0;
  9032. char *loc;
  9033. printf("initialConfigurationTable \n");
  9034. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9035. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9036. {
  9037. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9038. if(outfile == NULL) {
  9039. DEBUG_INFO("Error opening file");
  9040. return FALSE;
  9041. }
  9042. /*Core Profile*/
  9043. //AllowOfflineTxForUnknownId
  9044. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9045. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9049. //AuthorizationCacheEnabled
  9050. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9054. //AuthorizeRemoteTxRequests
  9055. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "TRUE");
  9059. //BlinkRepeat
  9060. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9064. //ClockAlignedDataInterval
  9065. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9069. //ConnectionTimeOut
  9070. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9074. //GetConfigurationMaxKeys
  9075. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9079. // HeartbeatInterval
  9080. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9084. // LightIntensity
  9085. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9089. // LocalAuthorizeOffline
  9090. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9094. // LocalPreAuthorize
  9095. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9099. // MaxEnergyOnInvalidId
  9100. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9103. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9105. // MeterValuesAlignedData
  9106. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9110. // MeterValuesAlignedDataMaxLength
  9111. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9115. // MeterValuesSampledData
  9116. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9120. // MeterValuesSampledDataMaxLength
  9121. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9125. // MeterValueSampleInterval
  9126. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9130. // MinimumStatusDuration
  9131. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9135. // NumberOfConnectors
  9136. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9138. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9139. {
  9140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9141. }
  9142. else
  9143. {
  9144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9145. }
  9146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9147. // ResetRetries
  9148. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9152. // ConnectorPhaseRotation
  9153. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9157. // ConnectorPhaseRotationMaxLength
  9158. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9162. // StopTransactionOnEVSideDisconnect
  9163. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9167. // StopTransactionOnInvalidId
  9168. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9172. // StopTxnAlignedData
  9173. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9177. // StopTxnAlignedDataMaxLength
  9178. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9182. // StopTxnSampledData
  9183. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9187. // StopTxnSampledDataMaxLength
  9188. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9191. {
  9192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9193. }
  9194. else
  9195. {
  9196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9197. }
  9198. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9200. // SupportedFeatureProfiles
  9201. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9205. // SupportedFeatureProfilesMaxLength
  9206. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9210. // TransactionMessageAttempts
  9211. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9214. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9216. // TransactionMessageRetryInterval
  9217. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9220. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9222. // UnlockConnectorOnEVSideDisconnect
  9223. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9227. // WebSocketPingInterval
  9228. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9232. //* Local Auth List Management Profile*/
  9233. #if 0
  9234. //For OCTT Test Case
  9235. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9238. #endif
  9239. #if 1
  9240. //LocalAuthListEnabled
  9241. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9245. #endif
  9246. //LocalAuthListMaxLength
  9247. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9251. //SendLocalListMaxLength
  9252. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9256. //ReserveConnectorZeroSupported
  9257. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9261. //* Smart Charging Profile */
  9262. //ChargeProfileMaxStackLevel
  9263. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9267. // ChargingScheduleAllowedChargingRateUnit
  9268. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9272. // ChargingScheduleMaxPeriods
  9273. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9277. // ConnectorSwitch3to1PhaseSupported
  9278. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9282. // MaxChargingProfilesInstalled
  9283. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9287. fclose(outfile);
  9288. }
  9289. else
  9290. {
  9291. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9292. char keystr[60]={0};
  9293. char readonlystr[10]={0};
  9294. char valuestr[100]={0};
  9295. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9296. if(fp == NULL) {
  9297. DEBUG_INFO("Error opening file");
  9298. return FALSE;
  9299. }
  9300. while( fgets (str, sizeof(str), fp)!=NULL )
  9301. {
  9302. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9303. //*************************key*********************************/
  9304. loc = strstr(str, "key");
  9305. c = 0;
  9306. memset(sstr ,0, sizeof(sstr) );
  9307. while (loc[strlen("key")+3+c] != '\"')
  9308. {
  9309. sstr[c] = loc[strlen("key")+3+c];
  9310. c++;
  9311. }
  9312. sstr[c] = '\0';
  9313. strcpy(keystr,sstr);
  9314. //*************************readonly*********************************/
  9315. loc = strstr(str, "readonly");
  9316. c = 0;
  9317. memset(sstr ,0, sizeof(sstr) );
  9318. while (loc[strlen("readonly")+2+c] != ',')
  9319. {
  9320. sstr[c] = loc[strlen("readonly")+2+c];
  9321. c++;
  9322. }
  9323. sstr[c] = '\0';
  9324. strcpy(readonlystr,sstr);
  9325. //*************************value*********************************/
  9326. loc = strstr(str, "value");
  9327. c = 0;
  9328. memset(sstr ,0, sizeof(sstr) );
  9329. while (loc[strlen("value")+3+c] != '\"')
  9330. {
  9331. sstr[c] = loc[strlen("value")+3+c];
  9332. c++;
  9333. }
  9334. sstr[c] = '\0';
  9335. strcpy(valuestr,sstr);
  9336. // DEBUG_INFO("keystr=%s\n",keystr);
  9337. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9338. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9339. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9340. {
  9341. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9342. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9344. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9345. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9346. }
  9347. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9348. {
  9349. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9350. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9352. }
  9353. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9354. {
  9355. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9357. }
  9358. if(strcmp(keystr, "BlinkRepeat") == 0)
  9359. {
  9360. //Charger.BlinkRepeat = Integer.parseInt(value);
  9361. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9363. }
  9364. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9365. {
  9366. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9368. }
  9369. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9370. {
  9371. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9373. }
  9374. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9375. {
  9376. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9378. }
  9379. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9380. {
  9381. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9383. HeartBeatWaitTime = atoi(valuestr);
  9384. }
  9385. if(strcmp(keystr, "LightIntensity") == 0)
  9386. {
  9387. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9389. }
  9390. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9391. {
  9392. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9394. }
  9395. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9396. {
  9397. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9399. }
  9400. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9401. {
  9402. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9404. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9405. }
  9406. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9407. {
  9408. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9410. }
  9411. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9412. {
  9413. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9415. }
  9416. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9417. {
  9418. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9420. }
  9421. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9422. {
  9423. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9425. }
  9426. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9427. {
  9428. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9430. }
  9431. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9432. {
  9433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9435. }
  9436. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9437. {
  9438. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9440. }
  9441. if(strcmp(keystr, "ResetRetries") == 0)
  9442. {
  9443. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9445. }
  9446. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9447. {
  9448. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9450. }
  9451. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9452. {
  9453. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9455. }
  9456. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9457. {
  9458. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9460. }
  9461. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9462. {
  9463. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9465. }
  9466. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9467. {
  9468. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9470. }
  9471. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9472. {
  9473. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9475. }
  9476. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9477. {
  9478. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9480. }
  9481. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9482. {
  9483. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9485. }
  9486. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9487. {
  9488. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9490. }
  9491. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9492. {
  9493. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9495. }
  9496. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9497. {
  9498. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9500. TransactionMessageAttemptsValue = atoi(valuestr);
  9501. }
  9502. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9503. {
  9504. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9506. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9507. }
  9508. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9509. {
  9510. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9512. }
  9513. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9514. {
  9515. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9517. }
  9518. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9519. {
  9520. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9522. }
  9523. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9524. {
  9525. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9527. }
  9528. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9529. {
  9530. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9532. }
  9533. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9534. {
  9535. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9537. }
  9538. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9539. {
  9540. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9542. }
  9543. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9544. {
  9545. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9547. }
  9548. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9549. {
  9550. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9552. }
  9553. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9554. {
  9555. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9557. }
  9558. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9559. {
  9560. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9562. }
  9563. }
  9564. fclose(fp);
  9565. }
  9566. return 0;
  9567. }
  9568. void StoreConfigurationTable(void)
  9569. {
  9570. FILE *outfile;
  9571. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9572. if(outfile == NULL)
  9573. {
  9574. DEBUG_INFO("Error opening file");
  9575. return ;
  9576. }
  9577. /*Core Profile*/
  9578. //AllowOfflineTxForUnknownId
  9579. /*
  9580. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9581. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9584. */
  9585. //DEBUG_INFO("data=%s\n",data);
  9586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9587. //AuthorizationCacheEnabled
  9588. /*
  9589. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9592. */
  9593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9594. //AuthorizeRemoteTxRequests
  9595. /*
  9596. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9599. */
  9600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9601. //BlinkRepeat
  9602. /*
  9603. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9606. */
  9607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9608. //ClockAlignedDataInterval
  9609. /*
  9610. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9613. */
  9614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9615. //ConnectionTimeOut
  9616. /*
  9617. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9620. */
  9621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9622. //GetConfigurationMaxKeys
  9623. /*
  9624. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9627. */
  9628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9629. // HeartbeatInterval
  9630. /*
  9631. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9634. */
  9635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9636. // LightIntensity
  9637. /*
  9638. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9641. */
  9642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9643. // LocalAuthorizeOffline
  9644. /*
  9645. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9648. */
  9649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9650. // LocalPreAuthorize
  9651. /*
  9652. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9655. */
  9656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9657. // MaxEnergyOnInvalidId
  9658. /*
  9659. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9662. */
  9663. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9665. // MeterValuesAlignedData
  9666. /*
  9667. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9670. */
  9671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9672. // MeterValuesAlignedDataMaxLength
  9673. /*
  9674. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9677. */
  9678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9679. // MeterValuesSampledData
  9680. /*
  9681. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9684. */
  9685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9686. // MeterValuesSampledDataMaxLength
  9687. /*
  9688. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9691. */
  9692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9693. // MeterValueSampleInterval
  9694. /*
  9695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9698. */
  9699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9700. // MinimumStatusDuration
  9701. /*
  9702. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9705. */
  9706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9707. // NumberOfConnectors
  9708. /*
  9709. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9711. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9712. {
  9713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9714. }
  9715. else
  9716. {
  9717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9718. }
  9719. */
  9720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9721. // ResetRetries
  9722. /*
  9723. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9726. */
  9727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9728. // ConnectorPhaseRotation
  9729. /*
  9730. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9733. */
  9734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9735. // ConnectorPhaseRotationMaxLength
  9736. /*
  9737. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9740. */
  9741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9742. // StopTransactionOnEVSideDisconnect
  9743. /*
  9744. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9747. */
  9748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9749. // StopTransactionOnInvalidId
  9750. /*
  9751. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9754. */
  9755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9756. // StopTxnAlignedData
  9757. /*
  9758. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9761. */
  9762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9763. // StopTxnAlignedDataMaxLength
  9764. /*
  9765. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9768. */
  9769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9770. // StopTxnSampledData
  9771. /*
  9772. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9775. */
  9776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9777. // StopTxnSampledDataMaxLength
  9778. /*
  9779. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9782. */
  9783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9784. // SupportedFeatureProfiles
  9785. /*
  9786. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9789. */
  9790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9791. // SupportedFeatureProfilesMaxLength
  9792. /*
  9793. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9796. */
  9797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9798. // TransactionMessageAttempts
  9799. /*
  9800. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9803. */
  9804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9805. // TransactionMessageRetryInterval
  9806. /*
  9807. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9810. */
  9811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9812. // UnlockConnectorOnEVSideDisconnect
  9813. /*
  9814. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9817. */
  9818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9819. // WebSocketPingInterval
  9820. /*
  9821. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9824. */
  9825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9826. //* Local Auth List Management Profile*/
  9827. //LocalAuthListEnabled
  9828. /*
  9829. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9832. */
  9833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9834. //LocalAuthListMaxLength
  9835. /*
  9836. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9839. */
  9840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9841. //SendLocalListMaxLength
  9842. /*
  9843. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9846. */
  9847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9848. //ReserveConnectorZeroSupported
  9849. /*
  9850. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9853. */
  9854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9855. //* Smart Charging Profile */
  9856. //ChargeProfileMaxStackLevel
  9857. /*
  9858. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9861. */
  9862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9863. // ChargingScheduleAllowedChargingRateUnit
  9864. /*
  9865. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9868. */
  9869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9870. // ChargingScheduleMaxPeriods
  9871. /*
  9872. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9875. */
  9876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9877. // ConnectorSwitch3to1PhaseSupported
  9878. /*
  9879. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9882. */
  9883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9884. // MaxChargingProfilesInstalled
  9885. /*
  9886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9889. */
  9890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9891. fclose(outfile);
  9892. }
  9893. void getKeyValue(char *keyReq)
  9894. {
  9895. int isEmpty = FALSE;
  9896. int isKnowKey = FALSE;
  9897. //int unKnowIndex = 0;
  9898. DEBUG_INFO("getKeyValue \n");
  9899. DEBUG_INFO("keyReq=%s \n",keyReq);
  9900. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9901. isEmpty = TRUE;
  9902. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9903. {
  9904. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9908. {
  9909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9910. }
  9911. else
  9912. {
  9913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9914. }
  9915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9916. isKnowKey = TRUE;
  9917. }
  9918. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9919. {
  9920. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9923. {
  9924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9925. }
  9926. else
  9927. {
  9928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9929. }
  9930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9931. isKnowKey = TRUE;
  9932. }
  9933. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9934. {
  9935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9938. {
  9939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9940. }
  9941. else
  9942. {
  9943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9944. }
  9945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9946. isKnowKey = TRUE;
  9947. }
  9948. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9949. {
  9950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9953. {
  9954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9955. }
  9956. else
  9957. {
  9958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9959. }
  9960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9961. isKnowKey = TRUE;
  9962. }
  9963. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9964. {
  9965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9968. {
  9969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9970. }
  9971. else
  9972. {
  9973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9974. }
  9975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9976. isKnowKey = TRUE;
  9977. }
  9978. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9979. {
  9980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9983. {
  9984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9985. }
  9986. else
  9987. {
  9988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9989. }
  9990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9991. isKnowKey = TRUE;
  9992. }
  9993. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9994. {
  9995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9998. {
  9999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10000. }
  10001. else
  10002. {
  10003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10004. }
  10005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10006. isKnowKey = TRUE;
  10007. }
  10008. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10009. {
  10010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10013. {
  10014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10015. }
  10016. else
  10017. {
  10018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10019. }
  10020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10021. isKnowKey = TRUE;
  10022. }
  10023. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10024. {
  10025. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10028. {
  10029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10030. }
  10031. else
  10032. {
  10033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10034. }
  10035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10036. isKnowKey = TRUE;
  10037. }
  10038. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10039. {
  10040. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10043. {
  10044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10045. }
  10046. else
  10047. {
  10048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10049. }
  10050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10051. isKnowKey = TRUE;
  10052. }
  10053. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10054. {
  10055. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10058. {
  10059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10060. }
  10061. else
  10062. {
  10063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10064. }
  10065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10066. isKnowKey = TRUE;
  10067. }
  10068. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10069. {
  10070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10073. {
  10074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10075. }
  10076. else
  10077. {
  10078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10079. }
  10080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10081. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10082. isKnowKey = TRUE;
  10083. }
  10084. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10085. {
  10086. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10089. {
  10090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10091. }
  10092. else
  10093. {
  10094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10095. }
  10096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10097. isKnowKey = TRUE;
  10098. }
  10099. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10100. {
  10101. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10104. {
  10105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10106. }
  10107. else
  10108. {
  10109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10110. }
  10111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10112. isKnowKey = TRUE;
  10113. }
  10114. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10115. {
  10116. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10119. {
  10120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10121. }
  10122. else
  10123. {
  10124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10125. }
  10126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10127. isKnowKey = TRUE;
  10128. }
  10129. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10130. {
  10131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10134. {
  10135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10136. }
  10137. else
  10138. {
  10139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10140. }
  10141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10142. isKnowKey = TRUE;
  10143. }
  10144. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10145. {
  10146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10149. {
  10150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10151. }
  10152. else
  10153. {
  10154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10155. }
  10156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10157. isKnowKey = TRUE;
  10158. }
  10159. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10160. {
  10161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10164. {
  10165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10166. }
  10167. else
  10168. {
  10169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10170. }
  10171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10172. isKnowKey = TRUE;
  10173. }
  10174. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10175. {
  10176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10179. {
  10180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10181. }
  10182. else
  10183. {
  10184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10185. }
  10186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10187. isKnowKey = TRUE;
  10188. }
  10189. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10190. {
  10191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10194. {
  10195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10196. }
  10197. else
  10198. {
  10199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10200. }
  10201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10202. isKnowKey = TRUE;
  10203. }
  10204. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10205. {
  10206. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10209. {
  10210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10211. }
  10212. else
  10213. {
  10214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10215. }
  10216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10217. isKnowKey = TRUE;
  10218. }
  10219. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10220. {
  10221. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10224. {
  10225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10226. }
  10227. else
  10228. {
  10229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10230. }
  10231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10232. isKnowKey = TRUE;
  10233. }
  10234. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10235. {
  10236. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10239. {
  10240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10241. }
  10242. else
  10243. {
  10244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10245. }
  10246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10247. isKnowKey = TRUE;
  10248. }
  10249. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10250. {
  10251. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10254. {
  10255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10256. }
  10257. else
  10258. {
  10259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10260. }
  10261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10262. isKnowKey = TRUE;
  10263. }
  10264. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10265. {
  10266. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10269. {
  10270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10271. }
  10272. else
  10273. {
  10274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10275. }
  10276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10277. isKnowKey = TRUE;
  10278. }
  10279. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10280. {
  10281. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10284. {
  10285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10286. }
  10287. else
  10288. {
  10289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10290. }
  10291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10292. isKnowKey = TRUE;
  10293. }
  10294. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10295. {
  10296. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10299. {
  10300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10301. }
  10302. else
  10303. {
  10304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10305. }
  10306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10307. isKnowKey = TRUE;
  10308. }
  10309. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10310. {
  10311. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10314. {
  10315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10316. }
  10317. else
  10318. {
  10319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10320. }
  10321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10322. isKnowKey = TRUE;
  10323. }
  10324. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10325. {
  10326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10329. {
  10330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10331. }
  10332. else
  10333. {
  10334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10335. }
  10336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10337. isKnowKey = TRUE;
  10338. }
  10339. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10340. {
  10341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10344. {
  10345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10346. }
  10347. else
  10348. {
  10349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10350. }
  10351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10352. isKnowKey = TRUE;
  10353. }
  10354. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10355. {
  10356. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10359. {
  10360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10361. }
  10362. else
  10363. {
  10364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10365. }
  10366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10367. isKnowKey = TRUE;
  10368. }
  10369. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10370. {
  10371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10374. {
  10375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10376. }
  10377. else
  10378. {
  10379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10380. }
  10381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10382. isKnowKey = TRUE;
  10383. }
  10384. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10385. {
  10386. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10388. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10389. {
  10390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10391. }
  10392. else
  10393. {
  10394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10395. }
  10396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10397. isKnowKey = TRUE;
  10398. }
  10399. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10400. {
  10401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10404. {
  10405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10406. }
  10407. else
  10408. {
  10409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10410. }
  10411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10412. isKnowKey = TRUE;
  10413. }
  10414. #if 0
  10415. //For OCTT Test Case
  10416. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10417. {
  10418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10420. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10421. {
  10422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10423. }
  10424. else
  10425. {
  10426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10427. }
  10428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10429. isKnowKey = TRUE;
  10430. }
  10431. #endif
  10432. #if 1
  10433. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10434. {
  10435. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10437. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10438. {
  10439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10440. }
  10441. else
  10442. {
  10443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10444. }
  10445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10446. isKnowKey = TRUE;
  10447. }
  10448. #endif
  10449. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10450. {
  10451. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10453. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10454. {
  10455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10456. }
  10457. else
  10458. {
  10459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10460. }
  10461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10462. isKnowKey = TRUE;
  10463. }
  10464. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10465. {
  10466. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10468. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10469. {
  10470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10471. }
  10472. else
  10473. {
  10474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10475. }
  10476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10477. isKnowKey = TRUE;
  10478. }
  10479. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10480. {
  10481. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10483. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10484. {
  10485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10486. }
  10487. else
  10488. {
  10489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10490. }
  10491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10492. isKnowKey = TRUE;
  10493. }
  10494. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10495. {
  10496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10498. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10499. {
  10500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10501. }
  10502. else
  10503. {
  10504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10505. }
  10506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10507. isKnowKey = TRUE;
  10508. }
  10509. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10510. {
  10511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10513. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10514. {
  10515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10516. }
  10517. else
  10518. {
  10519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10520. }
  10521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10522. isKnowKey = TRUE;
  10523. }
  10524. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10525. {
  10526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10528. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10529. {
  10530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10531. }
  10532. else
  10533. {
  10534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10535. }
  10536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10537. isKnowKey = TRUE;
  10538. }
  10539. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10540. {
  10541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10543. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10544. {
  10545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10546. }
  10547. else
  10548. {
  10549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10550. }
  10551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10552. isKnowKey = TRUE;
  10553. }
  10554. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10555. {
  10556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10558. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10559. {
  10560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10561. }
  10562. else
  10563. {
  10564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10565. }
  10566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10567. isKnowKey = TRUE;
  10568. }
  10569. //=========================================================
  10570. if(!isEmpty && !isKnowKey)
  10571. {
  10572. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10573. strcpy(unknownkey[UnknownKeynum], keyReq);
  10574. UnknownKeynum = UnknownKeynum + 1;
  10575. }
  10576. }
  10577. void processUnkownKey(void)
  10578. {
  10579. DEBUG_INFO("processUnkownKey\n");
  10580. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10581. for(int index=0; index < UnknownKeynum; index++)
  10582. {
  10583. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10584. {
  10585. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10586. }
  10587. }
  10588. }
  10589. int setKeyValue(char *key, char *value)
  10590. {
  10591. int isSuccess = NotSupported;
  10592. int check_ascii=0;
  10593. char str[10]={0};
  10594. #ifdef Debug
  10595. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10596. #endif
  10597. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10598. {
  10599. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10601. {
  10602. strcpy(str, (const char*)value);
  10603. for(int i = 0; str[i]; i++){
  10604. str[i] = tolower(str[i]);
  10605. }
  10606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10607. isSuccess = ConfigurationStatus_Accepted;
  10608. }
  10609. else
  10610. {
  10611. isSuccess = ConfigurationStatus_Rejected;
  10612. }
  10613. }
  10614. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10615. {
  10616. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10618. {
  10619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10620. isSuccess = ConfigurationStatus_Accepted;
  10621. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10622. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10623. }
  10624. else
  10625. {
  10626. isSuccess = ConfigurationStatus_Rejected;
  10627. }
  10628. }
  10629. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10630. {
  10631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10632. {
  10633. strcpy(str, (const char*)value);
  10634. for(int i = 0; str[i]; i++)
  10635. {
  10636. str[i] = tolower(str[i]);
  10637. }
  10638. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10640. isSuccess = ConfigurationStatus_Accepted;
  10641. }
  10642. else
  10643. {
  10644. isSuccess = ConfigurationStatus_Rejected;
  10645. }
  10646. }
  10647. if(strcmp(key, "BlinkRepeat") == 0)
  10648. {
  10649. //Charger.BlinkRepeat = Integer.parseInt(value);
  10650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10651. {
  10652. check_ascii = value[0];
  10653. if( (check_ascii < 48) || (check_ascii > 57) )
  10654. {
  10655. isSuccess = ConfigurationStatus_Rejected;
  10656. }
  10657. else
  10658. {
  10659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10660. isSuccess = ConfigurationStatus_Accepted;
  10661. }
  10662. }
  10663. else
  10664. {
  10665. isSuccess = ConfigurationStatus_Rejected;
  10666. }
  10667. }
  10668. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10669. {
  10670. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10671. {
  10672. check_ascii = value[0];
  10673. if( (check_ascii < 48) || (check_ascii > 57) )
  10674. {
  10675. isSuccess = ConfigurationStatus_Rejected;
  10676. }
  10677. else
  10678. {
  10679. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10681. isSuccess = ConfigurationStatus_Accepted;
  10682. }
  10683. }
  10684. else
  10685. {
  10686. isSuccess = ConfigurationStatus_Rejected;
  10687. }
  10688. }
  10689. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10690. {
  10691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10692. {
  10693. check_ascii = value[0];
  10694. if( (check_ascii < 48) || (check_ascii > 57) )
  10695. {
  10696. isSuccess = ConfigurationStatus_Rejected;
  10697. }
  10698. else
  10699. {
  10700. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10702. isSuccess = ConfigurationStatus_Accepted;
  10703. }
  10704. }
  10705. else
  10706. {
  10707. isSuccess = ConfigurationStatus_Rejected;
  10708. }
  10709. }
  10710. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10711. {
  10712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10713. {
  10714. check_ascii = value[0];
  10715. if( (check_ascii < 48) || (check_ascii > 57) )
  10716. {
  10717. isSuccess = ConfigurationStatus_Rejected;
  10718. }
  10719. else
  10720. {
  10721. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10723. isSuccess = ConfigurationStatus_Accepted;
  10724. }
  10725. }
  10726. else
  10727. {
  10728. isSuccess = ConfigurationStatus_Rejected;
  10729. }
  10730. }
  10731. if(strcmp(key, "HeartbeatInterval") == 0)
  10732. {
  10733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10734. {
  10735. check_ascii = value[0];
  10736. if( (check_ascii < 48) || (check_ascii > 57) )
  10737. {
  10738. isSuccess = ConfigurationStatus_Rejected;
  10739. }
  10740. else
  10741. {
  10742. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10744. HeartBeatWaitTime = atoi(value);
  10745. isSuccess = ConfigurationStatus_Accepted;
  10746. }
  10747. }
  10748. else
  10749. {
  10750. isSuccess = ConfigurationStatus_Rejected;
  10751. }
  10752. }
  10753. if(strcmp(key, "LightIntensity") == 0)
  10754. {
  10755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10756. {
  10757. check_ascii = value[0];
  10758. if( (check_ascii < 48) || (check_ascii > 57) )
  10759. {
  10760. isSuccess = ConfigurationStatus_Rejected;
  10761. }
  10762. else
  10763. {
  10764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10765. isSuccess = ConfigurationStatus_Accepted;
  10766. }
  10767. }
  10768. else
  10769. {
  10770. isSuccess = ConfigurationStatus_Rejected;
  10771. }
  10772. }
  10773. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10774. {
  10775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10776. {
  10777. strcpy(str, (const char*)value);
  10778. for(int i = 0; str[i]; i++)
  10779. {
  10780. str[i] = tolower(str[i]);
  10781. }
  10782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10783. isSuccess = ConfigurationStatus_Accepted;
  10784. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10785. }
  10786. else
  10787. {
  10788. isSuccess = ConfigurationStatus_Rejected;
  10789. }
  10790. }
  10791. if(strcmp(key, "LocalPreAuthorize") == 0)
  10792. {
  10793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10794. {
  10795. strcpy(str, (const char*)value);
  10796. for(int i = 0; str[i]; i++)
  10797. {
  10798. str[i] = tolower(str[i]);
  10799. }
  10800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10801. isSuccess = ConfigurationStatus_Accepted;
  10802. }
  10803. else
  10804. {
  10805. isSuccess = ConfigurationStatus_Rejected;
  10806. }
  10807. }
  10808. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10809. {
  10810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10811. {
  10812. check_ascii = value[0];
  10813. if( (check_ascii < 48) || (check_ascii > 57) )
  10814. {
  10815. isSuccess = ConfigurationStatus_Rejected;
  10816. }
  10817. else
  10818. {
  10819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10820. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10821. isSuccess = ConfigurationStatus_Accepted;
  10822. }
  10823. }
  10824. else
  10825. {
  10826. isSuccess = ConfigurationStatus_Rejected;
  10827. }
  10828. }
  10829. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10830. {
  10831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10832. {
  10833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10834. isSuccess = ConfigurationStatus_Accepted;
  10835. }
  10836. else
  10837. {
  10838. isSuccess = ConfigurationStatus_Rejected;
  10839. }
  10840. }
  10841. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10842. {
  10843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10844. {
  10845. check_ascii = value[0];
  10846. if( (check_ascii < 48) || (check_ascii > 57) )
  10847. {
  10848. isSuccess = ConfigurationStatus_Rejected;
  10849. }
  10850. else
  10851. {
  10852. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10854. isSuccess = ConfigurationStatus_Accepted;
  10855. }
  10856. }
  10857. else
  10858. {
  10859. isSuccess = ConfigurationStatus_Rejected;
  10860. }
  10861. }
  10862. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10863. {
  10864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10865. {
  10866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10867. isSuccess = ConfigurationStatus_Accepted;
  10868. }
  10869. else
  10870. {
  10871. isSuccess = ConfigurationStatus_Rejected;
  10872. }
  10873. }
  10874. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10875. {
  10876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10877. {
  10878. check_ascii = value[0];
  10879. if( (check_ascii < 48) || (check_ascii > 57) )
  10880. {
  10881. isSuccess = ConfigurationStatus_Rejected;
  10882. }
  10883. else
  10884. {
  10885. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10887. isSuccess = ConfigurationStatus_Accepted;
  10888. }
  10889. }
  10890. else
  10891. {
  10892. isSuccess = ConfigurationStatus_Rejected;
  10893. }
  10894. }
  10895. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10896. {
  10897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10898. {
  10899. check_ascii = value[0];
  10900. if( (check_ascii < 48) || (check_ascii > 57) )
  10901. {
  10902. isSuccess = ConfigurationStatus_Rejected;
  10903. }
  10904. else
  10905. {
  10906. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10908. isSuccess = ConfigurationStatus_Accepted;
  10909. }
  10910. }
  10911. else
  10912. {
  10913. isSuccess = ConfigurationStatus_Rejected;
  10914. }
  10915. }
  10916. if(strcmp(key, "MinimumStatusDuration") == 0)
  10917. {
  10918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10919. {
  10920. check_ascii = value[0];
  10921. if( (check_ascii < 48) || (check_ascii > 57) )
  10922. {
  10923. isSuccess = ConfigurationStatus_Rejected;
  10924. }
  10925. else
  10926. {
  10927. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10929. isSuccess = ConfigurationStatus_Accepted;
  10930. }
  10931. }
  10932. else
  10933. {
  10934. isSuccess = ConfigurationStatus_Rejected;
  10935. }
  10936. }
  10937. if(strcmp(key, "NumberOfConnectors") == 0)
  10938. {
  10939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10940. {
  10941. check_ascii = value[0];
  10942. if( (check_ascii < 48) || (check_ascii > 57) )
  10943. {
  10944. isSuccess = ConfigurationStatus_Rejected;
  10945. }
  10946. else
  10947. {
  10948. //Charger.ResetRetries = Integer.parseInt(value);
  10949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10950. isSuccess = ConfigurationStatus_Accepted;
  10951. }
  10952. }
  10953. else
  10954. {
  10955. isSuccess = ConfigurationStatus_Rejected;
  10956. }
  10957. }
  10958. if(strcmp(key, "ResetRetries") == 0)
  10959. {
  10960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10961. {
  10962. check_ascii = value[0];
  10963. if( (check_ascii < 48) || (check_ascii > 57) )
  10964. {
  10965. isSuccess = ConfigurationStatus_Rejected;
  10966. }
  10967. else
  10968. {
  10969. //Charger.ResetRetries = Integer.parseInt(value);
  10970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10971. isSuccess = ConfigurationStatus_Accepted;
  10972. }
  10973. }
  10974. else
  10975. {
  10976. isSuccess = ConfigurationStatus_Rejected;
  10977. }
  10978. }
  10979. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10980. {
  10981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10982. {
  10983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10984. isSuccess = ConfigurationStatus_Accepted;
  10985. }
  10986. else
  10987. {
  10988. isSuccess = ConfigurationStatus_Rejected;
  10989. }
  10990. }
  10991. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  10992. {
  10993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10994. {
  10995. check_ascii = value[0];
  10996. if( (check_ascii < 48) || (check_ascii > 57) )
  10997. {
  10998. isSuccess = ConfigurationStatus_Rejected;
  10999. }
  11000. else
  11001. {
  11002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11003. isSuccess = ConfigurationStatus_Accepted;
  11004. }
  11005. }
  11006. else
  11007. {
  11008. isSuccess = ConfigurationStatus_Rejected;
  11009. }
  11010. }
  11011. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11012. {
  11013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11014. {
  11015. strcpy(str, (const char*)value);
  11016. for(int i = 0; str[i]; i++)
  11017. {
  11018. str[i] = tolower(str[i]);
  11019. }
  11020. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11022. isSuccess = ConfigurationStatus_Accepted;
  11023. }
  11024. else
  11025. {
  11026. isSuccess = ConfigurationStatus_Rejected;
  11027. }
  11028. }
  11029. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11030. {
  11031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11032. {
  11033. strcpy(str, (const char*)value);
  11034. for(int i = 0; str[i]; i++)
  11035. {
  11036. str[i] = tolower(str[i]);
  11037. }
  11038. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11040. isSuccess = ConfigurationStatus_Accepted;
  11041. }
  11042. else
  11043. {
  11044. isSuccess = ConfigurationStatus_Rejected;
  11045. }
  11046. }
  11047. if(strcmp(key, "StopTxnAlignedData") == 0)
  11048. {
  11049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11050. {
  11051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11052. isSuccess = ConfigurationStatus_Accepted;
  11053. }
  11054. else
  11055. {
  11056. isSuccess = ConfigurationStatus_Rejected;
  11057. }
  11058. }
  11059. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11060. {
  11061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11062. {
  11063. check_ascii = value[0];
  11064. if( (check_ascii < 48) || (check_ascii > 57) )
  11065. {
  11066. isSuccess = ConfigurationStatus_Rejected;
  11067. }
  11068. else
  11069. {
  11070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11071. isSuccess = ConfigurationStatus_Accepted;
  11072. }
  11073. }
  11074. else
  11075. {
  11076. isSuccess = ConfigurationStatus_Rejected;
  11077. }
  11078. }
  11079. if(strcmp(key, "StopTxnSampledData") == 0)
  11080. {
  11081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11082. {
  11083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11084. isSuccess = ConfigurationStatus_Accepted;
  11085. }
  11086. else
  11087. {
  11088. isSuccess = ConfigurationStatus_Rejected;
  11089. }
  11090. }
  11091. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11092. {
  11093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11094. {
  11095. check_ascii = value[0];
  11096. if( (check_ascii < 48) || (check_ascii > 57) )
  11097. {
  11098. isSuccess = ConfigurationStatus_Rejected;
  11099. }
  11100. else
  11101. {
  11102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11103. isSuccess = ConfigurationStatus_Accepted;
  11104. }
  11105. }
  11106. else
  11107. {
  11108. isSuccess = ConfigurationStatus_Rejected;
  11109. }
  11110. }
  11111. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11112. {
  11113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11114. {
  11115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11116. isSuccess = ConfigurationStatus_Accepted;
  11117. }
  11118. else
  11119. {
  11120. isSuccess = ConfigurationStatus_Rejected;
  11121. }
  11122. }
  11123. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11124. {
  11125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11126. {
  11127. check_ascii = value[0];
  11128. if( (check_ascii < 48) || (check_ascii > 57) )
  11129. {
  11130. isSuccess = ConfigurationStatus_Rejected;
  11131. }
  11132. else
  11133. {
  11134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11135. isSuccess = ConfigurationStatus_Accepted;
  11136. }
  11137. }
  11138. else
  11139. {
  11140. isSuccess = ConfigurationStatus_Rejected;
  11141. }
  11142. }
  11143. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11144. {
  11145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11146. {
  11147. check_ascii = value[0];
  11148. if( (check_ascii < 48) || (check_ascii > 57) )
  11149. {
  11150. isSuccess = ConfigurationStatus_Rejected;
  11151. }
  11152. else
  11153. {
  11154. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11156. TransactionMessageAttemptsValue = atoi(value);
  11157. isSuccess = ConfigurationStatus_Accepted;
  11158. }
  11159. }
  11160. else
  11161. {
  11162. isSuccess = ConfigurationStatus_Rejected;
  11163. }
  11164. }
  11165. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11166. {
  11167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11168. {
  11169. check_ascii = value[0];
  11170. if( (check_ascii < 48) || (check_ascii > 57) )
  11171. {
  11172. isSuccess = ConfigurationStatus_Rejected;
  11173. }
  11174. else
  11175. {
  11176. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11178. TransactionMessageRetryIntervalValue = atoi(value);
  11179. isSuccess = ConfigurationStatus_Accepted;
  11180. }
  11181. }
  11182. else
  11183. {
  11184. isSuccess = ConfigurationStatus_Rejected;
  11185. }
  11186. }
  11187. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11188. {
  11189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11190. {
  11191. strcpy(str, (const char*)value);
  11192. for(int i = 0; str[i]; i++)
  11193. {
  11194. str[i] = tolower(str[i]);
  11195. }
  11196. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11198. isSuccess = ConfigurationStatus_Accepted;
  11199. }
  11200. else
  11201. {
  11202. isSuccess = ConfigurationStatus_Rejected;
  11203. }
  11204. }
  11205. if(strcmp(key, "WebSocketPingInterval") == 0)
  11206. {
  11207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11208. {
  11209. check_ascii = value[0];
  11210. if( (check_ascii < 48) || (check_ascii > 57) )
  11211. {
  11212. isSuccess = ConfigurationStatus_Rejected;
  11213. }
  11214. else
  11215. {
  11216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11217. isSuccess = ConfigurationStatus_Accepted;
  11218. }
  11219. }
  11220. else
  11221. {
  11222. isSuccess = ConfigurationStatus_Rejected;
  11223. }
  11224. }
  11225. #if 0
  11226. //For OCPP Test Case
  11227. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11228. {
  11229. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11230. {
  11231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11232. isSuccess = ConfigurationStatus_Accepted;
  11233. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11234. }
  11235. else
  11236. {
  11237. isSuccess = ConfigurationStatus_Rejected;
  11238. }
  11239. }
  11240. #endif
  11241. #if 1
  11242. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11243. {
  11244. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11245. {
  11246. strcpy(str, (const char*)value);
  11247. for(int i = 0; str[i]; i++)
  11248. {
  11249. str[i] = tolower(str[i]);
  11250. }
  11251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11252. isSuccess = ConfigurationStatus_Accepted;
  11253. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11254. }
  11255. else
  11256. {
  11257. isSuccess = ConfigurationStatus_Rejected;
  11258. }
  11259. }
  11260. #endif
  11261. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11262. {
  11263. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11264. {
  11265. check_ascii = value[0];
  11266. if( (check_ascii < 48) || (check_ascii > 57) )
  11267. {
  11268. isSuccess = ConfigurationStatus_Rejected;
  11269. }
  11270. else
  11271. {
  11272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11273. isSuccess = ConfigurationStatus_Accepted;
  11274. }
  11275. }
  11276. else
  11277. {
  11278. isSuccess = ConfigurationStatus_Rejected;
  11279. }
  11280. }
  11281. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11282. {
  11283. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11284. {
  11285. check_ascii = value[0];
  11286. if( (check_ascii < 48) || (check_ascii > 57) )
  11287. {
  11288. isSuccess = ConfigurationStatus_Rejected;
  11289. }
  11290. else
  11291. {
  11292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11293. isSuccess = ConfigurationStatus_Accepted;
  11294. }
  11295. }
  11296. else
  11297. {
  11298. isSuccess = ConfigurationStatus_Rejected;
  11299. }
  11300. }
  11301. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11302. {
  11303. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11304. {
  11305. strcpy(str, (const char*)value);
  11306. for(int i = 0; str[i]; i++)
  11307. {
  11308. str[i] = tolower(str[i]);
  11309. }
  11310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11311. isSuccess = ConfigurationStatus_Accepted;
  11312. }
  11313. else
  11314. {
  11315. isSuccess = ConfigurationStatus_Rejected;
  11316. }
  11317. }
  11318. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11319. {
  11320. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11321. {
  11322. check_ascii = value[0];
  11323. if( (check_ascii < 48) || (check_ascii > 57) )
  11324. {
  11325. isSuccess = ConfigurationStatus_Rejected;
  11326. }
  11327. else
  11328. {
  11329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11330. isSuccess = ConfigurationStatus_Accepted;
  11331. }
  11332. }
  11333. else
  11334. {
  11335. isSuccess = ConfigurationStatus_Rejected;
  11336. }
  11337. }
  11338. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11339. {
  11340. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11341. {
  11342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11343. isSuccess = ConfigurationStatus_Accepted;
  11344. }
  11345. else
  11346. {
  11347. isSuccess = ConfigurationStatus_Rejected;
  11348. }
  11349. }
  11350. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11351. {
  11352. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11353. {
  11354. check_ascii = value[0];
  11355. if( (check_ascii < 48) || (check_ascii > 57) )
  11356. {
  11357. isSuccess = ConfigurationStatus_Rejected;
  11358. }
  11359. else
  11360. {
  11361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11362. isSuccess = ConfigurationStatus_Accepted;
  11363. }
  11364. }
  11365. else
  11366. {
  11367. isSuccess = ConfigurationStatus_Rejected;
  11368. }
  11369. }
  11370. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11371. {
  11372. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11373. {
  11374. strcpy(str, (const char*)value);
  11375. for(int i = 0; str[i]; i++)
  11376. {
  11377. str[i] = tolower(str[i]);
  11378. }
  11379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11380. isSuccess = ConfigurationStatus_Accepted;
  11381. }
  11382. else
  11383. {
  11384. isSuccess = ConfigurationStatus_Rejected;
  11385. }
  11386. }
  11387. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11388. {
  11389. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11390. {
  11391. check_ascii = value[0];
  11392. if( (check_ascii < 48) || (check_ascii > 57) )
  11393. {
  11394. isSuccess = ConfigurationStatus_Rejected;
  11395. }
  11396. else
  11397. {
  11398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11399. isSuccess = ConfigurationStatus_Accepted;
  11400. }
  11401. }
  11402. else
  11403. {
  11404. isSuccess = ConfigurationStatus_Rejected;
  11405. }
  11406. }
  11407. return isSuccess;
  11408. }
  11409. int updateSetting(char *key, char *value)
  11410. {
  11411. mtrace();
  11412. int isSuccess = FALSE;
  11413. char string[1000]={0}, buffer[1000]={0};
  11414. char strtemp[50]={0};
  11415. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11416. int pos, c = 0;
  11417. char *loc;
  11418. int pos1=0;
  11419. FILE *f = fopen("/var/www/settings1", "r");
  11420. if(f == NULL)
  11421. {
  11422. #ifdef Debug
  11423. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11424. #endif
  11425. return isSuccess;
  11426. }
  11427. fseek(f, 0, SEEK_END);
  11428. long fsize = ftell(f);
  11429. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11430. fread(string, 1, fsize, f);
  11431. fclose(f);
  11432. string[fsize] = 0;
  11433. loc = strstr(string, key);
  11434. if(loc != NULL)
  11435. {
  11436. DEBUG_INFO("key exist!\n");
  11437. pos = loc - string-1;
  11438. f = fopen("/var/www/settings1", "w");
  11439. strncpy(buffer, string, pos);
  11440. fprintf(f, "%s", buffer);
  11441. memset(sstr ,0, sizeof(sstr) );
  11442. c = 0;
  11443. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11444. {
  11445. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11446. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11447. c++;
  11448. }
  11449. sstr[c] = '\0';
  11450. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11451. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11452. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11453. memset(buffer ,0, sizeof(buffer) );
  11454. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11455. //printf("buffer=%s",buffer);
  11456. fprintf(f, "%s", buffer);
  11457. fclose(f);
  11458. }
  11459. else
  11460. {
  11461. printf("key not exist!\n");
  11462. f = fopen("/var/www/settings1", "w+");
  11463. fputs(string, f);
  11464. fseek(f, -1, SEEK_CUR);
  11465. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11466. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11467. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11468. fclose(f);
  11469. }
  11470. isSuccess = TRUE;
  11471. return isSuccess;
  11472. }
  11473. int TransactionMessageAttemptsGet(void)
  11474. {
  11475. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11476. }
  11477. int FirstHeartBeatResponse(void)
  11478. {
  11479. return FirstHeartBeat;
  11480. }
  11481. int TransactionMessageRetryIntervalGet(void)
  11482. {
  11483. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11484. }
  11485. #define SA struct sockaddr
  11486. #define MAXBUF 1024
  11487. //static int m_socket_data;
  11488. //static int sockfd;
  11489. int ReadHttpStatus(int sock){
  11490. //char c;
  11491. char buff[1024]="",*ptr=buff+1;
  11492. int bytes_received, status;
  11493. DEBUG_INFO("Begin Response ..\n");
  11494. while((bytes_received = recv(sock, ptr, 1, 0))){
  11495. if(bytes_received==-1){
  11496. perror("ReadHttpStatus");
  11497. exit(1);
  11498. }
  11499. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11500. ptr++;
  11501. }
  11502. *ptr=0;
  11503. ptr=buff+1;
  11504. sscanf(ptr,"%*s %d ", &status);
  11505. DEBUG_INFO("%s\n",ptr);
  11506. DEBUG_INFO("status=%d\n",status);
  11507. DEBUG_INFO("End Response ..\n");
  11508. return (bytes_received>0)?status:0;
  11509. }
  11510. //the only filed that it parsed is 'Content-Length'
  11511. int ParseHeader(int sock){
  11512. //char c;
  11513. char buff[1024]="",*ptr=buff+4;
  11514. int bytes_received;
  11515. DEBUG_INFO("Begin HEADER ..\n");
  11516. while((bytes_received = recv(sock, ptr, 1, 0))){
  11517. if(bytes_received==-1){
  11518. perror("Parse Header");
  11519. exit(1);
  11520. }
  11521. if(
  11522. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11523. (ptr[-1]=='\r') && (*ptr=='\n' )
  11524. ) break;
  11525. ptr++;
  11526. }
  11527. *ptr=0;
  11528. ptr=buff+4;
  11529. //printf("%s",ptr);
  11530. if(bytes_received){
  11531. ptr=strstr(ptr,"Content-Length:");
  11532. if(ptr){
  11533. sscanf(ptr,"%*s %d",&bytes_received);
  11534. }else
  11535. bytes_received=-1; //unknown size
  11536. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11537. }
  11538. DEBUG_INFO("End HEADER ..\n");
  11539. return bytes_received ;
  11540. }
  11541. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11542. {
  11543. char rmFileCmd[100]={0};
  11544. char FilePath[100]={0};
  11545. char ftpbuf[200];
  11546. int systemresult;
  11547. //DEBUG_INFO("filename=%s\n",filename);
  11548. //DEBUG_INFO("url=%s\n",url);
  11549. sprintf(FilePath,"/mnt/%s",filename);
  11550. if((access(FilePath,F_OK))!=-1)
  11551. {
  11552. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11553. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11554. system(rmFileCmd);
  11555. }
  11556. memset(ftpbuf, 0, sizeof(ftpbuf));
  11557. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  11558. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11559. systemresult = system(ftpbuf);
  11560. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11561. if(systemresult != 0)
  11562. {
  11563. DEBUG_INFO("http DownLoad error!\n");
  11564. return FALSE;
  11565. }
  11566. return TRUE;
  11567. }
  11568. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11569. {
  11570. char rmFileCmd[100]={0};
  11571. char FilePath[100]={0};
  11572. char ftpbuf[200];
  11573. int systemresult;
  11574. //char temp[100];
  11575. #if 0
  11576. struct hostent* server;
  11577. char *IPbuffer;
  11578. server = gethostbyname(location);
  11579. // To convert an Internet network
  11580. // address into ASCII string
  11581. IPbuffer = inet_ntoa(*((struct in_addr*)
  11582. server->h_addr_list[0]));
  11583. #endif
  11584. sprintf(FilePath,"/mnt/%s",filename);
  11585. if((access(FilePath,F_OK))!=-1)
  11586. {
  11587. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11588. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11589. system(rmFileCmd);
  11590. }
  11591. memset(ftpbuf, 0, sizeof(ftpbuf));
  11592. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  11593. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11594. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11595. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11596. systemresult = system(ftpbuf);
  11597. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11598. if(systemresult != 0)
  11599. {
  11600. printf("wget error!\n");
  11601. return FALSE;
  11602. }
  11603. return TRUE;
  11604. }
  11605. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11606. {
  11607. char rmFileCmd[100]={0};
  11608. char FilePath[100]={0};
  11609. char ftpbuf[200];
  11610. char filenametemp[60]={0};
  11611. int systemresult;
  11612. //DEBUG_INFO("filename=%s\n",filename);
  11613. //DEBUG_INFO("url=%s\n",url);
  11614. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  11615. if((access(FilePath,F_OK))!=-1)
  11616. {
  11617. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11618. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11619. system(rmFileCmd);
  11620. }
  11621. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  11622. if(fp == NULL)
  11623. {
  11624. DEBUG_INFO("log is NULL\n");
  11625. return FALSE;
  11626. }
  11627. else
  11628. {
  11629. fprintf(fp, "%s\n", url);
  11630. sscanf(filename, "%*2[.]%s", filenametemp);
  11631. fprintf(fp, "%s\n", filenametemp);
  11632. fclose(fp);
  11633. }
  11634. memset(ftpbuf, 0, sizeof(ftpbuf));
  11635. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  11636. systemresult = system(ftpbuf);
  11637. DEBUG_INFO("systemresult=%d\n",systemresult);
  11638. if(systemresult != 0)
  11639. {
  11640. DEBUG_INFO("http upload error!\n");
  11641. return FALSE;
  11642. }
  11643. return TRUE;
  11644. }
  11645. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11646. {
  11647. struct hostent* server;
  11648. char *IPbuffer;
  11649. char ftpbuf[200];
  11650. int systemresult;
  11651. // To retrieve host information
  11652. server = gethostbyname(location);
  11653. // To convert an Internet network
  11654. // address into ASCII string
  11655. IPbuffer = inet_ntoa(*((struct in_addr*)
  11656. server->h_addr_list[0]));
  11657. memset(ftpbuf, 0, sizeof(ftpbuf));
  11658. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11659. /* format : ftpput -u username -p passwd IP target source*/
  11660. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11661. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11662. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11663. systemresult = system(ftpbuf);
  11664. DEBUG_INFO("systemresult=%d\n",systemresult);
  11665. if(systemresult != 0)
  11666. {
  11667. DEBUG_INFO("ftpput error!\n");
  11668. return FALSE;
  11669. }
  11670. return TRUE;
  11671. }
  11672. int SettingChargingRecord(int target, int transactionId)
  11673. {
  11674. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11675. {
  11676. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11677. {
  11678. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11679. {
  11680. addBuff(target, transactionId, 0);
  11681. return TRUE;
  11682. }
  11683. }
  11684. for (int index = 0; index < CCS_QUANTITY; index++)
  11685. {
  11686. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11687. {
  11688. addBuff(target, transactionId, 0);
  11689. return TRUE;
  11690. }
  11691. }
  11692. for (int index = 0; index < GB_QUANTITY; index++)
  11693. {
  11694. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11695. {
  11696. addBuff(target, transactionId, 0);
  11697. return TRUE;
  11698. }
  11699. }
  11700. }
  11701. else
  11702. {
  11703. for (int index = 0; index < AC_QUANTITY; index++)
  11704. {
  11705. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11706. {
  11707. addBuff(target, transactionId, 0);
  11708. return TRUE;
  11709. }
  11710. }
  11711. }
  11712. return FALSE;
  11713. }
  11714. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11715. {
  11716. int isSuccess = FALSE;
  11717. //char *query = NULL;
  11718. sqlite3_stmt *stmt;
  11719. int rc; // return code
  11720. char str[20];
  11721. sprintf(str,"%d",user_id);
  11722. 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 */
  11723. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11724. rc = sqlite3_step(stmt); /* 3 */
  11725. if (rc != SQLITE_DONE) {
  11726. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11727. goto out;
  11728. }
  11729. sqlite3_finalize(stmt);
  11730. // free(query);
  11731. out:
  11732. //----------------------
  11733. // close SQLite database
  11734. //----------------------
  11735. sqlite3_close(db);
  11736. printf("database closed.\n");
  11737. return isSuccess;
  11738. }
  11739. /**
  11740. * Place the contents of the specified file into a memory buffer
  11741. *
  11742. * @param[in] filename The path and name of the file to read
  11743. * @param[out] filebuffer A pointer to the contents in memory
  11744. * @return status 0 success, 1 on failure
  11745. */
  11746. int get_file_contents(const char* filename, char** outbuffer) {
  11747. FILE* file = NULL;
  11748. long filesize;
  11749. const int blocksize = 1;
  11750. size_t readsize;
  11751. char* filebuffer;
  11752. // Open the file
  11753. file = fopen(filename, "r");
  11754. if (NULL == file)
  11755. {
  11756. printf("'%s' not opened\n", filename);
  11757. exit(EXIT_FAILURE);
  11758. }
  11759. // Determine the file size
  11760. fseek(file, 0, SEEK_END);
  11761. filesize = ftell(file);
  11762. rewind (file);
  11763. // Allocate memory for the file contents
  11764. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11765. *outbuffer = filebuffer;
  11766. if (filebuffer == NULL)
  11767. {
  11768. fputs ("malloc out-of-memory", stderr);
  11769. exit(EXIT_FAILURE);
  11770. }
  11771. // Read in the file
  11772. readsize = fread(filebuffer, blocksize, filesize, file);
  11773. if (readsize != filesize)
  11774. {
  11775. fputs ("didn't read file completely",stderr);
  11776. exit(EXIT_FAILURE);
  11777. }
  11778. // Clean exit
  11779. fclose(file);
  11780. return EXIT_SUCCESS;
  11781. }
  11782. static int selectSqlCount = 0;
  11783. static int callback(void *data, int argc, char **argv, char **azColName){
  11784. int i;
  11785. printf("%s: ", (const char*)data);
  11786. selectSqlCount = argc;
  11787. for(i = 0; i<argc; i++){
  11788. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11789. }
  11790. printf("\n");
  11791. return 0;
  11792. }
  11793. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11794. //int i;
  11795. //printf("%s:\n", (const char*)data);
  11796. localversion = argv[5] ? atoi(argv[5]) : 0;
  11797. printf("localversion=%d\n", localversion);
  11798. return 0;
  11799. }
  11800. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11801. //int i;
  11802. //printf("%s:\n", (const char*)data);
  11803. //idTag
  11804. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11805. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11806. //parentIdTag
  11807. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11808. //expir_date
  11809. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11810. //status
  11811. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11812. //version
  11813. idTagQuery.listVersionInt = atoi(argv[5]);
  11814. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11815. return 0;
  11816. }
  11817. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11818. int i;
  11819. //printf("%s:\n", (const char*)data);
  11820. #if 1
  11821. for(i=0; i<argc; i++){
  11822. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11823. }
  11824. //printf("");
  11825. #endif
  11826. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11827. // printf("localversion=%d\n", localversion);
  11828. return 0;
  11829. }
  11830. /** sqlite3_exec的回调。
  11831. *
  11832. * 向控制台打印查询的结果。
  11833. *
  11834. * @param in data 传递给回调函数的数据。
  11835. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11836. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11837. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11838. * @return 状态码。
  11839. */
  11840. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11841. {
  11842. for (int i = 0; i < n_columns; i++)
  11843. {
  11844. DEBUG_INFO("%s/t", col_values[i]);
  11845. }
  11846. DEBUG_INFO("/n");
  11847. return 0;
  11848. }
  11849. void OCPP_getListVerion()
  11850. {
  11851. int rc = 0;
  11852. // const char* data = "Callback function called";
  11853. char sql[100];
  11854. char zErrMsg[100];
  11855. memset(sql, 0, 100);
  11856. memset(zErrMsg, 0, 100);
  11857. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11858. /* Execute SQL statement */
  11859. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11860. DEBUG_INFO("rc=%d\n",rc);
  11861. if( rc != SQLITE_OK ){
  11862. DEBUG_INFO("SQL error: %s", zErrMsg);
  11863. //sqlite3_free(zErrMsg);
  11864. }else{
  11865. DEBUG_INFO("Operation done successfully");
  11866. }
  11867. }
  11868. void OCPP_getIdTag(char *idTag)
  11869. {
  11870. int rc = 0;
  11871. // const char* data = "Callback function called";
  11872. char sql[100];
  11873. char zErrMsg[100];
  11874. memset(sql, 0, 100);
  11875. memset(zErrMsg, 0, 100);
  11876. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11877. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11878. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11879. /* Execute SQL statement */
  11880. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11881. if( rc != SQLITE_OK ){
  11882. DEBUG_INFO("SQL error: %s", zErrMsg);
  11883. //sqlite3_free(zErrMsg);
  11884. }else{
  11885. printf("Operation done successfully");
  11886. }
  11887. //return ver;
  11888. }
  11889. void OCPP_get_TableAuthlocalAllData(void)
  11890. {
  11891. int rc = 0;
  11892. // const char* data = "Callback function called";
  11893. char sql[100];
  11894. char zErrMsg[100];
  11895. memset(sql, 0, 100);
  11896. memset(zErrMsg, 0, 100);
  11897. sprintf(sql,"select * from ocpp_auth_local ");
  11898. /* Execute SQL statement */
  11899. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11900. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11901. if( rc != SQLITE_OK ){
  11902. DEBUG_INFO("SQL error: %s", zErrMsg);
  11903. //sqlite3_free(zErrMsg);
  11904. }else{
  11905. DEBUG_INFO("Operation done successfully");
  11906. }
  11907. //return ver;
  11908. }
  11909. int OCPP_cleanLocalList()
  11910. {
  11911. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11912. char *errMsg = 0;
  11913. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11914. if (SQLITE_OK != rc)
  11915. {
  11916. DEBUG_INFO("%s\n",errMsg);
  11917. return FALSE;
  11918. }
  11919. else
  11920. {
  11921. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11922. }
  11923. return TRUE;
  11924. }
  11925. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11926. {
  11927. int isSuccess = FALSE;
  11928. int ret = 0;
  11929. //const char* data = "Callback function called";
  11930. char sql[200];
  11931. char zErrMsg[100];
  11932. memset(sql, 0, 200);
  11933. memset(zErrMsg, 0, 100);
  11934. 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);
  11935. //* Execute SQL statement */
  11936. //zErrMsg = 0;
  11937. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11938. if( ret != SQLITE_OK ){
  11939. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11940. // free(zErrMsg);
  11941. // free(sql);
  11942. return isSuccess;
  11943. }
  11944. DEBUG_INFO("successfully Insert records created\n");
  11945. isSuccess = TRUE;
  11946. return isSuccess;
  11947. }
  11948. void OCPP_deleteIdTag(char *idTag)
  11949. {
  11950. //int ver = 0;
  11951. //int isSuccess = FALSE;
  11952. int rc = 0;
  11953. char sql[100];
  11954. char zErrMsg[100];
  11955. memset(sql, 0, 100);
  11956. memset(zErrMsg, 0, 100);
  11957. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11958. //* Execute SQL statement */
  11959. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  11960. if( rc != SQLITE_OK ){
  11961. DEBUG_INFO("SQL error: %s", zErrMsg);
  11962. //sqlite3_free(zErrMsg);
  11963. }else{
  11964. DEBUG_INFO("Operation done successfully");
  11965. }
  11966. }
  11967. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11968. {
  11969. int isSuccess = FALSE;
  11970. int ret = 0;
  11971. const char* data = "Callback function called";
  11972. char sql[200];
  11973. char zErrMsg[100];
  11974. memset(sql, 0, 200);
  11975. memset(zErrMsg, 0, 100);
  11976. //* selectFromTable */
  11977. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11978. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11979. //* Execute SQL statement */
  11980. selectSqlCount = 0;
  11981. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11982. if( ret != SQLITE_OK ){
  11983. printf("Error SQL: %s\n", zErrMsg);
  11984. }
  11985. printf("successfully select operation done\n");
  11986. memset(sql, 0, 200);
  11987. memset(zErrMsg, 0, 100);
  11988. if(selectSqlCount == 0)
  11989. {
  11990. //Insert
  11991. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11992. 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);
  11993. DEBUG_INFO("sql:%s\n", sql);
  11994. //* Execute SQL statement */
  11995. //zErrMsg = 0;
  11996. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11997. if( ret != SQLITE_OK ){
  11998. printf("SQL error: %s\n", zErrMsg);
  11999. return isSuccess;
  12000. }
  12001. DEBUG_INFO("successfully Insert records created\n");
  12002. isSuccess = TRUE;
  12003. }
  12004. else
  12005. {
  12006. //Update
  12007. //* Create merged SQL statement */
  12008. 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);
  12009. /* Execute SQL statement */
  12010. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12011. if( ret != SQLITE_OK ){
  12012. printf("SQL error: %s\n", zErrMsg);
  12013. //sqlite3_free(zErrMsg);
  12014. //sqlite3_free(sql);
  12015. return isSuccess;
  12016. }
  12017. DEBUG_INFO("Successfully operation done \n");
  12018. isSuccess = TRUE;
  12019. }
  12020. return isSuccess;
  12021. }
  12022. int GetOcppServerURL()
  12023. {
  12024. int result = FALSE;
  12025. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12026. memset(OcppHost, 0, sizeof(OcppHost));
  12027. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12028. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12029. {
  12030. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12031. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12032. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12033. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12034. result = TRUE;
  12035. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12036. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12037. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12038. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12039. goto End;
  12040. }
  12041. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12042. {
  12043. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12044. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12045. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12046. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12047. result = TRUE;
  12048. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12049. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12050. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12051. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12052. goto End;
  12053. }
  12054. else
  12055. {
  12056. strcpy(OcppHost,"");
  12057. }
  12058. End:
  12059. return result;
  12060. }
  12061. int GetOcppPath()
  12062. {
  12063. int result = FALSE;
  12064. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12065. {
  12066. if(OcppTempPath == NULL)
  12067. {
  12068. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12069. }
  12070. else
  12071. {
  12072. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12073. }
  12074. result = TRUE;
  12075. goto End;
  12076. }
  12077. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12078. {
  12079. if(OcppTempPath == NULL)
  12080. {
  12081. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12082. }
  12083. else
  12084. {
  12085. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12086. }
  12087. result = TRUE;
  12088. goto End;
  12089. }
  12090. else
  12091. {
  12092. strcpy(OcppPath,"");
  12093. }
  12094. End:
  12095. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12096. return result;
  12097. }
  12098. int GetOcppPort()
  12099. {
  12100. return OcppPort;
  12101. }
  12102. int GetOcppConnStatus(void)
  12103. {
  12104. return ShmOCPP16Data->OcppConnStatus;
  12105. }
  12106. void SetOcppConnStatus(uint8_t status)
  12107. {
  12108. ShmOCPP16Data->OcppConnStatus = status;
  12109. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12110. if(status == FALSE)
  12111. {
  12112. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12113. {
  12114. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12115. }
  12116. else
  12117. {
  12118. SystemInitial = AC_QUANTITY;
  12119. }
  12120. }
  12121. }
  12122. int GetHeartBeatWithNOResponse(void)
  12123. {
  12124. return HeartBeatWithNOResponse;
  12125. }
  12126. void SetHeartBeatWithNOResponse(void)
  12127. {
  12128. HeartBeatWithNOResponse = 0;
  12129. }
  12130. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12131. /*
  12132. src 源字串的首地址(buf的地址)
  12133. separator 指定的分割字元
  12134. dest 接收子字串的陣列
  12135. num 分割後子字串的個數
  12136. */
  12137. char *pNext;
  12138. int count = 0;
  12139. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12140. return;
  12141. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12142. return;
  12143. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12144. while(pNext != NULL) {
  12145. *dest++ = pNext;
  12146. ++count;
  12147. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12148. }
  12149. *num = count;
  12150. }
  12151. int GetTransactionId(int gunindex, unsigned char idTag[])
  12152. {
  12153. char ch;
  12154. FILE *fptr1;
  12155. int temptransactionId;
  12156. char str[100]={0};
  12157. temptransactionId = 0;
  12158. /*------ Read the file ----------------*/
  12159. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12160. ch=fgetc(fptr1);
  12161. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12162. rewind(fptr1);
  12163. if(ch!=EOF)
  12164. {
  12165. // printf("%c",ch);
  12166. while (fgets(str, 100, fptr1) != NULL)
  12167. {
  12168. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12169. if(str[0]=='\0')
  12170. {
  12171. break;
  12172. }
  12173. char *revbuf[8] = {0}; //存放分割後的子字串
  12174. int num = 0;//分割後子字串的個數
  12175. printf(" Now the content of the file 44444 is : \n");
  12176. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12177. printf(" Now the content of the file 5555 is : \n");
  12178. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12179. {
  12180. temptransactionId = atoi(revbuf[2]);
  12181. break;
  12182. }
  12183. }
  12184. }
  12185. fclose(fptr1);
  12186. /*------- End of reading ---------------*/
  12187. return temptransactionId;
  12188. }
  12189. void SetTransactionIdZero(int transactionId)
  12190. {
  12191. //TransactionId[gunindex] = 0;
  12192. char ch;
  12193. FILE *fptr1, *fptr2;
  12194. int temptransactionId;
  12195. char str[100]={0}, temp[] = "/Storage/OCPP/temp.txt";
  12196. printf("\n\n Delete a specific line from a file :\n");
  12197. printf("-----------------------------------------\n");
  12198. //scanf("%s",fname);
  12199. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12200. if (!fptr1)
  12201. {
  12202. printf(" File not found or unable to open the input file!!\n");
  12203. return ;
  12204. }
  12205. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12206. if (!fptr2)
  12207. {
  12208. printf("Unable to open a temporary file to write!!\n");
  12209. fclose(fptr1);
  12210. return ;
  12211. }
  12212. ch=fgetc(fptr1);
  12213. //printf(" Now the content of the file %s is : \n",fname);
  12214. rewind(fptr1);
  12215. if(ch!=EOF)
  12216. {
  12217. // copy all contents to the temporary file except the specific line
  12218. while (fgets(str, 100, fptr1) != NULL)
  12219. {
  12220. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12221. if(str[0]=='\0')
  12222. {
  12223. break;
  12224. }
  12225. char *revbuf[8] = {0}; //存放分割後的子字串
  12226. int num = 0;//分割後子字串的個數
  12227. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12228. temptransactionId = atoi(revbuf[2]);
  12229. if(transactionId != temptransactionId)
  12230. {
  12231. fprintf(fptr2, "%s", str);
  12232. }
  12233. }
  12234. }
  12235. fclose(fptr1);
  12236. fclose(fptr2);
  12237. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12238. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12239. /*------ Read the file ----------------*/
  12240. }
  12241. int InternetDisconnect(void)
  12242. {
  12243. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12244. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12245. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12246. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12247. }
  12248. void GetChargingProfileRequest(int gunindex)
  12249. {
  12250. mtrace();
  12251. //int connectorIdInt, durationInt;
  12252. //char chargingRateUnitStr[4]={0};
  12253. int tempdurationInt = 0;
  12254. int tempchargingProfileId = 0;
  12255. int tempstackLevel = 0;
  12256. int temptransactionId = 0;
  12257. float tempminChargingRateFloat = 0.0;
  12258. char tempchargingProfilePurposeStr[24]={0};
  12259. char tempchargingProfileKindStr[12]={0};
  12260. char temprecurrencyKindStr[8]={0};
  12261. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12262. char tempvalidToStr[28]={0};
  12263. int tempStartPeriodInt = 0;
  12264. float tempLimitInt = 0.0;//0.1;
  12265. int tempNumberPhasesInt=0;
  12266. char fname[200];
  12267. //char comfirmstr[20];
  12268. float MinChargingRate =0.0;
  12269. double diff_t;
  12270. struct tm tp;
  12271. FILE *fptr1;//, *fptr2;
  12272. int c = 0;
  12273. char * pch;
  12274. char *loc;
  12275. char sstr[200]={ 0 };
  12276. int n_chargingProfile = 0;
  12277. int n_SchedulePeriods = 0;
  12278. char SchedulePeriodList[10][200]={0};
  12279. char sLineWord[800]={0};
  12280. char word[1000]={0};
  12281. int confirmPeriods = 0;
  12282. struct StructProfile ChargePointMaxProfile;
  12283. struct StructProfile TxDefaultProfile;
  12284. struct StructProfile TxProfile;
  12285. struct StructProfile TxDefaultProfiletemp[2]={0};
  12286. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12287. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12288. struct StructChargingProfile TxProfile_TEMP={0};
  12289. int TxDefaultProfileFileIsNull=FALSE;
  12290. int ChargePointMaxProfileIsNull=FALSE;
  12291. int TxProfileIsNull=FALSE;
  12292. // int CompositeSceduleIndex = 0;
  12293. char ChargePointMaxProfileScheduleStr[30]={0};
  12294. char TxDefaultProfileScheduleStr[30]={0};
  12295. char TxProfileScheduleStr[30]={0};
  12296. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12297. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12298. memset(&TxProfile,0,sizeof(struct StructProfile));
  12299. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12300. DEBUG_INFO("GetChargingProfileRequest\n");
  12301. //*****************************ChargePointMaxProfile******************************************/
  12302. strcpy(fname, ChargePointMaxProfile_JSON);
  12303. ChargePointMaxProfileIsNull=TRUE;
  12304. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12305. {
  12306. fptr1 = fopen(fname, "r");
  12307. int c;
  12308. c = fgetc(fptr1);
  12309. //DEBUG_INFO("c:%d\n",c);
  12310. rewind(fptr1);
  12311. if(c == EOF)
  12312. {
  12313. DEBUG_INFO("\n End of file reached.");
  12314. ChargePointMaxProfileIsNull=TRUE;
  12315. fclose(fptr1);
  12316. }
  12317. else
  12318. {
  12319. ChargePointMaxProfileIsNull=FALSE;
  12320. while(fscanf(fptr1, "%s", word) != EOF)
  12321. {
  12322. if(strcmp(word, "chargingProfileId") == 0)
  12323. {
  12324. n_chargingProfile = n_chargingProfile + 1;
  12325. }
  12326. }
  12327. rewind(fptr1);
  12328. //search Charging Profile Element
  12329. int i = 0;
  12330. int j = 0;
  12331. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12332. //***********chargingProfileId**************/
  12333. c = 0;
  12334. loc = strstr(sLineWord, "chargingProfileId");
  12335. //DEBUG_INFO("loc=%s\n",loc);
  12336. memset(sstr ,0, sizeof(sstr) );
  12337. if(loc != NULL)
  12338. {
  12339. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12340. {
  12341. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12342. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12343. c++;
  12344. }
  12345. sstr[c] = '\0';
  12346. tempchargingProfileId = atoi(sstr);
  12347. }
  12348. else
  12349. {
  12350. tempchargingProfileId = 0;
  12351. }
  12352. //***********stackLevel**************/
  12353. c = 0;
  12354. loc = strstr(sLineWord, "stackLevel");
  12355. //DEBUG_INFO("loc=%s\n",loc);
  12356. memset(sstr ,0, sizeof(sstr) );
  12357. if(loc != NULL)
  12358. {
  12359. while (loc[2+strlen("stackLevel")+c] != '\"')
  12360. {
  12361. sstr[c] = loc[2+strlen("stackLevel")+c];
  12362. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12363. c++;
  12364. }
  12365. sstr[c] = '\0';
  12366. tempstackLevel = atoi(sstr);
  12367. }
  12368. else
  12369. {
  12370. tempstackLevel = 0;
  12371. }
  12372. //***********chargingProfilePurpose **************/
  12373. c = 0;
  12374. loc = strstr(sLineWord, "chargingProfilePurpose");
  12375. //DEBUG_INFO("loc=%s\n",loc);
  12376. memset(sstr ,0, sizeof(sstr) );
  12377. if(loc != NULL)
  12378. {
  12379. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12380. {
  12381. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12382. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12383. c++;
  12384. }
  12385. sstr[c] = '\0';
  12386. strcpy(tempchargingProfilePurposeStr,sstr);
  12387. }
  12388. else
  12389. {
  12390. strcpy(tempchargingProfilePurposeStr,"");
  12391. }
  12392. //***********chargingProfileKind **************/
  12393. c = 0;
  12394. loc = strstr(sLineWord, "chargingProfileKind");
  12395. //DEBUG_INFO("loc=%s\n",loc);
  12396. memset(sstr ,0, sizeof(sstr) );
  12397. if(loc != NULL)
  12398. {
  12399. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12400. {
  12401. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12402. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12403. c++;
  12404. }
  12405. sstr[c] = '\0';
  12406. strcpy(tempchargingProfileKindStr,sstr);
  12407. }
  12408. else
  12409. {
  12410. strcpy(tempchargingProfileKindStr,"");
  12411. }
  12412. //***********recurrencyKind **************/
  12413. c = 0;
  12414. loc = strstr(sLineWord, "recurrencyKind");
  12415. //DEBUG_INFO("loc=%s\n",loc);
  12416. memset(sstr ,0, sizeof(sstr) );
  12417. if(loc != NULL)
  12418. {
  12419. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12420. {
  12421. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12422. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12423. c++;
  12424. }
  12425. sstr[c] = '\0';
  12426. strcpy(temprecurrencyKindStr,sstr);
  12427. }
  12428. else
  12429. {
  12430. strcpy(temprecurrencyKindStr,"");
  12431. }
  12432. //***********validFrom**************/
  12433. c = 0;
  12434. loc = strstr(sLineWord, "validFrom");
  12435. //DEBUG_INFO("loc=%s\n",loc);
  12436. memset(sstr ,0, sizeof(sstr) );
  12437. if(loc != NULL)
  12438. {
  12439. while (loc[3+strlen("validFrom")+c] != '\"')
  12440. {
  12441. sstr[c] = loc[3+strlen("validFrom")+c];
  12442. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12443. c++;
  12444. }
  12445. sstr[c] = '\0';
  12446. strcpy(tempvalidFromStr,sstr);
  12447. }
  12448. else
  12449. {
  12450. strcpy(tempvalidFromStr,"");
  12451. }
  12452. //***********validTo **************/
  12453. c = 0;
  12454. loc = strstr(sLineWord, "validTo");
  12455. //DEBUG_INFO("loc=%s\n",loc);
  12456. memset(sstr ,0, sizeof(sstr) );
  12457. if(loc != NULL)
  12458. {
  12459. while (loc[3+strlen("validTo")+c] != '\"')
  12460. {
  12461. sstr[c] = loc[3+strlen("validTo")+c];
  12462. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12463. c++;
  12464. }
  12465. sstr[c] = '\0';
  12466. strcpy(tempvalidToStr,sstr);
  12467. }
  12468. else
  12469. {
  12470. strcpy(tempvalidToStr,"");
  12471. }
  12472. //***********validFrom**************/
  12473. c = 0;
  12474. loc = strstr(sLineWord, "validFrom");
  12475. if(loc != NULL)
  12476. {
  12477. memset(sstr ,0, sizeof(sstr) );
  12478. while (loc[3+strlen("validFrom")+c] != '\"')
  12479. {
  12480. sstr[c] = loc[3+strlen("validFrom")+c];
  12481. c++;
  12482. }
  12483. sstr[c] = '\0';
  12484. strcpy(tempvalidFromStr,sstr);
  12485. }
  12486. else
  12487. {
  12488. strcpy(tempvalidFromStr,"");
  12489. }
  12490. //***********validTo **************/
  12491. c = 0;
  12492. loc = strstr(sLineWord, "validTo");
  12493. if(loc != NULL)
  12494. {
  12495. memset(sstr ,0, sizeof(sstr) );
  12496. while (loc[3+strlen("validTo")+c] != '\"')
  12497. {
  12498. sstr[c] = loc[3+strlen("validTo")+c];
  12499. c++;
  12500. }
  12501. sstr[c] = '\0';
  12502. strcpy(tempvalidToStr,sstr);
  12503. }
  12504. else
  12505. {
  12506. strcpy(tempvalidToStr,"");
  12507. }
  12508. //***********duration**************/
  12509. c = 0;
  12510. loc = strstr(sLineWord, "duration");
  12511. if(loc != NULL)
  12512. {
  12513. memset(sstr ,0, sizeof(sstr) );
  12514. while (loc[2+strlen("duration")+c] != ',')
  12515. {
  12516. sstr[c] = loc[2+strlen("duration")+c];
  12517. c++;
  12518. }
  12519. sstr[c] = '\0';
  12520. tempdurationInt = atoi(sstr);
  12521. }
  12522. else
  12523. {
  12524. tempdurationInt = 0;
  12525. }
  12526. //**********startSchedule**********/
  12527. c = 0;
  12528. loc = strstr(sLineWord, "startSchedule");
  12529. memset(sstr ,0, sizeof(sstr) );
  12530. while (loc[3+strlen("startSchedule")+c] != '\"')
  12531. {
  12532. sstr[c] = loc[3+strlen("startSchedule")+c];
  12533. c++;
  12534. }
  12535. sstr[c] = '\0';
  12536. strcpy(tempstartScheduleStr, sstr);
  12537. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12538. //**********chargingRateUnit**********/
  12539. c = 0;
  12540. loc = strstr(sLineWord, "chargingRateUnit");
  12541. memset(sstr ,0, sizeof(sstr) );
  12542. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12543. {
  12544. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12545. c++;
  12546. }
  12547. sstr[c] = '\0';
  12548. strcpy(tempchargingRateUnitStr, sstr);
  12549. //**********minChargingRate*******/
  12550. c = 0;
  12551. loc = strstr(sLineWord, "minChargingRate");
  12552. if(loc != NULL)
  12553. {
  12554. memset(sstr ,0, sizeof(sstr) );
  12555. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12556. {
  12557. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12558. c++;
  12559. }
  12560. sstr[c] = '\0';
  12561. tempminChargingRateFloat = atof(sstr);
  12562. }
  12563. else
  12564. {
  12565. tempminChargingRateFloat = 0.0;
  12566. }
  12567. //
  12568. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12569. tp.tm_isdst = -1;
  12570. time_t utc = mktime(&tp);
  12571. time_t t = time(NULL);
  12572. diff_t = difftime(t, utc);
  12573. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12574. //parsing strings to words
  12575. i = 0;
  12576. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12577. loc = loc+3+strlen("chargingSchedulePeriod");
  12578. pch = strtok(loc ,"{");
  12579. while (pch != NULL)
  12580. {
  12581. strcpy(SchedulePeriodList[i], pch);
  12582. pch = strtok (NULL, "{");
  12583. i = i + 1;
  12584. }
  12585. n_SchedulePeriods = i;
  12586. for(int i=0;i<n_SchedulePeriods;i++)
  12587. {
  12588. //*************startPeriod****************/
  12589. c = 0;
  12590. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12591. memset(sstr ,0, sizeof(sstr) );
  12592. while (loc[strlen("startPeriod")+2+c] != ',')
  12593. {
  12594. sstr[c] = loc[strlen("startPeriod")+2+c];
  12595. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12596. c++;
  12597. }
  12598. sstr[c] = '\0';
  12599. tempStartPeriodInt = atoi(sstr);
  12600. //*************limit****************/
  12601. c = 0;
  12602. loc = strstr(SchedulePeriodList[i], "limit");
  12603. memset(sstr ,0, sizeof(sstr) );
  12604. while (loc[strlen("limit")+2+c] != ',')
  12605. {
  12606. sstr[c] = loc[strlen("limit")+2+c];
  12607. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12608. c++;
  12609. }
  12610. sstr[c] = '\0';
  12611. tempLimitInt = atof(sstr);
  12612. //*************numberPhases****************/
  12613. c = 0;
  12614. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12615. memset(sstr ,0, sizeof(sstr) );
  12616. while (loc[strlen("numberPhases")+2+c] != '}')
  12617. {
  12618. sstr[c] = loc[strlen("numberPhases")+2+c];
  12619. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12620. c++;
  12621. }
  12622. sstr[c] = '\0';
  12623. tempNumberPhasesInt = atoi(sstr);
  12624. if(j == 0)
  12625. {
  12626. ChargePointMaxProfile.Duration = tempdurationInt;
  12627. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12628. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12629. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12630. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12631. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12632. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12633. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12634. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12635. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12636. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12637. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12638. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12639. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12640. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12641. }
  12642. }
  12643. if(MinChargingRate < tempminChargingRateFloat)
  12644. {
  12645. MinChargingRate = tempminChargingRateFloat;
  12646. }
  12647. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12648. if(confirmPeriods < n_SchedulePeriods)
  12649. {
  12650. confirmPeriods = n_SchedulePeriods;
  12651. }
  12652. j = j + 1;
  12653. }
  12654. fclose(fptr1);
  12655. }
  12656. }// the end of access file ChargePointMaxProfile
  12657. //****************************TxDefaultProfile************************************************/
  12658. switch(gunindex + 1)
  12659. {
  12660. case 0:
  12661. strcpy(fname, TxDefaultProfile_0_JSON );
  12662. break;
  12663. case 1:
  12664. strcpy(fname, TxDefaultProfile_1_JSON );
  12665. break;
  12666. case 2:
  12667. strcpy(fname, TxDefaultProfile_2_JSON );
  12668. break;
  12669. default:
  12670. strcpy(fname, TxDefaultProfile_1_JSON );
  12671. break;
  12672. }
  12673. TxDefaultProfileFileIsNull=TRUE;
  12674. if((access(fname,F_OK))!=-1)
  12675. {
  12676. fptr1 = fopen(fname, "r");
  12677. c = 0;
  12678. c = fgetc(fptr1);
  12679. //DEBUG_INFO("c:%d\n",c);
  12680. rewind(fptr1);
  12681. if(c == EOF)
  12682. {
  12683. DEBUG_INFO("\n End of file reached.");
  12684. TxDefaultProfileFileIsNull=TRUE;
  12685. fclose(fptr1);
  12686. }
  12687. else
  12688. {
  12689. TxDefaultProfileFileIsNull=FALSE;
  12690. while(fscanf(fptr1, "%s", word) != EOF)
  12691. {
  12692. if(strcmp(word, "chargingProfileId") == 0)
  12693. {
  12694. n_chargingProfile = n_chargingProfile + 1;
  12695. }
  12696. }
  12697. rewind(fptr1);
  12698. //search Charging Profile Element
  12699. int i = 0;
  12700. int j = 0;
  12701. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12702. #if 0
  12703. /***********connectorId****************/
  12704. c = 0;
  12705. loc = strstr(sLineWord, "connectorId");
  12706. memset(sstr ,0, sizeof(sstr) );
  12707. while (loc[strlen("connectorId")+2+c] != ',')
  12708. {
  12709. sstr[c] = loc[strlen("connectorId")+2+c];
  12710. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12711. c++;
  12712. }
  12713. sstr[c] = '\0';
  12714. tempconnectorIdInt = atoi(sstr);
  12715. #endif
  12716. //***********chargingProfileId**************/
  12717. c = 0;
  12718. loc = strstr(sLineWord, "chargingProfileId");
  12719. //DEBUG_INFO("loc=%s\n",loc);
  12720. memset(sstr ,0, sizeof(sstr) );
  12721. if(loc != NULL)
  12722. {
  12723. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12724. {
  12725. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12726. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12727. c++;
  12728. }
  12729. sstr[c] = '\0';
  12730. tempchargingProfileId = atoi(sstr);
  12731. }
  12732. else
  12733. {
  12734. tempchargingProfileId = 0;
  12735. }
  12736. //***********stackLevel**************/
  12737. c = 0;
  12738. loc = strstr(sLineWord, "stackLevel");
  12739. //DEBUG_INFO("loc=%s\n",loc);
  12740. memset(sstr ,0, sizeof(sstr) );
  12741. if(loc != NULL)
  12742. {
  12743. while (loc[2+strlen("stackLevel")+c] != '\"')
  12744. {
  12745. sstr[c] = loc[2+strlen("stackLevel")+c];
  12746. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12747. c++;
  12748. }
  12749. sstr[c] = '\0';
  12750. tempstackLevel = atoi(sstr);
  12751. }
  12752. else
  12753. {
  12754. tempstackLevel = 0;
  12755. }
  12756. //***********chargingProfilePurpose **************/
  12757. c = 0;
  12758. loc = strstr(sLineWord, "chargingProfilePurpose");
  12759. //DEBUG_INFO("loc=%s\n",loc);
  12760. memset(sstr ,0, sizeof(sstr) );
  12761. if(loc != NULL)
  12762. {
  12763. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12764. {
  12765. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12766. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12767. c++;
  12768. }
  12769. sstr[c] = '\0';
  12770. strcpy(tempchargingProfilePurposeStr,sstr);
  12771. }
  12772. else
  12773. {
  12774. strcpy(tempchargingProfilePurposeStr,"");
  12775. }
  12776. //***********chargingProfileKind **************/
  12777. c = 0;
  12778. loc = strstr(sLineWord, "chargingProfileKind");
  12779. //DEBUG_INFO("loc=%s\n",loc);
  12780. memset(sstr ,0, sizeof(sstr) );
  12781. if(loc != NULL)
  12782. {
  12783. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12784. {
  12785. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12786. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12787. c++;
  12788. }
  12789. sstr[c] = '\0';
  12790. strcpy(tempchargingProfileKindStr,sstr);
  12791. }
  12792. else
  12793. {
  12794. strcpy(tempchargingProfileKindStr,"");
  12795. }
  12796. //***********recurrencyKind **************/
  12797. c = 0;
  12798. loc = strstr(sLineWord, "recurrencyKind");
  12799. //DEBUG_INFO("loc=%s\n",loc);
  12800. memset(sstr ,0, sizeof(sstr) );
  12801. if(loc != NULL)
  12802. {
  12803. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12804. {
  12805. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12807. c++;
  12808. }
  12809. sstr[c] = '\0';
  12810. strcpy(temprecurrencyKindStr,sstr);
  12811. }
  12812. else
  12813. {
  12814. strcpy(temprecurrencyKindStr,"");
  12815. }
  12816. //***********validFrom**************/
  12817. c = 0;
  12818. loc = strstr(sLineWord, "validFrom");
  12819. if(loc != NULL)
  12820. {
  12821. memset(sstr ,0, sizeof(sstr) );
  12822. while (loc[3+strlen("validFrom")+c] != '\"')
  12823. {
  12824. sstr[c] = loc[3+strlen("validFrom")+c];
  12825. c++;
  12826. }
  12827. sstr[c] = '\0';
  12828. strcpy(tempvalidFromStr,sstr);
  12829. }
  12830. else
  12831. {
  12832. strcpy(tempvalidFromStr,"");
  12833. }
  12834. //***********validTo **************/
  12835. c = 0;
  12836. loc = strstr(sLineWord, "validTo");
  12837. if(loc != NULL)
  12838. {
  12839. memset(sstr ,0, sizeof(sstr) );
  12840. while (loc[3+strlen("validTo")+c] != '\"')
  12841. {
  12842. sstr[c] = loc[3+strlen("validTo")+c];
  12843. c++;
  12844. }
  12845. sstr[c] = '\0';
  12846. strcpy(tempvalidToStr,sstr);
  12847. }
  12848. else
  12849. {
  12850. strcpy(tempvalidToStr,"");
  12851. }
  12852. //***********duration**************/
  12853. c = 0;
  12854. loc = strstr(sLineWord, "duration");
  12855. if(loc != NULL)
  12856. {
  12857. memset(sstr ,0, sizeof(sstr) );
  12858. while (loc[2+strlen("duration")+c] != ',')
  12859. {
  12860. sstr[c] = loc[2+strlen("duration")+c];
  12861. c++;
  12862. }
  12863. sstr[c] = '\0';
  12864. tempdurationInt = atoi(sstr);
  12865. }
  12866. else
  12867. {
  12868. tempdurationInt = 0;
  12869. }
  12870. //**********startSchedule**********/
  12871. c = 0;
  12872. loc = strstr(sLineWord, "startSchedule");
  12873. memset(sstr ,0, sizeof(sstr) );
  12874. while (loc[3+strlen("startSchedule")+c] != '\"')
  12875. {
  12876. sstr[c] = loc[3+strlen("startSchedule")+c];
  12877. c++;
  12878. }
  12879. sstr[c] = '\0';
  12880. strcpy(tempstartScheduleStr, sstr);
  12881. strcpy(TxDefaultProfileScheduleStr, sstr);
  12882. //**********chargingRateUnit**********/
  12883. c = 0;
  12884. loc = strstr(sLineWord, "chargingRateUnit");
  12885. memset(sstr ,0, sizeof(sstr) );
  12886. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12887. {
  12888. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12889. c++;
  12890. }
  12891. sstr[c] = '\0';
  12892. strcpy(tempchargingRateUnitStr, sstr);
  12893. //**********minChargingRate*******/
  12894. c = 0;
  12895. loc = strstr(sLineWord, "minChargingRate");
  12896. if(loc != NULL)
  12897. {
  12898. memset(sstr ,0, sizeof(sstr) );
  12899. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12900. {
  12901. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12902. c++;
  12903. }
  12904. sstr[c] = '\0';
  12905. tempminChargingRateFloat = atof(sstr);
  12906. }
  12907. else
  12908. {
  12909. tempminChargingRateFloat = 0.0;
  12910. }
  12911. //
  12912. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12913. tp.tm_isdst = -1;
  12914. time_t utc = mktime(&tp);
  12915. time_t t = time(NULL);
  12916. diff_t = difftime(t, utc);
  12917. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12918. //parsing strings to words
  12919. i = 0;
  12920. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12921. loc = loc+3+strlen("chargingSchedulePeriod");
  12922. pch = strtok(loc ,"{");
  12923. while (pch != NULL)
  12924. {
  12925. strcpy(SchedulePeriodList[i], pch);
  12926. pch = strtok (NULL, "{");
  12927. i = i + 1;
  12928. }
  12929. n_SchedulePeriods = i;
  12930. for(int i=0;i<n_SchedulePeriods;i++)
  12931. {
  12932. //*************startPeriod****************/
  12933. c = 0;
  12934. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12935. memset(sstr ,0, sizeof(sstr) );
  12936. while (loc[strlen("startPeriod")+2+c] != ',')
  12937. {
  12938. sstr[c] = loc[strlen("startPeriod")+2+c];
  12939. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12940. c++;
  12941. }
  12942. sstr[c] = '\0';
  12943. tempStartPeriodInt = atoi(sstr);
  12944. //*************limit****************/
  12945. c = 0;
  12946. loc = strstr(SchedulePeriodList[i], "limit");
  12947. memset(sstr ,0, sizeof(sstr) );
  12948. while (loc[strlen("limit")+2+c] != ',')
  12949. {
  12950. sstr[c] = loc[strlen("limit")+2+c];
  12951. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12952. c++;
  12953. }
  12954. sstr[c] = '\0';
  12955. tempLimitInt = atof(sstr);
  12956. //*************numberPhases****************/
  12957. c = 0;
  12958. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12959. memset(sstr ,0, sizeof(sstr) );
  12960. while (loc[strlen("numberPhases")+2+c] != '}')
  12961. {
  12962. sstr[c] = loc[strlen("numberPhases")+2+c];
  12963. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12964. c++;
  12965. }
  12966. sstr[c] = '\0';
  12967. tempNumberPhasesInt = atoi(sstr);
  12968. if(j == 0)
  12969. {
  12970. TxDefaultProfile.Duration = tempdurationInt;
  12971. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  12972. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  12973. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12974. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12975. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12976. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  12977. TxDefaultProfile_TEMP.TransactionId = 0;
  12978. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12979. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12980. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12981. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12982. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12983. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12984. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12985. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12986. }
  12987. else
  12988. {
  12989. //other stack level charging Profile
  12990. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  12991. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  12992. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  12993. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  12994. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  12995. }
  12996. }
  12997. if(MinChargingRate < tempminChargingRateFloat)
  12998. {
  12999. MinChargingRate = tempminChargingRateFloat;
  13000. }
  13001. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13002. if(confirmPeriods < n_SchedulePeriods)
  13003. confirmPeriods = n_SchedulePeriods;
  13004. j = j + 1;
  13005. }
  13006. fclose(fptr1);
  13007. //Stacking Charging Profiles
  13008. for(int l=0; l <(j-1) ;l++)
  13009. {
  13010. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13011. {
  13012. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13013. {
  13014. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13015. {
  13016. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13017. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13018. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13019. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13020. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13021. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13022. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13023. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13024. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13025. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13026. }
  13027. else
  13028. {
  13029. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13030. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13031. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13032. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13033. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13034. }
  13035. }
  13036. }
  13037. }
  13038. //end of Stacking Charging Profiles
  13039. }
  13040. }// the end of ACCESS TxDefaultProfile
  13041. //****************************TxProfile************************************************/
  13042. switch(gunindex + 1)
  13043. {
  13044. case 0:
  13045. break;
  13046. case 1:
  13047. strcpy(fname, TxProfile_1_JSON );
  13048. break;
  13049. case 2:
  13050. strcpy(fname, TxProfile_2_JSON );
  13051. break;
  13052. default:
  13053. strcpy(fname, TxProfile_1_JSON );
  13054. break;
  13055. }
  13056. TxProfileIsNull=TRUE;
  13057. if((access(fname,F_OK))!=-1)
  13058. {
  13059. fptr1 = fopen(fname, "r");
  13060. c = 0;
  13061. c = fgetc(fptr1);
  13062. //DEBUG_INFO("c:%d\n",c);
  13063. rewind(fptr1);
  13064. if(c == EOF)
  13065. {
  13066. DEBUG_INFO("\n End of file reached.");
  13067. TxProfileIsNull=TRUE;
  13068. fclose(fptr1);
  13069. }
  13070. else
  13071. {
  13072. TxProfileIsNull=FALSE;
  13073. while(fscanf(fptr1, "%s", word) != EOF)
  13074. {
  13075. if(strcmp(word, "chargingProfileId") == 0)
  13076. {
  13077. n_chargingProfile = n_chargingProfile + 1;
  13078. }
  13079. }
  13080. rewind(fptr1);
  13081. //search Charging Profile Element
  13082. int i= 0;
  13083. int j= 0;
  13084. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13085. #if 0
  13086. /***********connectorId****************/
  13087. c = 0;
  13088. loc = strstr(sLineWord, "connectorId");
  13089. memset(sstr ,0, sizeof(sstr) );
  13090. while (loc[strlen("connectorId")+2+c] != ',')
  13091. {
  13092. sstr[c] = loc[strlen("connectorId")+2+c];
  13093. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13094. c++;
  13095. }
  13096. sstr[c] = '\0';
  13097. tempconnectorIdInt = atoi(sstr);
  13098. #endif
  13099. //***********chargingProfileId**************/
  13100. c = 0;
  13101. loc = strstr(sLineWord, "chargingProfileId");
  13102. memset(sstr ,0, sizeof(sstr) );
  13103. if(loc != NULL)
  13104. {
  13105. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13106. {
  13107. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13108. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13109. c++;
  13110. }
  13111. sstr[c] = '\0';
  13112. tempchargingProfileId = atoi(sstr);
  13113. }
  13114. else
  13115. {
  13116. tempchargingProfileId = 0;
  13117. }
  13118. //***********transactionId **************/
  13119. c = 0;
  13120. loc = strstr(sLineWord, "transactionId");
  13121. //DEBUG_INFO("loc=%s\n",loc);
  13122. memset(sstr ,0, sizeof(sstr) );
  13123. if(loc != NULL)
  13124. {
  13125. while (loc[2+strlen("transactionId")+c] != '\"')
  13126. {
  13127. sstr[c] = loc[2+strlen("transactionId")+c];
  13128. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13129. c++;
  13130. }
  13131. sstr[c] = '\0';
  13132. temptransactionId = atoi(sstr);
  13133. }
  13134. else
  13135. {
  13136. temptransactionId = 0;
  13137. }
  13138. //***********stackLevel**************/
  13139. c = 0;
  13140. loc = strstr(sLineWord, "stackLevel");
  13141. //DEBUG_INFO("loc=%s\n",loc);
  13142. memset(sstr ,0, sizeof(sstr) );
  13143. if(loc != NULL)
  13144. {
  13145. while (loc[2+strlen("stackLevel")+c] != '\"')
  13146. {
  13147. sstr[c] = loc[2+strlen("stackLevel")+c];
  13148. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13149. c++;
  13150. }
  13151. sstr[c] = '\0';
  13152. tempstackLevel = atoi(sstr);
  13153. }
  13154. else
  13155. {
  13156. tempstackLevel = 0;
  13157. }
  13158. //***********chargingProfilePurpose **************/
  13159. c = 0;
  13160. loc = strstr(sLineWord, "chargingProfilePurpose");
  13161. //DEBUG_INFO("loc=%s\n",loc);
  13162. memset(sstr ,0, sizeof(sstr) );
  13163. if(loc != NULL)
  13164. {
  13165. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13166. {
  13167. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13168. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13169. c++;
  13170. }
  13171. sstr[c] = '\0';
  13172. strcpy(tempchargingProfilePurposeStr,sstr);
  13173. }
  13174. else
  13175. {
  13176. strcpy(tempchargingProfilePurposeStr,"");
  13177. }
  13178. //***********chargingProfileKind **************/
  13179. c = 0;
  13180. loc = strstr(sLineWord, "chargingProfileKind");
  13181. //DEBUG_INFO("loc=%s\n",loc);
  13182. memset(sstr ,0, sizeof(sstr) );
  13183. if(loc != NULL)
  13184. {
  13185. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13186. {
  13187. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13188. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13189. c++;
  13190. }
  13191. sstr[c] = '\0';
  13192. strcpy(tempchargingProfileKindStr,sstr);
  13193. }
  13194. else
  13195. {
  13196. strcpy(tempchargingProfileKindStr,"");
  13197. }
  13198. //***********recurrencyKind **************/
  13199. c = 0;
  13200. loc = strstr(sLineWord, "recurrencyKind");
  13201. //DEBUG_INFO("loc=%s\n",loc);
  13202. memset(sstr ,0, sizeof(sstr) );
  13203. if(loc != NULL)
  13204. {
  13205. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13206. {
  13207. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13209. c++;
  13210. }
  13211. sstr[c] = '\0';
  13212. strcpy(temprecurrencyKindStr,sstr);
  13213. }
  13214. else
  13215. {
  13216. strcpy(temprecurrencyKindStr,"");
  13217. }
  13218. //***********validFrom**************/
  13219. c = 0;
  13220. loc = strstr(sLineWord, "validFrom");
  13221. if(loc != NULL)
  13222. {
  13223. memset(sstr ,0, sizeof(sstr) );
  13224. while (loc[3+strlen("validFrom")+c] != '\"')
  13225. {
  13226. sstr[c] = loc[3+strlen("validFrom")+c];
  13227. c++;
  13228. }
  13229. sstr[c] = '\0';
  13230. strcpy(tempvalidFromStr,sstr);
  13231. }
  13232. else
  13233. {
  13234. strcpy(tempvalidFromStr,"");
  13235. }
  13236. //***********validTo**************/
  13237. c = 0;
  13238. loc = strstr(sLineWord, "validTo");
  13239. if(loc != NULL)
  13240. {
  13241. memset(sstr ,0, sizeof(sstr) );
  13242. while (loc[3+strlen("validTo")+c] != '\"')
  13243. {
  13244. sstr[c] = loc[3+strlen("validTo")+c];
  13245. c++;
  13246. }
  13247. sstr[c] = '\0';
  13248. strcpy(tempvalidToStr,sstr);
  13249. }
  13250. else
  13251. {
  13252. strcpy(tempvalidToStr,"");
  13253. }
  13254. //***********duration**************/
  13255. c = 0;
  13256. loc = strstr(sLineWord, "duration");
  13257. //DEBUG_INFO("loc=%s\n",loc);
  13258. memset(sstr ,0, sizeof(sstr) );
  13259. if(loc != NULL)
  13260. {
  13261. while (loc[2+strlen("duration")+c] != '\"')
  13262. {
  13263. sstr[c] = loc[2+strlen("duration")+c];
  13264. c++;
  13265. }
  13266. sstr[c] = '\0';
  13267. tempdurationInt = atoi(sstr);
  13268. }
  13269. else
  13270. {
  13271. tempdurationInt = 0;
  13272. }
  13273. //**********startSchedule**********/
  13274. c = 0;
  13275. loc = strstr(sLineWord, "startSchedule");
  13276. memset(sstr ,0, sizeof(sstr) );
  13277. while (loc[3+strlen("startSchedule")+c] != '\"')
  13278. {
  13279. sstr[c] = loc[3+strlen("startSchedule")+c];
  13280. c++;
  13281. }
  13282. sstr[c] = '\0';
  13283. strcpy(tempstartScheduleStr, sstr);
  13284. strcpy(TxProfileScheduleStr, sstr);
  13285. //**********chargingRateUnit**********/
  13286. c = 0;
  13287. loc = strstr(sLineWord, "chargingRateUnit");
  13288. memset(sstr ,0, sizeof(sstr) );
  13289. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13290. {
  13291. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13292. c++;
  13293. }
  13294. sstr[c] = '\0';
  13295. strcpy(tempchargingRateUnitStr, sstr);
  13296. //**********minChargingRate*******/
  13297. c = 0;
  13298. loc = strstr(sLineWord, "minChargingRate");
  13299. if(loc != NULL)
  13300. {
  13301. memset(sstr ,0, sizeof(sstr) );
  13302. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13303. {
  13304. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13305. c++;
  13306. }
  13307. sstr[c] = '\0';
  13308. tempminChargingRateFloat = atof(sstr);
  13309. }
  13310. else
  13311. {
  13312. tempminChargingRateFloat = 0.0;
  13313. }
  13314. //
  13315. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13316. tp.tm_isdst = -1;
  13317. time_t utc = mktime(&tp);
  13318. time_t t = time(NULL);
  13319. diff_t = difftime(t, utc);
  13320. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13321. //parsing strings to words
  13322. i = 0;
  13323. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13324. loc = loc+3+strlen("chargingSchedulePeriod");
  13325. pch = strtok(loc ,"{");
  13326. while (pch != NULL)
  13327. {
  13328. strcpy(SchedulePeriodList[i], pch);
  13329. pch = strtok (NULL, "{");
  13330. i = i + 1;
  13331. }
  13332. n_SchedulePeriods = i;
  13333. for(int i=0;i<n_SchedulePeriods;i++)
  13334. {
  13335. //*************startPeriod****************/
  13336. c = 0;
  13337. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13338. memset(sstr ,0, sizeof(sstr) );
  13339. while (loc[strlen("startPeriod")+2+c] != ',')
  13340. {
  13341. sstr[c] = loc[strlen("startPeriod")+2+c];
  13342. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13343. c++;
  13344. }
  13345. sstr[c] = '\0';
  13346. tempStartPeriodInt = atoi(sstr);
  13347. //*************limit****************/
  13348. c = 0;
  13349. loc = strstr(SchedulePeriodList[i], "limit");
  13350. memset(sstr ,0, sizeof(sstr) );
  13351. while (loc[strlen("limit")+2+c] != ',')
  13352. {
  13353. sstr[c] = loc[strlen("limit")+2+c];
  13354. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13355. c++;
  13356. }
  13357. sstr[c] = '\0';
  13358. tempLimitInt = atof(sstr);
  13359. //*************numberPhases****************/
  13360. c = 0;
  13361. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13362. memset(sstr ,0, sizeof(sstr) );
  13363. while (loc[strlen("numberPhases")+2+c] != '}')
  13364. {
  13365. sstr[c] = loc[strlen("numberPhases")+2+c];
  13366. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13367. c++;
  13368. }
  13369. sstr[c] = '\0';
  13370. tempNumberPhasesInt = atoi(sstr);
  13371. //TxProfile.Duration = durationInt;
  13372. TxProfile.TotalPeriod = n_SchedulePeriods;
  13373. TxProfile.Period[i].Limit = tempLimitInt;
  13374. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13375. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13376. }
  13377. if(MinChargingRate < tempminChargingRateFloat)
  13378. {
  13379. MinChargingRate = tempminChargingRateFloat;
  13380. }
  13381. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13382. if(confirmPeriods < n_SchedulePeriods)
  13383. confirmPeriods = n_SchedulePeriods;
  13384. if(j == 0)
  13385. {
  13386. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13387. TxProfile_TEMP.StackLevel = tempstackLevel;
  13388. TxProfile_TEMP.TransactionId = 0;
  13389. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13390. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13391. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13392. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13393. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13394. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13395. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13396. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13397. }
  13398. }
  13399. fclose(fptr1);
  13400. }
  13401. }// the end of ACCESS TxProfile
  13402. //CompositeSchedule
  13403. int period=0;
  13404. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13405. {
  13406. //TxProfile
  13407. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13408. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13409. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13410. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13411. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13412. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13413. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13414. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13415. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13416. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13417. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13418. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13419. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13420. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13421. {
  13422. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13423. {
  13424. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13425. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13426. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13427. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13428. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13429. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13430. period = period + 1;
  13431. }
  13432. else
  13433. {
  13434. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13435. {
  13436. }
  13437. else
  13438. {
  13439. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13440. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13441. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13442. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13443. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13444. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13445. period = period + 1;
  13446. }
  13447. }
  13448. }
  13449. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13450. {
  13451. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13452. {
  13453. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13454. {
  13455. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13456. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13457. }
  13458. else
  13459. {
  13460. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13461. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13462. }
  13463. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13464. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13465. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13466. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13467. period = period + 1;
  13468. }
  13469. }
  13470. }
  13471. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13472. {
  13473. //TxDefaultProfile
  13474. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13475. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13476. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13477. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13478. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13479. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13480. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13481. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13482. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13483. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13484. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13485. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13486. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13487. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13488. {
  13489. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13490. {
  13491. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13492. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13493. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13494. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13495. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13496. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13497. period = period + 1;
  13498. }
  13499. else
  13500. {
  13501. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13502. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13503. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13504. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13505. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13506. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13507. period = period + 1;
  13508. }
  13509. }
  13510. }
  13511. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13512. {
  13513. //TxDefaultProfile
  13514. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13515. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13516. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13517. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13518. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13519. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13520. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13521. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13522. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13523. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13524. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13525. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13526. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13527. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13528. {
  13529. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13530. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13531. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13532. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13533. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13534. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13535. period = period + 1;
  13536. }
  13537. }
  13538. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13539. {
  13540. //ChargePointMaxProfile
  13541. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13542. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13543. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13544. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13545. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13546. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13547. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13548. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13549. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13550. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13551. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13552. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13553. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13554. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13555. {
  13556. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13557. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13558. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13559. period = period + 1;
  13560. }
  13561. }
  13562. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13563. {
  13564. //TxProfile
  13565. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13566. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13567. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13568. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13569. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13570. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13571. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13572. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13573. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13574. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13575. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13576. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13577. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13578. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13579. {
  13580. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13581. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13582. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13583. }
  13584. }
  13585. confirmPeriods = period;
  13586. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13587. 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,"
  13588. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13589. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13590. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13591. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13592. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13593. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13594. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13595. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13596. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13597. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13598. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13599. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13600. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13601. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13602. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13603. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13604. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13605. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13606. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13607. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13608. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13609. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13610. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13611. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13612. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13613. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13614. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13615. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13616. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13617. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13618. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13619. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13620. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13621. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13622. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13623. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13624. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13625. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13626. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13627. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13628. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13629. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13630. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13631. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13632. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13633. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13634. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13635. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13636. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13637. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13638. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13639. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13640. }
  13641. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13642. {
  13643. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13644. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13645. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13646. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13647. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13648. }
  13649. void LWS_Send(char * str)
  13650. {
  13651. //=====================================================
  13652. // Check InternetConn 0: disconnected, 1: connected
  13653. //====================================================
  13654. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13655. {
  13656. DEBUG_INFO("\n offline now !!!\n");
  13657. return;
  13658. }
  13659. pthread_mutex_lock(&lock);
  13660. memset(SendBuffer,0,SendBufLen);
  13661. sprintf((char *)SendBuffer, "%s", str);
  13662. pthread_mutex_unlock(&lock);
  13663. lws_callback_on_writable(wsi_client);
  13664. lws_service(context, 10000);//timeout_ms
  13665. }