MessageHandler.c 582 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "define.h"
  24. #include "SystemLogMessage.h"
  25. //#include "config.h"
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <stdlib.h>
  29. /*for sendfile()*/
  30. #include <sys/sendfile.h>
  31. /*for O_RDONLY*/
  32. #include <fcntl.h>
  33. #include "sqlite3.h"
  34. #include <arpa/inet.h>
  35. //#define _GNU_SOURCE
  36. #include <time.h>
  37. #include "MessageHandler.h"
  38. #include <assert.h>
  39. #include <pthread.h>
  40. #include <mcheck.h>
  41. #define PASS 1
  42. #define FAIL -1
  43. #define FALSE 0
  44. #define TRUE 1 // Option 1
  45. //ChargePointMaxProfile
  46. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  47. //TxDefaultProfile
  48. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  49. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  50. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  51. //TxProfile
  52. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  53. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  54. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  55. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  56. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  57. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  58. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  59. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  60. struct StatusCodeData *ShmStatusCodeData;
  61. struct PsuData *ShmPsuData ;
  62. struct OCPP16Data *ShmOCPP16Data;
  63. // define Macro
  64. #define SystemLogMessage
  65. // OCPP Message Type
  66. #define MESSAGE_TYPE_CALL 2
  67. #define MESSAGE_TYPE_CALLRESULT 3
  68. #define MESSAGE_TYPE_CALLERROR 4
  69. //
  70. #define server_cycle_Status 120
  71. #define MACROSTR(k) #k
  72. //ConfigurationMaxKeys
  73. #define GetConfigurationMaxKeysNUM 43
  74. //char guid[37];
  75. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  76. char queuedata[2600]={0};
  77. //===============================
  78. // Configuration: unknownkey
  79. //===============================
  80. static char unknownkey[10][20]={0};
  81. static int UnknownKeynum = 0;
  82. //===============================
  83. // Gun Total Numbers
  84. //===============================
  85. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  86. static int gunTotalNumber=0;
  87. //===============================
  88. // Local List Version
  89. //===============================
  90. static int localversion=0;
  91. static char idTagAuthorization[32]={0};
  92. //===============================
  93. // OCPP Path
  94. //===============================
  95. extern char OcppPath[160];
  96. extern char OcppProtocol[10];
  97. extern char OcppHost[50];
  98. extern char OcppTempPath[50];
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP StartTransaction transactionId variables
  115. //===============================
  116. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  117. //===============================
  118. // OCPP other variables
  119. //===============================
  120. int isUpdateRequest = FALSE;
  121. static int HeartBeatWaitTime = 10;
  122. static int FirstHeartBeat = 0;
  123. static int FirmwareStatusNotificationStatus = 3; // Idle
  124. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  125. static char CurrentChargingProfileScheduleStr[30]={0};
  126. //========================================
  127. // OCPP status/previous related variables
  128. //========================================
  129. static int GunStatusInterval = 10;
  130. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  131. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  132. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  133. static int GbPreviousSystemStatus[GB_QUANTITY];
  134. static int AcPreviousSystemStatus[AC_QUANTITY];
  135. int TransactionMessageAttemptsValue = 0;
  136. int TransactionMessageRetryIntervalValue = 0;
  137. static struct OCPPAuthLocalElemet
  138. {
  139. int listVersionInt;
  140. char idTagstr[20];
  141. char parentIdTag[20];
  142. char expiryDate[30];
  143. char idTagstatus[16];
  144. }idTagQuery;
  145. //=============================================
  146. // OCPP HeartBeat Response Not Receive Counts
  147. //============================================
  148. static int HeartBeatWithNOResponse = 0;
  149. static int HeartBeatCountPerHour = 0;
  150. extern struct lws *wsi_client;
  151. extern struct lws_context *context;
  152. extern unsigned char SendBuffer[4096];
  153. extern int SendBufLen;
  154. extern char *random_uuid( char buf[37] );
  155. extern void split(char **arr, char *str, const char *del);
  156. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  157. extern pthread_mutex_t mutex1;
  158. extern struct Charger_Info Charger;
  159. extern sqlite3 *db;
  160. int TransactionMessageAttemptsGet(void);
  161. int TransactionMessageRetryIntervalGet(void);
  162. int GetOcppConnStatus(void);
  163. void SetOcppConnStatus(uint8_t status);
  164. int updateSetting(char *key, char *value);
  165. int setKeyValue(char *key, char *value);
  166. void OCPP_get_TableAuthlocalAllData(void);
  167. void processUnkownKey(void);
  168. struct StructOCPPMeterValue
  169. {
  170. unsigned char TimeStamp[28];
  171. struct StructSampledValue SampledValue[10];
  172. };
  173. struct ClientTime
  174. {
  175. unsigned int Heartbeat;
  176. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  177. unsigned int StartTransaction;
  178. unsigned int StopTransaction;
  179. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  180. }clientTime;
  181. typedef union
  182. {
  183. //Operations Initiated by Central System
  184. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  185. struct
  186. {
  187. //CsMsgValue[0]
  188. unsigned char StatusNotificationReq :1; //bit 0,
  189. unsigned char StatusNotificationConf :1; //bit 0,
  190. unsigned char :6; //bit 2~7
  191. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  192. }CpinitiateMsg;
  193. CpinitiateMsg cpinitateMsg;
  194. //==========================================
  195. // Init all Enumeration & Mapping String
  196. //==========================================
  197. /*ChargePointErrorCode*/
  198. typedef enum {
  199. ConnectorLockFailure,
  200. EVCommunicationError,
  201. GroundFailure,
  202. HighTemperature,
  203. InternalError,
  204. LocalListConflict,
  205. NoError,
  206. OtherError,
  207. OverCurrentFailure,
  208. OverVoltage,
  209. PowerMeterFailure,
  210. PowerSwitchFailure,
  211. ReaderFailure,
  212. ResetFailure,
  213. UnderVoltage,
  214. WeakSignal
  215. } ChargePointErrorCode;
  216. #if 0
  217. static char *ChargePointErrorCodeStr[] = {
  218. MACROSTR(ConnectorLockFailure),
  219. MACROSTR(EVCommunicationError),
  220. MACROSTR(GroundFailure),
  221. MACROSTR(HighTemperature),
  222. MACROSTR(InternalError),
  223. MACROSTR(LocalListConflict),
  224. MACROSTR(NoError),
  225. MACROSTR(OtherError),
  226. MACROSTR(OverCurrentFailure),
  227. MACROSTR(OverVoltage),
  228. MACROSTR(PowerMeterFailure),
  229. MACROSTR(PowerSwitchFailure),
  230. MACROSTR(ReaderFailure),
  231. MACROSTR(ResetFailure),
  232. MACROSTR(UnderVoltage),
  233. MACROSTR(WeakSignal)
  234. };
  235. #endif
  236. /*ChargePointStatus*/
  237. typedef enum {
  238. Available =0,
  239. Preparing,
  240. Charging,
  241. SuspendedEVSE,
  242. SuspendedEV,
  243. Finishing,
  244. Reserved,
  245. Unavailable,
  246. Faulted
  247. } ChargePointStatus;
  248. static char * ChargePointStatusStr[] = {
  249. MACROSTR(Available),
  250. MACROSTR(Preparing),
  251. MACROSTR(Charging),
  252. MACROSTR(SuspendedEVSE),
  253. MACROSTR(SuspendedEV),
  254. MACROSTR(Finishing),
  255. MACROSTR(Reserved),
  256. MACROSTR(Unavailable),
  257. MACROSTR(Faulted)
  258. };
  259. /*AvailabilityType*/
  260. typedef enum {
  261. RegistrationStatus_Accepted,
  262. RegistrationStatus_Pending,
  263. RegistrationStatus_Rejected
  264. } RegistrationStatus;
  265. static char *RegistrationStatusStr[] = {
  266. MACROSTR(Accepted),
  267. MACROSTR(Pending),
  268. MACROSTR(Rejected)
  269. };
  270. /*AvailabilityType*/
  271. typedef enum {
  272. Inoperative,
  273. Operative
  274. } AvailabilityType;
  275. static char *AvailabilityTypeStr[] = {
  276. MACROSTR(Inoperative),
  277. MACROSTR(Operative)
  278. };
  279. /*AvailabilityStatus*/
  280. typedef enum {
  281. Accepted,
  282. Rejected,
  283. Scheduled
  284. } AvailabilityStatus;
  285. static char *AvailabilityStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected),
  288. MACROSTR(Scheduled)
  289. };
  290. /*ConfigurationStatus*/
  291. typedef enum {
  292. ConfigurationStatus_Accepted,
  293. ConfigurationStatus_Rejected,
  294. RebootRequired,
  295. NotSupported
  296. } ConfigurationStatus;
  297. static char *ConfigurationStatusStr[] = {
  298. MACROSTR(Accepted),
  299. MACROSTR(Rejected),
  300. MACROSTR(RebootRequired),
  301. MACROSTR(NotSupported)
  302. };
  303. /*ClearCacheStatus*/
  304. typedef enum {
  305. ClearCacheStatus_Accepted,
  306. ClearCacheStatus_Rejected
  307. } ClearCacheStatus;
  308. static char *ClearCacheStatusStr[] = {
  309. MACROSTR(Accepted),
  310. MACROSTR(Rejected)
  311. };
  312. /*ChargingProfilePurposeType*/
  313. typedef enum {
  314. ChargePointMaxProfile,
  315. TxDefaultProfile,
  316. TxProfile
  317. } ChargingProfilePurposeType;
  318. static char *ChargingProfilePurposeTypeStr[] = {
  319. MACROSTR(ChargePointMaxProfile),
  320. MACROSTR(TxDefaultProfile),
  321. MACROSTR(TxProfile)
  322. };
  323. /*ChargingProfileStatus*/
  324. typedef enum {
  325. ChargingProfileStatus_Accepted,
  326. ChargingProfileStatus_Rejected,
  327. ChargingProfileStatus_NotSupported
  328. } ChargingProfileStatus;
  329. static char *ChargingProfileStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Rejected),
  332. MACROSTR(NotSupported)
  333. };
  334. /*ClearChargingProfileStatus*/
  335. typedef enum {
  336. ClearChargingProfileStatus_Accepted,
  337. ClearChargingProfileStatus_Unknown
  338. } ClearChargingProfileStatus;
  339. static char *ClearChargingProfileStatusStr[] = {
  340. MACROSTR(Accepted),
  341. MACROSTR(Unknown)
  342. };
  343. /*GetCompositeScheduleStatus*/
  344. typedef enum {
  345. GetCompositeScheduleStatus_Accepted,
  346. GetCompositeScheduleStatus_Rejected
  347. } GetCompositeScheduleStatus;
  348. static char *GetCompositeScheduleStatusStr[] = {
  349. MACROSTR(Accepted),
  350. MACROSTR(Rejected)
  351. };
  352. /*ChargingRateUnitType*/
  353. typedef enum {
  354. ChargingRateUnitType_W,
  355. ChargingRateUnitType_A
  356. } ChargingRateUnitType;
  357. /*AuthorizationStatus*/
  358. typedef enum {
  359. AuthorizationStatus_Accepted ,
  360. AuthorizationStatus_Blocked ,
  361. AuthorizationStatus_Expired ,
  362. AuthorizationStatus_Invalid ,
  363. AuthorizationStatus_ConcurrentTx
  364. } AuthorizationStatus;
  365. /*UpdateType*/
  366. typedef enum {
  367. Differential ,
  368. Full
  369. } UpdateType;
  370. static char *UpdateTypeStr[] = {
  371. MACROSTR(Differential),
  372. MACROSTR(Full)
  373. };
  374. /*UpdateStatus*/
  375. typedef enum {
  376. UpdateStatus_Accepted ,
  377. UpdateStatus_Failed ,
  378. UpdateStatus_NotSupported ,
  379. UpdateStatus_VersionMismatch
  380. } UpdateStatus;
  381. static char *UpdateStatusStr[] = {
  382. MACROSTR(Accepted),
  383. MACROSTR(Failed),
  384. MACROSTR(NotSupported),
  385. MACROSTR(VersionMismatch)
  386. };
  387. /*RemoteStartStopStatus*/
  388. typedef enum {
  389. RemoteStartStopStatus_Accepted,
  390. RemoteStartStopStatus_Rejected
  391. } RemoteStartStopStatus;
  392. static char *RemoteStartStopStatusStr[] = {
  393. MACROSTR(Accepted),
  394. MACROSTR(Rejected)
  395. };
  396. /*ReservationStatus*/
  397. typedef enum {
  398. ReservationStatus_Accepted,
  399. ReservationStatus_Faulted,
  400. ReservationStatus_Occupied,
  401. ReservationStatus_Rejected,
  402. ReservationStatus_Unavailable
  403. } ReservationStatus;
  404. static char *ReservationStatusStr[] = {
  405. MACROSTR(Accepted),
  406. MACROSTR(Faulted),
  407. MACROSTR(Occupied),
  408. MACROSTR(Rejected),
  409. MACROSTR(Unavailable)
  410. };
  411. /*ResetType*/
  412. typedef enum {
  413. Hard,
  414. Soft
  415. } ResetType;
  416. static char *ResetTypeStr[] = {
  417. MACROSTR(Hard),
  418. MACROSTR(Soft)
  419. };
  420. /*ResetStatus*/
  421. typedef enum {
  422. ResetStatus_Accepted,
  423. ResetStatus_Rejected
  424. } ResetStatus;
  425. static char *ResetStatusStr[] = {
  426. MACROSTR(Accepted),
  427. MACROSTR(Rejected)
  428. };
  429. /*DiagnosticsStatus*/
  430. typedef enum {
  431. DiagnosticsStatus_Idle,
  432. DiagnosticsStatus_Uploaded,
  433. DiagnosticsStatus_UploadFailed,
  434. DiagnosticsStatus_Uploading
  435. } DiagnosticsStatus;
  436. static char * DiagnosticsStatusStr[] = {
  437. MACROSTR(Idle),
  438. MACROSTR(Uploaded),
  439. MACROSTR(UploadFailed),
  440. MACROSTR(Uploading)
  441. };
  442. /*FirmwareStatus*/
  443. typedef enum {
  444. FirmwareStatus_Downloaded,
  445. FirmwareStatus_DownloadFailed,
  446. FirmwareStatus_Downloading,
  447. FirmwareStatus_Idle,
  448. FirmwareStatus_InstallationFailed,
  449. FirmwareStatus_Installing,
  450. FirmwareStatus_Installed
  451. } FirmwareStatus;
  452. static char * FirmwareStatusStr[] = {
  453. MACROSTR(Downloaded),
  454. MACROSTR(DownloadFailed),
  455. MACROSTR(Downloading),
  456. MACROSTR(Idle),
  457. MACROSTR(InstallationFailed),
  458. MACROSTR(Installing),
  459. MACROSTR(Installed)
  460. };
  461. /*MessageTrigger*/
  462. typedef enum {
  463. BootNotification,
  464. DiagnosticsStatusNotification,
  465. FirmwareStatusNotification,
  466. Heartbeat,
  467. MeterValues,
  468. StatusNotification
  469. } MessageTrigger;
  470. static char * MessageTriggerStr[] = {
  471. MACROSTR(BootNotification),
  472. MACROSTR(DiagnosticsStatusNotification),
  473. MACROSTR(FirmwareStatusNotification),
  474. MACROSTR(Heartbeat),
  475. MACROSTR(MeterValues),
  476. MACROSTR(StatusNotification)
  477. };
  478. /*TriggerMessageStatus*/
  479. typedef enum {
  480. TriggerMessageStatus_Accepted ,
  481. TriggerMessageStatus_Rejected ,
  482. TriggerMessageStatus_NotImplemented
  483. } TriggerMessageStatus;
  484. static char * TriggerMessageStatusStr[] = {
  485. MACROSTR(Accepted),
  486. MACROSTR(Rejected),
  487. MACROSTR(NotImplemented)
  488. };
  489. /*UnlockStatus*/
  490. typedef enum {
  491. Unlocked,
  492. UnlockFailed,
  493. UnlockStatus_NotSupported
  494. } UnlockStatus;
  495. static char * UnlockStatusStr[] = {
  496. MACROSTR(Unlocked),
  497. MACROSTR(UnlockFailed),
  498. MACROSTR(NotSupported)
  499. };
  500. /*StopTransactionReason*/
  501. typedef enum {
  502. EmergencyStop,
  503. EVDisconnected,
  504. HardReset,
  505. Local,
  506. Other,
  507. PowerLoss,
  508. Reboot,
  509. Remote,
  510. SoftReset,
  511. UnlockCommand,
  512. DeAuthorized
  513. } StopTransactionReason;
  514. #if 0
  515. static char * StopTransactionReasonStr[] = {
  516. MACROSTR(EmergencyStop),
  517. MACROSTR(EVDisconnected),
  518. MACROSTR(HardReset),
  519. MACROSTR(Local),
  520. MACROSTR(Other),
  521. MACROSTR(PowerLoss),
  522. MACROSTR(Reboot),
  523. MACROSTR(Remote),
  524. MACROSTR(SoftReset),
  525. MACROSTR(UnlockCommand),
  526. MACROSTR(DeAuthorized)
  527. };
  528. #endif
  529. /*CancelReservationStatus*/
  530. typedef enum {
  531. CancelReservationStatus_Accepted,
  532. CancelReservationStatus_Rejected
  533. } CancelReservationStatus;
  534. static char * CancelReservationStatusStr[] = {
  535. MACROSTR(Accepted),
  536. MACROSTR(Rejected)
  537. };
  538. /*ReadingContext*/
  539. typedef enum {
  540. ReadingContext_Interruption_Begin,
  541. ReadingContext_Interruption_End,
  542. ReadingContext_Other,
  543. ReadingContext_Sample_Clock,
  544. ReadingContext_Sample_Periodic ,
  545. ReadingContext_Transaction_Begin ,
  546. ReadingContext_Transaction_End,
  547. ReadingContext_Trigger
  548. } ReadingContext;
  549. static char * ReadingContextStr[] = {
  550. MACROSTR(Interruption.Begin),
  551. MACROSTR(Interruption.End),
  552. MACROSTR(Other),
  553. MACROSTR(Sample.Clock),
  554. MACROSTR(Sample.Periodic),
  555. MACROSTR(Transaction.Begin),
  556. MACROSTR(Transaction.End),
  557. MACROSTR(Trigger)
  558. };
  559. /*ValueFormat*/
  560. typedef enum {
  561. Raw,
  562. SignedData
  563. } ValueFormat;
  564. static char * ValueFormatStr[] = {
  565. MACROSTR(Raw),
  566. MACROSTR(SignedData)
  567. };
  568. /*Measurand*/
  569. typedef enum {
  570. Current_Export ,
  571. Current_Import,
  572. Current_Offered,
  573. Energy_Active_Export_Register,
  574. Energy_Active_Import_Register,
  575. Energy_Reactive_Export_Register,
  576. Energy_Reactive_Import_Register,
  577. Energy_Active_Export_Interval,
  578. Energy_Active_Import_Interval,
  579. Energy_Reactive_Export_Interval,
  580. Energy_Reactive_Import_Interval,
  581. Frequency,
  582. Power_Active_Export ,
  583. Power_Active_Import,
  584. Power_Factor,
  585. Power_Offered,
  586. Power_Reactive_Export,
  587. Power_Reactive_Import,
  588. RPM,
  589. SoC,
  590. Temperature ,
  591. Voltage
  592. } Measurand;
  593. static char * MeasurandStr[] = {
  594. MACROSTR(Current.Export),
  595. MACROSTR(Current.Import),
  596. MACROSTR(Current.Offered),
  597. MACROSTR(Energy.Active.Export.Register),
  598. MACROSTR(Energy.Active.Import.Register),
  599. MACROSTR(Energy.Reactive.Export.Register),
  600. MACROSTR(Energy.Reactive.Import.Register),
  601. MACROSTR(Energy.Active.Export.Interval),
  602. MACROSTR(Energy.Active.Import.Interval),
  603. MACROSTR(Energy.Reactive.Export.Interval),
  604. MACROSTR(Energy.Reactive.Import.Interval),
  605. MACROSTR(Frequency),
  606. MACROSTR(Power.Active.Export),
  607. MACROSTR(Power.Active.Import),
  608. MACROSTR(Power.Factor),
  609. MACROSTR(Power.Offered),
  610. MACROSTR(Power.Reactive.ExportMACROSTR),
  611. MACROSTR(Power.Reactive.Import),
  612. MACROSTR(RPM),
  613. MACROSTR(SoC),
  614. MACROSTR(Temperature),
  615. MACROSTR(Voltage)
  616. };
  617. /*Location*/
  618. typedef enum {
  619. Location_Body,
  620. Location_Cable,
  621. Location_EV,
  622. Location_Inlet ,
  623. Location_Outlet
  624. } Location;
  625. static char * LocationStr[] = {
  626. MACROSTR(Body),
  627. MACROSTR(Cable),
  628. MACROSTR(EV),
  629. MACROSTR(Inlet),
  630. MACROSTR(Outlet)
  631. };
  632. /*Phase*/
  633. typedef enum {
  634. L1,
  635. L2,
  636. L3,
  637. N,
  638. L1_N,
  639. L2_N,
  640. L3_N,
  641. L1_L2,
  642. L2_L3,
  643. L3_L1
  644. } Phase;
  645. static char * PhaseStr[] = {
  646. MACROSTR(L1),
  647. MACROSTR(L2),
  648. MACROSTR(L3),
  649. MACROSTR(N),
  650. MACROSTR(L1-N),
  651. MACROSTR(L2-N),
  652. MACROSTR(L3-N),
  653. MACROSTR(L1-L2),
  654. MACROSTR(L2-L3),
  655. MACROSTR(L3-L1)
  656. };
  657. /*UnitOfMeasure*/
  658. typedef enum {
  659. UnitOfMeasure_Wh,
  660. UnitOfMeasure_kWh ,
  661. UnitOfMeasure_varh ,
  662. UnitOfMeasure_kvarh ,
  663. UnitOfMeasure_W ,
  664. UnitOfMeasure_kW ,
  665. UnitOfMeasure_VA ,
  666. UnitOfMeasure_kVA ,
  667. UnitOfMeasure_var ,
  668. UnitOfMeasure_kvar ,
  669. UnitOfMeasure_A ,
  670. UnitOfMeasure_V ,
  671. UnitOfMeasure_Celsius ,
  672. UnitOfMeasure_Fahrenheit ,
  673. UnitOfMeasure_K ,
  674. UnitOfMeasure_Percent
  675. } UnitOfMeasure;
  676. static char * UnitOfMeasureStr[] = {
  677. MACROSTR(Wh),
  678. MACROSTR(kWh),
  679. MACROSTR(varh),
  680. MACROSTR(kvarh),
  681. MACROSTR(W),
  682. MACROSTR(kW),
  683. MACROSTR(VA),
  684. MACROSTR(kVA),
  685. MACROSTR(var),
  686. MACROSTR(kvar),
  687. MACROSTR(A),
  688. MACROSTR(V),
  689. MACROSTR(Celsius),
  690. MACROSTR(Fahrenheit),
  691. MACROSTR(K),
  692. MACROSTR(Percent)
  693. };
  694. #if 0
  695. /*Configuration enum*/
  696. enum CoreProfile {
  697. AllowOfflineTxForUnknownId=0,
  698. AuthorizationCacheEnabled,
  699. AuthorizeRemoteTxRequests,
  700. BlinkRepeat,
  701. ClockAlignedDataInterval,
  702. ConnectionTimeOut,
  703. GetConfigurationMaxKeys,
  704. HeartbeatInterval,
  705. LightIntensity,
  706. LocalAuthorizeOffline,
  707. LocalPreAuthorize,
  708. MaxEnergyOnInvalidId,
  709. MeterValuesAlignedData,
  710. MeterValuesAlignedDataMaxLength,
  711. MeterValuesSampledData,
  712. MeterValuesSampledDataMaxLength,
  713. MeterValueSampleInterval,
  714. MinimumStatusDuration,
  715. NumberOfConnectors,
  716. ResetRetries,
  717. ConnectorPhaseRotation,
  718. ConnectorPhaseRotationMaxLength,
  719. StopTransactionOnEVSideDisconnect,
  720. StopTransactionOnInvalidId,
  721. StopTxnAlignedData,
  722. StopTxnAlignedDataMaxLength,
  723. StopTxnSampledData,
  724. StopTxnSampledDataMaxLength,
  725. SupportedFeatureProfiles,
  726. SupportedFeatureProfilesMaxLength,
  727. TransactionMessageAttempts,
  728. TransactionMessageRetryInterval,
  729. UnlockConnectorOnEVSideDisconnect,
  730. WebSocketPingInterval,
  731. _CoreProfile_CNT
  732. };
  733. #endif
  734. enum LocalAuthListManagementProfile{
  735. LocalAuthListEnabled=0,
  736. LocalAuthListMaxLength,
  737. SendLocalListMaxLength,
  738. _LocalAuthListManagementProfile_CNT
  739. };
  740. enum ReservationProfile{
  741. ReserveConnectorZeroSupported
  742. };
  743. enum SmartChargingProfile{
  744. ChargeProfileMaxStackLevel,
  745. ChargingScheduleAllowedChargingRateUnit,
  746. ChargingScheduleMaxPeriods,
  747. ConnectorSwitch3to1PhaseSupported,
  748. MaxChargingProfilesInstalled
  749. };
  750. enum ChargerSystemStatus{
  751. ChargerSystemStatus_Booting,
  752. ChargerSystemStatus_Idle,
  753. ChargerSystemStatus_Authorizing,
  754. ChargerSystemStatus_Preparing,
  755. ChargerSystemStatus_Charging,
  756. ChargerSystemStatus_Terminating,
  757. ChargerSystemStatus_Alarm,
  758. ChargerSystemStatus_Fault
  759. };
  760. enum GetConfigurationKey {
  761. GetConfiguration_AllowOfflineTxForUnknownId=0,
  762. GetConfiguration_AuthorizationCacheEnabled,
  763. GetConfiguration_AuthorizeRemoteTxRequests,
  764. GetConfiguration_BlinkRepeat,
  765. GetConfiguration_ClockAlignedDataInterval,
  766. GetConfiguration_ConnectionTimeOut,
  767. GetConfiguration_GetConfigurationMaxKeys,
  768. GetConfiguration_HeartbeatInterval,
  769. GetConfiguration_LightIntensity,
  770. GetConfiguration_LocalAuthorizeOffline,
  771. GetConfiguration_LocalPreAuthorize,
  772. GetConfiguration_MaxEnergyOnInvalidId,
  773. GetConfiguration_MeterValuesAlignedData,
  774. GetConfiguration_MeterValuesAlignedDataMaxLength,
  775. GetConfiguration_MeterValuesSampledData,
  776. GetConfiguration_MeterValuesSampledDataMaxLength,
  777. GetConfiguration_MeterValueSampleInterval,
  778. GetConfiguration_MinimumStatusDuration,
  779. GetConfiguration_NumberOfConnectors,
  780. GetConfiguration_ResetRetries,
  781. GetConfiguration_ConnectorPhaseRotation,
  782. GetConfiguration_ConnectorPhaseRotationMaxLength,
  783. GetConfiguration_StopTransactionOnEVSideDisconnect,
  784. GetConfiguration_StopTransactionOnInvalidId,
  785. GetConfiguration_StopTxnAlignedData,
  786. GetConfiguration_StopTxnAlignedDataMaxLength,
  787. GetConfiguration_StopTxnSampledData,
  788. GetConfiguration_StopTxnSampledDataMaxLength,
  789. GetConfiguration_SupportedFeatureProfiles,
  790. GetConfiguration_SupportedFeatureProfilesMaxLength,
  791. GetConfiguration_TransactionMessageAttempts,
  792. GetConfiguration_TransactionMessageRetryInterval,
  793. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  794. GetConfiguration_WebSocketPingInterval,
  795. GetConfiguration_LocalAuthListEnabled,
  796. GetConfiguration_LocalAuthListMaxLength,
  797. GetConfiguration_SendLocalListMaxLength,
  798. GetConfiguration_ReserveConnectorZeroSupported,
  799. GetConfiguration_ChargeProfileMaxStackLevel,
  800. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  801. GetConfiguration_ChargingScheduleMaxPeriods,
  802. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  803. GetConfiguration_MaxChargingProfilesInstalled,
  804. };
  805. //GetConfiguration Array
  806. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  807. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  808. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  809. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  810. //==========================================
  811. // Init all share memory
  812. //==========================================
  813. int InitShareMemory()
  814. {
  815. int result = PASS;
  816. int MeterSMId;
  817. //creat ShmSysConfigAndInfo
  818. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  819. {
  820. #ifdef SystemLogMessage
  821. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  822. #endif
  823. result = FAIL;
  824. }
  825. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  826. {
  827. #ifdef SystemLogMessage
  828. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  829. #endif
  830. result = FAIL;
  831. }
  832. else
  833. {}
  834. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  835. {
  836. #ifdef SystemLogMessage
  837. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  838. #endif
  839. result = FAIL;
  840. }
  841. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else
  849. {}
  850. //creat ShmPsuData
  851. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmPsuData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmPsuData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmOCPP16Data
  868. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. /****************************** For Initial Settings************************************************/
  885. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  886. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  887. {
  888. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  889. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  890. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  891. }
  892. // Charger PRE_SYS_MODE
  893. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  894. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  895. clientTime.Heartbeat=time((time_t*)NULL);
  896. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  897. {
  898. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  899. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  900. }
  901. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  902. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  903. // allocate Configuration memory address
  904. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  905. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  906. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  907. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  909. {
  910. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  911. DEBUG_INFO("DC ...\n");
  912. }
  913. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  914. {
  915. SystemInitial = AC_QUANTITY;
  916. DEBUG_INFO("AC ...\n");
  917. }
  918. //Status Setting
  919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  920. {
  921. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  922. }
  923. for (int index = 0; index < CCS_QUANTITY; index++)
  924. {
  925. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  926. }
  927. for (int index = 0; index < GB_QUANTITY; index++)
  928. {
  929. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  930. }
  931. for (int index = 0; index < AC_QUANTITY; index++)
  932. {
  933. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  934. }
  935. return result;
  936. }
  937. int ProcessShareMemory()
  938. {
  939. if(InitShareMemory() == FAIL)
  940. {
  941. #ifdef SystemLogMessage
  942. DEBUG_ERROR("InitShareMemory NG\n");
  943. #endif
  944. if(ShmStatusCodeData!=NULL)
  945. {
  946. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  947. }
  948. sleep(5);
  949. return FAIL;
  950. }
  951. return PASS;
  952. }
  953. //---------------------------------------------
  954. // new:
  955. // enum SYSTEM_STATUS
  956. // {
  957. // SYS_MODE_BOOTING = 0,
  958. // SYS_MODE_IDLE = 1,
  959. // SYS_MODE_AUTHORIZING = 2,
  960. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  961. // SYS_MODE_REASSIGN = 4,
  962. // SYS_MODE_PREPARING = 5,
  963. // SYS_MODE_PREPARE_FOR_EV = 6,
  964. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  965. // SYS_MODE_CHARGING = 8,
  966. // SYS_MODE_TERMINATING = 9,
  967. // SYS_MODE_COMPLETE = 10,
  968. // SYS_MODE_ALARM = 11,
  969. // SYS_MODE_FAULT = 12,
  970. // SYS_MODE_RESERVATION = 13,
  971. // SYS_MODE_BOOKING = 14,
  972. // SYS_MODE_MAINTAIN = 15,
  973. // SYS_MODE_DEBUG = 16,
  974. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  975. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  976. // SYS_MODE_UPDATE = 19
  977. // };
  978. //
  979. //
  980. //-----------------------------------------
  981. void CheckSystemValue(void)
  982. {
  983. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  984. int IdleModeCnt = 0;
  985. char filenmae[100]={0};
  986. char str[100]={0};
  987. //===============================
  988. // send Heartbeat
  989. //===============================
  990. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  991. {
  992. printf("Heartbeat !!!\n");
  993. //parameter for test
  994. sendHeartbeatRequest(0);
  995. //==============================================
  996. // Reset Waiting Time
  997. //==============================================
  998. clientTime.Heartbeat=time((time_t*)NULL);
  999. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1000. }
  1001. //==============================================
  1002. // Update firmware request
  1003. //==============================================
  1004. if(isUpdateRequest == TRUE )
  1005. {
  1006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1007. {
  1008. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1009. {
  1010. //check SystemStatus
  1011. /*************************DC*******************************/
  1012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1013. {
  1014. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1015. {
  1016. IdleModeCnt = IdleModeCnt + 1;
  1017. }
  1018. }
  1019. for (int index = 0; index < CCS_QUANTITY; index++)
  1020. {
  1021. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1022. {
  1023. IdleModeCnt = IdleModeCnt + 1;
  1024. }
  1025. }
  1026. for (int index = 0; index < GB_QUANTITY; index++)
  1027. {
  1028. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1029. {
  1030. IdleModeCnt = IdleModeCnt + 1;
  1031. }
  1032. }
  1033. }
  1034. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1035. {
  1036. isUpdateRequest = FALSE;
  1037. }
  1038. }
  1039. else
  1040. {
  1041. /*************************AC*******************************/
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1045. {
  1046. IdleModeCnt = IdleModeCnt + 1;
  1047. }
  1048. }
  1049. if(IdleModeCnt == AC_QUANTITY)
  1050. {
  1051. isUpdateRequest = FALSE;
  1052. }
  1053. }
  1054. }
  1055. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1056. {
  1057. //===============================
  1058. // CSU Trigger Reset Conf
  1059. //===============================
  1060. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1061. {
  1062. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1063. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1064. {
  1065. server_sign = FALSE;
  1066. }
  1067. }
  1068. //===============================
  1069. // CSU Trigger Authorize Request
  1070. //===============================
  1071. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1072. {
  1073. sendAuthorizeRequest(0);
  1074. authorizeRetryTimes = authorizeRetryTimes + 1;
  1075. // authenrequest = TRUE
  1076. if(authorizeRetryTimes < 3)
  1077. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1078. }
  1079. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1080. {
  1081. authorizeRetryTimes = 0;
  1082. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1083. server_sign = FALSE;
  1084. }
  1085. else if((server_sign == FALSE) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  1086. {
  1087. sendAuthorizeRequest(0);
  1088. }
  1089. //===============================
  1090. // CSU Trigger Smart Charging Profilw
  1091. //===============================
  1092. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1093. {
  1094. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1095. GetChargingProfileRequest(gun_index);
  1096. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1097. }
  1098. //==============================================
  1099. // Charger start transaction
  1100. //==============================================
  1101. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1102. {
  1103. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1104. sendStartTransactionRequest(gun_index);
  1105. clientTime.StartTransaction = time((time_t*)NULL);
  1106. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1107. }
  1108. //==============================================
  1109. // Charger stop transaction
  1110. //==============================================
  1111. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1112. {
  1113. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1114. sendStopTransactionRequest(gun_index);
  1115. clientTime.StopTransaction = time((time_t*)NULL);
  1116. }
  1117. //==============================================
  1118. // Charger status report
  1119. //==============================================
  1120. /* Check Mode Change */
  1121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1122. {
  1123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1124. {
  1125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1126. {
  1127. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1128. {
  1129. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1130. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1131. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1132. statusModeChage[gun_index] = TRUE;
  1133. }
  1134. }
  1135. }
  1136. for (int index = 0; index < CCS_QUANTITY; index++)
  1137. {
  1138. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1139. {
  1140. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1141. {
  1142. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1143. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1144. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1145. statusModeChage[gun_index] = TRUE;
  1146. }
  1147. }
  1148. }
  1149. for (int index = 0; index < GB_QUANTITY; index++)
  1150. {
  1151. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1152. {
  1153. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1154. {
  1155. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1156. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1157. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1158. statusModeChage[gun_index] = TRUE;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. else //AC
  1164. {
  1165. for (int index = 0; index < AC_QUANTITY; index++)
  1166. {
  1167. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1168. {
  1169. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1170. {
  1171. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1172. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1173. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1174. statusModeChage[gun_index] = TRUE;
  1175. }
  1176. }
  1177. }// END OF FOR
  1178. }// END OF ELSE
  1179. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1180. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1181. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1182. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1183. {
  1184. if(SystemInitial != 0)
  1185. SystemInitial = SystemInitial -1;
  1186. sendStatusNotificationRequest(gun_index);
  1187. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1188. statusModeChage[gun_index] = FALSE;
  1189. }
  1190. //==============================================
  1191. // Meter report
  1192. //==============================================
  1193. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1194. {
  1195. //check Transaction active
  1196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1197. {
  1198. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1199. {
  1200. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1201. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1202. {
  1203. meterValueSend[gun_index] =1;
  1204. }
  1205. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1206. {
  1207. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1208. if((access(filenmae,F_OK))!=-1)
  1209. {
  1210. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1211. sprintf(str,"rm -f %s",filenmae);
  1212. system(str);
  1213. }
  1214. }
  1215. }// End for CHAdeMO
  1216. for (int index = 0; index < CCS_QUANTITY; index++)
  1217. {
  1218. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1219. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1220. {
  1221. meterValueSend[gun_index] =1;
  1222. }
  1223. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1224. {
  1225. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1226. if((access(filenmae,F_OK))!=-1)
  1227. {
  1228. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1229. sprintf(str,"rm -f %s",filenmae);
  1230. system(str);
  1231. }
  1232. }
  1233. } // End for CCS
  1234. for (int index = 0; index < GB_QUANTITY; index++)
  1235. {
  1236. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1237. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1238. {
  1239. meterValueSend[gun_index] =1;
  1240. }
  1241. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1242. {
  1243. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1244. if((access(filenmae,F_OK))!=-1)
  1245. {
  1246. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1247. sprintf(str,"rm -f %s",filenmae);
  1248. system(str);
  1249. }
  1250. }
  1251. }// End for GB
  1252. }
  1253. else
  1254. {
  1255. for (int index = 0; index < AC_QUANTITY; index++)
  1256. {
  1257. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1258. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1259. {
  1260. meterValueSend[gun_index] =1;
  1261. }
  1262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1263. {
  1264. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1265. if((access(filenmae,F_OK))!=-1)
  1266. {
  1267. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1268. sprintf(str,"rm -f %s",filenmae);
  1269. system(str);
  1270. }
  1271. }
  1272. }//End for AC
  1273. }//END OF ELSE
  1274. // sleep(1);
  1275. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1276. if(meterValueSend[gun_index] == 1)
  1277. sendMeterValuesRequest(gun_index);
  1278. }
  1279. //==============================================
  1280. // Check Connector reserved
  1281. //==============================================
  1282. //===============================
  1283. // Check if Reserve is expired
  1284. //===============================
  1285. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1286. {
  1287. double diff_t;
  1288. struct tm tp;
  1289. // current time
  1290. time_t t = time(NULL);
  1291. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1292. tp.tm_isdst = -1;
  1293. time_t utc = mktime(&tp);
  1294. diff_t = difftime(utc, t);
  1295. if(diff_t <= 0)
  1296. {
  1297. DEBUG_INFO("reserve expired !!! \n");
  1298. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1299. }
  1300. }//END OF Check if Reserve is expired
  1301. //==========================================
  1302. // csu trigger FirmwareStatusNotificationReq
  1303. //==========================================
  1304. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1305. {
  1306. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1307. }
  1308. //==========================================
  1309. // csu trigger CancelReservationConf
  1310. //==========================================
  1311. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1312. {
  1313. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1314. }
  1315. //==========================================
  1316. // csu trigger ChangeAvailabilityConf
  1317. //==========================================
  1318. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1319. {
  1320. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1321. }
  1322. //==========================================
  1323. // csu trigger UnlockConnectorConf
  1324. //==========================================
  1325. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1326. {
  1327. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1328. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1329. }
  1330. //==========================================
  1331. // csu trigger ReserveNowConf
  1332. //==========================================
  1333. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1334. {
  1335. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1336. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1337. }
  1338. //==========================================
  1339. // csu trigger DataTransferReq
  1340. //==========================================
  1341. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1342. {
  1343. sendDataTransferRequest(gun_index);
  1344. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1345. }
  1346. }
  1347. }
  1348. //==========================================
  1349. // send request routine
  1350. //==========================================
  1351. int sendAuthorizeRequest(int gun_index)
  1352. {
  1353. mtrace();
  1354. int result = FAIL;
  1355. char message[100]={0};
  1356. char guid[37];
  1357. char tempdata[65]={0};
  1358. DEBUG_INFO("sendAuthorizeRequest \n");
  1359. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1360. //Local Authorize
  1361. if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1362. {
  1363. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1364. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1365. {
  1366. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1367. {
  1368. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1369. }
  1370. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1371. {
  1372. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1373. }
  1374. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1375. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1376. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1377. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1378. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1379. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1380. authorizeRetryTimes = 0;
  1381. return result;
  1382. }
  1383. else
  1384. {
  1385. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1386. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1387. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1388. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1389. result = PASS;
  1390. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1391. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1392. authorizeRetryTimes = 0;
  1393. return result;
  1394. }
  1395. }
  1396. //initailize struct Authorize
  1397. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1398. //get data from shared memory
  1399. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1400. random_uuid(guid);
  1401. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1402. LWS_Send(message);
  1403. sprintf(tempdata, "Authorize,%d", gun_index);
  1404. if(hashmap_operation(0, guid, tempdata) == 1)
  1405. {
  1406. result = PASS;
  1407. DEBUG_ERROR("Authorize mapItem pass\n");
  1408. }
  1409. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1410. return result;
  1411. }
  1412. int sendBootNotificationRequest(void)
  1413. {
  1414. mtrace();
  1415. int result = FAIL;
  1416. char message[500]={0}, payload[700]={0};
  1417. char guid[37]={0};
  1418. char tempdata[65]={0};
  1419. int IsGunCharging = FALSE;
  1420. //check Transaction active
  1421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1422. {
  1423. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1424. {
  1425. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1426. {
  1427. IsGunCharging = TRUE;
  1428. }
  1429. }
  1430. for (int index = 0; index < CCS_QUANTITY; index++)
  1431. {
  1432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1433. {
  1434. IsGunCharging = TRUE;
  1435. }
  1436. }
  1437. for (int index = 0; index < GB_QUANTITY; index++)
  1438. {
  1439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1440. {
  1441. IsGunCharging = TRUE;
  1442. }
  1443. }
  1444. }
  1445. else
  1446. {
  1447. for (int index = 0; index < AC_QUANTITY; index++)
  1448. {
  1449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1450. {
  1451. IsGunCharging = TRUE;
  1452. }
  1453. }
  1454. }
  1455. if(IsGunCharging == TRUE)
  1456. {
  1457. server_sign = TRUE;
  1458. return result;
  1459. }
  1460. // Fill BootNotification fields
  1461. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1462. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1463. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1464. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1465. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1466. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1467. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1468. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1469. ShmOCPP16Data->ChargeBoxId
  1470. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1471. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1472. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1473. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1474. ,ShmOCPP16Data->BootNotification.CpIccid
  1475. ,ShmOCPP16Data->BootNotification.CpImsi
  1476. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1477. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1478. random_uuid(guid);
  1479. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1480. LWS_Send(message);
  1481. sprintf(tempdata, "BootNotification,0");
  1482. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1483. {
  1484. result = PASS;
  1485. }
  1486. memset(queuedata, 0, sizeof(queuedata));
  1487. strcpy(queuedata,message);
  1488. return result;
  1489. }
  1490. int sendDataTransferRequest(int gun_index)
  1491. {
  1492. mtrace();
  1493. char message[1000]={0};
  1494. char guid[37]={0};
  1495. char tempdata[65]={0};
  1496. int result = FAIL;
  1497. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1498. random_uuid(guid);
  1499. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1500. MESSAGE_TYPE_CALL,
  1501. guid,
  1502. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1503. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1504. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1505. LWS_Send(message);
  1506. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1507. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1508. {
  1509. result = PASS;
  1510. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1511. }
  1512. return result;
  1513. }
  1514. int sendDiagnosticsStatusNotificationRequest(char *status)
  1515. {
  1516. mtrace();
  1517. int result = FAIL;
  1518. char message[110]={0};
  1519. char guid[37]={0};
  1520. char tempdata[65]={0};
  1521. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1522. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1523. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1524. random_uuid(guid);
  1525. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1526. LWS_Send(message);
  1527. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1528. if(hashmap_operation(0, guid, tempdata) == 1)
  1529. {
  1530. result = PASS;
  1531. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1532. }
  1533. //#ifdef SystemLogMessage
  1534. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1535. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1536. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1537. //#endif
  1538. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1539. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1540. //record status
  1541. if(strcmp(status,"Idle")==0)
  1542. {
  1543. DiagnosticsStatusNotificationStatus = 0;
  1544. }
  1545. else if(strcmp(status,"Uploaded")==0)
  1546. {
  1547. DiagnosticsStatusNotificationStatus = 1;
  1548. }
  1549. else if(strcmp(status,"UploadFailed")==0)
  1550. {
  1551. DiagnosticsStatusNotificationStatus = 2;
  1552. }
  1553. else if(strcmp(status,"Uploading")==0)
  1554. {
  1555. DiagnosticsStatusNotificationStatus = 3;
  1556. }
  1557. return result;
  1558. }
  1559. int sendFirmwareStatusNotificationRequest(char *status)
  1560. {
  1561. mtrace();
  1562. int result = FAIL;
  1563. char message[110]={0};
  1564. char guid[37]={0};
  1565. char tempdata[65]={0};
  1566. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1567. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1568. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1569. random_uuid(guid);
  1570. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1571. LWS_Send(message);
  1572. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1573. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1574. {
  1575. result = PASS;
  1576. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1577. }
  1578. //#ifdef SystemLogMessage
  1579. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1580. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1581. //#endif
  1582. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1583. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1584. //record status
  1585. if(strcmp(status,"Downloaded")==0)
  1586. {
  1587. FirmwareStatusNotificationStatus = 0;
  1588. }
  1589. else if(strcmp(status,"DownloadFailed")==0)
  1590. {
  1591. FirmwareStatusNotificationStatus = 1;
  1592. }
  1593. else if(strcmp(status,"Downloading")==0)
  1594. {
  1595. FirmwareStatusNotificationStatus = 2;
  1596. }
  1597. else if(strcmp(status,"Idle")==0)
  1598. {
  1599. FirmwareStatusNotificationStatus = 3;
  1600. }
  1601. else if(strcmp(status,"InstallationFailed")==0)
  1602. {
  1603. FirmwareStatusNotificationStatus = 4;
  1604. }
  1605. else if(strcmp(status,"Installing")==0)
  1606. {
  1607. FirmwareStatusNotificationStatus = 5;
  1608. }
  1609. else if(strcmp(status,"Installed")==0)
  1610. {
  1611. FirmwareStatusNotificationStatus = 6;
  1612. }
  1613. return result;
  1614. }
  1615. int sendHeartbeatRequest(int gun_index)
  1616. {
  1617. mtrace();
  1618. int result = FAIL;
  1619. char message[80]={0};
  1620. char guid[37]={0};
  1621. char tempdata[65]={0};
  1622. random_uuid(guid);
  1623. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1624. , MESSAGE_TYPE_CALL
  1625. , guid );
  1626. LWS_Send(message);
  1627. sprintf(tempdata, "Heartbeat,%d", 0);
  1628. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1629. {
  1630. result = PASS;
  1631. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1632. }
  1633. return result;
  1634. }
  1635. int sendStartTransactionRequest(int gun_index)
  1636. {
  1637. mtrace();
  1638. int result = FAIL;
  1639. char message[250]={0};
  1640. char guid[37]={0};
  1641. struct timeval tmnow;
  1642. struct tm *tm;
  1643. char buf[28];//, usec_buf[6];
  1644. char tempdata[65]={0};
  1645. DEBUG_INFO("sendStartTransactionRequest...");
  1646. gettimeofday(&tmnow, NULL);
  1647. time_t t;
  1648. t = time(NULL);
  1649. /*UTC time and date*/
  1650. tm = gmtime(&t);
  1651. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1652. #if 0 // remove temporally
  1653. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1654. strcat(buf,".");
  1655. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1656. strcat(buf,usec_buf);
  1657. #endif
  1658. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1659. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1660. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1662. {
  1663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1664. {
  1665. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1666. {
  1667. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1668. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1669. }
  1670. }
  1671. for (int index = 0; index < CCS_QUANTITY; index++)
  1672. {
  1673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1674. {
  1675. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1676. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1677. }
  1678. }
  1679. for (int index = 0; index < GB_QUANTITY; index++)
  1680. {
  1681. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1682. {
  1683. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1684. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1685. }
  1686. }
  1687. }
  1688. else
  1689. {
  1690. for (int index = 0; index < AC_QUANTITY; index++)
  1691. {
  1692. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1693. {
  1694. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1695. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1696. }
  1697. }
  1698. }//END OF ELSE
  1699. random_uuid(guid);
  1700. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1701. , MESSAGE_TYPE_CALL
  1702. , guid
  1703. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1704. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1705. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1706. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1707. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1708. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1709. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1710. {
  1711. result = PASS;
  1712. }
  1713. strcpy(queuedata, message);
  1714. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1715. LWS_Send(message);
  1716. #if 0
  1717. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1718. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1719. {
  1720. result = PASS;
  1721. }
  1722. strcpy(queuedata, message);
  1723. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1724. #endif
  1725. //#ifdef SystemLogMessage
  1726. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1727. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1728. //#endif
  1729. return result;
  1730. }
  1731. int sendStatusNotificationRequest(int gun_index)
  1732. {
  1733. mtrace();
  1734. int result = FAIL;
  1735. char message[600]={0};
  1736. char guid[37];
  1737. int currentStatus = 0;
  1738. struct timeval tmnow;
  1739. struct tm *tm;
  1740. char buf[28];//, usec_buf[6];
  1741. char tempdata[65]={0};
  1742. gettimeofday(&tmnow, NULL);
  1743. time_t t;
  1744. t = time(NULL);
  1745. /*UTC time and date*/
  1746. tm = gmtime(&t);
  1747. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1748. #if 0 // remove temporally
  1749. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1750. strcat(buf,".");
  1751. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1752. strcat(buf,usec_buf);
  1753. #endif
  1754. printf("%s",buf);
  1755. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1756. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1757. // it's option
  1758. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1759. /*
  1760. enum _SYSTEM_STATUS
  1761. {
  1762. S_BOOTING = 0,
  1763. S_IDLE, = 1
  1764. S_AUTHORIZING, =2
  1765. S_REASSIGN_CHECK, =3
  1766. S_REASSIGN, =4
  1767. S_PRECHARGE, =5
  1768. S_PREPARING_FOR_EV, =6
  1769. S_PREPARING_FOR_EVSE, =7
  1770. S_CHARGING, =8
  1771. S_TERMINATING, =9
  1772. S_COMPLETE, =10
  1773. S_ALARM, =11
  1774. S_FAULT =12
  1775. }
  1776. */
  1777. //check Transaction active
  1778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1779. {
  1780. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1781. {
  1782. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1783. {
  1784. currentStatus = 0; //OCPP Status: Available
  1785. }
  1786. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1787. {
  1788. currentStatus = 1; //OCPP Status: Preparing
  1789. }
  1790. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1791. {
  1792. currentStatus = 2; //OCPP Status: Charging
  1793. }
  1794. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1795. {
  1796. currentStatus = 5; //OCPP Status: Finishing
  1797. }
  1798. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1799. {
  1800. currentStatus = 4; //OCPP Status: SuspendedEV
  1801. }
  1802. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) // ---> Unavailable
  1803. {
  1804. currentStatus = 7; //OCPP Status: Unavailable
  1805. }
  1806. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1807. {
  1808. currentStatus = 8; //OCPP Status: Faulted
  1809. }
  1810. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1811. {
  1812. currentStatus = 6; //OCPP Status: Reserved
  1813. }
  1814. }//end of for CHAdeMO_QUANTITY
  1815. for (int index = 0; index < CCS_QUANTITY; index++)
  1816. {
  1817. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1818. {
  1819. currentStatus = 0; //OCPP Status: Available
  1820. }
  1821. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1822. {
  1823. currentStatus = 1; //OCPP Status: Preparing
  1824. }
  1825. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1826. {
  1827. currentStatus = 2; //OCPP Status: Charging
  1828. }
  1829. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1830. {
  1831. currentStatus = 5; //OCPP Status: Finishing
  1832. }
  1833. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM ,S_TERMINATING ---> SuspendedEV
  1834. {
  1835. currentStatus = 4; //OCPP Status: SuspendedEV
  1836. }
  1837. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1838. {
  1839. currentStatus = 7; //OCPP Status : Unavailable
  1840. }
  1841. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1842. {
  1843. currentStatus = 8; //OCPP Status: Faulted
  1844. }
  1845. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1846. {
  1847. currentStatus = 6; //OCPP Status: Reserved
  1848. }
  1849. }
  1850. for (int index = 0; index < GB_QUANTITY; index++)
  1851. {
  1852. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1853. {
  1854. currentStatus = 0; //OCPP Status: Available
  1855. }
  1856. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1857. {
  1858. currentStatus = 1; //OCPP Status: Preparing
  1859. }
  1860. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1861. {
  1862. currentStatus = 2; //OCPP Status: Charging
  1863. }
  1864. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1865. {
  1866. currentStatus = 5; //OCPP Status: Finishing
  1867. }
  1868. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM , S_TERMINATING ---> SuspendedEV
  1869. {
  1870. currentStatus = 4; //OCPP Status: SuspendedEV
  1871. }
  1872. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1873. {
  1874. currentStatus = 7; //OCPP Status: Unavailable
  1875. }
  1876. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1877. {
  1878. currentStatus = 8; //OCPP Status: Faulted
  1879. }
  1880. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1881. {
  1882. currentStatus = 6; //OCPP Status: Reserved
  1883. }
  1884. }
  1885. }
  1886. else
  1887. {
  1888. for (int index = 0; index < AC_QUANTITY; index++)
  1889. {
  1890. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1891. {
  1892. currentStatus = 0; //OCPP Status: Available
  1893. }
  1894. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1895. {
  1896. currentStatus = 1; //OCPP Status: Preparing
  1897. }
  1898. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1899. {
  1900. currentStatus = 2; //OCPP Status: Charging
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1903. {
  1904. currentStatus = 5; //OCPP Status: Finishing
  1905. }
  1906. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1907. {
  1908. currentStatus = 4; //OCPP Status: SuspendedEV
  1909. }
  1910. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1911. {
  1912. currentStatus = 7; //OCPP Status: Unavailable
  1913. }
  1914. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1915. {
  1916. currentStatus = 8; //OCPP Status: Faulted
  1917. }
  1918. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1919. {
  1920. currentStatus = 6; //OCPP Status: Reserved
  1921. }
  1922. }//end of for AC_QUANTITY
  1923. }//END OF ELSE
  1924. //it's option
  1925. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1926. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1927. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1928. random_uuid(guid);
  1929. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1930. , MESSAGE_TYPE_CALL
  1931. , guid
  1932. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1933. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1934. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1935. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1936. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1937. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1938. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1939. LWS_Send(message);
  1940. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1941. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1942. {
  1943. //DEBUG_ERROR("statusNotification mapitem pass");
  1944. result = PASS;
  1945. }
  1946. return result;
  1947. }
  1948. int sendStopTransactionRequest(int gun_index)
  1949. {
  1950. mtrace();
  1951. int result = FAIL;
  1952. //char message[1500]={0};
  1953. char guid[37]={0};
  1954. char tempdata[65]={0};
  1955. //int idx_sample=0;
  1956. DEBUG_ERROR("sendStopTransactionRequest \n");
  1957. memset(queuedata, 0, sizeof(queuedata));
  1958. //ENERGY_ACTIVE_IMPORT_REGISTER
  1959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1960. {
  1961. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1962. {
  1963. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1964. {
  1965. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1966. }
  1967. }// END OF CHAdeMO_QUANTITY
  1968. for (int index = 0; index < CCS_QUANTITY; index++)
  1969. {
  1970. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1971. {
  1972. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1973. }
  1974. }// END OF CCS_QUANTITY
  1975. for (int index = 0; index < GB_QUANTITY; index++)
  1976. {
  1977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1978. {
  1979. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1980. }
  1981. }// END OF GB_QUANTITY
  1982. }
  1983. else
  1984. {
  1985. for (int index = 0; index < AC_QUANTITY; index++)
  1986. {
  1987. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1988. {
  1989. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1990. }
  1991. }// END OF AC_QUANTITY
  1992. }//END OF ELSE
  1993. //Stop Transaction Time
  1994. struct timeval tmnow;
  1995. struct tm *tm;
  1996. char buf[28];//, usec_buf[6];
  1997. gettimeofday(&tmnow, NULL);
  1998. time_t t;
  1999. t = time(NULL);
  2000. /*UTC time and date*/
  2001. tm = gmtime(&t);
  2002. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2004. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2005. random_uuid(guid);
  2006. /***********************************transactionData******************************************************/
  2007. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2009. //=================================
  2010. // Transaction_Begin
  2011. //=================================
  2012. // Energy.Active.Export.Interval
  2013. //idx_sample=0;
  2014. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Export_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2018. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2019. {
  2020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2021. }
  2022. else
  2023. {
  2024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2025. }
  2026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2028. //=================================
  2029. // Transaction_End
  2030. //=================================
  2031. //Current.Export
  2032. //idx_sample=1;
  2033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2034. {
  2035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2036. {
  2037. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2038. {
  2039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2040. }
  2041. }
  2042. for (int index = 0; index < CCS_QUANTITY; index++)
  2043. {
  2044. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2045. {
  2046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2047. }
  2048. }
  2049. for (int index = 0; index < GB_QUANTITY; index++)
  2050. {
  2051. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2052. {
  2053. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2054. }
  2055. }
  2056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2057. }
  2058. else
  2059. {
  2060. for (int index = 0; index < AC_QUANTITY; index++)
  2061. {
  2062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2063. {
  2064. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2065. }
  2066. }
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2068. }// END FOR AC ELSE
  2069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2072. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2075. //Energy.Active.Export.Interval
  2076. //idx_sample=2;
  2077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2078. {
  2079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2080. {
  2081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2082. {
  2083. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2084. }
  2085. }
  2086. for (int index = 0; index < CCS_QUANTITY; index++)
  2087. {
  2088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2089. {
  2090. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2091. }
  2092. }
  2093. for (int index = 0; index < GB_QUANTITY; index++)
  2094. {
  2095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2096. {
  2097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2098. }
  2099. }
  2100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2101. }
  2102. else
  2103. {
  2104. for (int index = 0; index < AC_QUANTITY; index++)
  2105. {
  2106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2107. {
  2108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2109. }
  2110. }
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2112. }// END FOR AC ELSE
  2113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2116. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2119. //Power.Active.Export
  2120. //idx_sample=3;
  2121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2122. {
  2123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2124. {
  2125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2126. {
  2127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2128. }
  2129. }
  2130. for (int index = 0; index < CCS_QUANTITY; index++)
  2131. {
  2132. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2133. {
  2134. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2135. }
  2136. }
  2137. for (int index = 0; index < GB_QUANTITY; index++)
  2138. {
  2139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2140. {
  2141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2142. }
  2143. }
  2144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2145. }
  2146. else
  2147. {
  2148. for (int index = 0; index < AC_QUANTITY; index++)
  2149. {
  2150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2151. {
  2152. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2153. }
  2154. }
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2156. }// END FOR AC ELSE
  2157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2160. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2163. //Voltage
  2164. //idx_sample=4;
  2165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2166. {
  2167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2168. {
  2169. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2170. {
  2171. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2172. }
  2173. }
  2174. for (int index = 0; index < CCS_QUANTITY; index++)
  2175. {
  2176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2177. {
  2178. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2179. }
  2180. }
  2181. for (int index = 0; index < GB_QUANTITY; index++)
  2182. {
  2183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2184. {
  2185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2186. }
  2187. }
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2189. }
  2190. else
  2191. {
  2192. for (int index = 0; index < AC_QUANTITY; index++)
  2193. {
  2194. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2195. {
  2196. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2197. }
  2198. }
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2200. }// END FOR AC ELSE
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2204. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2207. //SoC
  2208. //idx_sample=5;
  2209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2210. {
  2211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2212. {
  2213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2214. {
  2215. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2216. }
  2217. }
  2218. for (int index = 0; index < CCS_QUANTITY; index++)
  2219. {
  2220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2221. {
  2222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2223. }
  2224. }
  2225. for (int index = 0; index < GB_QUANTITY; index++)
  2226. {
  2227. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2228. {
  2229. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2230. }
  2231. }
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2238. } // END FOR DC CASE
  2239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2240. {
  2241. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2242. ,MESSAGE_TYPE_CALL
  2243. ,guid
  2244. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2245. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2246. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2248. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2249. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2257. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2258. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2259. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2260. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2261. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2262. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2263. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2264. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2265. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2266. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2268. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2269. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2286. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2287. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2288. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2289. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2290. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2291. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2292. );
  2293. }
  2294. else
  2295. {
  2296. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2297. ,MESSAGE_TYPE_CALL
  2298. ,guid
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2304. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2340. );
  2341. }
  2342. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2343. if(hashmap_operation(0, guid, tempdata) == 1)
  2344. {
  2345. result = PASS;
  2346. DEBUG_INFO("StopTransaction mapitem pass\n");
  2347. }
  2348. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2349. LWS_Send(queuedata);
  2350. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2351. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2352. {
  2353. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2354. }
  2355. #if 0
  2356. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2357. if(hashmap_operation(0, guid, tempdata) == 1)
  2358. {
  2359. result = PASS;
  2360. DEBUG_INFO("StopTransaction mapitem pass\n");
  2361. }
  2362. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2363. #endif
  2364. //for test
  2365. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2366. return result;
  2367. }
  2368. int sendMeterValuesRequest(int gun_index)
  2369. {
  2370. mtrace();
  2371. int result = FAIL;
  2372. // char message[1500]={0};
  2373. char guid[37]={0};
  2374. //int idx_sample=0;
  2375. //int length = 0;
  2376. char tempdata[65]={0};
  2377. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2378. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2379. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2380. {
  2381. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2382. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2383. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2384. return result;
  2385. }
  2386. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2387. {
  2388. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2389. }
  2390. memset(queuedata, 0, sizeof(queuedata));
  2391. //set value
  2392. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2393. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2394. random_uuid(guid);
  2395. //UTC Date time
  2396. struct timeval tmnow;
  2397. struct tm *tm;
  2398. char buf[28];//, usec_buf[6];
  2399. gettimeofday(&tmnow, NULL);
  2400. time_t t;
  2401. t = time(NULL);
  2402. /*UTC time and date*/
  2403. tm = gmtime(&t);
  2404. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2406. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2407. //idx_sample=0;
  2408. //********************************(1)Current.Export************************************************/
  2409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2410. {
  2411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2412. {
  2413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2414. {
  2415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2416. }
  2417. }
  2418. for (int index = 0; index < CCS_QUANTITY; index++)
  2419. {
  2420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2421. {
  2422. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2423. }
  2424. }
  2425. for (int index = 0; index < GB_QUANTITY; index++)
  2426. {
  2427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2428. {
  2429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2430. }
  2431. }
  2432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2433. }
  2434. else
  2435. {
  2436. for (int index = 0; index < AC_QUANTITY; index++)
  2437. {
  2438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2439. {
  2440. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2441. }
  2442. }
  2443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2444. }// END FOR AC ELSE
  2445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2448. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2451. //idx_sample=1;
  2452. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2454. {
  2455. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2456. {
  2457. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2458. {
  2459. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2460. }
  2461. }
  2462. for (int index = 0; index < CCS_QUANTITY; index++)
  2463. {
  2464. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2465. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2466. {
  2467. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2469. }
  2470. }
  2471. for (int index = 0; index < GB_QUANTITY; index++)
  2472. {
  2473. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2474. {
  2475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2476. }
  2477. }
  2478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2479. }
  2480. else
  2481. {
  2482. for (int index = 0; index < AC_QUANTITY; index++)
  2483. {
  2484. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2485. {
  2486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2487. }
  2488. }
  2489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2490. }//END FOR AC ELSE
  2491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2494. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2497. //idx_sample=2;
  2498. //********************************(4)Power.Active.Export************************************************/
  2499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2500. {
  2501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2502. {
  2503. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2504. {
  2505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2506. }
  2507. }
  2508. for (int index = 0; index < CCS_QUANTITY; index++)
  2509. {
  2510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2511. {
  2512. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2513. }
  2514. }
  2515. for (int index = 0; index < GB_QUANTITY; index++)
  2516. {
  2517. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2518. {
  2519. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2521. }
  2522. }
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2524. }
  2525. else
  2526. {
  2527. for (int index = 0; index < AC_QUANTITY; index++)
  2528. {
  2529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2530. {
  2531. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2532. }
  2533. }
  2534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2535. }// END FOR AC ELSE
  2536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2539. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2542. //idx_sample=3;
  2543. //***********************************************(5)VOLTAGE******************************************************/
  2544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2545. {
  2546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2547. {
  2548. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2549. {
  2550. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2551. }
  2552. }
  2553. for (int index = 0; index < CCS_QUANTITY; index++)
  2554. {
  2555. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2556. {
  2557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2558. }
  2559. }
  2560. for (int index = 0; index < GB_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2565. }
  2566. }
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2568. }
  2569. else
  2570. {
  2571. for (int index = 0; index < AC_QUANTITY; index++)
  2572. {
  2573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2574. {
  2575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2576. }
  2577. }
  2578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2579. }//END FOR AC ELSE
  2580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2583. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2587. {
  2588. //idx_sample=4;
  2589. //sampledValue = NULL;
  2590. //***********************************************(6)SOC******************************************************/
  2591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2592. {
  2593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2594. {
  2595. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2596. }
  2597. }
  2598. for (int index = 0; index < CCS_QUANTITY; index++)
  2599. {
  2600. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2601. {
  2602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2603. }
  2604. }
  2605. for (int index = 0; index < GB_QUANTITY; index++)
  2606. {
  2607. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2608. {
  2609. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2610. }
  2611. }
  2612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2618. }
  2619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2620. {
  2621. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2622. ,MESSAGE_TYPE_CALL
  2623. ,guid
  2624. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2625. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2626. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2656. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2657. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2658. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2659. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2662. );
  2663. }
  2664. else
  2665. {
  2666. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2667. ,MESSAGE_TYPE_CALL
  2668. ,guid
  2669. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2670. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2671. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2700. );
  2701. }
  2702. // Put request guid to hash map
  2703. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2704. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2705. {
  2706. result = PASS;
  2707. DEBUG_INFO("MeterValues mapitem pass\n");
  2708. }
  2709. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2710. LWS_Send(queuedata);
  2711. #if 0
  2712. // Put request guid to hash map
  2713. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2714. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2715. {
  2716. result = PASS;
  2717. DEBUG_INFO("MeterValues mapitem pass\n");
  2718. }
  2719. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2720. #endif
  2721. return result;
  2722. }
  2723. //==========================================
  2724. // send confirm routine
  2725. //==========================================
  2726. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2727. {
  2728. mtrace();
  2729. int result = FAIL;
  2730. char message[100]={0};
  2731. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2732. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2733. LWS_Send(message);
  2734. result = TRUE;
  2735. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2736. return result;
  2737. }
  2738. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2739. {
  2740. mtrace();
  2741. int result = FAIL;
  2742. char message[100]={0};
  2743. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2744. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2745. LWS_Send(message);
  2746. result = TRUE;
  2747. return result;
  2748. }
  2749. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2750. {
  2751. mtrace();
  2752. int result = FAIL;
  2753. char message[100]={0};
  2754. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2755. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2756. LWS_Send(message);
  2757. result = TRUE;
  2758. return result;
  2759. }
  2760. int sendClearCacheConfirmation(char *uuid,char *payload)
  2761. {
  2762. mtrace();
  2763. int result = FAIL;
  2764. char message[500]={0};
  2765. // int count = 0;
  2766. // int gun_index = 0;
  2767. // char guid[37];
  2768. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2769. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2770. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2771. LWS_Send(message);
  2772. return result;
  2773. }
  2774. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2775. {
  2776. mtrace();
  2777. int result = FAIL;
  2778. char message[500]={0};
  2779. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2780. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2781. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2782. LWS_Send(message);
  2783. return result;
  2784. }
  2785. int sendDataTransferConfirmation(char *uuid,char *payload)
  2786. {
  2787. mtrace();
  2788. char statusStr[20]={0};
  2789. char dataStr[10]={0};
  2790. char sstr[20]={0};
  2791. int c = 0;
  2792. char *loc;
  2793. int result = FAIL;
  2794. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2795. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2796. /**********************status**************************/
  2797. loc = strstr(payload, "status");
  2798. memset(sstr ,0, sizeof(sstr) );
  2799. c = 0;
  2800. while (loc[3+strlen("status")+c] != '\"')
  2801. {
  2802. sstr[c] = loc[3+strlen("status")+c];
  2803. c++;
  2804. }
  2805. sstr[c] = '\0';
  2806. strcpy(statusStr, sstr);
  2807. /**********************data**************************/
  2808. loc = strstr(payload, "data");
  2809. memset(sstr ,0, sizeof(sstr) );
  2810. c = 0;
  2811. while (loc[3+strlen("data")+c] != '\"')
  2812. {
  2813. sstr[c] = loc[3+strlen("data")+c];
  2814. c++;
  2815. }
  2816. sstr[c] = '\0';
  2817. strcpy(dataStr, sstr);
  2818. return result;
  2819. }
  2820. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2821. {
  2822. mtrace();
  2823. int result = FAIL;
  2824. char message[1000]={0};
  2825. double diff_f = 0.0;
  2826. int diff_i = 0;
  2827. int diffSeconds = 0;
  2828. struct tm tp;
  2829. int TimeZero = FALSE;
  2830. int CompositeScheduleIndex = 0;
  2831. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2832. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2833. {
  2834. TimeZero = TRUE;
  2835. }
  2836. else
  2837. {
  2838. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2839. }
  2840. if(TimeZero == FALSE)
  2841. {
  2842. tp.tm_isdst = -1;
  2843. time_t utc = mktime(&tp);
  2844. time_t t = time(NULL);
  2845. diff_f = difftime(t, utc);
  2846. diff_i = (int)diff_f;
  2847. diffSeconds = diff_i % 86400;//86400 seconds/day
  2848. }
  2849. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2850. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2851. #if 0 //remove temporally
  2852. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":6.0,\"numberPhases\":3},{\"startPeriod\":40,\"limit\":10.0,\"numberPhases\":3},{\"startPeriod\":100,\"limit\":8.0,\"numberPhases\":3}"
  2853. ,MESSAGE_TYPE_CALLRESULT
  2854. ,uuid
  2855. ,payload
  2856. ,connectorIdInt
  2857. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2858. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2859. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2860. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2861. #endif
  2862. if(nPeriod == 0)
  2863. {
  2864. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2865. ,MESSAGE_TYPE_CALLRESULT
  2866. ,uuid
  2867. ,payload
  2868. ,connectorIdInt
  2869. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2870. }
  2871. else
  2872. {
  2873. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2874. ,MESSAGE_TYPE_CALLRESULT
  2875. ,uuid
  2876. ,payload
  2877. ,connectorIdInt
  2878. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2879. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2880. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2881. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2882. int len = nPeriod;
  2883. //Last Period StartPriod is less than diffSeconds
  2884. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2885. {
  2886. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2887. , 0
  2888. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2890. }
  2891. else
  2892. {
  2893. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2894. {
  2895. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2896. {
  2897. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2898. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2899. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2900. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2901. }
  2902. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2903. {
  2904. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2905. , (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  2906. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2907. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2908. }
  2909. }
  2910. }
  2911. sprintf(message + strlen(message), "]}}]");
  2912. }
  2913. LWS_Send(message);
  2914. result = TRUE;
  2915. return result;
  2916. }
  2917. int sendGetConfigurationConfirmation(char *uuid)
  2918. {
  2919. mtrace();
  2920. int result = FAIL;
  2921. int MaxKeySupported = 0;
  2922. int sentConfigurationNumber= 0;
  2923. int sentunConfigurationNumber= 0;
  2924. char message[4000]={0};
  2925. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2926. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2927. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2928. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  2929. ,MESSAGE_TYPE_CALLRESULT
  2930. ,uuid );
  2931. //configuration key
  2932. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2933. {
  2934. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2935. {
  2936. if (sentConfigurationNumber == 0)
  2937. {
  2938. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  2939. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2940. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2941. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2942. }
  2943. else
  2944. {
  2945. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2946. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2947. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2948. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2949. }
  2950. sentConfigurationNumber = sentConfigurationNumber + 1;
  2951. }
  2952. }
  2953. sprintf(message + strlen(message), "]");
  2954. if(UnknownKeynum != 0)
  2955. {
  2956. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2957. //unkown key
  2958. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2959. {
  2960. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2961. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2962. if(sentunConfigurationNumber == 0)
  2963. {
  2964. sprintf(message + strlen(message), "\"%s\""
  2965. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2966. }
  2967. else
  2968. {
  2969. sprintf(message + strlen(message), ",\"%s\""
  2970. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2971. }
  2972. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  2973. }
  2974. sprintf(message + strlen(message), "]");
  2975. }
  2976. sprintf(message + strlen(message), "} ]");
  2977. LWS_Send(message);
  2978. return result;
  2979. }
  2980. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2981. {
  2982. mtrace();
  2983. int result = FAIL;
  2984. char message[400]={0};
  2985. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  2986. if(strcmp(payload,"")==0)
  2987. {
  2988. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  2989. }
  2990. else
  2991. {
  2992. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  2993. }
  2994. LWS_Send(message);
  2995. result = TRUE;
  2996. return result;
  2997. }
  2998. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2999. {
  3000. mtrace();
  3001. int result = FAIL;
  3002. char message[80]={0};
  3003. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3004. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3005. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3006. LWS_Send(message);
  3007. result = TRUE;
  3008. return result;
  3009. }
  3010. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3011. {
  3012. mtrace();
  3013. int result = FAIL;
  3014. char message[80]={0};
  3015. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3016. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3017. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3018. LWS_Send(message);
  3019. result = TRUE;
  3020. return result;
  3021. }
  3022. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3023. {
  3024. mtrace();
  3025. int result = FAIL;
  3026. char message[80]={0};
  3027. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3028. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3029. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3030. LWS_Send(message);
  3031. result = TRUE;
  3032. return result;
  3033. }
  3034. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3035. {
  3036. mtrace();
  3037. int result = FAIL;
  3038. char message[80]={0};
  3039. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3040. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3041. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3042. LWS_Send(message);
  3043. result = TRUE;
  3044. return result;
  3045. }
  3046. int sendResetConfirmation(char *uuid,char *payload)
  3047. {
  3048. mtrace();
  3049. int result = FAIL;
  3050. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3051. char message[80]={0};
  3052. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3053. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3054. LWS_Send(message);
  3055. result = TRUE;
  3056. return result;
  3057. }
  3058. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3059. {
  3060. mtrace();
  3061. int result = FAIL;
  3062. char message[500]={0};
  3063. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3064. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3065. LWS_Send(message);
  3066. result = TRUE;
  3067. return result;
  3068. }
  3069. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3070. {
  3071. mtrace();
  3072. int result = FAIL;
  3073. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3074. char message[80]={0};
  3075. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3076. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3077. LWS_Send(message);
  3078. result = TRUE;
  3079. return result;
  3080. }
  3081. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3082. {
  3083. mtrace();
  3084. int result = FAIL;
  3085. char message[80]={0};
  3086. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3087. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3088. LWS_Send(message);
  3089. result = TRUE;
  3090. return result;
  3091. }
  3092. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3093. {
  3094. mtrace();
  3095. int result = FAIL;
  3096. char message[80]={0};
  3097. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3098. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3099. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3100. LWS_Send(message);
  3101. result = TRUE;
  3102. return result;
  3103. }
  3104. int sendUpdateFirmwareConfirmation(char *uuid)
  3105. {
  3106. mtrace();
  3107. int result = FAIL;
  3108. char message[60]={0};
  3109. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3110. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3111. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3112. LWS_Send(message);
  3113. result = TRUE;
  3114. return result;
  3115. }
  3116. //==========================================
  3117. // send CallError routine
  3118. //==========================================
  3119. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3120. {
  3121. mtrace();
  3122. //int result = FAIL;
  3123. char message[220]={0};
  3124. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3125. #ifdef SystemLogMessage
  3126. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3127. uniqueId, action, errorCode, errorDescription);
  3128. #endif
  3129. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3130. LWS_Send(message);
  3131. //result = TRUE;
  3132. }
  3133. //==========================================
  3134. // Handle server request routine Start
  3135. //==========================================
  3136. #define GUN_NUM 1
  3137. int handleCancelReservationRequest(char *uuid, char *payload)
  3138. {
  3139. mtrace();
  3140. int result = FAIL;
  3141. int gunNO = 0;
  3142. int reservationIdInt =0;
  3143. char comfirmstr[20];
  3144. int c = 0;
  3145. char *loc;
  3146. char sstr[100]={0};
  3147. DEBUG_INFO("handle CancelReservationRequest\n");
  3148. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3149. c = 0;
  3150. loc = strstr(payload, "reservationId");
  3151. memset(sstr ,0, sizeof(sstr) );
  3152. while (loc[strlen("reservationId")+2+c] != '}')
  3153. {
  3154. sstr[c] = loc[strlen("reservationId")+2+c];
  3155. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3156. c++;
  3157. }
  3158. sstr[c] = '\0';
  3159. reservationIdInt = atoi(sstr);
  3160. memset(comfirmstr, 0, sizeof comfirmstr);
  3161. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3162. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3163. //check Transaction active
  3164. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3165. {
  3166. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3167. {
  3168. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3169. {
  3170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3171. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3172. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3173. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3174. goto end;
  3175. }
  3176. }
  3177. for (int index = 0; index < CCS_QUANTITY; index++)
  3178. {
  3179. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3180. {
  3181. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3182. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3183. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3184. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3185. goto end;
  3186. }
  3187. }
  3188. for (int index = 0; index < GB_QUANTITY; index++)
  3189. {
  3190. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3191. {
  3192. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3193. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3194. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3195. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3196. goto end;
  3197. }
  3198. }
  3199. }
  3200. else
  3201. {
  3202. for (int index = 0; index < AC_QUANTITY; index++)
  3203. {
  3204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3205. {
  3206. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3207. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3208. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3209. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3210. goto end;
  3211. }
  3212. }
  3213. }// END FOR AC ELSE
  3214. //The reservationId does NOT match the reservationId
  3215. sendCancelReservationConfirmation(uuid, comfirmstr);
  3216. end:
  3217. // Fill in ocpp packet uuid
  3218. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3219. return result;
  3220. }
  3221. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3222. {
  3223. mtrace();
  3224. int result = FAIL;
  3225. int gunIndex = 0;
  3226. char sstr[90]={0};
  3227. char typeStr[16]={0};
  3228. char comfirmstr[20];
  3229. int specificId = FALSE;
  3230. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3231. char *loc;
  3232. //int intervalInt = 0;
  3233. int c = 0;
  3234. /*** connectorId ****/
  3235. c = 0;
  3236. loc = strstr(payload, "connectorId");
  3237. memset(sstr ,0, sizeof(sstr) );
  3238. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3239. {
  3240. sstr[c] = loc[strlen("connectorId")+2+c];
  3241. c++;
  3242. }
  3243. sstr[c] = '\0';
  3244. gunIndex = atoi(sstr);
  3245. /***type ****/
  3246. loc = strstr(payload, "type");
  3247. memset(sstr ,0, sizeof(sstr) );
  3248. c = 0;
  3249. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3250. {
  3251. sstr[c] = loc[3+strlen("type")+c];
  3252. c++;
  3253. }
  3254. sstr[c] = '\0';
  3255. strcpy(typeStr, sstr);
  3256. if(gunIndex != 0)
  3257. {
  3258. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3259. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3260. }
  3261. else
  3262. {
  3263. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3264. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3265. }
  3266. memset(comfirmstr, 0, sizeof comfirmstr);
  3267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3268. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3269. {
  3270. specificId = TRUE;
  3271. }
  3272. if(specificId == FALSE)
  3273. goto end;
  3274. if(gunIndex != 0)
  3275. {
  3276. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3277. }
  3278. else
  3279. {
  3280. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3281. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3282. }
  3283. /*
  3284. enum SYSTEM_STATUS
  3285. {
  3286. SYS_MODE_BOOTING = 0,
  3287. SYS_MODE_IDLE = 1,
  3288. SYS_MODE_AUTHORIZING = 2,
  3289. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3290. SYS_MODE_REASSIGN = 4,
  3291. SYS_MODE_PREPARING = 5,
  3292. SYS_MODE_PREPARE_FOR_EV = 6,
  3293. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3294. SYS_MODE_CHARGING = 8,
  3295. SYS_MODE_TERMINATING = 9,
  3296. SYS_MODE_COMPLETE = 10,
  3297. SYS_MODE_ALARM = 11,
  3298. SYS_MODE_FAULT = 12,
  3299. SYS_MODE_RESERVATION = 13,
  3300. SYS_MODE_BOOKING = 14,
  3301. SYS_MODE_MAINTAIN = 15,
  3302. SYS_MODE_DEBUG = 16,
  3303. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3304. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3305. SYS_MODE_UPDATE = 19
  3306. };
  3307. */
  3308. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3309. {
  3310. //check Transaction active
  3311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3312. {
  3313. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3314. {
  3315. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3316. {
  3317. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3318. {
  3319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3320. }
  3321. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3322. {
  3323. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3324. }
  3325. else
  3326. {
  3327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3328. }
  3329. goto end;
  3330. }
  3331. }//END FOR CHAdeMO_QUANTITY
  3332. for (int index = 0; index < CCS_QUANTITY; index++)
  3333. {
  3334. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3335. {
  3336. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3337. {
  3338. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3339. }
  3340. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3341. {
  3342. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3343. }
  3344. else
  3345. {
  3346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3347. }
  3348. goto end;
  3349. }
  3350. }//END FOR CCS_QUANTITY
  3351. for (int index = 0; index < GB_QUANTITY; index++)
  3352. {
  3353. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3354. {
  3355. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3356. {
  3357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3358. }
  3359. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3360. {
  3361. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3362. }
  3363. else
  3364. {
  3365. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3366. }
  3367. goto end;
  3368. }
  3369. }// END FOR GB_QUANTITY
  3370. }
  3371. else
  3372. {
  3373. for (int index = 0; index < AC_QUANTITY; index++)
  3374. {
  3375. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3376. {
  3377. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3378. {
  3379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3380. }
  3381. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3382. {
  3383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3384. }
  3385. else
  3386. {
  3387. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3388. }
  3389. goto end;
  3390. }
  3391. }//END FOR AC_QUANTITY
  3392. }// END FOR AC ELSE
  3393. }//END FOR AvailabilityTypeStr[Inoperative]
  3394. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3395. {
  3396. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3397. //check Transaction active
  3398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3399. {
  3400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3401. {
  3402. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3403. {
  3404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3405. goto end;
  3406. }
  3407. }//END FOR CHAdeMO_QUANTITY
  3408. for (int index = 0; index < CCS_QUANTITY; index++)
  3409. {
  3410. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3411. {
  3412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3413. goto end;
  3414. }
  3415. }//END FOR CCS_QUANTITY
  3416. for (int index = 0; index < GB_QUANTITY; index++)
  3417. {
  3418. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3419. {
  3420. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3422. goto end;
  3423. }
  3424. }// END FOR GB_QUANTITY
  3425. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3426. }
  3427. else
  3428. {
  3429. for (int index = 0; index < AC_QUANTITY; index++)
  3430. {
  3431. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3432. {
  3433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3434. goto end;
  3435. }
  3436. }//END FOR CHAdeMO_QUANTITY
  3437. }//END FOR AC ELSE
  3438. }//END FOR AvailabilityTypeStr[Operative]
  3439. end:
  3440. if(gunIndex != 0)
  3441. {
  3442. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3443. }
  3444. else
  3445. {
  3446. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3447. }
  3448. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3449. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3450. return result;
  3451. }
  3452. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3453. {
  3454. mtrace();
  3455. int result = FAIL;
  3456. char sstr[100]={0};
  3457. char keystr[40]={0};
  3458. char valuestr[100]={0};
  3459. char *loc;
  3460. int c = 0;
  3461. char comfirmstr[20]={0};
  3462. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3463. /***key ****/
  3464. loc = strstr(payload, "key");
  3465. memset(sstr ,0, sizeof(sstr) );
  3466. c = 0;
  3467. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3468. {
  3469. sstr[c] = loc[3+strlen("key")+c];
  3470. c++;
  3471. }
  3472. sstr[c] = '\0';
  3473. strcpy(keystr, sstr);
  3474. //DEBUG_INFO( "keystr=%s\n",keystr);
  3475. /***value ****/
  3476. loc = strstr(payload, "value");
  3477. memset(sstr ,0, sizeof(sstr) );
  3478. c = 0;
  3479. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3480. {
  3481. sstr[c] = loc[3+strlen("value")+c];
  3482. c++;
  3483. }
  3484. sstr[c] = '\0';
  3485. strcpy(valuestr, sstr);
  3486. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3487. if((uuid==NULL) || (payload ==NULL) )
  3488. {
  3489. #ifdef Debug
  3490. DEBUG_INFO("payload is null\n");
  3491. #endif
  3492. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3493. }
  3494. else
  3495. {
  3496. int status = setKeyValue(keystr, valuestr);
  3497. switch(status)
  3498. {
  3499. case ConfigurationStatus_Accepted:
  3500. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3501. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3502. StoreConfigurationTable();
  3503. break;
  3504. case ConfigurationStatus_Rejected:
  3505. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3506. break;
  3507. case RebootRequired:
  3508. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3509. StoreConfigurationTable();
  3510. break;
  3511. case NotSupported:
  3512. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3513. break;
  3514. default:
  3515. break;
  3516. }
  3517. }
  3518. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3519. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3520. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3521. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3522. {
  3523. ChageWebSocketPingInterval(atoi(valuestr));
  3524. }
  3525. return result;
  3526. }
  3527. int handleClearCacheRequest(char *uuid, char *payload)
  3528. {
  3529. mtrace();
  3530. int result = FAIL;
  3531. char comfirmstr[20];
  3532. int fd;
  3533. char rmFileCmd[100]={0};
  3534. struct stat stats;
  3535. DEBUG_INFO("handle ClearCacheRequest\n");
  3536. stat("/Storage/OCPP", &stats);
  3537. // Check for directory existence
  3538. if (S_ISDIR(stats.st_mode) == 1)
  3539. {
  3540. //DEBUG_ERROR("\n OCPP directory exist \n");
  3541. }
  3542. else
  3543. {
  3544. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3545. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3546. system(rmFileCmd);
  3547. }
  3548. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3549. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3550. {
  3551. DEBUG_INFO("AuthorizationCache file exist.\n");
  3552. }
  3553. else
  3554. {
  3555. DEBUG_INFO("AuthorizationCache file not exist\n");
  3556. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3557. if(log == NULL)
  3558. {
  3559. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3560. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3561. goto end;
  3562. }
  3563. else
  3564. {
  3565. fclose(log);
  3566. }
  3567. }
  3568. fd = open(AuthorizationCache_JSON,O_RDWR);
  3569. if(fd < 0)
  3570. {
  3571. DEBUG_INFO("open AuthorizationCache file failed\n");
  3572. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3573. }
  3574. else
  3575. {
  3576. DEBUG_INFO("open AuthorizationCache file successful\n");
  3577. //* 清空? 件 */
  3578. ftruncate(fd,0);
  3579. //* ? 新设置? 件? 移??*/
  3580. lseek(fd,0,SEEK_SET);
  3581. close(fd);
  3582. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3583. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3584. }
  3585. end:
  3586. sendClearCacheConfirmation(uuid, comfirmstr);
  3587. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3588. return result;
  3589. }
  3590. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3591. {
  3592. mtrace();
  3593. int result = FAIL;
  3594. int resultRename;
  3595. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3596. char chargingProfilePurposeStr[26]={0};
  3597. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3598. char tempchargingProfilePurposeStr[26]={0};
  3599. char sstr[160]={0};//sstr[200]={ 0 };
  3600. char str[100]={0};
  3601. int c = 0;
  3602. //int i = 0;
  3603. //char * pch;
  3604. char *loc;
  3605. char fname[200];
  3606. char comfirmstr[20]={0};
  3607. char word[1000]={0};
  3608. int clearflag = FALSE;
  3609. int chargingProfileIdIsNULL = FALSE;
  3610. int connectorIsNULL = FALSE;
  3611. int chargingProfilePurposeIsNULL = FALSE;
  3612. int stackLevelIsNULL = FALSE;
  3613. int GotoEnd = FALSE;
  3614. FILE *fptr1, *fptr2;
  3615. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json";
  3616. int n_chargingProfile=0;
  3617. char sLineWord[1060]={0};
  3618. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3619. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3620. //***id ****/
  3621. c = 0;
  3622. loc = strstr(payload, "id");
  3623. memset(sstr ,0, sizeof(sstr) );
  3624. if(loc == NULL)
  3625. {
  3626. chargingProfileIdIsNULL = TRUE;
  3627. }
  3628. else
  3629. {
  3630. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3631. {
  3632. sstr[c] = loc[strlen("id")+2+c];
  3633. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3634. c++;
  3635. }
  3636. sstr[c] = '\0';
  3637. chargingProfileIdInt = atoi(sstr);
  3638. }
  3639. //***connectorId ****/
  3640. c=0;
  3641. loc = strstr(payload, "connectorId");
  3642. memset(sstr ,0, sizeof(sstr) );
  3643. if(loc == NULL)
  3644. {
  3645. connectorIsNULL = TRUE;
  3646. }
  3647. else
  3648. {
  3649. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3650. {
  3651. sstr[c] = loc[strlen("connectorId")+2+c];
  3652. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3653. c++;
  3654. }
  3655. sstr[c] = '\0';
  3656. connectorIdInt = atoi(sstr);
  3657. }
  3658. //***chargingProfilePurpose ****/
  3659. loc = strstr(payload, "chargingProfilePurpose");
  3660. memset(sstr ,0, sizeof(sstr) );
  3661. c = 0;
  3662. if(loc == NULL)
  3663. {
  3664. chargingProfilePurposeIsNULL = TRUE;
  3665. }
  3666. else
  3667. {
  3668. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3669. {
  3670. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3671. c++;
  3672. }
  3673. sstr[c] = '\0';
  3674. strcpy(chargingProfilePurposeStr, sstr);
  3675. }
  3676. //***stackLevel ****/
  3677. c=0;
  3678. loc = strstr(payload, "stackLevel");
  3679. memset(sstr ,0, sizeof(sstr) );
  3680. if(loc == NULL)
  3681. {
  3682. stackLevelIsNULL = TRUE;
  3683. }
  3684. else
  3685. {
  3686. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3687. {
  3688. sstr[c] = loc[strlen("stackLevel")+2+c];
  3689. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3690. c++;
  3691. }
  3692. sstr[c] = '\0';
  3693. stackLevelInt = atoi(sstr);
  3694. }
  3695. if(connectorIsNULL == FALSE)
  3696. {
  3697. switch(connectorIdInt)
  3698. {
  3699. case 0:
  3700. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3701. {
  3702. strcpy(fname, ChargePointMaxProfile_JSON);
  3703. }
  3704. else
  3705. {
  3706. strcpy(fname, TxDefaultProfile_0_JSON);
  3707. }
  3708. break;
  3709. case 1:
  3710. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3711. {
  3712. strcpy(fname, TxDefaultProfile_1_JSON);
  3713. }
  3714. // else
  3715. // {
  3716. // strcpy(fname, TxProfile_1_JSON);
  3717. // }
  3718. break;
  3719. case 2:
  3720. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3721. {
  3722. strcpy(fname, TxDefaultProfile_2_JSON);
  3723. }
  3724. // else
  3725. // {
  3726. // strcpy(fname, TxProfile_2_JSON);
  3727. // }
  3728. break;
  3729. default:
  3730. strcpy(fname, ChargePointMaxProfile_JSON );
  3731. break;
  3732. }
  3733. }
  3734. else
  3735. {
  3736. strcpy(fname, ChargePointMaxProfile_JSON );
  3737. }
  3738. fptr1 = fopen(fname, "r");
  3739. if (!fptr1)
  3740. {
  3741. //file not exist
  3742. DEBUG_INFO("Unable to open the input file!!\n");
  3743. fptr1 = fopen(fname, "w+");
  3744. }
  3745. fclose(fptr1);
  3746. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3747. {
  3748. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3749. goto end;
  3750. }
  3751. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3752. {
  3753. //clear file in C
  3754. sprintf(str,"rm -f %s",fname);
  3755. system(str);
  3756. // clear temp file
  3757. sprintf(str,"rm -f %s",temp);
  3758. system(str);
  3759. #if 0
  3760. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3761. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3762. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3763. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3764. fclose(fopen(TxProfile_1_JSON, "w"));
  3765. fclose(fopen(TxProfile_2_JSON, "w"));
  3766. #endif
  3767. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3768. goto end;
  3769. }
  3770. else
  3771. {
  3772. fptr1 = fopen(fname, "r");
  3773. fptr2 = fopen(temp, "w+");
  3774. while(fscanf(fptr1, "%s", word) != EOF)
  3775. {
  3776. //DEBUG_INFO("word=%s\n",word);
  3777. if(strcmp(word, "chargingProfileId") == 0)
  3778. {
  3779. n_chargingProfile = n_chargingProfile + 1;
  3780. DEBUG_INFO("chargingProfileId Found\n");
  3781. }
  3782. }
  3783. rewind(fptr1);
  3784. //search Charging Profile Element
  3785. //int i= 0;
  3786. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3787. {
  3788. //*************************tempconnectorIdInt*********************************/
  3789. loc = strstr(sLineWord, "connectorId");
  3790. c = 0;
  3791. memset(sstr ,0, sizeof(sstr) );
  3792. while (loc[strlen("connectorId")+2+c] != ',')
  3793. {
  3794. sstr[c] = loc[strlen("connectorId")+2+c];
  3795. c++;
  3796. }
  3797. sstr[c] = '\0';
  3798. tempconnectorIdInt = atoi(sstr);
  3799. //chargingProfileId
  3800. c = 0;
  3801. loc = strstr(sLineWord, "chargingProfileId");
  3802. memset(sstr ,0, sizeof(sstr) );
  3803. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3804. {
  3805. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3807. c++;
  3808. }
  3809. sstr[c] = '\0';
  3810. tempchargingProfileIdInt = atoi(sstr);
  3811. //stackLevel
  3812. c = 0;
  3813. loc = strstr(sLineWord, "stackLevel");
  3814. memset(sstr ,0, sizeof(sstr) );
  3815. while (loc[strlen("stackLevel")+2+c] != ',')
  3816. {
  3817. sstr[c] = loc[strlen("stackLevel")+2+c];
  3818. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3819. c++;
  3820. }
  3821. sstr[c] = '\0';
  3822. tempstackLevelInt = atoi(sstr);
  3823. c = 0;
  3824. loc = strstr(sLineWord, "chargingProfilePurpose");
  3825. memset(sstr ,0, sizeof(sstr) );
  3826. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3827. {
  3828. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3829. c++;
  3830. }
  3831. sstr[c] = '\0';
  3832. strcpy(tempchargingProfilePurposeStr, sstr);
  3833. if(chargingProfileIdIsNULL == FALSE)
  3834. {
  3835. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3836. {
  3837. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3838. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3839. clearflag = TRUE;
  3840. continue;
  3841. }
  3842. else
  3843. {
  3844. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3845. //json_object_array_add(newHeatMap, jsonitem);
  3846. fprintf(fptr2, sLineWord);//writing data into file
  3847. }
  3848. }
  3849. else
  3850. {
  3851. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3852. {
  3853. if(stackLevelIsNULL == TRUE)//((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3854. {
  3855. fclose(fptr1);
  3856. fclose(fptr2);
  3857. sprintf(str,"rm -f %s",fname);
  3858. system(str);
  3859. // clear temp file
  3860. sprintf(str,"rm -f %s",temp);
  3861. system(str);
  3862. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3863. clearflag = TRUE;
  3864. GotoEnd = TRUE;
  3865. break;
  3866. }
  3867. else if((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt))
  3868. {
  3869. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3870. clearflag = TRUE;
  3871. continue;
  3872. }
  3873. }
  3874. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3875. {
  3876. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3877. {
  3878. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3879. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3880. {
  3881. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3882. clearflag = TRUE;
  3883. continue;
  3884. }
  3885. }
  3886. }
  3887. else
  3888. {
  3889. //json_object_array_add(newHeatMap, jsonitem);
  3890. fprintf(fptr2, sLineWord);//writing data into file
  3891. }
  3892. }
  3893. memset(sLineWord, 0, sizeof sLineWord);
  3894. }
  3895. if((clearflag == FALSE) && (GotoEnd == TRUE))
  3896. {
  3897. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3898. sprintf(str,"rm -f %s",temp);
  3899. system(str);
  3900. goto end;
  3901. }
  3902. else
  3903. {
  3904. goto end;
  3905. }
  3906. fclose(fptr1);
  3907. fclose(fptr2);
  3908. sprintf(str,"rm -f %s",fname);
  3909. system(str);
  3910. resultRename = rename(temp, fname);
  3911. if(resultRename == 0)
  3912. {
  3913. DEBUG_INFO("File ChargingProfile renamed successfully");
  3914. }
  3915. else
  3916. {
  3917. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3918. }
  3919. }
  3920. end:
  3921. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3922. return result;
  3923. }
  3924. int handleDataTransferRequest(char *uuid, char *payload)
  3925. {
  3926. mtrace();
  3927. int result = FAIL;
  3928. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3929. char tempvendorId[255]={0};
  3930. char tempmessageId[50]={0};
  3931. char tempdata[50]={0};
  3932. char sstr[160]={0};//sstr[200]={ 0 };
  3933. char message[80]={0};
  3934. int c = 0;
  3935. char *loc;
  3936. DEBUG_INFO("handle DataTransferRequest\n");
  3937. if((uuid != NULL) && (payload != NULL))
  3938. {
  3939. //===============================
  3940. // vendorId
  3941. //===============================
  3942. c = 0;
  3943. loc = strstr(payload, "vendorId");
  3944. while (loc[strlen("vendorId")+3+c] != '\"')
  3945. {
  3946. sstr[c] = loc[strlen("vendorId")+3+c];
  3947. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3948. c++;
  3949. }
  3950. sstr[c] = '\0';
  3951. strcpy(tempvendorId,sstr);
  3952. //===============================
  3953. // messageId
  3954. //===============================
  3955. memset(sstr ,0, sizeof(sstr) );
  3956. c = 0;
  3957. loc = strstr(payload, "messageId");
  3958. while (loc[strlen("messageId")+3+c] != '\"')
  3959. {
  3960. sstr[c] = loc[strlen("messageId")+3+c];
  3961. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3962. c++;
  3963. }
  3964. sstr[c] = '\0';
  3965. strcpy(tempmessageId,sstr);
  3966. //===============================
  3967. // data
  3968. //===============================
  3969. memset(sstr ,0, sizeof(sstr) );
  3970. c = 0;
  3971. loc = strstr(payload, "data");
  3972. printf("loc=%s\n",loc);
  3973. while (loc[strlen("data")+3+c] != '\"')
  3974. {
  3975. sstr[c] = loc[strlen("data")+3+c];
  3976. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3977. c++;
  3978. }
  3979. sstr[c] = '\0';
  3980. strcpy(tempdata,sstr);
  3981. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  3982. }
  3983. else
  3984. {
  3985. char guid[37]={0};
  3986. random_uuid(guid);
  3987. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  3988. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  3989. }
  3990. LWS_Send(message);
  3991. return result;
  3992. }
  3993. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3994. {
  3995. mtrace();
  3996. int result = FAIL;
  3997. int connectorIdInt, durationInt;
  3998. char chargingRateUnitStr[4]={0};
  3999. //int tempconnectorIdInt,
  4000. int tempdurationInt;
  4001. float tempminChargingRateFloat = 0.0;
  4002. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4003. int tempStartPeriodInt=0;
  4004. float tempLimitInt=0.0;//0.1;
  4005. int tempNumberPhasesInt=0;
  4006. char fname[200];
  4007. char comfirmstr[20];
  4008. //float totallimit =0.0;
  4009. float MinChargingRate =0.0;
  4010. //double diff_t;
  4011. //struct tm tp;
  4012. FILE *fptr1;
  4013. int c = 0;
  4014. //int i = 0;
  4015. char * pch;
  4016. char *loc;
  4017. char sstr[200]={ 0 };
  4018. int n_chargingProfile = 0;
  4019. int n_SchedulePeriods = 0;
  4020. char SchedulePeriodList[10][200]={0};
  4021. char sLineWord[800]={0};
  4022. //int n_periods = 0;
  4023. char word[1000]={0};
  4024. int confirmPeriods = 0;
  4025. struct StructProfile ChargePointMaxProfile;
  4026. struct StructProfile TxDefaultProfile;
  4027. struct StructProfile TxProfile;
  4028. struct StructProfile TxDefaultProfiletemp[2]={0};
  4029. int TxDefaultProfileFileIsNull=FALSE;
  4030. int ChargePointMaxProfileIsNull=FALSE;
  4031. int TxProfileIsNull=FALSE;
  4032. int CompositeSceduleIndex = 0;
  4033. char ChargePointMaxProfileScheduleStr[30]={0};
  4034. char TxDefaultProfileScheduleStr[30]={0};
  4035. char TxProfileScheduleStr[30]={0};
  4036. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4037. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4038. memset(&TxProfile,0,sizeof(struct StructProfile));
  4039. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4040. c=0;
  4041. loc = strstr(payload, "connectorId");
  4042. memset(sstr ,0, sizeof(sstr) );
  4043. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4044. {
  4045. sstr[c] = loc[strlen("connectorId")+2+c];
  4046. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4047. c++;
  4048. }
  4049. sstr[c] = '\0';
  4050. connectorIdInt = atoi(sstr);
  4051. c=0;
  4052. loc = strstr(payload, "duration");
  4053. memset(sstr ,0, sizeof(sstr) );
  4054. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4055. {
  4056. sstr[c] = loc[strlen("duration")+2+c];
  4057. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4058. c++;
  4059. }
  4060. sstr[c] = '\0';
  4061. durationInt = atoi(sstr);
  4062. c = 0;
  4063. loc = strstr(payload, "chargingRateUnit");
  4064. memset(sstr ,0, sizeof(sstr) );
  4065. if(loc == NULL)
  4066. {
  4067. }
  4068. else
  4069. {
  4070. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4071. {
  4072. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4073. c++;
  4074. }
  4075. sstr[c] = '\0';
  4076. strcpy(chargingRateUnitStr, sstr);
  4077. }
  4078. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4079. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4080. if(connectorIdInt==0) // connectorId is 0
  4081. {
  4082. //******************************ChargePointMaxProfile*****************************************************/
  4083. strcpy(fname, ChargePointMaxProfile_JSON );
  4084. char word[30]={0};
  4085. char sLineWord[1060]={0};
  4086. int n_chargingProfile=0;
  4087. ChargePointMaxProfileIsNull=TRUE;
  4088. if((access(fname,F_OK))!=-1)
  4089. {
  4090. fptr1 = fopen(fname, "r");
  4091. int c;
  4092. c = fgetc(fptr1);
  4093. //DEBUG_INFO("c:%d\n",c);
  4094. rewind(fptr1);
  4095. if(c == EOF)
  4096. {
  4097. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4098. ChargePointMaxProfileIsNull=TRUE;
  4099. fclose(fptr1);
  4100. }
  4101. else
  4102. {
  4103. ChargePointMaxProfileIsNull=FALSE;
  4104. while(fscanf(fptr1, "%s", word) != EOF)
  4105. {
  4106. if(strcmp(word, "chargingProfileId") == 0)
  4107. {
  4108. n_chargingProfile = n_chargingProfile + 1;
  4109. printf("Found\n");
  4110. }
  4111. }
  4112. rewind(fptr1);
  4113. //search Charging Profile Element
  4114. int i= 0;
  4115. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4116. #if 0
  4117. /***********connectorId****************/
  4118. c = 0;
  4119. loc = strstr(sLineWord, "connectorId");
  4120. // printf("loc=%s\n",loc);
  4121. memset(sstr ,0, sizeof(sstr) );
  4122. while (loc[strlen("connectorId")+2+c] != ',')
  4123. {
  4124. sstr[c] = loc[strlen("connectorId")+2+c];
  4125. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4126. c++;
  4127. }
  4128. sstr[c] = '\0';
  4129. tempconnectorIdInt = atoi(sstr);
  4130. #endif
  4131. //***********validFrom**************/
  4132. c = 0;
  4133. loc = strstr(sLineWord, "validFrom");
  4134. //DEBUG_INFO("loc=%s\n",loc);
  4135. memset(sstr ,0, sizeof(sstr) );
  4136. if(loc != NULL)
  4137. {
  4138. while (loc[3+strlen("validFrom")+c] != '\"')
  4139. {
  4140. sstr[c] = loc[3+strlen("validFrom")+c];
  4141. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4142. c++;
  4143. }
  4144. sstr[c] = '\0';
  4145. DEBUG_INFO("validFrom=%s\n",sstr);
  4146. strcpy(tempvalidFromStr,sstr);
  4147. }
  4148. else
  4149. {
  4150. strcpy(tempvalidFromStr,"");
  4151. }
  4152. //**********startSchedule**********/
  4153. c = 0;
  4154. loc = strstr(sLineWord, "startSchedule");
  4155. //DEBUG_INFO("loc=%s\n",loc);
  4156. memset(sstr ,0, sizeof(sstr) );
  4157. while (loc[3+strlen("startSchedule")+c] != '\"')
  4158. {
  4159. sstr[c] = loc[3+strlen("startSchedule")+c];
  4160. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4161. c++;
  4162. }
  4163. sstr[c] = '\0';
  4164. strcpy(tempstartScheduleStr, sstr);
  4165. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4166. //**********chargingRateUnit**********/
  4167. c = 0;
  4168. loc = strstr(sLineWord, "chargingRateUnit");
  4169. memset(sstr ,0, sizeof(sstr) );
  4170. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4171. {
  4172. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4173. c++;
  4174. }
  4175. sstr[c] = '\0';
  4176. strcpy(tempchargingRateUnitStr, sstr);
  4177. //**********minChargingRate*******/
  4178. c = 0;
  4179. loc = strstr(sLineWord, "minChargingRate");
  4180. //printf("loc=%s\n",loc);
  4181. if(loc != NULL)
  4182. {
  4183. memset(sstr ,0, sizeof(sstr) );
  4184. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4185. {
  4186. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4187. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4188. c++;
  4189. }
  4190. sstr[c] = '\0';
  4191. tempminChargingRateFloat = atof(sstr);
  4192. }
  4193. else
  4194. {
  4195. tempminChargingRateFloat = 0.0;
  4196. }
  4197. //
  4198. #if 0
  4199. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4200. tp.tm_isdst = -1;
  4201. time_t utc = mktime(&tp);
  4202. // current time
  4203. time_t t = time(NULL);
  4204. #endif
  4205. //diff_t = difftime(t, utc);
  4206. //parsing strings to words
  4207. i = 0;
  4208. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4209. loc = loc+3+strlen("chargingSchedulePeriod");
  4210. pch = strtok(loc ,"{");
  4211. while (pch != NULL)
  4212. {
  4213. strcpy(SchedulePeriodList[i], pch);
  4214. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4215. //printf ("%s\n",pch);
  4216. pch = strtok (NULL, "{");
  4217. i = i + 1;
  4218. }
  4219. n_SchedulePeriods = i;
  4220. for(int i=0;i<n_SchedulePeriods;i++)
  4221. {
  4222. //*************startPeriod****************/
  4223. c = 0;
  4224. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4225. memset(sstr ,0, sizeof(sstr) );
  4226. while (loc[strlen("startPeriod")+2+c] != ',')
  4227. {
  4228. sstr[c] = loc[strlen("startPeriod")+2+c];
  4229. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4230. c++;
  4231. }
  4232. sstr[c] = '\0';
  4233. tempStartPeriodInt = atoi(sstr);
  4234. //*************limit****************/
  4235. c = 0;
  4236. loc = strstr(SchedulePeriodList[i], "limit");
  4237. memset(sstr ,0, sizeof(sstr) );
  4238. while (loc[strlen("limit")+2+c] != ',')
  4239. {
  4240. sstr[c] = loc[strlen("limit")+2+c];
  4241. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4242. c++;
  4243. }
  4244. sstr[c] = '\0';
  4245. tempLimitInt = atof(sstr);
  4246. //*************numberPhases****************/
  4247. c = 0;
  4248. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4249. memset(sstr ,0, sizeof(sstr) );
  4250. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4251. {
  4252. sstr[c] = loc[strlen("numberPhases")+2+c];
  4253. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4254. c++;
  4255. }
  4256. sstr[c] = '\0';
  4257. tempNumberPhasesInt = atoi(sstr);
  4258. ChargePointMaxProfile.Duration = durationInt;
  4259. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4260. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4261. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4262. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4263. }
  4264. if(MinChargingRate < tempminChargingRateFloat)
  4265. MinChargingRate = tempminChargingRateFloat;
  4266. }
  4267. }// End of file ChargingProfile
  4268. } //THE END OF ACCESS ChargePointMaxProfile
  4269. //******************************TxDefaultProfile***********************************************/
  4270. strcpy(fname, TxDefaultProfile_0_JSON);
  4271. memset(word, 0, 30);
  4272. memset(sLineWord, 0, 1060);
  4273. //char word[30]={0};
  4274. //char sLineWord[1060]={0};
  4275. n_chargingProfile=0;
  4276. TxDefaultProfileFileIsNull=TRUE;
  4277. if((access(fname,F_OK))!=-1)
  4278. {
  4279. fptr1 = fopen(fname, "r");
  4280. c = 0;
  4281. c = fgetc(fptr1);
  4282. //DEBUG_INFO("c:%d\n",c);
  4283. rewind(fptr1);
  4284. if(c == EOF)
  4285. {
  4286. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4287. TxDefaultProfileFileIsNull=TRUE;
  4288. fclose(fptr1);
  4289. }
  4290. else
  4291. {
  4292. TxDefaultProfileFileIsNull=FALSE;
  4293. while(fscanf(fptr1, "%s", word) != EOF)
  4294. {
  4295. if(strcmp(word, "chargingProfileId") == 0)
  4296. {
  4297. n_chargingProfile = n_chargingProfile + 1;
  4298. printf("Found\n");
  4299. }
  4300. }
  4301. rewind(fptr1);
  4302. //search Charging Profile Element
  4303. int i= 0;
  4304. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4305. #if 0
  4306. /***********connectorId****************/
  4307. c = 0;
  4308. loc = strstr(sLineWord, "connectorId");
  4309. // printf("loc=%s\n",loc);
  4310. memset(sstr ,0, sizeof(sstr) );
  4311. while (loc[strlen("connectorId")+2+c] != ',')
  4312. {
  4313. sstr[c] = loc[strlen("connectorId")+2+c];
  4314. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4315. c++;
  4316. }
  4317. sstr[c] = '\0';
  4318. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4319. tempconnectorIdInt = atoi(sstr);
  4320. #endif
  4321. //***********validFrom**************/
  4322. c = 0;
  4323. loc = strstr(sLineWord, "validFrom");
  4324. //DEBUG_INFO("loc=%s\n",loc);
  4325. memset(sstr ,0, sizeof(sstr) );
  4326. if(loc != NULL)
  4327. {
  4328. while (loc[3+strlen("validFrom")+c] != '\"')
  4329. {
  4330. sstr[c] = loc[3+strlen("validFrom")+c];
  4331. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4332. c++;
  4333. }
  4334. sstr[c] = '\0';
  4335. DEBUG_INFO("validFrom=%s\n",sstr);
  4336. strcpy(tempvalidFromStr,sstr);
  4337. }
  4338. else
  4339. {
  4340. strcpy(tempvalidFromStr,"");
  4341. }
  4342. //**********startSchedule**********/
  4343. c = 0;
  4344. loc = strstr(sLineWord, "startSchedule");
  4345. //DEBUG_INFO("loc=%s\n",loc);
  4346. memset(sstr ,0, sizeof(sstr) );
  4347. while (loc[3+strlen("startSchedule")+c] != '\"')
  4348. {
  4349. sstr[c] = loc[3+strlen("startSchedule")+c];
  4350. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4351. c++;
  4352. }
  4353. sstr[c] = '\0';
  4354. strcpy(tempstartScheduleStr, sstr);
  4355. strcpy(TxDefaultProfileScheduleStr, sstr);
  4356. DEBUG_INFO(" debug 3-1\n");
  4357. //**********chargingRateUnit**********/
  4358. c = 0;
  4359. loc = strstr(sLineWord, "chargingRateUnit");
  4360. memset(sstr ,0, sizeof(sstr) );
  4361. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4362. {
  4363. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4364. c++;
  4365. }
  4366. sstr[c] = '\0';
  4367. strcpy(tempchargingRateUnitStr, sstr);
  4368. //**********minChargingRate*******/
  4369. c = 0;
  4370. loc = strstr(sLineWord, "minChargingRate");
  4371. //printf("loc=%s\n",loc);
  4372. if(loc != NULL)
  4373. {
  4374. memset(sstr ,0, sizeof(sstr) );
  4375. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4376. {
  4377. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4378. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4379. c++;
  4380. }
  4381. sstr[c] = '\0';
  4382. tempminChargingRateFloat = atof(sstr);
  4383. }
  4384. else
  4385. {
  4386. tempminChargingRateFloat = 0.0;
  4387. }
  4388. #if 0
  4389. //
  4390. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4391. tp.tm_isdst = -1;
  4392. time_t utc = mktime(&tp);
  4393. // current time
  4394. time_t t = time(NULL);
  4395. //diff_t = difftime(t, utc);
  4396. #endif
  4397. //parsing strings to words
  4398. i = 0;
  4399. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4400. loc = loc+3+strlen("chargingSchedulePeriod");
  4401. pch = strtok(loc ,"{");
  4402. while (pch != NULL)
  4403. {
  4404. strcpy(SchedulePeriodList[i], pch);
  4405. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4406. //printf ("%s\n",pch);
  4407. pch = strtok (NULL, "{");
  4408. i = i + 1;
  4409. }
  4410. n_SchedulePeriods = i;
  4411. for(int i=0;i<n_SchedulePeriods;i++)
  4412. {
  4413. //*************startPeriod****************/
  4414. c = 0;
  4415. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4416. memset(sstr ,0, sizeof(sstr) );
  4417. while (loc[strlen("startPeriod")+2+c] != ',')
  4418. {
  4419. sstr[c] = loc[strlen("startPeriod")+2+c];
  4420. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4421. c++;
  4422. }
  4423. sstr[c] = '\0';
  4424. tempStartPeriodInt = atoi(sstr);
  4425. //*************limit****************/
  4426. c = 0;
  4427. loc = strstr(SchedulePeriodList[i], "limit");
  4428. memset(sstr ,0, sizeof(sstr) );
  4429. while (loc[strlen("limit")+2+c] != ',')
  4430. {
  4431. sstr[c] = loc[strlen("limit")+2+c];
  4432. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4433. c++;
  4434. }
  4435. sstr[c] = '\0';
  4436. tempLimitInt = atof(sstr);
  4437. //*************numberPhases****************/
  4438. c = 0;
  4439. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4440. memset(sstr ,0, sizeof(sstr) );
  4441. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4442. {
  4443. sstr[c] = loc[strlen("numberPhases")+2+c];
  4444. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4445. c++;
  4446. }
  4447. sstr[c] = '\0';
  4448. tempNumberPhasesInt = atoi(sstr);
  4449. TxDefaultProfile.Duration = durationInt;
  4450. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4451. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4452. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4453. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4454. }
  4455. if(MinChargingRate < tempminChargingRateFloat)
  4456. MinChargingRate = tempminChargingRateFloat;
  4457. }
  4458. }
  4459. }// the end of ACCESS TxDefaultProfile
  4460. // Composite Schedule
  4461. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4462. {
  4463. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4464. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4465. {
  4466. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4467. {
  4468. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4469. }
  4470. else
  4471. {
  4472. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4473. }
  4474. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4475. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4476. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4477. }
  4478. }
  4479. //* Define temporary variables */
  4480. struct tm *gtime;
  4481. time_t now;
  4482. char buf[28];
  4483. /* Read the current system time */
  4484. time(&now);
  4485. /* Convert the system time to GMT (now UTC) */
  4486. gtime = gmtime(&now);
  4487. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4488. // make .conf
  4489. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4490. //MaxChargingProfilesInstalled is 10
  4491. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4492. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4493. //nPeriod = 1;
  4494. if(chargingRateUnitStr[0] != 0)
  4495. {
  4496. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4497. }
  4498. else
  4499. {
  4500. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4501. }
  4502. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4503. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4504. confirmPeriods = 1;
  4505. }
  4506. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4507. {
  4508. //*****************************ChargePointMaxProfile******************************************/
  4509. strcpy(fname, ChargePointMaxProfile_JSON);
  4510. ChargePointMaxProfileIsNull=TRUE;
  4511. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4512. {
  4513. fptr1 = fopen(fname, "r");
  4514. int c;
  4515. c = fgetc(fptr1);
  4516. //DEBUG_INFO("c:%d\n",c);
  4517. rewind(fptr1);
  4518. if(c == EOF)
  4519. {
  4520. DEBUG_INFO("\n End of file reached.");
  4521. ChargePointMaxProfileIsNull=TRUE;
  4522. fclose(fptr1);
  4523. }
  4524. else
  4525. {
  4526. ChargePointMaxProfileIsNull=FALSE;
  4527. while(fscanf(fptr1, "%s", word) != EOF)
  4528. {
  4529. if(strcmp(word, "chargingProfileId") == 0)
  4530. {
  4531. n_chargingProfile = n_chargingProfile + 1;
  4532. }
  4533. }
  4534. rewind(fptr1);
  4535. //search Charging Profile Element
  4536. int i = 0;
  4537. int j = 0;
  4538. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4539. #if 0
  4540. /***********connectorId****************/
  4541. c = 0;
  4542. loc = strstr(sLineWord, "connectorId");
  4543. memset(sstr ,0, sizeof(sstr) );
  4544. while (loc[strlen("connectorId")+2+c] != ',')
  4545. {
  4546. sstr[c] = loc[strlen("connectorId")+2+c];
  4547. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4548. c++;
  4549. }
  4550. sstr[c] = '\0';
  4551. tempconnectorIdInt = atoi(sstr);
  4552. #endif
  4553. //***********validFrom**************/
  4554. c = 0;
  4555. loc = strstr(sLineWord, "validFrom");
  4556. if(loc != NULL)
  4557. {
  4558. memset(sstr ,0, sizeof(sstr) );
  4559. while (loc[3+strlen("validFrom")+c] != '\"')
  4560. {
  4561. sstr[c] = loc[3+strlen("validFrom")+c];
  4562. c++;
  4563. }
  4564. sstr[c] = '\0';
  4565. strcpy(tempvalidFromStr,sstr);
  4566. }
  4567. else
  4568. {
  4569. strcpy(tempvalidFromStr,"");
  4570. }
  4571. //***********validFrom**************/
  4572. c = 0;
  4573. loc = strstr(sLineWord, "duration");
  4574. if(loc != NULL)
  4575. {
  4576. memset(sstr ,0, sizeof(sstr) );
  4577. while (loc[2+strlen("duration")+c] != ',')
  4578. {
  4579. sstr[c] = loc[2+strlen("duration")+c];
  4580. c++;
  4581. }
  4582. sstr[c] = '\0';
  4583. tempdurationInt = atoi(sstr);
  4584. }
  4585. else
  4586. {
  4587. tempdurationInt = 0;
  4588. }
  4589. //**********startSchedule**********/
  4590. c = 0;
  4591. loc = strstr(sLineWord, "startSchedule");
  4592. memset(sstr ,0, sizeof(sstr) );
  4593. while (loc[3+strlen("startSchedule")+c] != '\"')
  4594. {
  4595. sstr[c] = loc[3+strlen("startSchedule")+c];
  4596. c++;
  4597. }
  4598. sstr[c] = '\0';
  4599. strcpy(tempstartScheduleStr, sstr);
  4600. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4601. //**********chargingRateUnit**********/
  4602. c = 0;
  4603. loc = strstr(sLineWord, "chargingRateUnit");
  4604. memset(sstr ,0, sizeof(sstr) );
  4605. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4606. {
  4607. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4608. c++;
  4609. }
  4610. sstr[c] = '\0';
  4611. strcpy(tempchargingRateUnitStr, sstr);
  4612. //**********minChargingRate*******/
  4613. c = 0;
  4614. loc = strstr(sLineWord, "minChargingRate");
  4615. if(loc != NULL)
  4616. {
  4617. memset(sstr ,0, sizeof(sstr) );
  4618. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4619. {
  4620. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4621. c++;
  4622. }
  4623. sstr[c] = '\0';
  4624. tempminChargingRateFloat = atof(sstr);
  4625. }
  4626. else
  4627. {
  4628. tempminChargingRateFloat = 0.0;
  4629. }
  4630. #if 0
  4631. //
  4632. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4633. tp.tm_isdst = -1;
  4634. time_t utc = mktime(&tp);
  4635. time_t t = time(NULL);
  4636. //diff_t = difftime(t, utc);
  4637. #endif
  4638. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4639. //DEBUG_INFO(" debug 5 -1\n");
  4640. //parsing strings to words
  4641. i = 0;
  4642. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4643. loc = loc+3+strlen("chargingSchedulePeriod");
  4644. pch = strtok(loc ,"{");
  4645. while (pch != NULL)
  4646. {
  4647. strcpy(SchedulePeriodList[i], pch);
  4648. pch = strtok (NULL, "{");
  4649. i = i + 1;
  4650. }
  4651. n_SchedulePeriods = i;
  4652. for(int i=0;i<n_SchedulePeriods;i++)
  4653. {
  4654. //*************startPeriod****************/
  4655. c = 0;
  4656. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4657. memset(sstr ,0, sizeof(sstr) );
  4658. while (loc[strlen("startPeriod")+2+c] != ',')
  4659. {
  4660. sstr[c] = loc[strlen("startPeriod")+2+c];
  4661. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4662. c++;
  4663. }
  4664. sstr[c] = '\0';
  4665. tempStartPeriodInt = atoi(sstr);
  4666. //*************limit****************/
  4667. c = 0;
  4668. loc = strstr(SchedulePeriodList[i], "limit");
  4669. memset(sstr ,0, sizeof(sstr) );
  4670. while (loc[strlen("limit")+2+c] != ',')
  4671. {
  4672. sstr[c] = loc[strlen("limit")+2+c];
  4673. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4674. c++;
  4675. }
  4676. sstr[c] = '\0';
  4677. tempLimitInt = atof(sstr);
  4678. //*************numberPhases****************/
  4679. c = 0;
  4680. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4681. memset(sstr ,0, sizeof(sstr) );
  4682. while (loc[strlen("numberPhases")+2+c] != '}')
  4683. {
  4684. sstr[c] = loc[strlen("numberPhases")+2+c];
  4685. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4686. c++;
  4687. }
  4688. sstr[c] = '\0';
  4689. tempNumberPhasesInt = atoi(sstr);
  4690. if(j == 0)
  4691. {
  4692. ChargePointMaxProfile.Duration = tempdurationInt;
  4693. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4694. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4695. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4696. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4697. }
  4698. }
  4699. if(MinChargingRate < tempminChargingRateFloat)
  4700. {
  4701. MinChargingRate = tempminChargingRateFloat;
  4702. }
  4703. if(confirmPeriods < n_SchedulePeriods)
  4704. {
  4705. confirmPeriods = n_SchedulePeriods;
  4706. }
  4707. j = j + 1;
  4708. }
  4709. fclose(fptr1);
  4710. }
  4711. }// the end of access file ChargePointMaxProfile
  4712. //****************************TxDefaultProfile************************************************/
  4713. switch(connectorIdInt)
  4714. {
  4715. case 0:
  4716. break;
  4717. case 1:
  4718. strcpy(fname, TxDefaultProfile_1_JSON );
  4719. break;
  4720. case 2:
  4721. strcpy(fname, TxDefaultProfile_2_JSON );
  4722. break;
  4723. default:
  4724. strcpy(fname, TxDefaultProfile_1_JSON );
  4725. break;
  4726. }
  4727. TxDefaultProfileFileIsNull=TRUE;
  4728. if((access(fname,F_OK))!=-1)
  4729. {
  4730. fptr1 = fopen(fname, "r");
  4731. c = 0;
  4732. c = fgetc(fptr1);
  4733. //DEBUG_INFO("c:%d\n",c);
  4734. rewind(fptr1);
  4735. if(c == EOF)
  4736. {
  4737. DEBUG_INFO("\n End of file reached.");
  4738. TxDefaultProfileFileIsNull=TRUE;
  4739. fclose(fptr1);
  4740. }
  4741. else
  4742. {
  4743. TxDefaultProfileFileIsNull=FALSE;
  4744. while(fscanf(fptr1, "%s", word) != EOF)
  4745. {
  4746. if(strcmp(word, "chargingProfileId") == 0)
  4747. {
  4748. n_chargingProfile = n_chargingProfile + 1;
  4749. }
  4750. }
  4751. rewind(fptr1);
  4752. //search Charging Profile Element
  4753. int i = 0;
  4754. int j = 0;
  4755. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4756. //DEBUG_INFO(" 1-1\n");
  4757. #if 0
  4758. /***********connectorId****************/
  4759. c = 0;
  4760. loc = strstr(sLineWord, "connectorId");
  4761. memset(sstr ,0, sizeof(sstr) );
  4762. while (loc[strlen("connectorId")+2+c] != ',')
  4763. {
  4764. sstr[c] = loc[strlen("connectorId")+2+c];
  4765. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4766. c++;
  4767. }
  4768. sstr[c] = '\0';
  4769. tempconnectorIdInt = atoi(sstr);
  4770. #endif
  4771. //***********validFrom**************/
  4772. c = 0;
  4773. loc = strstr(sLineWord, "validFrom");
  4774. if(loc != NULL)
  4775. {
  4776. memset(sstr ,0, sizeof(sstr) );
  4777. while (loc[3+strlen("validFrom")+c] != '\"')
  4778. {
  4779. sstr[c] = loc[3+strlen("validFrom")+c];
  4780. c++;
  4781. }
  4782. sstr[c] = '\0';
  4783. strcpy(tempvalidFromStr,sstr);
  4784. }
  4785. else
  4786. {
  4787. strcpy(tempvalidFromStr,"");
  4788. }
  4789. //***********validFrom**************/
  4790. c = 0;
  4791. loc = strstr(sLineWord, "duration");
  4792. if(loc != NULL)
  4793. {
  4794. memset(sstr ,0, sizeof(sstr) );
  4795. while (loc[2+strlen("duration")+c] != ',')
  4796. {
  4797. sstr[c] = loc[2+strlen("duration")+c];
  4798. c++;
  4799. }
  4800. sstr[c] = '\0';
  4801. tempdurationInt = atoi(sstr);
  4802. }
  4803. else
  4804. {
  4805. tempdurationInt = 0;
  4806. }
  4807. //**********startSchedule**********/
  4808. c = 0;
  4809. loc = strstr(sLineWord, "startSchedule");
  4810. memset(sstr ,0, sizeof(sstr) );
  4811. while (loc[3+strlen("startSchedule")+c] != '\"')
  4812. {
  4813. sstr[c] = loc[3+strlen("startSchedule")+c];
  4814. c++;
  4815. }
  4816. sstr[c] = '\0';
  4817. strcpy(tempstartScheduleStr, sstr);
  4818. strcpy(TxDefaultProfileScheduleStr, sstr);
  4819. //**********chargingRateUnit**********/
  4820. c = 0;
  4821. loc = strstr(sLineWord, "chargingRateUnit");
  4822. memset(sstr ,0, sizeof(sstr) );
  4823. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4824. {
  4825. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4826. c++;
  4827. }
  4828. sstr[c] = '\0';
  4829. strcpy(tempchargingRateUnitStr, sstr);
  4830. //**********minChargingRate*******/
  4831. c = 0;
  4832. loc = strstr(sLineWord, "minChargingRate");
  4833. if(loc != NULL)
  4834. {
  4835. memset(sstr ,0, sizeof(sstr) );
  4836. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4837. {
  4838. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4839. c++;
  4840. }
  4841. sstr[c] = '\0';
  4842. tempminChargingRateFloat = atof(sstr);
  4843. }
  4844. else
  4845. {
  4846. tempminChargingRateFloat = 0.0;
  4847. }
  4848. #if 0
  4849. //
  4850. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4851. tp.tm_isdst = -1;
  4852. time_t utc = mktime(&tp);
  4853. time_t t = time(NULL);
  4854. //diff_t = difftime(t, utc);
  4855. #endif
  4856. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4857. //parsing strings to words
  4858. i = 0;
  4859. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4860. loc = loc+3+strlen("chargingSchedulePeriod");
  4861. pch = strtok(loc ,"{");
  4862. while (pch != NULL)
  4863. {
  4864. strcpy(SchedulePeriodList[i], pch);
  4865. pch = strtok (NULL, "{");
  4866. i = i + 1;
  4867. }
  4868. n_SchedulePeriods = i;
  4869. for(int i=0;i<n_SchedulePeriods;i++)
  4870. {
  4871. //*************startPeriod****************/
  4872. c = 0;
  4873. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4874. memset(sstr ,0, sizeof(sstr) );
  4875. while (loc[strlen("startPeriod")+2+c] != ',')
  4876. {
  4877. sstr[c] = loc[strlen("startPeriod")+2+c];
  4878. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4879. c++;
  4880. }
  4881. sstr[c] = '\0';
  4882. tempStartPeriodInt = atoi(sstr);
  4883. //*************limit****************/
  4884. c = 0;
  4885. loc = strstr(SchedulePeriodList[i], "limit");
  4886. memset(sstr ,0, sizeof(sstr) );
  4887. while (loc[strlen("limit")+2+c] != ',')
  4888. {
  4889. sstr[c] = loc[strlen("limit")+2+c];
  4890. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4891. c++;
  4892. }
  4893. sstr[c] = '\0';
  4894. tempLimitInt = atof(sstr);
  4895. //*************numberPhases****************/
  4896. c = 0;
  4897. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4898. memset(sstr ,0, sizeof(sstr) );
  4899. while (loc[strlen("numberPhases")+2+c] != '}')
  4900. {
  4901. sstr[c] = loc[strlen("numberPhases")+2+c];
  4902. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4903. c++;
  4904. }
  4905. sstr[c] = '\0';
  4906. tempNumberPhasesInt = atoi(sstr);
  4907. if(j == 0)
  4908. {
  4909. TxDefaultProfile.Duration = tempdurationInt;
  4910. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4911. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4912. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4913. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4914. }
  4915. else
  4916. {
  4917. //other stack level charging Profile
  4918. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4919. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4920. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4921. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4922. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4923. }
  4924. }
  4925. if(MinChargingRate < tempminChargingRateFloat)
  4926. MinChargingRate = tempminChargingRateFloat;
  4927. if(confirmPeriods < n_SchedulePeriods)
  4928. confirmPeriods = n_SchedulePeriods;
  4929. j = j + 1;
  4930. //DEBUG_INFO(" 1-2\n");
  4931. }
  4932. fclose(fptr1);
  4933. //Stacking Charging Profiles
  4934. for(int l=0; l <(j-1) ;l++)
  4935. {
  4936. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4937. {
  4938. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4939. {
  4940. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4941. {
  4942. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4943. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4944. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4945. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4946. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4947. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4948. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4949. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4950. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4951. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4952. }
  4953. else
  4954. {
  4955. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4956. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4957. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4958. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4959. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4960. }
  4961. }
  4962. }
  4963. }
  4964. //end of Stacking Charging Profiles
  4965. }
  4966. }// the end of ACCESS TxDefaultProfile
  4967. //****************************TxProfile************************************************/
  4968. switch(connectorIdInt)
  4969. {
  4970. case 0:
  4971. break;
  4972. case 1:
  4973. strcpy(fname, TxProfile_1_JSON );
  4974. break;
  4975. case 2:
  4976. strcpy(fname, TxProfile_2_JSON );
  4977. break;
  4978. default:
  4979. strcpy(fname, TxProfile_1_JSON );
  4980. break;
  4981. }
  4982. TxProfileIsNull=TRUE;
  4983. if((access(fname,F_OK))!=-1)
  4984. {
  4985. fptr1 = fopen(fname, "r");
  4986. c = 0;
  4987. c = fgetc(fptr1);
  4988. //DEBUG_INFO("c:%d\n",c);
  4989. rewind(fptr1);
  4990. if(c == EOF)
  4991. {
  4992. DEBUG_INFO("\n End of file reached.");
  4993. TxProfileIsNull=TRUE;
  4994. fclose(fptr1);
  4995. }
  4996. else
  4997. {
  4998. TxProfileIsNull=FALSE;
  4999. while(fscanf(fptr1, "%s", word) != EOF)
  5000. {
  5001. if(strcmp(word, "chargingProfileId") == 0)
  5002. {
  5003. n_chargingProfile = n_chargingProfile + 1;
  5004. }
  5005. }
  5006. rewind(fptr1);
  5007. //search Charging Profile Element
  5008. int i= 0;
  5009. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5010. #if 0
  5011. /***********connectorId****************/
  5012. c = 0;
  5013. loc = strstr(sLineWord, "connectorId");
  5014. memset(sstr ,0, sizeof(sstr) );
  5015. while (loc[strlen("connectorId")+2+c] != ',')
  5016. {
  5017. sstr[c] = loc[strlen("connectorId")+2+c];
  5018. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5019. c++;
  5020. }
  5021. sstr[c] = '\0';
  5022. tempconnectorIdInt = atoi(sstr);
  5023. #endif
  5024. //***********validFrom**************/
  5025. c = 0;
  5026. loc = strstr(sLineWord, "validFrom");
  5027. if(loc != NULL)
  5028. {
  5029. memset(sstr ,0, sizeof(sstr) );
  5030. while (loc[3+strlen("validFrom")+c] != '\"')
  5031. {
  5032. sstr[c] = loc[3+strlen("validFrom")+c];
  5033. c++;
  5034. }
  5035. sstr[c] = '\0';
  5036. strcpy(tempvalidFromStr,sstr);
  5037. }
  5038. else
  5039. {
  5040. strcpy(tempvalidFromStr,"");
  5041. }
  5042. //**********startSchedule**********/
  5043. c = 0;
  5044. loc = strstr(sLineWord, "startSchedule");
  5045. memset(sstr ,0, sizeof(sstr) );
  5046. while (loc[3+strlen("startSchedule")+c] != '\"')
  5047. {
  5048. sstr[c] = loc[3+strlen("startSchedule")+c];
  5049. c++;
  5050. }
  5051. sstr[c] = '\0';
  5052. strcpy(tempstartScheduleStr, sstr);
  5053. strcpy(TxProfileScheduleStr, sstr);
  5054. //**********chargingRateUnit**********/
  5055. c = 0;
  5056. loc = strstr(sLineWord, "chargingRateUnit");
  5057. memset(sstr ,0, sizeof(sstr) );
  5058. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5059. {
  5060. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5061. c++;
  5062. }
  5063. sstr[c] = '\0';
  5064. strcpy(tempchargingRateUnitStr, sstr);
  5065. //**********minChargingRate*******/
  5066. c = 0;
  5067. loc = strstr(sLineWord, "minChargingRate");
  5068. if(loc != NULL)
  5069. {
  5070. memset(sstr ,0, sizeof(sstr) );
  5071. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5072. {
  5073. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5074. c++;
  5075. }
  5076. sstr[c] = '\0';
  5077. tempminChargingRateFloat = atof(sstr);
  5078. }
  5079. else
  5080. {
  5081. tempminChargingRateFloat = 0.0;
  5082. }
  5083. #if 0
  5084. //
  5085. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5086. tp.tm_isdst = -1;
  5087. time_t utc = mktime(&tp);
  5088. time_t t = time(NULL);
  5089. //diff_t = difftime(t, utc);
  5090. #endif
  5091. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5092. //parsing strings to words
  5093. i = 0;
  5094. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5095. loc = loc+3+strlen("chargingSchedulePeriod");
  5096. pch = strtok(loc ,"{");
  5097. while (pch != NULL)
  5098. {
  5099. strcpy(SchedulePeriodList[i], pch);
  5100. pch = strtok (NULL, "{");
  5101. i = i + 1;
  5102. }
  5103. n_SchedulePeriods = i;
  5104. for(int i=0;i<n_SchedulePeriods;i++)
  5105. {
  5106. //*************startPeriod****************/
  5107. c = 0;
  5108. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5109. memset(sstr ,0, sizeof(sstr) );
  5110. while (loc[strlen("startPeriod")+2+c] != ',')
  5111. {
  5112. sstr[c] = loc[strlen("startPeriod")+2+c];
  5113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5114. c++;
  5115. }
  5116. sstr[c] = '\0';
  5117. tempStartPeriodInt = atoi(sstr);
  5118. //*************limit****************/
  5119. c = 0;
  5120. loc = strstr(SchedulePeriodList[i], "limit");
  5121. memset(sstr ,0, sizeof(sstr) );
  5122. while (loc[strlen("limit")+2+c] != ',')
  5123. {
  5124. sstr[c] = loc[strlen("limit")+2+c];
  5125. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5126. c++;
  5127. }
  5128. sstr[c] = '\0';
  5129. tempLimitInt = atof(sstr);
  5130. //*************numberPhases****************/
  5131. c = 0;
  5132. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5133. memset(sstr ,0, sizeof(sstr) );
  5134. while (loc[strlen("numberPhases")+2+c] != '}')
  5135. {
  5136. sstr[c] = loc[strlen("numberPhases")+2+c];
  5137. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5138. c++;
  5139. }
  5140. sstr[c] = '\0';
  5141. tempNumberPhasesInt = atoi(sstr);
  5142. TxProfile.Duration = durationInt;
  5143. TxProfile.TotalPeriod = n_SchedulePeriods;
  5144. TxProfile.Period[i].Limit = tempLimitInt;
  5145. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5146. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5147. }
  5148. if(MinChargingRate < tempminChargingRateFloat)
  5149. MinChargingRate = tempminChargingRateFloat;
  5150. if(confirmPeriods < n_SchedulePeriods)
  5151. confirmPeriods = n_SchedulePeriods;
  5152. }
  5153. fclose(fptr1);
  5154. }
  5155. }// the end of ACCESS TxProfile
  5156. //CompositeSchedule
  5157. int period=0;
  5158. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5159. {
  5160. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5161. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5162. {
  5163. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5164. {
  5165. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5166. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5167. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5168. period = period + 1;
  5169. }
  5170. else
  5171. {
  5172. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5173. {
  5174. }
  5175. else
  5176. {
  5177. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5178. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5179. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5180. period = period + 1;
  5181. }
  5182. }
  5183. }
  5184. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5185. {
  5186. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5187. {
  5188. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5189. {
  5190. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5191. }
  5192. else
  5193. {
  5194. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5195. }
  5196. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5197. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5198. period = period + 1;
  5199. }
  5200. }
  5201. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5202. {
  5203. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5204. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5205. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5206. period = period + 1;
  5207. }
  5208. }
  5209. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5210. {
  5211. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5212. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5213. {
  5214. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5215. {
  5216. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5217. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5218. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5219. period = period + 1;
  5220. }
  5221. else
  5222. {
  5223. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5224. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5225. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5226. period = period + 1;
  5227. }
  5228. }
  5229. }
  5230. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5231. {
  5232. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5233. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5234. {
  5235. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5236. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5237. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5238. period = period + 1;
  5239. }
  5240. }
  5241. confirmPeriods = period;
  5242. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5243. //* Define temporary variables */
  5244. struct tm *gtime;
  5245. time_t now;
  5246. char buf[28];
  5247. //* Read the current system time */
  5248. time(&now);
  5249. //* Convert the system time to GMT (now UTC) */
  5250. gtime = gmtime(&now);
  5251. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5252. // make .conf
  5253. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5254. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5255. //DEBUG_INFO(" debug 11\n");
  5256. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5257. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5258. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5259. }
  5260. else
  5261. {
  5262. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5263. }
  5264. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5265. return result;
  5266. }
  5267. int handleGetConfigurationRequest(char *uuid, char *payload)
  5268. {
  5269. mtrace();
  5270. int result = FAIL;
  5271. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5272. //struct json_object *jsonitem;
  5273. int MaxKeySupported = 0;
  5274. int n_keys = 0;
  5275. char requestKey[43][50]={0};
  5276. char search[]="[";
  5277. char sstr[500]={ 0 };
  5278. //int pos;
  5279. int l, c = 0;
  5280. int i = 0;
  5281. char *delim = "\",\"";
  5282. char * pch;
  5283. char *loc = strstr(payload, search);
  5284. //********************* Parsing String ***********************************/
  5285. if(loc == NULL) {
  5286. DEBUG_INFO("no key match in Configuration \n");
  5287. }
  5288. else {
  5289. //pos = loc - payload;
  5290. l = strlen(loc)-4;
  5291. while (c < l)
  5292. {
  5293. sstr[c] = loc[c+2];
  5294. c++;
  5295. }
  5296. sstr[c] = '\0';
  5297. //parsing strings to words
  5298. pch = strtok(sstr,delim);
  5299. if(pch == NULL)
  5300. {
  5301. strcpy(requestKey[0], sstr);
  5302. }
  5303. else
  5304. {
  5305. while (pch != NULL)
  5306. {
  5307. strcpy(requestKey[i], pch);
  5308. pch = strtok (NULL, delim);
  5309. i = i + 1;
  5310. }
  5311. n_keys = i;
  5312. }
  5313. }
  5314. UnknownKeynum = 0;
  5315. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5316. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5317. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5318. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5319. if(n_keys != 0)
  5320. {
  5321. for(int i=0;i<n_keys;i++)
  5322. {
  5323. getKeyValue(requestKey[i]);
  5324. //json_object_put(jsonitem);
  5325. }
  5326. }
  5327. else
  5328. {
  5329. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5330. getKeyValue("");
  5331. }
  5332. processUnkownKey();
  5333. sendGetConfigurationConfirmation(uuid);
  5334. return result;
  5335. }
  5336. static char fnamePlusPath[100]={0};
  5337. static char fnamePWithNoPath[60]={0};
  5338. void checkUploadLog(void)
  5339. {
  5340. FILE *fp;
  5341. /* Open the command for reading. */
  5342. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5343. if (fp == NULL) {
  5344. printf("Failed to run command\n" );
  5345. exit(1);
  5346. }
  5347. int ftppathlen = 0;
  5348. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5349. int i = 0;
  5350. /* Read the output a line at a time - output it. */
  5351. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5352. if(i==0)
  5353. {
  5354. ftppathlen = strlen(fnamePlusPath);
  5355. printf("%s\n", fnamePlusPath);
  5356. fnamePlusPath[ftppathlen]='\0';
  5357. break;
  5358. }
  5359. i= i+1;
  5360. }
  5361. /* close */
  5362. pclose(fp);
  5363. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5364. {
  5365. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5366. {
  5367. fnamePlusPath[k]='\0';
  5368. }
  5369. }
  5370. i=1;
  5371. //char fname[60]={0};
  5372. while(i < ftppathlen)
  5373. {
  5374. int len=ftppathlen-i;
  5375. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5376. {
  5377. printf("compare '/' all right\n");
  5378. break;
  5379. }
  5380. i=i+1;
  5381. }
  5382. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5383. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5384. fnamePWithNoPath[i+1] = '\0';
  5385. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5386. {
  5387. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5388. {
  5389. fnamePWithNoPath[j]='\0';
  5390. }
  5391. }
  5392. FILE* fp1 = fopen(fnamePlusPath, "r");
  5393. if (fp1)
  5394. {
  5395. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5396. // file exists
  5397. fclose(fp1);
  5398. }
  5399. else
  5400. {
  5401. // file doesn't exist
  5402. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5403. }
  5404. }
  5405. static char GetDiagnosticspayloadData[300]={0};
  5406. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5407. {
  5408. mtrace();
  5409. int result = FAIL;
  5410. pthread_t t; // pthread 變數
  5411. system("exec /root/logPackTools 'log' 6");
  5412. #if 0
  5413. //char buffer [128];
  5414. time (&rawtime);
  5415. //printf("%ld\n", rawtime);
  5416. timeinfo = localtime (&rawtime);
  5417. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5418. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5419. if((access(fnamePlusPath,F_OK))!=-1)
  5420. {
  5421. DEBUG_INFO("fnamePlusPath exist.\n");
  5422. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5423. }
  5424. else
  5425. {
  5426. DEBUG_INFO("fnamePlusPath not exist!\n");
  5427. }
  5428. #endif
  5429. checkUploadLog();
  5430. memset(GetDiagnosticspayloadData, 0, 300);
  5431. strcpy(GetDiagnosticspayloadData, payload);
  5432. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5433. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5434. return result;
  5435. }
  5436. void* GetDiagnosticsProcess(void* data)
  5437. {
  5438. pthread_detach(pthread_self());
  5439. mtrace();
  5440. int retriesInt=0, retryIntervalInt=0;
  5441. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5442. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5443. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  5444. int port=0;
  5445. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5446. int c = 0;
  5447. char *loc;
  5448. int isSuccess = FALSE;
  5449. char ftpbuf[200]={0};
  5450. //char temp[100]={0};
  5451. char * pch;
  5452. // [2,"137d88c7-a403-4ead-bb2d-fc6ec90531c1","GetDiagnostics",{"location":"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/","retries":0,"retryInterval":0,"startTime":"0001-01-01T00:00:00.000Z","stopTime":"0001-01-01T00:00:00.000Z"}]
  5453. char str[300]={ 0 };
  5454. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5455. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5456. DEBUG_INFO("GetDiagnosticsProcess\n");
  5457. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5458. //****************location*******************/
  5459. c = 0;
  5460. memset(sstr ,0, sizeof(sstr) );
  5461. loc = strstr(str, "location");
  5462. while (loc[3+strlen("location")+c] != '\"')
  5463. {
  5464. sstr[c] = loc[3+strlen("location")+c];
  5465. c++;
  5466. }
  5467. sstr[c] = '\0';
  5468. strcpy(locationstr,sstr);
  5469. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5470. if(strcmp(locationstr,"")==0)
  5471. {
  5472. DEBUG_INFO("location is <Empty>!\n");
  5473. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5474. goto end;
  5475. }
  5476. //****************retries*******************/
  5477. c = 0;
  5478. loc = strstr(str, "retries");
  5479. if(loc == NULL)
  5480. {
  5481. retriesIsNULL = TRUE;
  5482. }
  5483. else
  5484. {
  5485. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5486. {
  5487. sstr[c] = loc[strlen("retries")+2+c];
  5488. c++;
  5489. }
  5490. sstr[c] = '\0';
  5491. retriesInt = atoi(sstr);
  5492. }
  5493. if(retriesIsNULL == TRUE)
  5494. {
  5495. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5496. }
  5497. //****************retryInterval*******************/
  5498. c = 0;
  5499. loc = strstr(str, "retryInterval");
  5500. if(loc == NULL)
  5501. {
  5502. retryIntervalIsNULL = TRUE;
  5503. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5504. }
  5505. else
  5506. {
  5507. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5508. {
  5509. sstr[c] = loc[strlen("retryInterval")+2+c];
  5510. c++;
  5511. }
  5512. sstr[c] = '\0';
  5513. retryIntervalInt = atoi(sstr);
  5514. }
  5515. //****************startTime*******************/
  5516. c = 0;
  5517. memset(sstr ,0, sizeof(sstr) );
  5518. loc = strstr(str, "startTime");
  5519. if(loc == NULL)
  5520. {
  5521. startTimeIsNULL = TRUE;
  5522. }
  5523. else
  5524. {
  5525. while (loc[3+strlen("startTime")+c] != '\"')
  5526. {
  5527. sstr[c] = loc[3+strlen("startTime")+c];
  5528. c++;
  5529. }
  5530. sstr[c] = '\0';
  5531. strcpy(startTimestr,sstr);
  5532. }
  5533. //****************stopTime*******************/
  5534. c = 0;
  5535. memset(sstr ,0, sizeof(sstr) );
  5536. loc = strstr(str, "stopTime");
  5537. if(loc == NULL)
  5538. {
  5539. stopTimeIsNULL = TRUE;
  5540. }
  5541. else
  5542. {
  5543. while (loc[3+strlen("stopTime")+c] != '\"')
  5544. {
  5545. sstr[c] = loc[3+strlen("stopTime")+c];
  5546. c++;
  5547. }
  5548. sstr[c] = '\0';
  5549. strcpy(stopTimestr,sstr);
  5550. }
  5551. memset(protocol, 0, sizeof(protocol));
  5552. memset(user, 0, sizeof(user) );
  5553. memset(password, 0, sizeof(password));
  5554. memset(host, 0, sizeof(host));
  5555. memset(path, 0, sizeof(path));
  5556. memset(ftppath, 0, sizeof(ftppath));
  5557. memset(host1, 0, sizeof(host1));
  5558. memset(path1, 0, sizeof(path1));
  5559. /*location: ftp://user:password@host:port/path*/
  5560. #if 0
  5561. time_t rawtime;
  5562. struct tm * timeinfo;
  5563. //char buffer [128];
  5564. time (&rawtime);
  5565. //printf("%ld\n", rawtime);
  5566. timeinfo = localtime (&rawtime);
  5567. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5568. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5569. #endif
  5570. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5571. if((access(fnamePlusPath,F_OK))!=-1)
  5572. {
  5573. DEBUG_INFO("fnamePlusPath exist.\n");
  5574. }
  5575. else
  5576. {
  5577. DEBUG_INFO("fnamePlusPath not exist!\n");
  5578. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5579. goto end;
  5580. }
  5581. pch=strchr(locationstr,'@');
  5582. if(pch==NULL)
  5583. {
  5584. sscanf(locationstr,
  5585. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5586. protocol, host, &port, path);
  5587. strcpy(user,"anonymous");
  5588. strcpy(password,"");
  5589. }
  5590. else
  5591. {
  5592. //DEBUG_INFO("pch=%s\n", pch);
  5593. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5594. protocol, user, password, host, &port, path);
  5595. }
  5596. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5597. {
  5598. DEBUG_INFO("protocol is not ftp/http ! \n");
  5599. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5600. goto end;
  5601. }
  5602. if(strncmp(locationstr,"http", 4) == 0)
  5603. {
  5604. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  5605. sprintf(ftppath,"/%s", path);
  5606. do{
  5607. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5608. sleep(retryIntervalInt);
  5609. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5610. if(!isSuccess)
  5611. {
  5612. DEBUG_INFO("Diagnostics fail.\n");
  5613. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5614. }
  5615. else
  5616. {
  5617. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5618. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5619. }
  5620. }
  5621. else
  5622. {
  5623. sscanf(host,"%[^/]%s",host1, path1);
  5624. sprintf(ftppath,"%s", path1);
  5625. int ftppathlen=strlen(ftppath);
  5626. int i=1;
  5627. char filenametemp[50];
  5628. while(i < ftppathlen)
  5629. {
  5630. int len=ftppathlen-i;
  5631. if(ftppath[len]== 47) // '/' ascll code: 47
  5632. {
  5633. DEBUG_INFO("find '/' all right\n");
  5634. break;
  5635. }
  5636. i=i+1;
  5637. }
  5638. memset(filenametemp, 0, sizeof(filenametemp));
  5639. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5640. filenametemp[i+1] = 0;
  5641. memset(ftpbuf, 0, sizeof(ftpbuf));
  5642. if(port == 0)
  5643. port = 21;
  5644. do{
  5645. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5646. sleep(retryIntervalInt);
  5647. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5648. if(!isSuccess)
  5649. {
  5650. DEBUG_INFO("Diagnostics fail.\n");
  5651. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5652. }
  5653. else
  5654. {
  5655. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5656. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5657. }
  5658. }
  5659. end:
  5660. DiagnosticsStatusNotificationStatus = 0; //Idle
  5661. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5662. }
  5663. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5664. {
  5665. mtrace();
  5666. int result = FAIL;
  5667. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5668. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5669. {
  5670. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5671. localversion = -1;
  5672. }
  5673. else
  5674. {
  5675. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5676. OCPP_getListVerion();
  5677. }
  5678. //from db.OCPP_getListVerion
  5679. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5680. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5681. sendGetLocalListVersionConfirmation(uuid,"");
  5682. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5683. return result;
  5684. }
  5685. int handleRemoteStartRequest(char *uuid, char *payload)
  5686. {
  5687. mtrace();
  5688. int result = FAIL;
  5689. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5690. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5691. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5692. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5693. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5694. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5695. int chargingSchedulePeriodCount = 0;
  5696. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5697. int c = 0;
  5698. char *loc;
  5699. char comfirmstr[20]={0};
  5700. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5701. if(server_pending == TRUE)
  5702. {
  5703. return 0;
  5704. }
  5705. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5706. //**********connectorId****************/
  5707. c = 0;
  5708. memset(sstr ,0, sizeof(sstr) );
  5709. loc = strstr(payload, "connectorId");
  5710. if(loc == NULL)
  5711. {
  5712. connectorIdIsNULL = TRUE;
  5713. }
  5714. else
  5715. {
  5716. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5717. {
  5718. sstr[c] = loc[strlen("connectorId")+2+c];
  5719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5720. c++;
  5721. }
  5722. sstr[c] = '\0';
  5723. connectorIdInt = atoi(sstr);
  5724. }
  5725. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  5726. {
  5727. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5728. goto end;
  5729. }
  5730. //****************idTag*******************/
  5731. c = 0;
  5732. memset(sstr ,0, sizeof(sstr) );
  5733. loc = strstr(payload, "idTag");
  5734. while (loc[3+strlen("idTag")+c] != '\"')
  5735. {
  5736. sstr[c] = loc[3+strlen("idTag")+c];
  5737. c++;
  5738. }
  5739. sstr[c] = '\0';
  5740. strcpy(idTagstr,sstr);
  5741. //****************chargingProfile*******************/
  5742. c = 0;
  5743. memset(sstr ,0, sizeof(sstr) );
  5744. loc = strstr(payload, "chargingProfile");
  5745. if(loc == NULL)
  5746. {
  5747. chargingProfileIsNULL = TRUE;
  5748. }
  5749. else
  5750. {
  5751. //****************chargingProfileId*******************/
  5752. c=0;
  5753. loc = strstr(payload, "chargingProfileId");
  5754. memset(sstr ,0, sizeof(sstr) );
  5755. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5756. {
  5757. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5759. c++;
  5760. }
  5761. sstr[c] = '\0';
  5762. chargingProfileIdInt = atoi(sstr);
  5763. //****************transactionId*******************/
  5764. loc = strstr(payload, "transactionId");
  5765. if(loc == NULL)
  5766. {
  5767. transactionIdIsNULL = TRUE;
  5768. }
  5769. else
  5770. {
  5771. c=0;
  5772. memset(sstr ,0, sizeof(sstr) );
  5773. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5774. {
  5775. sstr[c] = loc[strlen("transactionId")+2+c];
  5776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5777. c++;
  5778. }
  5779. sstr[c] = '\0';
  5780. transactionIdInt = atoi(sstr);
  5781. }
  5782. //****************stackLevel*******************/
  5783. c=0;
  5784. loc = strstr(payload, "stackLevel");
  5785. memset(sstr ,0, sizeof(sstr) );
  5786. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5787. {
  5788. sstr[c] = loc[strlen("stackLevel")+2+c];
  5789. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5790. c++;
  5791. }
  5792. sstr[c] = '\0';
  5793. stackLevelInt = atoi(sstr);
  5794. //****************chargingProfilePurpose*******************/
  5795. c = 0;
  5796. memset(sstr ,0, sizeof(sstr) );
  5797. loc = strstr(payload, "chargingProfilePurpose");
  5798. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5799. {
  5800. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5801. c++;
  5802. }
  5803. sstr[c] = '\0';
  5804. strcpy(chargingProfilePurposestr,sstr);
  5805. //****************chargingProfileKind*******************/
  5806. c = 0;
  5807. memset(sstr ,0, sizeof(sstr) );
  5808. loc = strstr(payload, "chargingProfileKind");
  5809. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5810. {
  5811. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5812. c++;
  5813. }
  5814. sstr[c] = '\0';
  5815. strcpy(chargingProfileKindstr,sstr);
  5816. //****************recurrencyKind*******************/
  5817. loc = strstr(payload, "recurrencyKind");
  5818. if(loc == NULL)
  5819. {
  5820. recurrencyKindIsNULL = TRUE;
  5821. }
  5822. else
  5823. {
  5824. c = 0;
  5825. memset(sstr ,0, sizeof(sstr) );
  5826. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5827. {
  5828. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5829. c++;
  5830. }
  5831. sstr[c] = '\0';
  5832. strcpy(recurrencyKindstr,sstr);
  5833. }
  5834. //****************validFrom*******************/
  5835. loc = strstr(payload, "validFrom");
  5836. if(loc == NULL)
  5837. {
  5838. validFromIsNULL = TRUE;
  5839. }
  5840. else
  5841. {
  5842. c = 0;
  5843. memset(sstr ,0, sizeof(sstr) );
  5844. while (loc[3+strlen("validFrom")+c] != '\"')
  5845. {
  5846. sstr[c] = loc[3+strlen("validFrom")+c];
  5847. c++;
  5848. }
  5849. sstr[c] = '\0';
  5850. strcpy(validFromstr,sstr);
  5851. }
  5852. //****************validTo*******************/
  5853. loc = strstr(payload, "validTo");
  5854. if(loc == NULL)
  5855. {
  5856. validToIsNULL = TRUE;
  5857. }
  5858. else
  5859. {
  5860. c = 0;
  5861. memset(sstr ,0, sizeof(sstr) );
  5862. while (loc[3+strlen("validTo")+c] != '\"')
  5863. {
  5864. sstr[c] = loc[3+strlen("validTo")+c];
  5865. c++;
  5866. }
  5867. sstr[c] = '\0';
  5868. strcpy(validTostr,sstr);
  5869. }
  5870. //****************chargingSchedule*******************/
  5871. loc = strstr(payload, "chargingSchedule");
  5872. if(loc != NULL)
  5873. {
  5874. //****************duration*******************/
  5875. loc = strstr(payload, "duration");
  5876. if(loc == NULL)
  5877. {
  5878. durationIsNULL = TRUE;
  5879. }
  5880. else
  5881. {
  5882. c=0;
  5883. memset(sstr ,0, sizeof(sstr) );
  5884. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5885. {
  5886. sstr[c] = loc[strlen("duration")+2+c];
  5887. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5888. c++;
  5889. }
  5890. sstr[c] = '\0';
  5891. durationInt = atoi(sstr);
  5892. }
  5893. //****************startSchedule******************/
  5894. loc = strstr(payload, "startSchedule");
  5895. if(loc == NULL)
  5896. {
  5897. startScheduleIsNULL = TRUE;
  5898. }
  5899. else
  5900. {
  5901. c = 0;
  5902. memset(sstr ,0, sizeof(sstr) );
  5903. while (loc[3+strlen("startSchedule")+c] != '\"')
  5904. {
  5905. sstr[c] = loc[3+strlen("startSchedule")+c];
  5906. c++;
  5907. }
  5908. sstr[c] = '\0';
  5909. strcpy(startSchedulestr,sstr);
  5910. }
  5911. //****************chargingRateUnit*******************/
  5912. c = 0;
  5913. memset(sstr ,0, sizeof(sstr) );
  5914. loc = strstr(payload, "chargingRateUnit");
  5915. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5916. {
  5917. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5918. c++;
  5919. }
  5920. sstr[c] = '\0';
  5921. strcpy(chargingRateUnitstr,sstr);
  5922. //****************minChargingRate*******************/
  5923. loc = strstr(payload, "minChargingRate");
  5924. if(loc == NULL)
  5925. {
  5926. minChargingRateIsNULL = TRUE;
  5927. }
  5928. else
  5929. {
  5930. c=0;
  5931. memset(sstr ,0, sizeof(sstr) );
  5932. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5933. {
  5934. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5936. c++;
  5937. }
  5938. sstr[c] = '\0';
  5939. minChargingRateflaot = atof(sstr);
  5940. }
  5941. //****************chargingSchedulePeriod count*******************/
  5942. int what_len = strlen("startPeriod");
  5943. char *where = payload;
  5944. while ((where = strstr(where, "startPeriod"))) {
  5945. where += what_len;
  5946. chargingSchedulePeriodCount++;
  5947. }
  5948. where = payload;
  5949. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5950. {
  5951. //****************startPeriod*******************/
  5952. c=0;
  5953. loc = strstr(where, "startPeriod");
  5954. memset(sstr ,0, sizeof(sstr) );
  5955. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5956. {
  5957. sstr[c] = loc[strlen("startPeriod")+2+c];
  5958. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5959. c++;
  5960. }
  5961. sstr[c] = '\0';
  5962. startPeriodInt[periodNums] = atoi(sstr);
  5963. //****************limit*******************/
  5964. c=0;
  5965. loc = strstr(where, "limit");
  5966. memset(sstr ,0, sizeof(sstr) );
  5967. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5968. {
  5969. sstr[c] = loc[strlen("limit")+2+c];
  5970. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5971. c++;
  5972. }
  5973. sstr[c] = '\0';
  5974. limitflaot[periodNums] = atof(sstr);
  5975. //****************numberPhases*******************/
  5976. loc = strstr(where, "numberPhases");
  5977. if(loc == NULL)
  5978. {
  5979. numberPhasesIsNULL = TRUE;
  5980. }
  5981. else
  5982. {
  5983. c=0;
  5984. memset(sstr ,0, sizeof(sstr) );
  5985. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5986. {
  5987. sstr[c] = loc[strlen("numberPhases")+2+c];
  5988. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5989. c++;
  5990. }
  5991. sstr[c] = '\0';
  5992. numberPhasesInt[periodNums] = atoi(sstr);
  5993. }
  5994. where = loc;
  5995. }
  5996. }
  5997. }
  5998. /*
  5999. enum _SYSTEM_STATUS
  6000. {
  6001. S_BOOTING = 0,
  6002. S_IDLE, = 1
  6003. S_AUTHORIZING, =2
  6004. S_REASSIGN_CHECK, =3
  6005. S_REASSIGN, =4
  6006. S_PRECHARGE, =5
  6007. S_PREPARING_FOR_EV, =6
  6008. S_PREPARING_FOR_EVSE, =7
  6009. S_CHARGING, =8
  6010. S_TERMINATING, =9
  6011. S_COMPLETE, =10
  6012. S_ALARM, =11
  6013. S_FAULT =12
  6014. }
  6015. */
  6016. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6017. {
  6018. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6019. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6020. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6021. //check Transaction active
  6022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6023. {
  6024. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6025. {
  6026. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6027. {
  6028. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6029. {
  6030. //Reserved
  6031. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6032. }
  6033. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6034. {
  6035. //Reserved
  6036. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6038. goto end;
  6039. }
  6040. else
  6041. {
  6042. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6043. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6044. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6045. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6046. {
  6047. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6048. goto end;
  6049. }
  6050. }//END FOR ELSE
  6051. }
  6052. }// END FOR CHAdeMO_QUANTITY
  6053. for (int index = 0; index < CCS_QUANTITY; index++)
  6054. {
  6055. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6056. {
  6057. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6058. {
  6059. //Reserved
  6060. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6061. }
  6062. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6063. {
  6064. //Reserved
  6065. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6066. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6067. goto end;
  6068. }
  6069. else
  6070. {
  6071. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6072. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6073. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6074. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6075. {
  6076. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6077. goto end;
  6078. }
  6079. }// END FOR ELSE
  6080. }
  6081. }// END FOR CCS_QUANTITY
  6082. for (int index = 0; index < GB_QUANTITY; index++)
  6083. {
  6084. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6085. {
  6086. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6087. {
  6088. //Reserved
  6089. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6090. }
  6091. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6092. {
  6093. //Reserved
  6094. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6095. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6096. goto end;
  6097. }
  6098. else
  6099. {
  6100. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6101. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6102. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6103. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6104. {
  6105. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6106. goto end;
  6107. }
  6108. }// END FOR ELSE
  6109. }
  6110. } // END FOR GB_QUANTITY
  6111. }
  6112. else
  6113. {
  6114. for (int index = 0; index < AC_QUANTITY; index++)
  6115. {
  6116. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6117. {
  6118. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6119. {
  6120. //Reserved
  6121. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6122. }
  6123. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6124. {
  6125. //Reserved
  6126. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6127. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6128. goto end;
  6129. }
  6130. else
  6131. {
  6132. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6133. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6134. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6135. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6136. {
  6137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6138. goto end;
  6139. }
  6140. }//END FOR ELSE
  6141. }
  6142. }// END FOR AC_QUANTITY
  6143. }
  6144. if(chargingProfileIsNULL == FALSE)
  6145. {
  6146. //ChargingProfile
  6147. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6148. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6149. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6150. if(recurrencyKindIsNULL == FALSE) //OPTION
  6151. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6152. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6153. if(transactionIdIsNULL == FALSE) // OPTION
  6154. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6155. if(validFromIsNULL == FALSE) // OPTION
  6156. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6157. if(validToIsNULL == FALSE) //OPTION
  6158. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6159. //ChargingSchedule
  6160. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6161. if(durationIsNULL == FALSE) //OPTION
  6162. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6163. if(minChargingRateIsNULL == FALSE) //OPTION
  6164. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6165. if(startScheduleIsNULL == FALSE) //OPTION
  6166. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6167. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6168. {
  6169. //ChargingSchedulePeriod
  6170. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6171. if(numberPhasesIsNULL == FALSE)
  6172. {
  6173. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6174. }
  6175. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6176. }
  6177. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6178. {
  6179. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6180. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6181. //memset idTag
  6182. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6183. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6184. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6185. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6186. }
  6187. else
  6188. {
  6189. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6190. }
  6191. }
  6192. else
  6193. {
  6194. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6196. //memset idTag
  6197. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6198. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6199. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6200. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6201. }
  6202. }
  6203. else
  6204. {
  6205. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6206. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6207. }
  6208. end:
  6209. if(connectorIdIsNULL == FALSE)
  6210. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6211. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6212. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6213. //OCPP send RemoteStartConfirmation by first.
  6214. sendRemoteStartConfirmation(uuid, comfirmstr);
  6215. return result;
  6216. }
  6217. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6218. {
  6219. mtrace();
  6220. int result = FAIL;
  6221. int match = FALSE;
  6222. int GunNO = 0;
  6223. int transactionIdInt=0;
  6224. int transactionIdIsNULL= FALSE;
  6225. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6226. int c = 0;
  6227. char *loc;
  6228. char comfirmstr[20];
  6229. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6230. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6231. if(server_pending == TRUE)
  6232. {
  6233. return 0;
  6234. }
  6235. c=0;
  6236. loc = strstr(payload, "transactionId");
  6237. if(loc == NULL)
  6238. {
  6239. transactionIdIsNULL= TRUE;
  6240. }
  6241. else
  6242. {
  6243. memset(sstr ,0, sizeof(sstr) );
  6244. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6245. {
  6246. sstr[c] = loc[strlen("transactionId")+2+c];
  6247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6248. c++;
  6249. }
  6250. sstr[c] = '\0';
  6251. transactionIdInt = atoi(sstr);
  6252. }
  6253. if(transactionIdIsNULL == FALSE)
  6254. {
  6255. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6256. {
  6257. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6258. {
  6259. //check Transaction active
  6260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6261. {
  6262. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6263. {
  6264. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6265. {
  6266. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6267. {
  6268. match = TRUE;
  6269. GunNO = gun_index;
  6270. }
  6271. }
  6272. }// END FOR CHAdeMO_QUANTITY
  6273. for (int index = 0; index < CCS_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6276. {
  6277. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6278. {
  6279. match = TRUE;
  6280. GunNO = gun_index;
  6281. }
  6282. }
  6283. }// END FOR CCS_QUANTITY
  6284. for (int index = 0; index < GB_QUANTITY; index++)
  6285. {
  6286. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6287. {
  6288. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6289. {
  6290. match = TRUE;
  6291. GunNO = gun_index;
  6292. }
  6293. }
  6294. }// END FOR GB_QUANTITY
  6295. }
  6296. else
  6297. {
  6298. for (int index = 0; index < AC_QUANTITY; index++)
  6299. {
  6300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6301. {
  6302. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6303. {
  6304. match = TRUE;
  6305. GunNO = gun_index;
  6306. }
  6307. }
  6308. }// END FOR CHAdeMO_QUANTITY
  6309. }// END FOR AC ELSE
  6310. }// CHECK IF ResponseTransactionId == transactionIdInt
  6311. }//END FOR
  6312. if( match == TRUE)
  6313. {
  6314. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6316. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6317. }
  6318. else
  6319. {
  6320. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6321. }
  6322. }
  6323. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6324. return result;
  6325. }
  6326. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6327. {
  6328. mtrace();
  6329. int result = FAIL;
  6330. int connectorIdInt=0, reservationIdInt=0;
  6331. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6332. char comfirmstr[20]={0};
  6333. char sstr[180]={ 0 };
  6334. int c = 0;
  6335. char *loc;
  6336. //char *ptr;
  6337. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6338. //***(1)connectorId ****/
  6339. c=0;
  6340. loc = strstr(payload, "connectorId");
  6341. memset(sstr ,0, sizeof(sstr) );
  6342. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6343. {
  6344. sstr[c] = loc[strlen("connectorId")+2+c];
  6345. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6346. c++;
  6347. }
  6348. sstr[c] = '\0';
  6349. connectorIdInt = atoi(sstr);
  6350. //***(2)expiryDate ****/
  6351. loc = strstr(payload, "expiryDate");
  6352. memset(sstr ,0, sizeof(sstr) );
  6353. c = 0;
  6354. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6355. {
  6356. sstr[c] = loc[3+strlen("expiryDate")+c];
  6357. c++;
  6358. }
  6359. sstr[c] = '\0';
  6360. strcpy(expiryDatestr, sstr);
  6361. //***(3)idTag ****/
  6362. loc = strstr(payload, "idTag");
  6363. memset(sstr ,0, sizeof(sstr) );
  6364. c = 0;
  6365. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6366. {
  6367. sstr[c] = loc[3+strlen("idTag")+c];
  6368. c++;
  6369. }
  6370. sstr[c] = '\0';
  6371. strcpy(idTagstr, sstr);
  6372. //***(4)parentIdTag ****/
  6373. loc = strstr(payload, "parentIdTag");
  6374. memset(sstr ,0, sizeof(sstr) );
  6375. c = 0;
  6376. if(loc == NULL)
  6377. {
  6378. strcpy(parentIdTagstr, "");
  6379. }
  6380. else
  6381. {
  6382. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6383. {
  6384. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6385. c++;
  6386. }
  6387. sstr[c] = '\0';
  6388. strcpy(parentIdTagstr, sstr);
  6389. }
  6390. //***(5)reservationId ****/
  6391. c=0;
  6392. loc = strstr(payload, "reservationId");
  6393. memset(sstr ,0, sizeof(sstr) );
  6394. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6395. {
  6396. sstr[c] = loc[strlen("reservationId")+2+c];
  6397. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6398. c++;
  6399. }
  6400. sstr[c] = '\0';
  6401. reservationIdInt = atoi(sstr);
  6402. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6403. /*
  6404. enum SYSTEM_STATUS
  6405. {
  6406. SYS_MODE_BOOTING = 0,
  6407. SYS_MODE_IDLE = 1,
  6408. SYS_MODE_AUTHORIZING = 2,
  6409. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6410. SYS_MODE_REASSIGN = 4,
  6411. SYS_MODE_PREPARING = 5,
  6412. SYS_MODE_PREPARE_FOR_EV = 6,
  6413. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6414. SYS_MODE_CHARGING = 8,
  6415. SYS_MODE_TERMINATING = 9,
  6416. SYS_MODE_COMPLETE = 10,
  6417. SYS_MODE_ALARM = 11,
  6418. SYS_MODE_FAULT = 12,
  6419. SYS_MODE_RESERVATION = 13,
  6420. SYS_MODE_BOOKING = 14,
  6421. SYS_MODE_MAINTAIN = 15,
  6422. SYS_MODE_DEBUG = 16,
  6423. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6424. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6425. SYS_MODE_UPDATE = 19
  6426. };
  6427. */
  6428. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6429. {
  6430. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6431. goto end;
  6432. }
  6433. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6434. {
  6435. //check Transaction active
  6436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6437. {
  6438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6441. {
  6442. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6443. {
  6444. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6445. {
  6446. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6447. {
  6448. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6449. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6450. }
  6451. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6452. {
  6453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6454. }
  6455. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6456. {
  6457. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6458. }
  6459. else
  6460. {
  6461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6462. }
  6463. }
  6464. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6465. {
  6466. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6467. }
  6468. }
  6469. else
  6470. {
  6471. //replace reservation
  6472. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6474. }
  6475. }
  6476. } // END FOR CHAdeMO_QUANTITY
  6477. for (int index = 0; index < CCS_QUANTITY; index++)
  6478. {
  6479. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6480. {
  6481. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6482. {
  6483. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6484. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6485. {
  6486. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6487. {
  6488. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6490. }
  6491. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6492. {
  6493. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6494. }
  6495. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6496. {
  6497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6498. }
  6499. else
  6500. {
  6501. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6502. }
  6503. }
  6504. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6505. {
  6506. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6507. }
  6508. }
  6509. else
  6510. {
  6511. //replace reservation
  6512. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6513. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6514. }
  6515. }
  6516. } // END FOR CCS_QUANTITY
  6517. for (int index = 0; index < GB_QUANTITY; index++)
  6518. {
  6519. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6520. {
  6521. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6522. {
  6523. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6524. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6525. {
  6526. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6527. {
  6528. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6530. }
  6531. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6532. {
  6533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6534. }
  6535. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6536. {
  6537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6538. }
  6539. else
  6540. {
  6541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6542. }
  6543. }
  6544. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6545. {
  6546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6547. }
  6548. }
  6549. else
  6550. {
  6551. //replace reservation
  6552. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6554. }
  6555. }
  6556. }// END FOR GB_QUANTITY
  6557. }
  6558. else
  6559. {
  6560. for (int index = 0; index < AC_QUANTITY; index++)
  6561. {
  6562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6563. {
  6564. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6565. {
  6566. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6567. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6568. {
  6569. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6570. {
  6571. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6573. }
  6574. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6575. {
  6576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6577. }
  6578. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6579. {
  6580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6581. }
  6582. else
  6583. {
  6584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6585. }
  6586. }
  6587. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6588. {
  6589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6590. }
  6591. }
  6592. else
  6593. {
  6594. //replace reservation
  6595. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6596. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6597. }
  6598. }
  6599. } // END FOR AC_QUANTITY
  6600. }//END FOR AC ELSE
  6601. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6602. }
  6603. else if(connectorIdInt == 0)
  6604. {
  6605. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6606. {
  6607. //check Transaction active
  6608. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6609. {
  6610. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6611. {
  6612. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6613. {
  6614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6615. goto end;
  6616. }
  6617. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6618. {
  6619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6620. goto end;
  6621. }
  6622. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6623. {
  6624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6625. goto end;
  6626. }
  6627. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6628. {
  6629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6630. goto end;
  6631. }
  6632. }
  6633. }// END FOR CHAdeMO_QUANTITY
  6634. for (int index = 0; index < CCS_QUANTITY; index++)
  6635. {
  6636. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6637. {
  6638. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6639. {
  6640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6641. }
  6642. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6643. {
  6644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6645. }
  6646. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6647. {
  6648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6649. }
  6650. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6651. {
  6652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6653. }
  6654. }
  6655. } // END FOR CCS_QUANTITY
  6656. for (int index = 0; index < GB_QUANTITY; index++)
  6657. {
  6658. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6659. {
  6660. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6661. {
  6662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6663. }
  6664. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6665. {
  6666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6667. }
  6668. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6669. {
  6670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6671. }
  6672. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6673. {
  6674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6675. }
  6676. }
  6677. } // END FOR GB_QUANTITY
  6678. }
  6679. else
  6680. {
  6681. for (int index = 0; index < AC_QUANTITY; index++)
  6682. {
  6683. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6684. {
  6685. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6686. {
  6687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6688. goto end;
  6689. }
  6690. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6691. {
  6692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6693. goto end;
  6694. }
  6695. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6696. {
  6697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6698. goto end;
  6699. }
  6700. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6701. {
  6702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6703. goto end;
  6704. }
  6705. }
  6706. }// END FOR AC_QUANTITY
  6707. }
  6708. //The connectorId is 0
  6709. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6711. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6712. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6713. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6714. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6715. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6716. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6717. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6718. result = TRUE;
  6719. return result;
  6720. }
  6721. else
  6722. {
  6723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6724. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6725. }
  6726. if(strcmp(comfirmstr,"Accepted") == 0)
  6727. {
  6728. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6729. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6730. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6731. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6732. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6733. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6734. result = TRUE;
  6735. return result;
  6736. }
  6737. end:
  6738. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6739. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6740. return result;
  6741. }
  6742. int handleResetRequest(char *uuid, char *payload)
  6743. {
  6744. mtrace();
  6745. int result = FAIL;
  6746. char sstr[10]={0};
  6747. char typestr[10]={0};
  6748. char comfirmstr[20]={0};
  6749. int c = 0;
  6750. char *loc;
  6751. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6752. DEBUG_INFO("handleResetRequest ...\n");
  6753. loc = strstr(payload, "type");
  6754. memset(sstr ,0, sizeof(sstr) );
  6755. c = 0;
  6756. while (loc[3+strlen("type")+c] != '\"')
  6757. {
  6758. sstr[c] = loc[3+strlen("type")+c];
  6759. c++;
  6760. }
  6761. sstr[c] = '\0';
  6762. strcpy(typestr,sstr);
  6763. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6764. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6765. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6766. {
  6767. //check Transaction active
  6768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6769. {
  6770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6773. {
  6774. //0: unplug, 1: Plug-in
  6775. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6776. }
  6777. }
  6778. for (int index = 0; index < CCS_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6781. {
  6782. //0: unplug, 1: Plug-in
  6783. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6784. }
  6785. }
  6786. for (int index = 0; index < GB_QUANTITY; index++)
  6787. {
  6788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6789. {
  6790. //0: unplug, 1: Plug-in
  6791. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6792. }
  6793. }
  6794. }
  6795. else
  6796. {
  6797. for (int index = 0; index < AC_QUANTITY; index++)
  6798. {
  6799. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6800. {
  6801. //0: unplug, 1: Plug-in
  6802. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6803. }
  6804. }
  6805. }// END FOR AC ELSE
  6806. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6807. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6808. result = TRUE;
  6809. return result;
  6810. }
  6811. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6812. {
  6813. //check Transaction active
  6814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6815. {
  6816. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6817. {
  6818. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6819. {
  6820. //0: unplug, 1: Plug-in
  6821. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6822. }
  6823. }
  6824. for (int index = 0; index < CCS_QUANTITY; index++)
  6825. {
  6826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6827. {
  6828. //0: unplug, 1: Plug-in
  6829. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6830. }
  6831. }
  6832. for (int index = 0; index < GB_QUANTITY; index++)
  6833. {
  6834. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6835. {
  6836. //0: unplug, 1: Plug-in
  6837. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6838. }
  6839. }
  6840. }
  6841. else
  6842. {
  6843. for (int index = 0; index < AC_QUANTITY; index++)
  6844. {
  6845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6846. {
  6847. //0: unplug, 1: Plug-in
  6848. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6849. }
  6850. }
  6851. }// END FOR AC ELSE
  6852. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6853. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6854. result = TRUE;
  6855. return result;
  6856. }
  6857. else
  6858. {
  6859. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6860. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6861. goto errorend;
  6862. }
  6863. errorend:
  6864. sendResetConfirmation(uuid, comfirmstr);
  6865. return result;
  6866. }
  6867. int handleSendLocalListRequest(char *uuid, char *payload)
  6868. {
  6869. mtrace();
  6870. int result = FAIL;
  6871. int listVersionInt;
  6872. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6873. char listsearch[]="listVersion";
  6874. char updateTypesearch[]="updateType";
  6875. char localAuthorizationListsearch[]="localAuthorizationList";
  6876. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6877. char CardList[500][160]={0};
  6878. char updateTypestr[15]={0};
  6879. char idTagstr[20]={0};
  6880. char parentIdTag[20]={0};
  6881. char expiryDate[30]={0};
  6882. char idTagstatus[16]={0};
  6883. int c = 0;
  6884. int i = 0;
  6885. char *delim1 = "}";
  6886. char * pch;
  6887. char *loc;
  6888. //char *ptr;
  6889. char comfirmstr[20];
  6890. //int n_localAuthorizations = 0;
  6891. int checkState_Faulted = FALSE;
  6892. DEBUG_INFO("handleSendLocalListRequest\n");
  6893. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6894. {
  6895. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6896. goto end;
  6897. }
  6898. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6899. {
  6900. //check Charge Point state
  6901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6902. {
  6903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6904. {
  6905. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6906. }
  6907. }
  6908. for (int index = 0; index < CCS_QUANTITY; index++)
  6909. {
  6910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6911. {
  6912. checkState_Faulted = TRUE; //OCPP Status
  6913. }
  6914. }
  6915. for (int index = 0; index < GB_QUANTITY; index++)
  6916. {
  6917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6918. {
  6919. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6920. }
  6921. }
  6922. }
  6923. else
  6924. {
  6925. //check Charge Point state
  6926. for (int index = 0; index < AC_QUANTITY; index++)
  6927. {
  6928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6929. {
  6930. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6931. }
  6932. }
  6933. }// END FOR AC ELSE
  6934. if(checkState_Faulted == TRUE)
  6935. {
  6936. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6937. goto end;
  6938. }
  6939. //listVersion
  6940. c = 0;
  6941. loc = strstr(payload, listsearch);
  6942. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  6943. {
  6944. sstr[c] = loc[strlen("listVersion")+2+c];
  6945. c++;
  6946. }
  6947. sstr[c] = '\0';
  6948. listVersionInt = atoi(sstr);
  6949. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6950. //updateType
  6951. loc = strstr(payload, updateTypesearch);
  6952. c = 0;
  6953. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6954. {
  6955. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6956. c++;
  6957. }
  6958. sstr[c] = '\0';
  6959. strcpy(updateTypestr, sstr);
  6960. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6961. //localAuthorizationList
  6962. memset(sstr ,0, sizeof(sstr) );
  6963. loc = strstr(payload, localAuthorizationListsearch);
  6964. if(loc != NULL) // localAuthorizationList is not NULL
  6965. {
  6966. //Check UpdateType
  6967. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6968. {
  6969. //Local list full update
  6970. printf("Local list full update.\n");
  6971. OCPP_cleanLocalList();
  6972. }
  6973. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6974. {
  6975. //Local list different update
  6976. printf("Local list different update.\n");
  6977. OCPP_getListVerion();
  6978. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6979. {
  6980. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6981. goto end;
  6982. }
  6983. }
  6984. else
  6985. {
  6986. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6987. goto end;
  6988. }
  6989. c = 0;
  6990. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6991. {
  6992. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6993. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6994. c++;
  6995. }
  6996. sstr[c] = '\0';
  6997. //DEBUG_INFO("sstr=%s\n", sstr);
  6998. //parsing strings to words
  6999. i = 0;
  7000. pch = strtok(sstr,delim1);
  7001. while (pch != NULL)
  7002. {
  7003. strcpy(CardList[i], pch);
  7004. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7005. pch = strtok (NULL, delim1);
  7006. i = i + 1;
  7007. }
  7008. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7009. //local Authorizations List Numbers
  7010. //n_localAuthorizations = i;
  7011. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7012. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7013. c= 0;
  7014. while(c < i)
  7015. {
  7016. //Search "IdToken"
  7017. memset(sstr ,0, sizeof(sstr) );
  7018. loc = strstr(CardList[c], "idTag");
  7019. int j = 0;
  7020. while (loc[3+strlen("idTag")+j] != '\"')
  7021. {
  7022. sstr[j] = loc[3+strlen("idTag")+j];
  7023. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7024. j++;
  7025. }
  7026. sstr[j] = '\0';
  7027. strcpy(idTagstr, sstr);
  7028. DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7029. //Search "expiryDate"
  7030. memset(sstr ,0, sizeof(sstr) );
  7031. loc = strstr(CardList[c], "expiryDate");
  7032. j = 0;
  7033. if(loc != NULL)
  7034. {
  7035. while (loc[3+strlen("expiryDate")+j] != '\"')
  7036. {
  7037. sstr[j] = loc[3+strlen("expiryDate")+j];
  7038. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7039. j++;
  7040. }
  7041. sstr[j] = '\0';
  7042. strcpy(expiryDate, sstr);
  7043. }
  7044. else
  7045. {
  7046. strcpy(expiryDate, "");
  7047. }
  7048. DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7049. //Search "parentIdTag"
  7050. memset(sstr ,0, sizeof(sstr) );
  7051. loc = strstr(CardList[c], "parentIdTag");
  7052. j = 0;
  7053. if(loc != NULL)
  7054. {
  7055. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7056. {
  7057. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7058. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7059. j++;
  7060. }
  7061. sstr[j] = '\0';
  7062. strcpy(parentIdTag, sstr);
  7063. }
  7064. else
  7065. {
  7066. strcpy(parentIdTag, "");
  7067. }
  7068. DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7069. //Search "status"
  7070. memset(sstr ,0, sizeof(sstr) );
  7071. loc = strstr(CardList[c], "status");
  7072. j = 0;
  7073. while (loc[3+strlen("status")+j] != '\"')
  7074. {
  7075. sstr[j] = loc[3+strlen("status")+j];
  7076. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7077. j++;
  7078. }
  7079. sstr[j] = '\0';
  7080. strcpy(idTagstatus, sstr);
  7081. DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7082. OCPP_getIdTag(idTagstr);
  7083. //OCPP_getIdTag("test"); For Test
  7084. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7085. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7086. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7087. {
  7088. //Local list full update
  7089. DEBUG_INFO("Local list full update.\n");
  7090. // update list
  7091. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7092. //DEBUG_INFO("Local list full update. 1\n");
  7093. //OCPP_get_TableAuthlocalAllData();
  7094. //DEBUG_INFO("Local list full update. 2\n");
  7095. }
  7096. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7097. {
  7098. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7099. {
  7100. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7101. }
  7102. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7103. {
  7104. OCPP_deleteIdTag(idTagstr);
  7105. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7106. //OCPP_deleteIdTag(idTagstr);
  7107. }
  7108. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7109. {
  7110. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7111. }
  7112. }
  7113. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7114. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7115. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7116. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7117. c++;
  7118. }
  7119. }
  7120. else
  7121. {
  7122. //Check UpdateType
  7123. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7124. {
  7125. //Local list full update
  7126. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7127. OCPP_cleanLocalList();
  7128. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7129. goto end;
  7130. }
  7131. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7132. {
  7133. //Local list different update
  7134. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7135. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7136. goto end;
  7137. }
  7138. }
  7139. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7140. end:
  7141. sendSendLocalListConfirmation(uuid, comfirmstr);
  7142. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7143. return result;
  7144. }
  7145. #define MAX 200
  7146. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7147. {
  7148. mtrace();
  7149. int result = FAIL;
  7150. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7151. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7152. char chargingProfilePurposeStr[30]={0};
  7153. char chargingProfileKindStr[16]={0};
  7154. char recurrencyKindStr[10]={0};
  7155. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7156. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7157. int chargingSchedulePeriodCount = 0;
  7158. //int updateflag = FALSE;
  7159. char comfirmstr[20]={0};
  7160. int meet= FALSE;
  7161. char sstr[10]={0};
  7162. int c = 0;
  7163. char *loc;
  7164. FILE *fptr1;//, *fptr2;
  7165. //int lno=0;//, linectr = 0;
  7166. //int modifyflag = FALSE;
  7167. char filename[MAX]={0};
  7168. char tempfile[] = "/Storage/OCPP/temp.json";
  7169. //int resultRename=0;
  7170. char rmFileCmd[50]={0};
  7171. char tempchargingProfilePurposeStr[30]={0};
  7172. //[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}}}]
  7173. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7174. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7175. //*********************connectorId***************************/
  7176. loc = strstr(payload, "connectorId");
  7177. c = 0;
  7178. memset(sstr ,0, sizeof(sstr) );
  7179. while (loc[strlen("connectorId")+2+c] != ',')
  7180. {
  7181. sstr[c] = loc[strlen("connectorId")+2+c];
  7182. c++;
  7183. }
  7184. sstr[c] = '\0';
  7185. connectorIdInt = atoi(sstr);
  7186. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7187. {
  7188. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7189. }
  7190. else
  7191. {
  7192. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7193. }
  7194. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7195. //*********************chargingProfileId***************************/
  7196. loc = strstr(payload, "chargingProfileId");
  7197. c = 0;
  7198. memset(sstr ,0, sizeof(sstr) );
  7199. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7200. {
  7201. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7202. c++;
  7203. }
  7204. sstr[c] = '\0';
  7205. chargingProfileIdInt = atoi(sstr);
  7206. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7207. {
  7208. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7209. }
  7210. else
  7211. {
  7212. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7213. }
  7214. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7215. //*********************transactionId***************************/
  7216. loc = strstr(payload, "transactionId");
  7217. if(loc != NULL)
  7218. {
  7219. c = 0;
  7220. memset(sstr ,0, sizeof(sstr) );
  7221. while (loc[strlen("transactionId")+2+c] != ',')
  7222. {
  7223. sstr[c] = loc[strlen("transactionId")+2+c];
  7224. c++;
  7225. }
  7226. sstr[c] = '\0';
  7227. transactionIdInt = atoi(sstr);
  7228. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7229. {
  7230. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7231. }
  7232. else
  7233. {
  7234. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7235. }
  7236. }
  7237. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7238. //*********************stackLevel***************************/
  7239. loc = strstr(payload, "stackLevel");
  7240. c = 0;
  7241. memset(sstr ,0, sizeof(sstr) );
  7242. while (loc[strlen("stackLevel")+2+c] != ',')
  7243. {
  7244. sstr[c] = loc[strlen("stackLevel")+2+c];
  7245. c++;
  7246. }
  7247. sstr[c] = '\0';
  7248. stackLevelInt = atoi(sstr);
  7249. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7250. {
  7251. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7252. }
  7253. else
  7254. {
  7255. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7256. }
  7257. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7258. //*********************chargingProfilePurpose***************************/
  7259. loc = strstr(payload, "chargingProfilePurpose");
  7260. c = 0;
  7261. memset(sstr ,0, sizeof(sstr) );
  7262. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7263. {
  7264. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7266. c++;
  7267. }
  7268. sstr[c] = '\0';
  7269. strcpy(chargingProfilePurposeStr,sstr);
  7270. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7271. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7272. {
  7273. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7274. }
  7275. else
  7276. {
  7277. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7278. }
  7279. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7280. //*********************chargingProfileKind***************************/
  7281. loc = strstr(payload, "chargingProfileKind");
  7282. c = 0;
  7283. memset(sstr ,0, sizeof(sstr) );
  7284. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7285. {
  7286. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7287. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7288. c++;
  7289. }
  7290. sstr[c] = '\0';
  7291. strcpy(chargingProfileKindStr,sstr);
  7292. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7293. {
  7294. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7295. }
  7296. else
  7297. {
  7298. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7299. }
  7300. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7301. //*********************recurrencyKind***************************/
  7302. loc = strstr(payload, "recurrencyKind");
  7303. if(loc != NULL)
  7304. {
  7305. c = 0;
  7306. memset(sstr ,0, sizeof(sstr) );
  7307. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7308. {
  7309. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7310. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7311. c++;
  7312. }
  7313. sstr[c] = '\0';
  7314. strcpy(recurrencyKindStr,sstr);
  7315. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7316. {
  7317. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7318. }
  7319. else
  7320. {
  7321. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7322. }
  7323. }
  7324. else
  7325. {
  7326. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7327. {
  7328. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7329. }
  7330. else
  7331. {
  7332. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7333. }
  7334. }
  7335. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7336. //*********************validFrom***************************/
  7337. loc = strstr(payload, "validFrom");
  7338. if(loc != NULL)
  7339. {
  7340. c = 0;
  7341. memset(sstr ,0, sizeof(sstr) );
  7342. while (loc[3+strlen("validFrom")+c] != '\"')
  7343. {
  7344. sstr[c] = loc[3+strlen("validFrom")+c];
  7345. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7346. c++;
  7347. }
  7348. sstr[c] = '\0';
  7349. strcpy(validFromStr,sstr);
  7350. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7351. {
  7352. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7353. }
  7354. else
  7355. {
  7356. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7357. }
  7358. }
  7359. else
  7360. {
  7361. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7362. {
  7363. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7364. }
  7365. else
  7366. {
  7367. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7368. }
  7369. }
  7370. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7371. //*********************validTo***************************/
  7372. loc = strstr(payload, "validTo");
  7373. if(loc != NULL)
  7374. {
  7375. c = 0;
  7376. memset(sstr ,0, sizeof(sstr) );
  7377. while (loc[3+strlen("validTo")+c] != '\"')
  7378. {
  7379. sstr[c] = loc[3+strlen("validTo")+c];
  7380. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7381. c++;
  7382. }
  7383. sstr[c] = '\0';
  7384. strcpy(validToStr,sstr);
  7385. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7386. {
  7387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7388. }
  7389. else
  7390. {
  7391. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7392. }
  7393. }
  7394. else
  7395. {
  7396. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7397. {
  7398. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7399. }
  7400. else
  7401. {
  7402. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7403. }
  7404. }
  7405. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7406. //*********************duration***************************/
  7407. loc = strstr(payload, "duration");
  7408. if(loc != NULL)
  7409. {
  7410. c = 0;
  7411. memset(sstr ,0, sizeof(sstr) );
  7412. while (loc[strlen("duration")+2+c] != ',')
  7413. {
  7414. sstr[c] = loc[strlen("duration")+2+c];
  7415. c++;
  7416. }
  7417. sstr[c] = '\0';
  7418. durationInt = atoi(sstr);
  7419. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7420. {
  7421. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7422. }
  7423. else
  7424. {
  7425. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7426. }
  7427. }
  7428. else
  7429. {
  7430. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7431. {
  7432. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7433. }
  7434. else
  7435. {
  7436. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7437. }
  7438. }
  7439. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7440. //*********************startSchedule***************************/
  7441. loc = strstr(payload, "startSchedule");
  7442. if(loc != NULL)
  7443. {
  7444. c = 0;
  7445. memset(sstr ,0, sizeof(sstr) );
  7446. while (loc[3+strlen("startSchedule")+c] != '\"')
  7447. {
  7448. sstr[c] = loc[3+strlen("startSchedule")+c];
  7449. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7450. c++;
  7451. }
  7452. sstr[c] = '\0';
  7453. strcpy(startScheduleStr,sstr);
  7454. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7455. {
  7456. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7457. }
  7458. else
  7459. {
  7460. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7461. }
  7462. }
  7463. else
  7464. {
  7465. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7466. {
  7467. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7468. }
  7469. else
  7470. {
  7471. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7472. }
  7473. }
  7474. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7475. //*********************chargingRateUnit***************************/
  7476. loc = strstr(payload, "chargingRateUnit");
  7477. if(loc != NULL)
  7478. {
  7479. c = 0;
  7480. memset(sstr ,0, sizeof(sstr) );
  7481. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7482. {
  7483. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7484. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7485. c++;
  7486. }
  7487. sstr[c] = '\0';
  7488. strcpy(chargingRateUnitStr,sstr);
  7489. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7490. {
  7491. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7492. goto end;
  7493. }
  7494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7495. {
  7496. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7497. }
  7498. else
  7499. {
  7500. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7501. }
  7502. }
  7503. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7504. //****************chargingSchedulePeriod count start*******************/
  7505. int what_len = strlen("startPeriod");
  7506. char tempChargingProfile[1000]={0};
  7507. strcpy(tempChargingProfile,(const char*)payload);
  7508. char *where = tempChargingProfile;
  7509. if (what_len)
  7510. {
  7511. while ((where = strstr(where, "startPeriod"))) {
  7512. where += what_len;
  7513. chargingSchedulePeriodCount++;
  7514. }
  7515. }
  7516. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  7517. {
  7518. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7519. goto end;
  7520. }
  7521. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7522. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7523. //where = payload;
  7524. int templength = 0;
  7525. //int searchstart = 0;
  7526. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7527. {
  7528. //****************startPeriod*******************/
  7529. c=0;
  7530. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7531. memset(sstr ,0, sizeof(sstr) );
  7532. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7533. {
  7534. sstr[c] = loc[strlen("startPeriod")+2+c];
  7535. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7536. c++;
  7537. }
  7538. sstr[c] = '\0';
  7539. startPeriodInt[periodNums] = atoi(sstr);
  7540. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7541. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7542. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7543. {
  7544. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7545. }
  7546. else
  7547. {
  7548. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7549. }
  7550. templength = strlen("startPeriod")+2+c;
  7551. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7552. //****************limit*******************/
  7553. c=0;
  7554. loc = strstr(tempChargingProfile + templength, "limit");
  7555. memset(sstr ,0, sizeof(sstr) );
  7556. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7557. {
  7558. sstr[c] = loc[strlen("limit")+2+c];
  7559. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7560. c++;
  7561. }
  7562. sstr[c] = '\0';
  7563. limitflaot[periodNums] = atof(sstr);
  7564. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7565. {
  7566. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7567. }
  7568. else
  7569. {
  7570. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7571. }
  7572. templength = templength + strlen("limit")+2+c;
  7573. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7574. //****************numberPhases*******************/
  7575. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7576. if(loc != NULL)
  7577. {
  7578. c=0;
  7579. memset(sstr ,0, sizeof(sstr) );
  7580. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7581. {
  7582. sstr[c] = loc[strlen("numberPhases")+2+c];
  7583. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7584. c++;
  7585. }
  7586. sstr[c] = '\0';
  7587. numberPhasesInt[periodNums] = atoi(sstr);
  7588. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7589. {
  7590. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7591. }
  7592. else
  7593. {
  7594. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7595. }
  7596. templength = templength + strlen("numberPhases")+2+c;
  7597. }
  7598. //where = loc;
  7599. }
  7600. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7601. //****************chargingSchedulePeriod count end*******************/
  7602. //*********************minChargingRate***************************/
  7603. loc = strstr(payload, "minChargingRate");
  7604. if(loc != NULL)
  7605. {
  7606. c = 0;
  7607. memset(sstr ,0, sizeof(sstr) );
  7608. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7609. {
  7610. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7611. c++;
  7612. }
  7613. sstr[c] = '\0';
  7614. minChargingRateFloat = atof(sstr);
  7615. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7616. {
  7617. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7618. }
  7619. else
  7620. {
  7621. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7622. }
  7623. }
  7624. else
  7625. {
  7626. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7627. {
  7628. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7629. }
  7630. else
  7631. {
  7632. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7633. }
  7634. }
  7635. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7636. {
  7637. //printf("set chargingProfile 1-2\n");
  7638. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7639. if(connectorIdInt != 0)
  7640. {
  7641. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7642. goto end;
  7643. }
  7644. strcpy(filename, ChargePointMaxProfile_JSON );
  7645. fptr1 = fopen(filename, "r");
  7646. if (!fptr1)
  7647. {
  7648. //file not exist
  7649. DEBUG_INFO("Unable to open the input file!!\n");
  7650. fptr1 = fopen(filename, "w+");
  7651. }
  7652. fclose(fptr1);
  7653. }
  7654. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7655. {
  7656. //printf("set chargingProfile 1-3\n");
  7657. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7658. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7659. {
  7660. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7661. goto end;
  7662. }
  7663. switch(connectorIdInt)
  7664. {
  7665. case 0:
  7666. strcpy(filename, TxDefaultProfile_0_JSON );
  7667. break;
  7668. case 1:
  7669. strcpy(filename, TxDefaultProfile_1_JSON );
  7670. break;
  7671. case 2:
  7672. strcpy(filename, TxDefaultProfile_2_JSON );
  7673. break;
  7674. default:
  7675. strcpy(filename, TxDefaultProfile_0_JSON );
  7676. break;
  7677. }
  7678. fptr1 = fopen(filename, "r");
  7679. if (!fptr1)
  7680. {
  7681. //file not exist
  7682. //DEBUG_INFO("Unable to open the input file!!\n");
  7683. fptr1 = fopen(filename, "w+");
  7684. }
  7685. fclose(fptr1);
  7686. }
  7687. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7688. {
  7689. //printf("set chargingProfile 1-4\n");
  7690. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7691. //check Transaction active
  7692. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7693. {
  7694. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7695. {
  7696. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7697. {
  7698. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7699. {
  7700. meet = TRUE;
  7701. break;
  7702. }
  7703. }
  7704. }
  7705. }
  7706. for (int index = 0; index < CCS_QUANTITY; index++)
  7707. {
  7708. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7709. {
  7710. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7711. {
  7712. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7713. {
  7714. meet = TRUE;
  7715. break;
  7716. }
  7717. }
  7718. }
  7719. }
  7720. for (int index = 0; index < GB_QUANTITY; index++)
  7721. {
  7722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7723. {
  7724. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7725. {
  7726. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7727. {
  7728. meet = TRUE;
  7729. break;
  7730. }
  7731. }
  7732. }
  7733. }
  7734. if(meet == FALSE)
  7735. {
  7736. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7737. goto end;
  7738. }
  7739. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7740. {
  7741. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7742. goto end;
  7743. }
  7744. switch(connectorIdInt)
  7745. {
  7746. case 0:
  7747. break;
  7748. case 1:
  7749. strcpy(filename, TxProfile_1_JSON);
  7750. break;
  7751. case 2:
  7752. strcpy(filename, TxProfile_2_JSON);
  7753. break;
  7754. default:
  7755. strcpy(filename, TxProfile_1_JSON);
  7756. break;
  7757. }
  7758. fptr1 = fopen(filename, "r");
  7759. if (!fptr1)
  7760. {
  7761. //file not exist
  7762. DEBUG_INFO("Unable to open the input file!!\n");
  7763. fptr1 = fopen(filename, "w+");
  7764. }
  7765. fclose(fptr1);
  7766. }
  7767. //**********************************Write to File********************************************************/
  7768. FILE *infile;
  7769. FILE *outfile;
  7770. // open file for writing
  7771. infile = fopen (filename, "r");
  7772. outfile = fopen (tempfile, "w");
  7773. int d =0;
  7774. d = fgetc(infile);
  7775. //DEBUG_INFO("d:%d\n",d);
  7776. rewind(infile);
  7777. //*检测到文件结束标识返回1,否则返回0。*/
  7778. if(d == EOF)
  7779. {
  7780. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7781. fprintf(outfile,"%s\n",payload);
  7782. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7783. fclose(infile);
  7784. fclose(outfile);
  7785. sprintf(rmFileCmd,"rm -f %s",filename);
  7786. system(rmFileCmd);
  7787. rename(tempfile, filename);
  7788. #if 0
  7789. resultRename = rename(tempfile, filename);
  7790. if(resultRename == 0)
  7791. {
  7792. DEBUG_INFO("File chargingProfile renamed successfully");
  7793. }
  7794. else
  7795. {
  7796. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7797. }
  7798. #endif
  7799. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7800. //system(rmFileCmd);
  7801. }
  7802. else
  7803. {
  7804. char buf[1000]={0};
  7805. int ChargingProfileAdded = FALSE;
  7806. while (fgets(buf, sizeof(buf), infile) != NULL)
  7807. {
  7808. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7809. //*************************tempconnectorIdInt*********************************/
  7810. loc = strstr(buf, "connectorId");
  7811. c = 0;
  7812. memset(sstr ,0, sizeof(sstr) );
  7813. while (loc[strlen("connectorId")+2+c] != ',')
  7814. {
  7815. sstr[c] = loc[strlen("connectorId")+2+c];
  7816. c++;
  7817. }
  7818. sstr[c] = '\0';
  7819. tempconnectorIdInt = atoi(sstr);
  7820. //*************************tempchargingProfileIdInt*********************************/
  7821. loc = strstr(buf, "chargingProfileId");
  7822. c = 0;
  7823. memset(sstr ,0, sizeof(sstr) );
  7824. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7825. {
  7826. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7827. c++;
  7828. }
  7829. sstr[c] = '\0';
  7830. tempchargingProfileIdInt = atoi(sstr);
  7831. //*************************tempstackLevelInt*********************************/
  7832. loc = strstr(buf, "stackLevel");
  7833. c = 0;
  7834. memset(sstr ,0, sizeof(sstr) );
  7835. while (loc[strlen("stackLevel")+2+c] != ',')
  7836. {
  7837. sstr[c] = loc[strlen("stackLevel")+2+c];
  7838. c++;
  7839. }
  7840. sstr[c] = '\0';
  7841. tempstackLevelInt = atoi(sstr);
  7842. //*************************tempchargingProfilePurposeStr*********************************/
  7843. loc = strstr(payload, "chargingProfilePurpose");
  7844. c = 0;
  7845. memset(sstr ,0, sizeof(sstr) );
  7846. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7847. {
  7848. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7849. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7850. c++;
  7851. }
  7852. sstr[c] = '\0';
  7853. strcpy(tempchargingProfilePurposeStr,sstr);
  7854. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7855. {
  7856. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7857. {
  7858. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7859. if(ChargingProfileAdded == FALSE)
  7860. {
  7861. fprintf(outfile,"%s\n",payload);
  7862. ChargingProfileAdded = TRUE;
  7863. }
  7864. }
  7865. else
  7866. {
  7867. if(tempstackLevelInt < stackLevelInt)
  7868. {
  7869. if(ChargingProfileAdded == FALSE)
  7870. {
  7871. fprintf(outfile,"%s\n",payload);
  7872. ChargingProfileAdded = TRUE;
  7873. fprintf(outfile,"%s\n",buf);
  7874. }
  7875. else
  7876. {
  7877. fprintf(outfile,"%s\n",buf);
  7878. }
  7879. }
  7880. else
  7881. {
  7882. if(ChargingProfileAdded == FALSE)
  7883. {
  7884. fprintf(outfile,"%s\n",buf);
  7885. fprintf(outfile,"%s\n",payload);
  7886. ChargingProfileAdded = TRUE;
  7887. }
  7888. else
  7889. {
  7890. fprintf(outfile,"%s\n",buf);
  7891. }
  7892. }
  7893. }
  7894. }
  7895. else
  7896. {
  7897. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7898. {
  7899. if(ChargingProfileAdded == FALSE)
  7900. {
  7901. fprintf(outfile,"%s\n",payload);
  7902. ChargingProfileAdded = TRUE;
  7903. fprintf(outfile,"%s\n",buf);
  7904. }
  7905. else
  7906. {
  7907. fprintf(outfile,"%s\n",buf);
  7908. }
  7909. }
  7910. else if(tempstackLevelInt < stackLevelInt)
  7911. {
  7912. if(ChargingProfileAdded == FALSE)
  7913. {
  7914. fprintf(outfile,"%s\n",payload);
  7915. ChargingProfileAdded = TRUE;
  7916. fprintf(outfile,"%s\n",buf);
  7917. }
  7918. else
  7919. {
  7920. fprintf(outfile,"%s\n",buf);
  7921. }
  7922. }
  7923. else
  7924. {
  7925. if(ChargingProfileAdded == FALSE)
  7926. {
  7927. fprintf(outfile,"%s\n",buf);
  7928. fprintf(outfile,"%s\n",payload);
  7929. ChargingProfileAdded = TRUE;
  7930. }
  7931. else
  7932. {
  7933. fprintf(outfile,"%s\n",buf);
  7934. }
  7935. }
  7936. }
  7937. } // end of while loop
  7938. fclose(infile);
  7939. fclose(outfile);
  7940. sprintf(rmFileCmd,"rm -f %s",filename);
  7941. system(rmFileCmd);
  7942. rename(tempfile, filename);
  7943. #if 0
  7944. resultRename = rename(tempfile, filename);
  7945. if(resultRename == 0)
  7946. {
  7947. DEBUG_INFO("File chargingProfile renamed successfully");
  7948. }
  7949. else
  7950. {
  7951. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7952. }
  7953. #endif
  7954. result = TRUE;
  7955. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7956. }
  7957. end:
  7958. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7959. return result;
  7960. return result;
  7961. }
  7962. int handleTriggerMessageRequest(char *uuid, char *payload)
  7963. {
  7964. mtrace();
  7965. int result = FAIL;
  7966. int connectorIdIsNULL = FALSE;
  7967. int connectorIdInt =0;
  7968. char sstr[40]={0};
  7969. char requestedMessagestr[40]={0};
  7970. char comfirmstr[20]={0};
  7971. int c = 0;
  7972. char *loc;
  7973. DEBUG_INFO("handleTriggerMessageRequest\n");
  7974. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7975. c = 0;
  7976. loc = strstr(payload, "requestedMessage");
  7977. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7978. {
  7979. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7980. c++;
  7981. }
  7982. sstr[c] = '\0';
  7983. strcpy(requestedMessagestr, sstr);
  7984. c = 0;
  7985. loc = strstr(payload, "connectorId");
  7986. if(loc == NULL)
  7987. {
  7988. connectorIdIsNULL = TRUE;
  7989. }
  7990. else
  7991. {
  7992. memset(sstr ,0, sizeof(sstr) );
  7993. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7994. {
  7995. sstr[c] = loc[strlen("connectorId")+2+c];
  7996. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7997. c++;
  7998. }
  7999. sstr[c] = '\0';
  8000. connectorIdInt = atoi(sstr);
  8001. }
  8002. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8003. {
  8004. //connectorIdInt = json_object_get_int(connectorId);
  8005. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8006. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8007. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8008. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8009. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8010. }
  8011. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8012. {
  8013. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8014. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8015. return TRUE;
  8016. }
  8017. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8018. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8019. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8020. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8021. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8022. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8023. {
  8024. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8025. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8026. return TRUE;
  8027. }
  8028. else
  8029. {
  8030. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8031. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8032. }
  8033. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8034. {
  8035. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8036. {
  8037. FirmwareStatusNotificationStatus = 3;
  8038. }
  8039. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8040. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8041. }
  8042. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8043. {
  8044. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8045. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8046. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8047. }
  8048. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8049. {
  8050. sendBootNotificationRequest();
  8051. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8052. }
  8053. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8054. {
  8055. sendHeartbeatRequest(connectorIdInt);
  8056. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8057. }
  8058. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8059. {
  8060. if(connectorIdIsNULL == FALSE)
  8061. {
  8062. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8063. {
  8064. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8065. sendMeterValuesRequest(connectorIdInt -1);
  8066. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8067. }
  8068. }
  8069. else
  8070. {
  8071. for(int idx=0;idx< gunTotalNumber;idx++)
  8072. {
  8073. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8074. sendMeterValuesRequest(idx);
  8075. }
  8076. }
  8077. }
  8078. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8079. {
  8080. if(connectorIdIsNULL == FALSE)
  8081. {
  8082. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8083. {
  8084. sendStatusNotificationRequest(connectorIdInt -1);
  8085. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8086. }
  8087. }
  8088. else
  8089. {
  8090. for(int idx=0;idx< gunTotalNumber;idx++)
  8091. sendStatusNotificationRequest(idx);
  8092. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8093. }
  8094. }
  8095. return result;
  8096. }
  8097. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8098. {
  8099. mtrace();
  8100. int result = FAIL;
  8101. char sstr[6]={0};
  8102. int connectorIdInt =0;
  8103. char comfirmstr[20]={0};
  8104. int c = 0;
  8105. char *loc;
  8106. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8107. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8108. c = 0;
  8109. loc = strstr(payload, "connectorId");
  8110. memset(sstr ,0, sizeof(sstr) );
  8111. while (loc[strlen("connectorId")+2+c] != '}')
  8112. {
  8113. sstr[c] = loc[strlen("connectorId")+2+c];
  8114. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8115. c++;
  8116. }
  8117. sstr[c] = '\0';
  8118. connectorIdInt = atoi(sstr);
  8119. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8120. if(gunTotalNumber == 0)
  8121. {
  8122. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8123. goto end;
  8124. }
  8125. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8126. {
  8127. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8128. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8129. goto end;
  8130. }
  8131. else
  8132. {
  8133. //check Transaction active
  8134. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8135. {
  8136. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8137. {
  8138. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8139. {
  8140. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8141. }
  8142. }
  8143. for (int index = 0; index < CCS_QUANTITY; index++)
  8144. {
  8145. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8146. {
  8147. //stop Transaction
  8148. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8149. }
  8150. }
  8151. for (int index = 0; index < GB_QUANTITY; index++)
  8152. {
  8153. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8154. {
  8155. //stop Transaction
  8156. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8157. }
  8158. }
  8159. }
  8160. else
  8161. {
  8162. for (int index = 0; index < AC_QUANTITY; index++)
  8163. {
  8164. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8165. {
  8166. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8167. }
  8168. }
  8169. }// END FOR AC ELSE
  8170. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8171. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8172. result = TRUE;
  8173. return result;
  8174. }
  8175. end:
  8176. //json_object_put(obj); --- remove temporally
  8177. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8178. return result;
  8179. }
  8180. static char UpdateFirmwarepayloadData[300]={0};
  8181. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8182. {
  8183. mtrace();
  8184. int result = FAIL;
  8185. pthread_t t;
  8186. sendUpdateFirmwareConfirmation(uuid);
  8187. memset(UpdateFirmwarepayloadData, 0, 300);
  8188. strcpy(UpdateFirmwarepayloadData, payload);
  8189. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8190. ////pthread_join(t, NULL); //
  8191. //pthread_detach(t);
  8192. //sendUpdateFirmwareConfirmation(uuid);
  8193. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8194. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8195. return result;
  8196. }
  8197. void *UpdateFirmwareProcess(void *data)
  8198. {
  8199. pthread_detach(pthread_self());
  8200. mtrace();
  8201. int retriesInt =0, retryIntervalInt=0;
  8202. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8203. int port=0;
  8204. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8205. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8206. //char comfirmstr[20];
  8207. int isSuccess = 0;
  8208. char ftpbuf[200];
  8209. char temp[100];
  8210. char * pch;
  8211. int retriesISNULL=FALSE;
  8212. int retryInterval=FALSE;
  8213. int c = 0;
  8214. //int i = 0;
  8215. char *loc;
  8216. char sstr[300]={ 0 };
  8217. char str[300]={ 0 };
  8218. //char *str = (char*) data; // ? ?輸入資 ?
  8219. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8220. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8221. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8222. //***************location **************/
  8223. loc = strstr(str, "location");
  8224. memset(sstr ,0, sizeof(sstr) );
  8225. c = 0;
  8226. while (loc[3+strlen("location")+c] != '\"')
  8227. {
  8228. sstr[c] = loc[3+strlen("location")+c];
  8229. c++;
  8230. }
  8231. sstr[c] = '\0';
  8232. strcpy(locationstr, sstr);
  8233. //***************retries**************/
  8234. c = 0;
  8235. loc = strstr(str, "retries");
  8236. if(loc == NULL)
  8237. {
  8238. retriesISNULL=TRUE;
  8239. }
  8240. else
  8241. {
  8242. memset(sstr ,0, sizeof(sstr) );
  8243. while (loc[strlen("retries")+2+c] != ',')
  8244. {
  8245. sstr[c] = loc[strlen("retries")+2+c];
  8246. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8247. c++;
  8248. }
  8249. sstr[c] = '\0';
  8250. }
  8251. if(retriesISNULL == FALSE)
  8252. {
  8253. retriesInt = atoi(sstr);
  8254. }
  8255. //***************retrieveDate **************/
  8256. loc = strstr(str, "retrieveDate");
  8257. memset(sstr ,0, sizeof(sstr) );
  8258. c = 0;
  8259. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8260. {
  8261. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8262. c++;
  8263. }
  8264. sstr[c] = '\0';
  8265. strcpy(retrieveDatestr, sstr);
  8266. //***************retryInterval **************/
  8267. c = 0;
  8268. loc = strstr(str, "retryInterval");
  8269. memset(sstr ,0, sizeof(sstr) );
  8270. if(loc == NULL)
  8271. {
  8272. retryInterval=TRUE;
  8273. }
  8274. else
  8275. {
  8276. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8277. {
  8278. sstr[c] = loc[strlen("retryInterval")+2+c];
  8279. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8280. c++;
  8281. }
  8282. sstr[c] = '\0';
  8283. }
  8284. if(retryInterval==FALSE)
  8285. {
  8286. retryIntervalInt = atoi(sstr);
  8287. }
  8288. memset(ftppath, 0, sizeof(ftppath));
  8289. memset(path, 0, sizeof(path));
  8290. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8291. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8292. if(strncmp(locationstr,"http", 4) == 0)
  8293. {
  8294. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8295. protocol, host, path);
  8296. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8297. // protocol, user, password, host, path);
  8298. sprintf(ftppath,"/%s", path);
  8299. //DEBUG_INFO("protocol =%s\n",protocol);
  8300. //DEBUG_INFO("host =%s\n",host);
  8301. //DEBUG_INFO("path =%s\n",path);
  8302. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8303. int ftppathlen=strlen(ftppath);
  8304. int i=1;
  8305. char filenametemp[50];
  8306. while(i < ftppathlen)
  8307. {
  8308. int len=ftppathlen-i;
  8309. if(ftppath[len]== 47) // '/' ascll code: 47
  8310. {
  8311. DEBUG_INFO("compare '/' all right\n");
  8312. break;
  8313. }
  8314. i=i+1;
  8315. }
  8316. memset(filenametemp, 0, sizeof(filenametemp));
  8317. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8318. filenametemp[i+1] = 0;
  8319. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8320. do{
  8321. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8322. sleep(retryIntervalInt);
  8323. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8324. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8325. if(!isSuccess)
  8326. {
  8327. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8328. }
  8329. else
  8330. {
  8331. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8332. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8333. isUpdateRequest = TRUE;
  8334. }
  8335. }
  8336. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8337. {
  8338. memset(ftpbuf, 0, sizeof(ftpbuf));
  8339. memset(temp, 0, sizeof(temp));
  8340. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8341. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8342. int ftppathlen=strlen(ftpbuf);
  8343. int i=1;
  8344. char filenametemp[50];
  8345. while(i < ftppathlen)
  8346. {
  8347. int len=ftppathlen-i;
  8348. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8349. {
  8350. DEBUG_INFO(" compare '/' all right\n");
  8351. break;
  8352. }
  8353. i=i+1;
  8354. }
  8355. memset(filenametemp, 0, sizeof(filenametemp));
  8356. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8357. filenametemp[i+1] = 0;
  8358. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8359. pch=strchr(temp,'@');
  8360. if(pch==NULL)
  8361. {
  8362. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8363. protocol, host, &port, path);
  8364. strcpy(user,"anonymous");
  8365. strcpy(password,"");
  8366. }
  8367. else
  8368. {
  8369. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8370. protocol, user, password, host, &port, path);
  8371. }
  8372. sscanf(host,"%[^/]%s",host1, path1);
  8373. sprintf(ftppath,"%s", path1);
  8374. //DEBUG_INFO("protocol =%s\n",protocol);
  8375. //DEBUG_INFO("user =%s\n",user);
  8376. //DEBUG_INFO("password =%s\n",password);
  8377. //DEBUG_INFO("host1 =%s\n",host1);
  8378. //DEBUG_INFO("port =%d\n",port);
  8379. //DEBUG_INFO("path1 =%s\n",path1);
  8380. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8381. //ftpFile(host, user, password, port, ftppath, fname);
  8382. //download firmware pthred
  8383. if(port == 0)
  8384. {
  8385. port = 21;
  8386. }
  8387. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8388. do{
  8389. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8390. sleep(retryIntervalInt);
  8391. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8392. if(!isSuccess)
  8393. {
  8394. //BulldogUtil.sleepMs(interval*1000);
  8395. DEBUG_INFO("Update firmware request and download file fail.\n");
  8396. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8397. }
  8398. else
  8399. {
  8400. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8401. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8402. isUpdateRequest = TRUE;
  8403. }
  8404. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8405. }
  8406. else
  8407. {
  8408. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8409. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8410. }
  8411. pthread_exit(NULL);
  8412. }
  8413. //==========================================
  8414. // Handle server response routine
  8415. //==========================================
  8416. void handleAuthorizeResponse(char *payload, int gun_index)
  8417. {
  8418. mtrace();
  8419. char expiryDatestr[30]={0};
  8420. char parentIdTagstr[20]={0};
  8421. char statusstr[20]={0};
  8422. char expiryDatestrtemp[30]={0};
  8423. char parentIdTagstrtemp[20]={0};
  8424. char IdTagstrtemp[20]={0};
  8425. char statusstrtemp[20]={0};
  8426. int expiryDateISNULL=FALSE;
  8427. int parentIdTagISNULL=FALSE;
  8428. char sstr[160]={ 0 };
  8429. char* filename = AuthorizationCache_JSON;
  8430. char tempfile[] = "/Storage/OCPP/temp.json";
  8431. int c = 0;
  8432. char *loc;
  8433. int resultRename=0;
  8434. int responseIdTagInfoAsZero= 0;
  8435. char rmFileCmd[50]={0};
  8436. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8437. //***********expiryDate*************/
  8438. loc = strstr(payload, "expiryDate");
  8439. memset(sstr ,0, sizeof(sstr) );
  8440. c = 0;
  8441. if(loc == NULL)
  8442. {
  8443. expiryDateISNULL = TRUE;
  8444. }
  8445. else
  8446. {
  8447. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8448. {
  8449. sstr[c] = loc[3+strlen("expiryDate")+c];
  8450. c++;
  8451. }
  8452. sstr[c] = '\0';
  8453. strcpy(expiryDatestr, sstr);
  8454. }
  8455. //***********parentIdTag*************/
  8456. loc = strstr(payload, "parentIdTag");
  8457. memset(sstr ,0, sizeof(sstr) );
  8458. c = 0;
  8459. if(loc == NULL)
  8460. {
  8461. parentIdTagISNULL = TRUE;
  8462. }
  8463. else
  8464. {
  8465. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8466. {
  8467. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8468. c++;
  8469. }
  8470. sstr[c] = '\0';
  8471. strcpy(parentIdTagstr, sstr);
  8472. }
  8473. //***********status*************/
  8474. loc = strstr(payload, "status");
  8475. memset(sstr ,0, sizeof(sstr) );
  8476. c = 0;
  8477. while (loc[3+strlen("status")+c] != '\"')
  8478. {
  8479. sstr[c] = loc[3+strlen("status")+c];
  8480. c++;
  8481. }
  8482. sstr[c] = '\0';
  8483. strcpy(statusstr, sstr);
  8484. if(expiryDateISNULL == FALSE)
  8485. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8486. if(parentIdTagISNULL == FALSE)
  8487. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8488. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8489. //Update idTag information to authorization cache if supproted
  8490. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8491. {
  8492. if((access(filename,F_OK))!=-1)
  8493. {
  8494. printf("AuthorizationCache exist.\n");
  8495. }
  8496. else
  8497. {
  8498. printf("AuthorizationCache not exist\n");
  8499. FILE *log = fopen(filename, "w+");
  8500. if(log == NULL)
  8501. {
  8502. printf("log is NULL\n");
  8503. goto out;
  8504. }
  8505. else
  8506. {
  8507. fclose(log);
  8508. }
  8509. }
  8510. FILE *infile;
  8511. FILE *outfile;
  8512. // open file for writing
  8513. infile = fopen (filename, "r");
  8514. outfile = fopen (tempfile, "w");
  8515. //*检测到文件结束标识返回1,否则返回0。*/
  8516. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8517. int c;
  8518. c = fgetc(infile);
  8519. //DEBUG_INFO("c:%d\n",c);
  8520. rewind(infile);
  8521. if(c == EOF)
  8522. {
  8523. DEBUG_INFO("Orignal File is NULL\n");
  8524. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8525. {
  8526. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8527. }
  8528. else
  8529. {
  8530. strcpy(expiryDatestrtemp, "");
  8531. }
  8532. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8533. {
  8534. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8535. }
  8536. else
  8537. {
  8538. //write Authorize IdTag
  8539. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8540. }
  8541. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8542. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8543. fclose(infile);
  8544. fclose(outfile);
  8545. sprintf(rmFileCmd,"rm -f %s",filename);
  8546. system(rmFileCmd);
  8547. resultRename = rename(tempfile, filename);
  8548. if(resultRename == 0)
  8549. {
  8550. printf("File renamed successfully");
  8551. }
  8552. else
  8553. {
  8554. printf("Error: unable to rename the file");
  8555. }
  8556. }
  8557. else
  8558. {
  8559. char buf[160]={0};
  8560. while (fgets(buf, sizeof(buf), infile) != NULL)
  8561. {
  8562. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8563. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8564. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8565. memset(statusstr, 0, sizeof(statusstrtemp));
  8566. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8567. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8568. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8569. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8570. //------------------IdTag-----------------------
  8571. loc = strstr(buf, "idTag");
  8572. memset(sstr ,0, sizeof(sstr) );
  8573. c = 0;
  8574. while (loc[3+strlen("idTag")+c] != '\"')
  8575. {
  8576. sstr[c] = loc[3+strlen("idTag")+c];
  8577. c++;
  8578. }
  8579. sstr[c] = '\0';
  8580. strcpy(IdTagstrtemp,sstr);
  8581. //*********************expiryDate***************/
  8582. loc = strstr(buf, "expiryDate");
  8583. memset(sstr ,0, sizeof(sstr) );
  8584. c = 0;
  8585. while (loc[3+strlen("expiryDate")+c] != '\"')
  8586. {
  8587. sstr[c] = loc[3+strlen("expiryDate")+c];
  8588. c++;
  8589. }
  8590. sstr[c] = '\0';
  8591. strcpy(expiryDatestr,sstr);
  8592. //*********************parentIdTag***************/
  8593. loc = strstr(buf, "parentIdTag");
  8594. memset(sstr ,0, sizeof(sstr) );
  8595. c = 0;
  8596. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8597. {
  8598. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8599. c++;
  8600. }
  8601. sstr[c] = '\0';
  8602. strcpy(parentIdTagstr,sstr);
  8603. //*********************status***************/
  8604. loc = strstr(buf, "status");
  8605. memset(sstr ,0, sizeof(sstr) );
  8606. c = 0;
  8607. while (loc[3+strlen("status")+c] != '\"')
  8608. {
  8609. sstr[c] = loc[3+strlen("status")+c];
  8610. c++;
  8611. }
  8612. sstr[c] = '\0';
  8613. strcpy(statusstr,sstr);
  8614. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8615. {
  8616. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8617. responseIdTagInfoAsZero = 1;
  8618. }
  8619. else
  8620. {
  8621. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8622. }
  8623. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8624. {
  8625. //modify item
  8626. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8627. {
  8628. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8629. }
  8630. else
  8631. {
  8632. strcpy(expiryDatestrtemp, "");
  8633. }
  8634. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8635. {
  8636. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8637. }
  8638. else
  8639. {
  8640. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8641. }
  8642. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8643. }
  8644. else
  8645. {
  8646. //wrie original item
  8647. strcpy(expiryDatestrtemp, expiryDatestr);
  8648. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8649. strcpy(statusstrtemp, statusstr);
  8650. }
  8651. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8652. }
  8653. fclose(infile);
  8654. fclose(outfile);
  8655. sprintf(rmFileCmd,"rm -f %s",filename);
  8656. system(rmFileCmd);
  8657. resultRename = rename(tempfile, filename);
  8658. if(resultRename == 0)
  8659. {
  8660. DEBUG_INFO("File renamed successfully");
  8661. }
  8662. else
  8663. {
  8664. DEBUG_INFO("Error: unable to rename the file");
  8665. }
  8666. }
  8667. }
  8668. out:
  8669. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8670. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8671. authorizeRetryTimes = 0;
  8672. }
  8673. void handleBootNotificationResponse(char *payload, int gun_index)
  8674. {
  8675. mtrace();
  8676. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8677. char statusStr[12]={0};
  8678. char currentTimeStr[30]={0};
  8679. char *loc;
  8680. int intervalInt = 0;
  8681. int c = 0;
  8682. //double diff_t;
  8683. struct tm tp;
  8684. char buf[28]={0};
  8685. char timebuf[50]={0};
  8686. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8687. //*** interval ****/
  8688. c = 0;
  8689. loc = strstr(payload, "interval");
  8690. //printf("loc=%s\n",loc);
  8691. memset(sstr ,0, sizeof(sstr) );
  8692. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8693. {
  8694. sstr[c] = loc[strlen("interval")+2+c];
  8695. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8696. c++;
  8697. }
  8698. sstr[c] = '\0';
  8699. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8700. intervalInt = atoi(sstr);
  8701. //***status ****/
  8702. loc = strstr(payload, "status");
  8703. memset(sstr ,0, sizeof(sstr) );
  8704. c = 0;
  8705. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8706. {
  8707. sstr[c] = loc[3+strlen("status")+c];
  8708. c++;
  8709. }
  8710. sstr[c] = '\0';
  8711. strcpy(statusStr, sstr);
  8712. //***currentTime ****/
  8713. loc = strstr(payload, "currentTime");
  8714. //printf("loc=%s\n",loc);
  8715. memset(sstr ,0, sizeof(sstr) );
  8716. c = 0;
  8717. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8718. {
  8719. sstr[c] = loc[3+strlen("currentTime")+c];
  8720. c++;
  8721. }
  8722. sstr[c] = '\0';
  8723. strcpy(currentTimeStr, sstr);
  8724. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8725. HeartBeatWaitTime = BootNotificationInterval;
  8726. clientTime.Heartbeat=time((time_t*)NULL);
  8727. //write back to ShmOCPP16Data->BootNotification
  8728. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8729. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8730. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8731. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8732. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8733. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8734. {
  8735. server_sign = TRUE;
  8736. server_pending =FALSE;
  8737. }
  8738. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8739. {
  8740. server_pending = TRUE;
  8741. }
  8742. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8743. tp.tm_isdst = -1;
  8744. //time_t utc = mktime(&tp);
  8745. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8746. memset(timebuf, 0, sizeof timebuf);
  8747. sprintf(timebuf,"date -s '%s'",buf);
  8748. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8749. system(timebuf);
  8750. //==============================================
  8751. // RTC sync
  8752. //==============================================
  8753. system("/sbin/hwclock -w --systohc");
  8754. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8755. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8756. }
  8757. void handleDataTransferResponse(char *payload, int gun_index)
  8758. {
  8759. char sstr[160]={0};//sstr[200]={ 0 };
  8760. int c = 0;
  8761. char *loc;
  8762. DEBUG_INFO("handleDataTransferResponse ...\n");
  8763. loc = strstr(payload, "status");
  8764. printf("loc=%s\n",loc);
  8765. c = 0;
  8766. while (loc[3+strlen("status")+c] != '\"')
  8767. {
  8768. sstr[c] = loc[3+strlen("status")+c];
  8769. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8770. c++;
  8771. }
  8772. sstr[c] = '\0';
  8773. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8774. }
  8775. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8776. {
  8777. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8778. //struct json_object *obj;
  8779. // obj = json_tokener_parse(payload);
  8780. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8781. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8782. //No fields are defined.
  8783. }
  8784. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8785. {
  8786. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8787. //struct json_object *obj;
  8788. // obj = json_tokener_parse(payload);
  8789. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8790. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8791. //No fields are defined.
  8792. }
  8793. void handleHeartbeatResponse(char *payload, int gun_index)
  8794. {
  8795. mtrace();
  8796. //double diff_t;
  8797. struct tm tp;
  8798. char buf[28]={0};
  8799. char timebuf[50]={0};
  8800. char sstr[30]={ 0 };
  8801. int c = 0;
  8802. char *loc;
  8803. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8804. c = 0;
  8805. loc = strstr(payload, "currentTime");
  8806. memset(sstr ,0, sizeof(sstr) );
  8807. while (loc[3+strlen("currentTime")+c] != '\"')
  8808. {
  8809. sstr[c] = loc[3+strlen("currentTime")+c];
  8810. c++;
  8811. }
  8812. sstr[c] = '\0';
  8813. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8814. // #ifdef SystemLogMessage
  8815. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8816. // #endif
  8817. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8818. tp.tm_isdst = -1;
  8819. //time_t utc = mktime(&tp);
  8820. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8821. memset(timebuf, 0, sizeof timebuf);
  8822. sprintf(timebuf,"date -s '%s'",buf);
  8823. system(timebuf);
  8824. //==============================================
  8825. // RTC sync
  8826. //==============================================
  8827. system("/sbin/hwclock -w --systohc");
  8828. if(FirstHeartBeat == 0)
  8829. {
  8830. FirstHeartBeat = 1;
  8831. }
  8832. HeartBeatWithNOResponse = 0;
  8833. //--------Print Out HeartBeat log
  8834. {
  8835. double diff_t;
  8836. struct tm tp,tp1;
  8837. // BootNotification Receive Time
  8838. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8839. tp.tm_isdst = -1;
  8840. time_t BootNotificationReceiveTime = mktime(&tp);
  8841. //HeartBeat Receive Time
  8842. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  8843. tp1.tm_isdst = -1;
  8844. time_t HeartBeatReceiveTime = mktime(&tp1);
  8845. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  8846. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  8847. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  8848. {
  8849. HeartBeatCountPerHour = (int)diff_t / 3600;
  8850. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8851. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8852. }
  8853. }
  8854. }
  8855. void handleMeterValuesResponse(char *payload, int gun_index)
  8856. {
  8857. mtrace();
  8858. //struct json_object *obj;
  8859. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8860. //No fields are defined.
  8861. }
  8862. void handleStartTransactionResponse(char *payload, int gun_index)
  8863. {
  8864. mtrace();
  8865. char sstr[28]={ 0 };
  8866. int c = 0;
  8867. char *loc;
  8868. int transactionIdInt = 0;
  8869. FILE *outfile;
  8870. char data[100]={0};
  8871. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8872. DEBUG_INFO("handleStartTransactionResponse\n");
  8873. //****************expiryDate********************/
  8874. loc = strstr(payload, "expiryDate");
  8875. if(loc == NULL)
  8876. {
  8877. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8878. }
  8879. else
  8880. {
  8881. c = 0;
  8882. memset(sstr ,0, sizeof(sstr) );
  8883. while (loc[3+strlen("expiryDate")+c] != '\"')
  8884. {
  8885. sstr[c] = loc[3+strlen("expiryDate")+c];
  8886. c++;
  8887. }
  8888. sstr[c] = '\0';
  8889. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8890. }
  8891. //****************parentIdTag********************/
  8892. loc = strstr(payload, "parentIdTag");
  8893. if(loc == NULL)
  8894. {
  8895. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8896. }
  8897. else
  8898. {
  8899. c = 0;
  8900. memset(sstr ,0, sizeof(sstr) );
  8901. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8902. {
  8903. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8904. c++;
  8905. }
  8906. sstr[c] = '\0';
  8907. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8908. }
  8909. //****************status********************/
  8910. loc = strstr(payload, "status");
  8911. if(loc == NULL)
  8912. {
  8913. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8914. }
  8915. else
  8916. {
  8917. c = 0;
  8918. memset(sstr ,0, sizeof(sstr) );
  8919. while (loc[3+strlen("status")+c] != '\"')
  8920. {
  8921. sstr[c] = loc[3+strlen("status")+c];
  8922. c++;
  8923. }
  8924. sstr[c] = '\0';
  8925. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8926. }
  8927. //****************transactionId********************/
  8928. c=0;
  8929. loc = strstr(payload, "transactionId");
  8930. memset(sstr ,0, sizeof(sstr) );
  8931. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8932. {
  8933. sstr[c] = loc[strlen("transactionId")+2+c];
  8934. c++;
  8935. }
  8936. sstr[c] = '\0';
  8937. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8938. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8939. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8940. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8941. //-----------Start : write to the Queue TransactionId file -----------------//
  8942. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  8943. {
  8944. //DEBUG_INFO("QueueTransactionId exist.\n");
  8945. }
  8946. else
  8947. {
  8948. //DEBUG_INFO("QueueTransactionId not exist\n");
  8949. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  8950. if(log == NULL)
  8951. {
  8952. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  8953. return ;
  8954. }
  8955. else
  8956. {
  8957. fclose(log);
  8958. }
  8959. }
  8960. // open file for writing
  8961. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  8962. //DEBUG_INFO("data=%s\n",data);
  8963. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  8964. fputs(data, outfile);
  8965. //fputs("\n", outfile);
  8966. fclose (outfile);
  8967. //-------------End: write to the Queue TransactionId file------------------------------------------//
  8968. TransactionId[gun_index] = transactionIdInt;
  8969. //DEBUG_INFO("gun_index: %d\n", gun_index);
  8970. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8971. #ifdef SystemLogMessage
  8972. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8973. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8974. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8975. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8976. #endif
  8977. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8978. {
  8979. //add Charging Record
  8980. SettingChargingRecord(gun_index, transactionIdInt);
  8981. }
  8982. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8983. }
  8984. void handleStatusNotificationResponse(char *payload, int gun_index)
  8985. {
  8986. mtrace();
  8987. printf("handleStatusNotificationResponse\n");
  8988. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8989. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8990. }
  8991. void handleStopTransactionnResponse(char *payload, int gun_index)
  8992. {
  8993. mtrace();
  8994. char sstr[30]={ 0 };
  8995. int c = 0;
  8996. char *loc;
  8997. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8998. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8999. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9000. loc = strstr(payload, "idTagInfo");
  9001. //***********************idTagInfo************************/
  9002. if(loc != NULL)
  9003. {
  9004. //***********************expiryDate************************/
  9005. loc = strstr(payload, "expiryDate");
  9006. if(loc != NULL)
  9007. {
  9008. memset(sstr ,0, sizeof(sstr) );
  9009. c = 0;
  9010. while (loc[3+strlen("expiryDate")+c] != '\"')
  9011. {
  9012. sstr[c] = loc[3+strlen("expiryDate")+c];
  9013. c++;
  9014. }
  9015. sstr[c] = '\0';
  9016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9017. }
  9018. //***********************parentIdTag************************/
  9019. loc = strstr(payload, "parentIdTag");
  9020. if(loc != NULL)
  9021. {
  9022. memset(sstr ,0, sizeof(sstr) );
  9023. c = 0;
  9024. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9025. {
  9026. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9027. c++;
  9028. }
  9029. sstr[c] = '\0';
  9030. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9031. }
  9032. //***********************status************************/
  9033. loc = strstr(payload, "status");
  9034. memset(sstr ,0, sizeof(sstr) );
  9035. c = 0;
  9036. while (loc[3+strlen("status")+c] != '\"')
  9037. {
  9038. sstr[c] = loc[3+strlen("status")+c];
  9039. c++;
  9040. }
  9041. sstr[c] = '\0';
  9042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9043. }
  9044. #ifdef SystemLogMessage
  9045. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9046. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9047. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9048. #endif
  9049. }
  9050. //==========================================
  9051. // Handle Error routine
  9052. //==========================================
  9053. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9054. {
  9055. mtrace();
  9056. #ifdef SystemLogMessage
  9057. DEBUG_INFO("errorCode: %s\n", errorCode);
  9058. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9059. DEBUG_INFO("errorDetails: %s\n", payload);
  9060. #endif
  9061. }
  9062. //===============================================
  9063. // Common routine
  9064. //===============================================
  9065. int initialConfigurationTable(void)
  9066. {
  9067. FILE *fp;
  9068. FILE *outfile;
  9069. char str[200]={0};
  9070. char sstr[100]={0};
  9071. int c = 0;
  9072. char *loc;
  9073. printf("initialConfigurationTable \n");
  9074. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9075. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9076. {
  9077. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9078. if(outfile == NULL) {
  9079. DEBUG_INFO("Error opening file");
  9080. return FALSE;
  9081. }
  9082. /*Core Profile*/
  9083. //AllowOfflineTxForUnknownId
  9084. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9085. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9089. //AuthorizationCacheEnabled
  9090. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9094. //AuthorizeRemoteTxRequests
  9095. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9099. //BlinkRepeat
  9100. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9104. //ClockAlignedDataInterval
  9105. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9109. //ConnectionTimeOut
  9110. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9114. //GetConfigurationMaxKeys
  9115. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9119. // HeartbeatInterval
  9120. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9124. // LightIntensity
  9125. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9129. // LocalAuthorizeOffline
  9130. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9134. // LocalPreAuthorize
  9135. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9139. // MaxEnergyOnInvalidId
  9140. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9143. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9145. // MeterValuesAlignedData
  9146. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9150. // MeterValuesAlignedDataMaxLength
  9151. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9155. // MeterValuesSampledData
  9156. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9160. // MeterValuesSampledDataMaxLength
  9161. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9165. // MeterValueSampleInterval
  9166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9170. // MinimumStatusDuration
  9171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9175. // NumberOfConnectors
  9176. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9179. {
  9180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9181. }
  9182. else
  9183. {
  9184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9185. }
  9186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9187. // ResetRetries
  9188. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9192. // ConnectorPhaseRotation
  9193. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9197. // ConnectorPhaseRotationMaxLength
  9198. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9202. // StopTransactionOnEVSideDisconnect
  9203. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9207. // StopTransactionOnInvalidId
  9208. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9212. // StopTxnAlignedData
  9213. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9217. // StopTxnAlignedDataMaxLength
  9218. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9222. // StopTxnSampledData
  9223. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9227. // StopTxnSampledDataMaxLength
  9228. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9230. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9231. {
  9232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9233. }
  9234. else
  9235. {
  9236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9237. }
  9238. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9240. // SupportedFeatureProfiles
  9241. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9245. // SupportedFeatureProfilesMaxLength
  9246. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9250. // TransactionMessageAttempts
  9251. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9254. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9256. // TransactionMessageRetryInterval
  9257. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9260. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9262. // UnlockConnectorOnEVSideDisconnect
  9263. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9267. // WebSocketPingInterval
  9268. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9272. //* Local Auth List Management Profile*/
  9273. #if 0
  9274. //For OCTT Test Case
  9275. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9278. #endif
  9279. #if 1
  9280. //LocalAuthListEnabled
  9281. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9285. #endif
  9286. //LocalAuthListMaxLength
  9287. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9291. //SendLocalListMaxLength
  9292. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9296. //ReserveConnectorZeroSupported
  9297. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9301. //* Smart Charging Profile */
  9302. //ChargeProfileMaxStackLevel
  9303. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9307. // ChargingScheduleAllowedChargingRateUnit
  9308. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9312. // ChargingScheduleMaxPeriods
  9313. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9317. // ConnectorSwitch3to1PhaseSupported
  9318. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9322. // MaxChargingProfilesInstalled
  9323. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9327. fclose(outfile);
  9328. }
  9329. else
  9330. {
  9331. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9332. char keystr[60]={0};
  9333. char readonlystr[10]={0};
  9334. char valuestr[100]={0};
  9335. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9336. if(fp == NULL) {
  9337. DEBUG_INFO("Error opening file");
  9338. return FALSE;
  9339. }
  9340. while( fgets (str, sizeof(str), fp)!=NULL )
  9341. {
  9342. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9343. //*************************key*********************************/
  9344. loc = strstr(str, "key");
  9345. c = 0;
  9346. memset(sstr ,0, sizeof(sstr) );
  9347. while (loc[strlen("key")+3+c] != '\"')
  9348. {
  9349. sstr[c] = loc[strlen("key")+3+c];
  9350. c++;
  9351. }
  9352. sstr[c] = '\0';
  9353. strcpy(keystr,sstr);
  9354. //*************************readonly*********************************/
  9355. loc = strstr(str, "readonly");
  9356. c = 0;
  9357. memset(sstr ,0, sizeof(sstr) );
  9358. while (loc[strlen("readonly")+2+c] != ',')
  9359. {
  9360. sstr[c] = loc[strlen("readonly")+2+c];
  9361. c++;
  9362. }
  9363. sstr[c] = '\0';
  9364. strcpy(readonlystr,sstr);
  9365. //*************************value*********************************/
  9366. loc = strstr(str, "value");
  9367. c = 0;
  9368. memset(sstr ,0, sizeof(sstr) );
  9369. while (loc[strlen("value")+3+c] != '\"')
  9370. {
  9371. sstr[c] = loc[strlen("value")+3+c];
  9372. c++;
  9373. }
  9374. sstr[c] = '\0';
  9375. strcpy(valuestr,sstr);
  9376. // DEBUG_INFO("keystr=%s\n",keystr);
  9377. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9378. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9379. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9380. {
  9381. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9382. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9383. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9384. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9385. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9386. }
  9387. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9388. {
  9389. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9390. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9392. }
  9393. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9394. {
  9395. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9397. }
  9398. if(strcmp(keystr, "BlinkRepeat") == 0)
  9399. {
  9400. //Charger.BlinkRepeat = Integer.parseInt(value);
  9401. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9403. }
  9404. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9405. {
  9406. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9408. }
  9409. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9410. {
  9411. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9413. }
  9414. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9415. {
  9416. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9418. }
  9419. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9420. {
  9421. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9423. HeartBeatWaitTime = atoi(valuestr);
  9424. }
  9425. if(strcmp(keystr, "LightIntensity") == 0)
  9426. {
  9427. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9429. }
  9430. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9431. {
  9432. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9434. }
  9435. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9436. {
  9437. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9439. }
  9440. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9441. {
  9442. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9444. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9445. }
  9446. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9447. {
  9448. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9450. }
  9451. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9452. {
  9453. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9455. }
  9456. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9457. {
  9458. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9460. }
  9461. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9462. {
  9463. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9465. }
  9466. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9467. {
  9468. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9470. }
  9471. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9472. {
  9473. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9475. }
  9476. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9477. {
  9478. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9480. }
  9481. if(strcmp(keystr, "ResetRetries") == 0)
  9482. {
  9483. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9485. }
  9486. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9487. {
  9488. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9490. }
  9491. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9492. {
  9493. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9495. }
  9496. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9497. {
  9498. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9500. }
  9501. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9502. {
  9503. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9505. }
  9506. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9507. {
  9508. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9510. }
  9511. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9512. {
  9513. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9515. }
  9516. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9517. {
  9518. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9520. }
  9521. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9522. {
  9523. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9525. }
  9526. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9527. {
  9528. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9530. }
  9531. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9532. {
  9533. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9535. }
  9536. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9537. {
  9538. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9540. TransactionMessageAttemptsValue = atoi(valuestr);
  9541. }
  9542. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9543. {
  9544. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9546. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9547. }
  9548. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9549. {
  9550. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9552. }
  9553. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9554. {
  9555. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9557. }
  9558. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9559. {
  9560. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9562. }
  9563. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9564. {
  9565. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9567. }
  9568. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9569. {
  9570. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9572. }
  9573. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9574. {
  9575. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9577. }
  9578. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9579. {
  9580. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9582. }
  9583. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9584. {
  9585. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9587. }
  9588. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9589. {
  9590. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9592. }
  9593. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9594. {
  9595. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9597. }
  9598. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9599. {
  9600. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9602. }
  9603. }
  9604. fclose(fp);
  9605. }
  9606. return 0;
  9607. }
  9608. void StoreConfigurationTable(void)
  9609. {
  9610. FILE *outfile;
  9611. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9612. if(outfile == NULL)
  9613. {
  9614. DEBUG_INFO("Error opening file");
  9615. return ;
  9616. }
  9617. /*Core Profile*/
  9618. //AllowOfflineTxForUnknownId
  9619. /*
  9620. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9621. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9624. */
  9625. //DEBUG_INFO("data=%s\n",data);
  9626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9627. //AuthorizationCacheEnabled
  9628. /*
  9629. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9632. */
  9633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9634. //AuthorizeRemoteTxRequests
  9635. /*
  9636. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9639. */
  9640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9641. //BlinkRepeat
  9642. /*
  9643. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9646. */
  9647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9648. //ClockAlignedDataInterval
  9649. /*
  9650. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9653. */
  9654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9655. //ConnectionTimeOut
  9656. /*
  9657. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9660. */
  9661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9662. //GetConfigurationMaxKeys
  9663. /*
  9664. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9667. */
  9668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9669. // HeartbeatInterval
  9670. /*
  9671. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9674. */
  9675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9676. // LightIntensity
  9677. /*
  9678. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9681. */
  9682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9683. // LocalAuthorizeOffline
  9684. /*
  9685. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9688. */
  9689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9690. // LocalPreAuthorize
  9691. /*
  9692. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9695. */
  9696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9697. // MaxEnergyOnInvalidId
  9698. /*
  9699. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9702. */
  9703. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9705. // MeterValuesAlignedData
  9706. /*
  9707. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9710. */
  9711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9712. // MeterValuesAlignedDataMaxLength
  9713. /*
  9714. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9717. */
  9718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9719. // MeterValuesSampledData
  9720. /*
  9721. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9724. */
  9725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9726. // MeterValuesSampledDataMaxLength
  9727. /*
  9728. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9731. */
  9732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9733. // MeterValueSampleInterval
  9734. /*
  9735. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9738. */
  9739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9740. // MinimumStatusDuration
  9741. /*
  9742. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9745. */
  9746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9747. // NumberOfConnectors
  9748. /*
  9749. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9751. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9752. {
  9753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9754. }
  9755. else
  9756. {
  9757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9758. }
  9759. */
  9760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9761. // ResetRetries
  9762. /*
  9763. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9766. */
  9767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9768. // ConnectorPhaseRotation
  9769. /*
  9770. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9773. */
  9774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9775. // ConnectorPhaseRotationMaxLength
  9776. /*
  9777. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9780. */
  9781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9782. // StopTransactionOnEVSideDisconnect
  9783. /*
  9784. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9787. */
  9788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9789. // StopTransactionOnInvalidId
  9790. /*
  9791. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9794. */
  9795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9796. // StopTxnAlignedData
  9797. /*
  9798. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9801. */
  9802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9803. // StopTxnAlignedDataMaxLength
  9804. /*
  9805. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9808. */
  9809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9810. // StopTxnSampledData
  9811. /*
  9812. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9815. */
  9816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9817. // StopTxnSampledDataMaxLength
  9818. /*
  9819. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9822. */
  9823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9824. // SupportedFeatureProfiles
  9825. /*
  9826. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9829. */
  9830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9831. // SupportedFeatureProfilesMaxLength
  9832. /*
  9833. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9836. */
  9837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9838. // TransactionMessageAttempts
  9839. /*
  9840. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9843. */
  9844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9845. // TransactionMessageRetryInterval
  9846. /*
  9847. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9850. */
  9851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9852. // UnlockConnectorOnEVSideDisconnect
  9853. /*
  9854. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9857. */
  9858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9859. // WebSocketPingInterval
  9860. /*
  9861. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9864. */
  9865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9866. //* Local Auth List Management Profile*/
  9867. //LocalAuthListEnabled
  9868. /*
  9869. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9872. */
  9873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9874. //LocalAuthListMaxLength
  9875. /*
  9876. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9879. */
  9880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9881. //SendLocalListMaxLength
  9882. /*
  9883. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9886. */
  9887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9888. //ReserveConnectorZeroSupported
  9889. /*
  9890. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9893. */
  9894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9895. //* Smart Charging Profile */
  9896. //ChargeProfileMaxStackLevel
  9897. /*
  9898. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9901. */
  9902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9903. // ChargingScheduleAllowedChargingRateUnit
  9904. /*
  9905. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9908. */
  9909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9910. // ChargingScheduleMaxPeriods
  9911. /*
  9912. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9915. */
  9916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9917. // ConnectorSwitch3to1PhaseSupported
  9918. /*
  9919. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9922. */
  9923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9924. // MaxChargingProfilesInstalled
  9925. /*
  9926. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9929. */
  9930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9931. fclose(outfile);
  9932. }
  9933. void getKeyValue(char *keyReq)
  9934. {
  9935. int isEmpty = FALSE;
  9936. int isKnowKey = FALSE;
  9937. //int unKnowIndex = 0;
  9938. DEBUG_INFO("getKeyValue \n");
  9939. DEBUG_INFO("keyReq=%s \n",keyReq);
  9940. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9941. isEmpty = TRUE;
  9942. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9943. {
  9944. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9948. {
  9949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9950. }
  9951. else
  9952. {
  9953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9954. }
  9955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9956. isKnowKey = TRUE;
  9957. }
  9958. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9959. {
  9960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9963. {
  9964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9965. }
  9966. else
  9967. {
  9968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9969. }
  9970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9971. isKnowKey = TRUE;
  9972. }
  9973. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9974. {
  9975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9978. {
  9979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9980. }
  9981. else
  9982. {
  9983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9984. }
  9985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9986. isKnowKey = TRUE;
  9987. }
  9988. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9989. {
  9990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9993. {
  9994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9995. }
  9996. else
  9997. {
  9998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9999. }
  10000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10001. isKnowKey = TRUE;
  10002. }
  10003. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10004. {
  10005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10008. {
  10009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10010. }
  10011. else
  10012. {
  10013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10014. }
  10015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10016. isKnowKey = TRUE;
  10017. }
  10018. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10019. {
  10020. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10023. {
  10024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10025. }
  10026. else
  10027. {
  10028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10029. }
  10030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10031. isKnowKey = TRUE;
  10032. }
  10033. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10034. {
  10035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10038. {
  10039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10040. }
  10041. else
  10042. {
  10043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10044. }
  10045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10046. isKnowKey = TRUE;
  10047. }
  10048. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10049. {
  10050. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10053. {
  10054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10055. }
  10056. else
  10057. {
  10058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10059. }
  10060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10061. isKnowKey = TRUE;
  10062. }
  10063. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10064. {
  10065. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10068. {
  10069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10070. }
  10071. else
  10072. {
  10073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10074. }
  10075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10076. isKnowKey = TRUE;
  10077. }
  10078. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10079. {
  10080. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10083. {
  10084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10085. }
  10086. else
  10087. {
  10088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10089. }
  10090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10091. isKnowKey = TRUE;
  10092. }
  10093. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10094. {
  10095. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10098. {
  10099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10100. }
  10101. else
  10102. {
  10103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10104. }
  10105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10106. isKnowKey = TRUE;
  10107. }
  10108. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10109. {
  10110. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10113. {
  10114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10115. }
  10116. else
  10117. {
  10118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10119. }
  10120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10121. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10122. isKnowKey = TRUE;
  10123. }
  10124. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10125. {
  10126. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10129. {
  10130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10131. }
  10132. else
  10133. {
  10134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10135. }
  10136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10137. isKnowKey = TRUE;
  10138. }
  10139. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10140. {
  10141. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10144. {
  10145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10146. }
  10147. else
  10148. {
  10149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10150. }
  10151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10152. isKnowKey = TRUE;
  10153. }
  10154. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10155. {
  10156. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10159. {
  10160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10161. }
  10162. else
  10163. {
  10164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10165. }
  10166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10167. isKnowKey = TRUE;
  10168. }
  10169. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10170. {
  10171. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10174. {
  10175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10176. }
  10177. else
  10178. {
  10179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10180. }
  10181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10182. isKnowKey = TRUE;
  10183. }
  10184. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10185. {
  10186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10189. {
  10190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10191. }
  10192. else
  10193. {
  10194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10195. }
  10196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10197. isKnowKey = TRUE;
  10198. }
  10199. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10200. {
  10201. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10204. {
  10205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10206. }
  10207. else
  10208. {
  10209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10210. }
  10211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10212. isKnowKey = TRUE;
  10213. }
  10214. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10215. {
  10216. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10219. {
  10220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10221. }
  10222. else
  10223. {
  10224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10225. }
  10226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10227. isKnowKey = TRUE;
  10228. }
  10229. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10230. {
  10231. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10234. {
  10235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10236. }
  10237. else
  10238. {
  10239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10240. }
  10241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10242. isKnowKey = TRUE;
  10243. }
  10244. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10245. {
  10246. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10249. {
  10250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10251. }
  10252. else
  10253. {
  10254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10255. }
  10256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10257. isKnowKey = TRUE;
  10258. }
  10259. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10260. {
  10261. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10264. {
  10265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10266. }
  10267. else
  10268. {
  10269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10270. }
  10271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10272. isKnowKey = TRUE;
  10273. }
  10274. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10275. {
  10276. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10278. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10279. {
  10280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10281. }
  10282. else
  10283. {
  10284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10285. }
  10286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10287. isKnowKey = TRUE;
  10288. }
  10289. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10290. {
  10291. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10294. {
  10295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10296. }
  10297. else
  10298. {
  10299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10300. }
  10301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10302. isKnowKey = TRUE;
  10303. }
  10304. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10305. {
  10306. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10309. {
  10310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10311. }
  10312. else
  10313. {
  10314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10315. }
  10316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10317. isKnowKey = TRUE;
  10318. }
  10319. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10320. {
  10321. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10324. {
  10325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10326. }
  10327. else
  10328. {
  10329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10330. }
  10331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10332. isKnowKey = TRUE;
  10333. }
  10334. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10335. {
  10336. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10339. {
  10340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10341. }
  10342. else
  10343. {
  10344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10345. }
  10346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10347. isKnowKey = TRUE;
  10348. }
  10349. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10350. {
  10351. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10354. {
  10355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10356. }
  10357. else
  10358. {
  10359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10360. }
  10361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10362. isKnowKey = TRUE;
  10363. }
  10364. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10365. {
  10366. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10369. {
  10370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10371. }
  10372. else
  10373. {
  10374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10375. }
  10376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10377. isKnowKey = TRUE;
  10378. }
  10379. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10380. {
  10381. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10384. {
  10385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10386. }
  10387. else
  10388. {
  10389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10390. }
  10391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10392. isKnowKey = TRUE;
  10393. }
  10394. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10395. {
  10396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10399. {
  10400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10401. }
  10402. else
  10403. {
  10404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10405. }
  10406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10407. isKnowKey = TRUE;
  10408. }
  10409. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10410. {
  10411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10414. {
  10415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10416. }
  10417. else
  10418. {
  10419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10420. }
  10421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10422. isKnowKey = TRUE;
  10423. }
  10424. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10425. {
  10426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10429. {
  10430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10431. }
  10432. else
  10433. {
  10434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10435. }
  10436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10437. isKnowKey = TRUE;
  10438. }
  10439. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10440. {
  10441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10444. {
  10445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10446. }
  10447. else
  10448. {
  10449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10450. }
  10451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10452. isKnowKey = TRUE;
  10453. }
  10454. #if 0
  10455. //For OCTT Test Case
  10456. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10457. {
  10458. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10460. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10461. {
  10462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10463. }
  10464. else
  10465. {
  10466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10467. }
  10468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10469. isKnowKey = TRUE;
  10470. }
  10471. #endif
  10472. #if 1
  10473. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10474. {
  10475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10477. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10478. {
  10479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10480. }
  10481. else
  10482. {
  10483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10484. }
  10485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10486. isKnowKey = TRUE;
  10487. }
  10488. #endif
  10489. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10490. {
  10491. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10493. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10494. {
  10495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10496. }
  10497. else
  10498. {
  10499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10500. }
  10501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10502. isKnowKey = TRUE;
  10503. }
  10504. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10505. {
  10506. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10508. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10509. {
  10510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10511. }
  10512. else
  10513. {
  10514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10515. }
  10516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10517. isKnowKey = TRUE;
  10518. }
  10519. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10520. {
  10521. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10523. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10524. {
  10525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10526. }
  10527. else
  10528. {
  10529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10530. }
  10531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10532. isKnowKey = TRUE;
  10533. }
  10534. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10535. {
  10536. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10538. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10539. {
  10540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10541. }
  10542. else
  10543. {
  10544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10545. }
  10546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10547. isKnowKey = TRUE;
  10548. }
  10549. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10550. {
  10551. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10553. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10554. {
  10555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10556. }
  10557. else
  10558. {
  10559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10560. }
  10561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10562. isKnowKey = TRUE;
  10563. }
  10564. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10565. {
  10566. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10568. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10569. {
  10570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10571. }
  10572. else
  10573. {
  10574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10575. }
  10576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10577. isKnowKey = TRUE;
  10578. }
  10579. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10580. {
  10581. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10583. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10584. {
  10585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10586. }
  10587. else
  10588. {
  10589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10590. }
  10591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10592. isKnowKey = TRUE;
  10593. }
  10594. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10595. {
  10596. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10598. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10599. {
  10600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10601. }
  10602. else
  10603. {
  10604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10605. }
  10606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10607. isKnowKey = TRUE;
  10608. }
  10609. //=========================================================
  10610. if(!isEmpty && !isKnowKey)
  10611. {
  10612. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10613. strcpy(unknownkey[UnknownKeynum], keyReq);
  10614. UnknownKeynum = UnknownKeynum + 1;
  10615. }
  10616. }
  10617. void processUnkownKey(void)
  10618. {
  10619. DEBUG_INFO("processUnkownKey\n");
  10620. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10621. for(int index=0; index < UnknownKeynum; index++)
  10622. {
  10623. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10624. {
  10625. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10626. }
  10627. }
  10628. }
  10629. int setKeyValue(char *key, char *value)
  10630. {
  10631. int isSuccess = NotSupported;
  10632. int check_ascii=0;
  10633. char str[10]={0};
  10634. #ifdef Debug
  10635. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10636. #endif
  10637. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10638. {
  10639. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10641. {
  10642. strcpy(str, (const char*)value);
  10643. for(int i = 0; str[i]; i++){
  10644. str[i] = tolower(str[i]);
  10645. }
  10646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10647. isSuccess = ConfigurationStatus_Accepted;
  10648. }
  10649. else
  10650. {
  10651. isSuccess = ConfigurationStatus_Rejected;
  10652. }
  10653. }
  10654. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10655. {
  10656. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10658. {
  10659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10660. isSuccess = ConfigurationStatus_Accepted;
  10661. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10662. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10663. }
  10664. else
  10665. {
  10666. isSuccess = ConfigurationStatus_Rejected;
  10667. }
  10668. }
  10669. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10670. {
  10671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10672. {
  10673. strcpy(str, (const char*)value);
  10674. for(int i = 0; str[i]; i++)
  10675. {
  10676. str[i] = tolower(str[i]);
  10677. }
  10678. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10680. isSuccess = ConfigurationStatus_Accepted;
  10681. }
  10682. else
  10683. {
  10684. isSuccess = ConfigurationStatus_Rejected;
  10685. }
  10686. }
  10687. if(strcmp(key, "BlinkRepeat") == 0)
  10688. {
  10689. //Charger.BlinkRepeat = Integer.parseInt(value);
  10690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10691. {
  10692. check_ascii = value[0];
  10693. if( (check_ascii < 48) || (check_ascii > 57) )
  10694. {
  10695. isSuccess = ConfigurationStatus_Rejected;
  10696. }
  10697. else
  10698. {
  10699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10700. isSuccess = ConfigurationStatus_Accepted;
  10701. }
  10702. }
  10703. else
  10704. {
  10705. isSuccess = ConfigurationStatus_Rejected;
  10706. }
  10707. }
  10708. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10709. {
  10710. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10711. {
  10712. check_ascii = value[0];
  10713. if( (check_ascii < 48) || (check_ascii > 57) )
  10714. {
  10715. isSuccess = ConfigurationStatus_Rejected;
  10716. }
  10717. else
  10718. {
  10719. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10721. isSuccess = ConfigurationStatus_Accepted;
  10722. }
  10723. }
  10724. else
  10725. {
  10726. isSuccess = ConfigurationStatus_Rejected;
  10727. }
  10728. }
  10729. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10730. {
  10731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10732. {
  10733. check_ascii = value[0];
  10734. if( (check_ascii < 48) || (check_ascii > 57) )
  10735. {
  10736. isSuccess = ConfigurationStatus_Rejected;
  10737. }
  10738. else
  10739. {
  10740. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10742. isSuccess = ConfigurationStatus_Accepted;
  10743. }
  10744. }
  10745. else
  10746. {
  10747. isSuccess = ConfigurationStatus_Rejected;
  10748. }
  10749. }
  10750. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10751. {
  10752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10753. {
  10754. check_ascii = value[0];
  10755. if( (check_ascii < 48) || (check_ascii > 57) )
  10756. {
  10757. isSuccess = ConfigurationStatus_Rejected;
  10758. }
  10759. else
  10760. {
  10761. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10763. isSuccess = ConfigurationStatus_Accepted;
  10764. }
  10765. }
  10766. else
  10767. {
  10768. isSuccess = ConfigurationStatus_Rejected;
  10769. }
  10770. }
  10771. if(strcmp(key, "HeartbeatInterval") == 0)
  10772. {
  10773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10774. {
  10775. check_ascii = value[0];
  10776. if( (check_ascii < 48) || (check_ascii > 57) )
  10777. {
  10778. isSuccess = ConfigurationStatus_Rejected;
  10779. }
  10780. else
  10781. {
  10782. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10784. HeartBeatWaitTime = atoi(value);
  10785. isSuccess = ConfigurationStatus_Accepted;
  10786. }
  10787. }
  10788. else
  10789. {
  10790. isSuccess = ConfigurationStatus_Rejected;
  10791. }
  10792. }
  10793. if(strcmp(key, "LightIntensity") == 0)
  10794. {
  10795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10796. {
  10797. check_ascii = value[0];
  10798. if( (check_ascii < 48) || (check_ascii > 57) )
  10799. {
  10800. isSuccess = ConfigurationStatus_Rejected;
  10801. }
  10802. else
  10803. {
  10804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10805. isSuccess = ConfigurationStatus_Accepted;
  10806. }
  10807. }
  10808. else
  10809. {
  10810. isSuccess = ConfigurationStatus_Rejected;
  10811. }
  10812. }
  10813. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10814. {
  10815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10816. {
  10817. strcpy(str, (const char*)value);
  10818. for(int i = 0; str[i]; i++)
  10819. {
  10820. str[i] = tolower(str[i]);
  10821. }
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10823. isSuccess = ConfigurationStatus_Accepted;
  10824. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10825. }
  10826. else
  10827. {
  10828. isSuccess = ConfigurationStatus_Rejected;
  10829. }
  10830. }
  10831. if(strcmp(key, "LocalPreAuthorize") == 0)
  10832. {
  10833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10834. {
  10835. strcpy(str, (const char*)value);
  10836. for(int i = 0; str[i]; i++)
  10837. {
  10838. str[i] = tolower(str[i]);
  10839. }
  10840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10841. isSuccess = ConfigurationStatus_Accepted;
  10842. }
  10843. else
  10844. {
  10845. isSuccess = ConfigurationStatus_Rejected;
  10846. }
  10847. }
  10848. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10849. {
  10850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10851. {
  10852. check_ascii = value[0];
  10853. if( (check_ascii < 48) || (check_ascii > 57) )
  10854. {
  10855. isSuccess = ConfigurationStatus_Rejected;
  10856. }
  10857. else
  10858. {
  10859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10860. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10861. isSuccess = ConfigurationStatus_Accepted;
  10862. }
  10863. }
  10864. else
  10865. {
  10866. isSuccess = ConfigurationStatus_Rejected;
  10867. }
  10868. }
  10869. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10870. {
  10871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10872. {
  10873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10874. isSuccess = ConfigurationStatus_Accepted;
  10875. }
  10876. else
  10877. {
  10878. isSuccess = ConfigurationStatus_Rejected;
  10879. }
  10880. }
  10881. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10882. {
  10883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10884. {
  10885. check_ascii = value[0];
  10886. if( (check_ascii < 48) || (check_ascii > 57) )
  10887. {
  10888. isSuccess = ConfigurationStatus_Rejected;
  10889. }
  10890. else
  10891. {
  10892. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10894. isSuccess = ConfigurationStatus_Accepted;
  10895. }
  10896. }
  10897. else
  10898. {
  10899. isSuccess = ConfigurationStatus_Rejected;
  10900. }
  10901. }
  10902. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10903. {
  10904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10905. {
  10906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10907. isSuccess = ConfigurationStatus_Accepted;
  10908. }
  10909. else
  10910. {
  10911. isSuccess = ConfigurationStatus_Rejected;
  10912. }
  10913. }
  10914. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10915. {
  10916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10917. {
  10918. check_ascii = value[0];
  10919. if( (check_ascii < 48) || (check_ascii > 57) )
  10920. {
  10921. isSuccess = ConfigurationStatus_Rejected;
  10922. }
  10923. else
  10924. {
  10925. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10927. isSuccess = ConfigurationStatus_Accepted;
  10928. }
  10929. }
  10930. else
  10931. {
  10932. isSuccess = ConfigurationStatus_Rejected;
  10933. }
  10934. }
  10935. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10936. {
  10937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10938. {
  10939. check_ascii = value[0];
  10940. if( (check_ascii < 48) || (check_ascii > 57) )
  10941. {
  10942. isSuccess = ConfigurationStatus_Rejected;
  10943. }
  10944. else
  10945. {
  10946. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10948. isSuccess = ConfigurationStatus_Accepted;
  10949. }
  10950. }
  10951. else
  10952. {
  10953. isSuccess = ConfigurationStatus_Rejected;
  10954. }
  10955. }
  10956. if(strcmp(key, "MinimumStatusDuration") == 0)
  10957. {
  10958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10959. {
  10960. check_ascii = value[0];
  10961. if( (check_ascii < 48) || (check_ascii > 57) )
  10962. {
  10963. isSuccess = ConfigurationStatus_Rejected;
  10964. }
  10965. else
  10966. {
  10967. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10969. isSuccess = ConfigurationStatus_Accepted;
  10970. }
  10971. }
  10972. else
  10973. {
  10974. isSuccess = ConfigurationStatus_Rejected;
  10975. }
  10976. }
  10977. if(strcmp(key, "NumberOfConnectors") == 0)
  10978. {
  10979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10980. {
  10981. check_ascii = value[0];
  10982. if( (check_ascii < 48) || (check_ascii > 57) )
  10983. {
  10984. isSuccess = ConfigurationStatus_Rejected;
  10985. }
  10986. else
  10987. {
  10988. //Charger.ResetRetries = Integer.parseInt(value);
  10989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10990. isSuccess = ConfigurationStatus_Accepted;
  10991. }
  10992. }
  10993. else
  10994. {
  10995. isSuccess = ConfigurationStatus_Rejected;
  10996. }
  10997. }
  10998. if(strcmp(key, "ResetRetries") == 0)
  10999. {
  11000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11001. {
  11002. check_ascii = value[0];
  11003. if( (check_ascii < 48) || (check_ascii > 57) )
  11004. {
  11005. isSuccess = ConfigurationStatus_Rejected;
  11006. }
  11007. else
  11008. {
  11009. //Charger.ResetRetries = Integer.parseInt(value);
  11010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11011. isSuccess = ConfigurationStatus_Accepted;
  11012. }
  11013. }
  11014. else
  11015. {
  11016. isSuccess = ConfigurationStatus_Rejected;
  11017. }
  11018. }
  11019. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11020. {
  11021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11022. {
  11023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11024. isSuccess = ConfigurationStatus_Accepted;
  11025. }
  11026. else
  11027. {
  11028. isSuccess = ConfigurationStatus_Rejected;
  11029. }
  11030. }
  11031. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11032. {
  11033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11034. {
  11035. check_ascii = value[0];
  11036. if( (check_ascii < 48) || (check_ascii > 57) )
  11037. {
  11038. isSuccess = ConfigurationStatus_Rejected;
  11039. }
  11040. else
  11041. {
  11042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11043. isSuccess = ConfigurationStatus_Accepted;
  11044. }
  11045. }
  11046. else
  11047. {
  11048. isSuccess = ConfigurationStatus_Rejected;
  11049. }
  11050. }
  11051. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11052. {
  11053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11054. {
  11055. strcpy(str, (const char*)value);
  11056. for(int i = 0; str[i]; i++)
  11057. {
  11058. str[i] = tolower(str[i]);
  11059. }
  11060. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11062. isSuccess = ConfigurationStatus_Accepted;
  11063. }
  11064. else
  11065. {
  11066. isSuccess = ConfigurationStatus_Rejected;
  11067. }
  11068. }
  11069. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11070. {
  11071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11072. {
  11073. strcpy(str, (const char*)value);
  11074. for(int i = 0; str[i]; i++)
  11075. {
  11076. str[i] = tolower(str[i]);
  11077. }
  11078. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11080. isSuccess = ConfigurationStatus_Accepted;
  11081. }
  11082. else
  11083. {
  11084. isSuccess = ConfigurationStatus_Rejected;
  11085. }
  11086. }
  11087. if(strcmp(key, "StopTxnAlignedData") == 0)
  11088. {
  11089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11090. {
  11091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11092. isSuccess = ConfigurationStatus_Accepted;
  11093. }
  11094. else
  11095. {
  11096. isSuccess = ConfigurationStatus_Rejected;
  11097. }
  11098. }
  11099. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11100. {
  11101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11102. {
  11103. check_ascii = value[0];
  11104. if( (check_ascii < 48) || (check_ascii > 57) )
  11105. {
  11106. isSuccess = ConfigurationStatus_Rejected;
  11107. }
  11108. else
  11109. {
  11110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11111. isSuccess = ConfigurationStatus_Accepted;
  11112. }
  11113. }
  11114. else
  11115. {
  11116. isSuccess = ConfigurationStatus_Rejected;
  11117. }
  11118. }
  11119. if(strcmp(key, "StopTxnSampledData") == 0)
  11120. {
  11121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11122. {
  11123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11124. isSuccess = ConfigurationStatus_Accepted;
  11125. }
  11126. else
  11127. {
  11128. isSuccess = ConfigurationStatus_Rejected;
  11129. }
  11130. }
  11131. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11132. {
  11133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11134. {
  11135. check_ascii = value[0];
  11136. if( (check_ascii < 48) || (check_ascii > 57) )
  11137. {
  11138. isSuccess = ConfigurationStatus_Rejected;
  11139. }
  11140. else
  11141. {
  11142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11143. isSuccess = ConfigurationStatus_Accepted;
  11144. }
  11145. }
  11146. else
  11147. {
  11148. isSuccess = ConfigurationStatus_Rejected;
  11149. }
  11150. }
  11151. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11152. {
  11153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11154. {
  11155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11156. isSuccess = ConfigurationStatus_Accepted;
  11157. }
  11158. else
  11159. {
  11160. isSuccess = ConfigurationStatus_Rejected;
  11161. }
  11162. }
  11163. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11164. {
  11165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11166. {
  11167. check_ascii = value[0];
  11168. if( (check_ascii < 48) || (check_ascii > 57) )
  11169. {
  11170. isSuccess = ConfigurationStatus_Rejected;
  11171. }
  11172. else
  11173. {
  11174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11175. isSuccess = ConfigurationStatus_Accepted;
  11176. }
  11177. }
  11178. else
  11179. {
  11180. isSuccess = ConfigurationStatus_Rejected;
  11181. }
  11182. }
  11183. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11184. {
  11185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11186. {
  11187. check_ascii = value[0];
  11188. if( (check_ascii < 48) || (check_ascii > 57) )
  11189. {
  11190. isSuccess = ConfigurationStatus_Rejected;
  11191. }
  11192. else
  11193. {
  11194. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11196. TransactionMessageAttemptsValue = atoi(value);
  11197. isSuccess = ConfigurationStatus_Accepted;
  11198. }
  11199. }
  11200. else
  11201. {
  11202. isSuccess = ConfigurationStatus_Rejected;
  11203. }
  11204. }
  11205. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11206. {
  11207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].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. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11218. TransactionMessageRetryIntervalValue = atoi(value);
  11219. isSuccess = ConfigurationStatus_Accepted;
  11220. }
  11221. }
  11222. else
  11223. {
  11224. isSuccess = ConfigurationStatus_Rejected;
  11225. }
  11226. }
  11227. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11228. {
  11229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11230. {
  11231. strcpy(str, (const char*)value);
  11232. for(int i = 0; str[i]; i++)
  11233. {
  11234. str[i] = tolower(str[i]);
  11235. }
  11236. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11238. isSuccess = ConfigurationStatus_Accepted;
  11239. }
  11240. else
  11241. {
  11242. isSuccess = ConfigurationStatus_Rejected;
  11243. }
  11244. }
  11245. if(strcmp(key, "WebSocketPingInterval") == 0)
  11246. {
  11247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11248. {
  11249. check_ascii = value[0];
  11250. if( (check_ascii < 48) || (check_ascii > 57) )
  11251. {
  11252. isSuccess = ConfigurationStatus_Rejected;
  11253. }
  11254. else
  11255. {
  11256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11257. isSuccess = ConfigurationStatus_Accepted;
  11258. }
  11259. }
  11260. else
  11261. {
  11262. isSuccess = ConfigurationStatus_Rejected;
  11263. }
  11264. }
  11265. #if 0
  11266. //For OCPP Test Case
  11267. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11268. {
  11269. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11270. {
  11271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11272. isSuccess = ConfigurationStatus_Accepted;
  11273. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11274. }
  11275. else
  11276. {
  11277. isSuccess = ConfigurationStatus_Rejected;
  11278. }
  11279. }
  11280. #endif
  11281. #if 1
  11282. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11283. {
  11284. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11285. {
  11286. strcpy(str, (const char*)value);
  11287. for(int i = 0; str[i]; i++)
  11288. {
  11289. str[i] = tolower(str[i]);
  11290. }
  11291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11292. isSuccess = ConfigurationStatus_Accepted;
  11293. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11294. }
  11295. else
  11296. {
  11297. isSuccess = ConfigurationStatus_Rejected;
  11298. }
  11299. }
  11300. #endif
  11301. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11302. {
  11303. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11304. {
  11305. check_ascii = value[0];
  11306. if( (check_ascii < 48) || (check_ascii > 57) )
  11307. {
  11308. isSuccess = ConfigurationStatus_Rejected;
  11309. }
  11310. else
  11311. {
  11312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11313. isSuccess = ConfigurationStatus_Accepted;
  11314. }
  11315. }
  11316. else
  11317. {
  11318. isSuccess = ConfigurationStatus_Rejected;
  11319. }
  11320. }
  11321. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11322. {
  11323. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11324. {
  11325. check_ascii = value[0];
  11326. if( (check_ascii < 48) || (check_ascii > 57) )
  11327. {
  11328. isSuccess = ConfigurationStatus_Rejected;
  11329. }
  11330. else
  11331. {
  11332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11333. isSuccess = ConfigurationStatus_Accepted;
  11334. }
  11335. }
  11336. else
  11337. {
  11338. isSuccess = ConfigurationStatus_Rejected;
  11339. }
  11340. }
  11341. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11342. {
  11343. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11344. {
  11345. strcpy(str, (const char*)value);
  11346. for(int i = 0; str[i]; i++)
  11347. {
  11348. str[i] = tolower(str[i]);
  11349. }
  11350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11351. isSuccess = ConfigurationStatus_Accepted;
  11352. }
  11353. else
  11354. {
  11355. isSuccess = ConfigurationStatus_Rejected;
  11356. }
  11357. }
  11358. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11359. {
  11360. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11361. {
  11362. check_ascii = value[0];
  11363. if( (check_ascii < 48) || (check_ascii > 57) )
  11364. {
  11365. isSuccess = ConfigurationStatus_Rejected;
  11366. }
  11367. else
  11368. {
  11369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11370. isSuccess = ConfigurationStatus_Accepted;
  11371. }
  11372. }
  11373. else
  11374. {
  11375. isSuccess = ConfigurationStatus_Rejected;
  11376. }
  11377. }
  11378. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11379. {
  11380. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11381. {
  11382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11383. isSuccess = ConfigurationStatus_Accepted;
  11384. }
  11385. else
  11386. {
  11387. isSuccess = ConfigurationStatus_Rejected;
  11388. }
  11389. }
  11390. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11391. {
  11392. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11393. {
  11394. check_ascii = value[0];
  11395. if( (check_ascii < 48) || (check_ascii > 57) )
  11396. {
  11397. isSuccess = ConfigurationStatus_Rejected;
  11398. }
  11399. else
  11400. {
  11401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11402. isSuccess = ConfigurationStatus_Accepted;
  11403. }
  11404. }
  11405. else
  11406. {
  11407. isSuccess = ConfigurationStatus_Rejected;
  11408. }
  11409. }
  11410. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11411. {
  11412. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11413. {
  11414. strcpy(str, (const char*)value);
  11415. for(int i = 0; str[i]; i++)
  11416. {
  11417. str[i] = tolower(str[i]);
  11418. }
  11419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11420. isSuccess = ConfigurationStatus_Accepted;
  11421. }
  11422. else
  11423. {
  11424. isSuccess = ConfigurationStatus_Rejected;
  11425. }
  11426. }
  11427. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11428. {
  11429. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11430. {
  11431. check_ascii = value[0];
  11432. if( (check_ascii < 48) || (check_ascii > 57) )
  11433. {
  11434. isSuccess = ConfigurationStatus_Rejected;
  11435. }
  11436. else
  11437. {
  11438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11439. isSuccess = ConfigurationStatus_Accepted;
  11440. }
  11441. }
  11442. else
  11443. {
  11444. isSuccess = ConfigurationStatus_Rejected;
  11445. }
  11446. }
  11447. return isSuccess;
  11448. }
  11449. int updateSetting(char *key, char *value)
  11450. {
  11451. mtrace();
  11452. int isSuccess = FALSE;
  11453. char string[1000]={0}, buffer[1000]={0};
  11454. char strtemp[50]={0};
  11455. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11456. int pos, c = 0;
  11457. char *loc;
  11458. int pos1=0;
  11459. FILE *f = fopen("/var/www/settings1", "r");
  11460. if(f == NULL)
  11461. {
  11462. #ifdef Debug
  11463. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11464. #endif
  11465. return isSuccess;
  11466. }
  11467. fseek(f, 0, SEEK_END);
  11468. long fsize = ftell(f);
  11469. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11470. fread(string, 1, fsize, f);
  11471. fclose(f);
  11472. string[fsize] = 0;
  11473. loc = strstr(string, key);
  11474. if(loc != NULL)
  11475. {
  11476. DEBUG_INFO("key exist!\n");
  11477. pos = loc - string-1;
  11478. f = fopen("/var/www/settings1", "w");
  11479. strncpy(buffer, string, pos);
  11480. fprintf(f, "%s", buffer);
  11481. memset(sstr ,0, sizeof(sstr) );
  11482. c = 0;
  11483. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11484. {
  11485. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11486. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11487. c++;
  11488. }
  11489. sstr[c] = '\0';
  11490. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11491. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11492. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11493. memset(buffer ,0, sizeof(buffer) );
  11494. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11495. //printf("buffer=%s",buffer);
  11496. fprintf(f, "%s", buffer);
  11497. fclose(f);
  11498. }
  11499. else
  11500. {
  11501. printf("key not exist!\n");
  11502. f = fopen("/var/www/settings1", "w+");
  11503. fputs(string, f);
  11504. fseek(f, -1, SEEK_CUR);
  11505. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11506. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11507. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11508. fclose(f);
  11509. }
  11510. isSuccess = TRUE;
  11511. return isSuccess;
  11512. }
  11513. int TransactionMessageAttemptsGet(void)
  11514. {
  11515. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11516. }
  11517. int FirstHeartBeatResponse(void)
  11518. {
  11519. return FirstHeartBeat;
  11520. }
  11521. int TransactionMessageRetryIntervalGet(void)
  11522. {
  11523. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11524. }
  11525. #define SA struct sockaddr
  11526. #define MAXBUF 1024
  11527. //static int m_socket_data;
  11528. //static int sockfd;
  11529. int ReadHttpStatus(int sock){
  11530. //char c;
  11531. char buff[1024]="",*ptr=buff+1;
  11532. int bytes_received, status;
  11533. DEBUG_INFO("Begin Response ..\n");
  11534. while((bytes_received = recv(sock, ptr, 1, 0))){
  11535. if(bytes_received==-1){
  11536. perror("ReadHttpStatus");
  11537. exit(1);
  11538. }
  11539. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11540. ptr++;
  11541. }
  11542. *ptr=0;
  11543. ptr=buff+1;
  11544. sscanf(ptr,"%*s %d ", &status);
  11545. DEBUG_INFO("%s\n",ptr);
  11546. DEBUG_INFO("status=%d\n",status);
  11547. DEBUG_INFO("End Response ..\n");
  11548. return (bytes_received>0)?status:0;
  11549. }
  11550. //the only filed that it parsed is 'Content-Length'
  11551. int ParseHeader(int sock){
  11552. //char c;
  11553. char buff[1024]="",*ptr=buff+4;
  11554. int bytes_received;
  11555. DEBUG_INFO("Begin HEADER ..\n");
  11556. while((bytes_received = recv(sock, ptr, 1, 0))){
  11557. if(bytes_received==-1){
  11558. perror("Parse Header");
  11559. exit(1);
  11560. }
  11561. if(
  11562. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11563. (ptr[-1]=='\r') && (*ptr=='\n' )
  11564. ) break;
  11565. ptr++;
  11566. }
  11567. *ptr=0;
  11568. ptr=buff+4;
  11569. //printf("%s",ptr);
  11570. if(bytes_received){
  11571. ptr=strstr(ptr,"Content-Length:");
  11572. if(ptr){
  11573. sscanf(ptr,"%*s %d",&bytes_received);
  11574. }else
  11575. bytes_received=-1; //unknown size
  11576. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11577. }
  11578. DEBUG_INFO("End HEADER ..\n");
  11579. return bytes_received ;
  11580. }
  11581. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11582. {
  11583. char rmFileCmd[100]={0};
  11584. char FilePath[100]={0};
  11585. char ftpbuf[200];
  11586. int systemresult;
  11587. //DEBUG_INFO("filename=%s\n",filename);
  11588. //DEBUG_INFO("url=%s\n",url);
  11589. sprintf(FilePath,"/mnt/%s",filename);
  11590. if((access(FilePath,F_OK))!=-1)
  11591. {
  11592. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11593. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11594. system(rmFileCmd);
  11595. }
  11596. memset(ftpbuf, 0, sizeof(ftpbuf));
  11597. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  11598. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11599. systemresult = system(ftpbuf);
  11600. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11601. if(systemresult != 0)
  11602. {
  11603. DEBUG_INFO("http DownLoad error!\n");
  11604. return FALSE;
  11605. }
  11606. return TRUE;
  11607. }
  11608. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11609. {
  11610. char rmFileCmd[100]={0};
  11611. char FilePath[100]={0};
  11612. char ftpbuf[200];
  11613. int systemresult;
  11614. //char temp[100];
  11615. #if 0
  11616. struct hostent* server;
  11617. char *IPbuffer;
  11618. server = gethostbyname(location);
  11619. // To convert an Internet network
  11620. // address into ASCII string
  11621. IPbuffer = inet_ntoa(*((struct in_addr*)
  11622. server->h_addr_list[0]));
  11623. #endif
  11624. sprintf(FilePath,"/mnt/%s",filename);
  11625. if((access(FilePath,F_OK))!=-1)
  11626. {
  11627. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11628. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11629. system(rmFileCmd);
  11630. }
  11631. memset(ftpbuf, 0, sizeof(ftpbuf));
  11632. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  11633. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11634. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11635. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11636. systemresult = system(ftpbuf);
  11637. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11638. if(systemresult != 0)
  11639. {
  11640. printf("wget error!\n");
  11641. return FALSE;
  11642. }
  11643. return TRUE;
  11644. }
  11645. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11646. {
  11647. char rmFileCmd[100]={0};
  11648. char FilePath[100]={0};
  11649. char ftpbuf[200];
  11650. char filenametemp[60]={0};
  11651. int systemresult;
  11652. //DEBUG_INFO("filename=%s\n",filename);
  11653. //DEBUG_INFO("url=%s\n",url);
  11654. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  11655. if((access(FilePath,F_OK))!=-1)
  11656. {
  11657. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11658. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11659. system(rmFileCmd);
  11660. }
  11661. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  11662. if(fp == NULL)
  11663. {
  11664. DEBUG_INFO("log is NULL\n");
  11665. return FALSE;
  11666. }
  11667. else
  11668. {
  11669. fprintf(fp, "%s\n", url);
  11670. sscanf(filename, "%*2[.]%s", filenametemp);
  11671. fprintf(fp, "%s\n", filenametemp);
  11672. fclose(fp);
  11673. }
  11674. memset(ftpbuf, 0, sizeof(ftpbuf));
  11675. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  11676. systemresult = system(ftpbuf);
  11677. DEBUG_INFO("systemresult=%d\n",systemresult);
  11678. if(systemresult != 0)
  11679. {
  11680. DEBUG_INFO("http upload error!\n");
  11681. return FALSE;
  11682. }
  11683. return TRUE;
  11684. }
  11685. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11686. {
  11687. struct hostent* server;
  11688. char *IPbuffer;
  11689. char ftpbuf[200];
  11690. int systemresult;
  11691. // To retrieve host information
  11692. server = gethostbyname(location);
  11693. // To convert an Internet network
  11694. // address into ASCII string
  11695. IPbuffer = inet_ntoa(*((struct in_addr*)
  11696. server->h_addr_list[0]));
  11697. memset(ftpbuf, 0, sizeof(ftpbuf));
  11698. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11699. /* format : ftpput -u username -p passwd IP target source*/
  11700. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11701. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11702. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11703. systemresult = system(ftpbuf);
  11704. DEBUG_INFO("systemresult=%d\n",systemresult);
  11705. if(systemresult != 0)
  11706. {
  11707. DEBUG_INFO("ftpput error!\n");
  11708. return FALSE;
  11709. }
  11710. return TRUE;
  11711. }
  11712. int SettingChargingRecord(int target, int transactionId)
  11713. {
  11714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11715. {
  11716. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11717. {
  11718. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11719. {
  11720. addBuff(target, transactionId, 0);
  11721. return TRUE;
  11722. }
  11723. }
  11724. for (int index = 0; index < CCS_QUANTITY; index++)
  11725. {
  11726. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11727. {
  11728. addBuff(target, transactionId, 0);
  11729. return TRUE;
  11730. }
  11731. }
  11732. for (int index = 0; index < GB_QUANTITY; index++)
  11733. {
  11734. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11735. {
  11736. addBuff(target, transactionId, 0);
  11737. return TRUE;
  11738. }
  11739. }
  11740. }
  11741. else
  11742. {
  11743. for (int index = 0; index < AC_QUANTITY; index++)
  11744. {
  11745. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11746. {
  11747. addBuff(target, transactionId, 0);
  11748. return TRUE;
  11749. }
  11750. }
  11751. }
  11752. return FALSE;
  11753. }
  11754. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11755. {
  11756. int isSuccess = FALSE;
  11757. //char *query = NULL;
  11758. sqlite3_stmt *stmt;
  11759. int rc; // return code
  11760. char str[20];
  11761. sprintf(str,"%d",user_id);
  11762. 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 */
  11763. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11764. rc = sqlite3_step(stmt); /* 3 */
  11765. if (rc != SQLITE_DONE) {
  11766. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11767. goto out;
  11768. }
  11769. sqlite3_finalize(stmt);
  11770. // free(query);
  11771. out:
  11772. //----------------------
  11773. // close SQLite database
  11774. //----------------------
  11775. sqlite3_close(db);
  11776. printf("database closed.\n");
  11777. return isSuccess;
  11778. }
  11779. /**
  11780. * Place the contents of the specified file into a memory buffer
  11781. *
  11782. * @param[in] filename The path and name of the file to read
  11783. * @param[out] filebuffer A pointer to the contents in memory
  11784. * @return status 0 success, 1 on failure
  11785. */
  11786. int get_file_contents(const char* filename, char** outbuffer) {
  11787. FILE* file = NULL;
  11788. long filesize;
  11789. const int blocksize = 1;
  11790. size_t readsize;
  11791. char* filebuffer;
  11792. // Open the file
  11793. file = fopen(filename, "r");
  11794. if (NULL == file)
  11795. {
  11796. printf("'%s' not opened\n", filename);
  11797. exit(EXIT_FAILURE);
  11798. }
  11799. // Determine the file size
  11800. fseek(file, 0, SEEK_END);
  11801. filesize = ftell(file);
  11802. rewind (file);
  11803. // Allocate memory for the file contents
  11804. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11805. *outbuffer = filebuffer;
  11806. if (filebuffer == NULL)
  11807. {
  11808. fputs ("malloc out-of-memory", stderr);
  11809. exit(EXIT_FAILURE);
  11810. }
  11811. // Read in the file
  11812. readsize = fread(filebuffer, blocksize, filesize, file);
  11813. if (readsize != filesize)
  11814. {
  11815. fputs ("didn't read file completely",stderr);
  11816. exit(EXIT_FAILURE);
  11817. }
  11818. // Clean exit
  11819. fclose(file);
  11820. return EXIT_SUCCESS;
  11821. }
  11822. static int selectSqlCount = 0;
  11823. static int callback(void *data, int argc, char **argv, char **azColName){
  11824. int i;
  11825. printf("%s: ", (const char*)data);
  11826. selectSqlCount = argc;
  11827. for(i = 0; i<argc; i++){
  11828. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11829. }
  11830. printf("\n");
  11831. return 0;
  11832. }
  11833. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11834. //int i;
  11835. //printf("%s:\n", (const char*)data);
  11836. localversion = argv[5] ? atoi(argv[5]) : 0;
  11837. printf("localversion=%d\n", localversion);
  11838. return 0;
  11839. }
  11840. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11841. //int i;
  11842. //printf("%s:\n", (const char*)data);
  11843. //idTag
  11844. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11845. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11846. //parentIdTag
  11847. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11848. //expir_date
  11849. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11850. //status
  11851. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11852. //version
  11853. idTagQuery.listVersionInt = atoi(argv[5]);
  11854. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11855. return 0;
  11856. }
  11857. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11858. int i;
  11859. //printf("%s:\n", (const char*)data);
  11860. #if 1
  11861. for(i=0; i<argc; i++){
  11862. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11863. }
  11864. //printf("");
  11865. #endif
  11866. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11867. // printf("localversion=%d\n", localversion);
  11868. return 0;
  11869. }
  11870. /** sqlite3_exec的回调。
  11871. *
  11872. * 向控制台打印查询的结果。
  11873. *
  11874. * @param in data 传递给回调函数的数据。
  11875. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11876. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11877. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11878. * @return 状态码。
  11879. */
  11880. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11881. {
  11882. for (int i = 0; i < n_columns; i++)
  11883. {
  11884. DEBUG_INFO("%s/t", col_values[i]);
  11885. }
  11886. DEBUG_INFO("/n");
  11887. return 0;
  11888. }
  11889. void OCPP_getListVerion()
  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. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11898. /* Execute SQL statement */
  11899. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11900. DEBUG_INFO("rc=%d\n",rc);
  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. }
  11908. void OCPP_getIdTag(char idTag[])
  11909. {
  11910. int rc = 0;
  11911. // const char* data = "Callback function called";
  11912. char sql[100];
  11913. char zErrMsg[100];
  11914. memset(sql, 0, 100);
  11915. memset(zErrMsg, 0, 100);
  11916. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11917. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11918. DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  11919. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11920. /* Execute SQL statement */
  11921. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11922. if( rc != SQLITE_OK ){
  11923. DEBUG_INFO("SQL error: %s", zErrMsg);
  11924. //sqlite3_free(zErrMsg);
  11925. }else{
  11926. printf("Operation done successfully");
  11927. }
  11928. //return ver;
  11929. }
  11930. void OCPP_get_TableAuthlocalAllData(void)
  11931. {
  11932. int rc = 0;
  11933. // const char* data = "Callback function called";
  11934. char sql[100];
  11935. char zErrMsg[100];
  11936. memset(sql, 0, 100);
  11937. memset(zErrMsg, 0, 100);
  11938. sprintf(sql,"select * from ocpp_auth_local ");
  11939. /* Execute SQL statement */
  11940. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11941. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11942. if( rc != SQLITE_OK ){
  11943. DEBUG_INFO("SQL error: %s", zErrMsg);
  11944. //sqlite3_free(zErrMsg);
  11945. }else{
  11946. DEBUG_INFO("Operation done successfully");
  11947. }
  11948. //return ver;
  11949. }
  11950. int OCPP_cleanLocalList()
  11951. {
  11952. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11953. char *errMsg = 0;
  11954. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11955. if (SQLITE_OK != rc)
  11956. {
  11957. DEBUG_INFO("%s\n",errMsg);
  11958. return FALSE;
  11959. }
  11960. else
  11961. {
  11962. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11963. }
  11964. return TRUE;
  11965. }
  11966. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11967. {
  11968. int isSuccess = FALSE;
  11969. int ret = 0;
  11970. //const char* data = "Callback function called";
  11971. char sql[300];
  11972. char zErrMsg[200];
  11973. memset(sql, 0, 300);
  11974. memset(zErrMsg, 0, 200);
  11975. 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);
  11976. //* Execute SQL statement */
  11977. //zErrMsg = 0;
  11978. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11979. if( ret != SQLITE_OK ){
  11980. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11981. // free(zErrMsg);
  11982. // free(sql);
  11983. return isSuccess;
  11984. }
  11985. DEBUG_INFO("successfully Insert records created\n");
  11986. isSuccess = TRUE;
  11987. return isSuccess;
  11988. }
  11989. void OCPP_deleteIdTag(char idTag[])
  11990. {
  11991. //int ver = 0;
  11992. //int isSuccess = FALSE;
  11993. int rc = 0;
  11994. char sql[100];
  11995. char zErrMsg[100];
  11996. memset(sql, 0, 100);
  11997. memset(zErrMsg, 0, 100);
  11998. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11999. //* Execute SQL statement */
  12000. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12001. if( rc != SQLITE_OK ){
  12002. DEBUG_INFO("SQL error: %s", zErrMsg);
  12003. //sqlite3_free(zErrMsg);
  12004. }else{
  12005. DEBUG_INFO("Operation done successfully");
  12006. }
  12007. }
  12008. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12009. {
  12010. int isSuccess = FALSE;
  12011. int ret = 0;
  12012. const char* data = "Callback function called";
  12013. char sql[200];
  12014. char zErrMsg[100];
  12015. memset(sql, 0, 200);
  12016. memset(zErrMsg, 0, 100);
  12017. //* selectFromTable */
  12018. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12019. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12020. //* Execute SQL statement */
  12021. selectSqlCount = 0;
  12022. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12023. if( ret != SQLITE_OK ){
  12024. printf("Error SQL: %s\n", zErrMsg);
  12025. }
  12026. printf("successfully select operation done\n");
  12027. memset(sql, 0, 200);
  12028. memset(zErrMsg, 0, 100);
  12029. if(selectSqlCount == 0)
  12030. {
  12031. //Insert
  12032. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12033. 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);
  12034. DEBUG_INFO("sql:%s\n", sql);
  12035. //* Execute SQL statement */
  12036. //zErrMsg = 0;
  12037. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12038. if( ret != SQLITE_OK ){
  12039. printf("SQL error: %s\n", zErrMsg);
  12040. return isSuccess;
  12041. }
  12042. DEBUG_INFO("successfully Insert records created\n");
  12043. isSuccess = TRUE;
  12044. }
  12045. else
  12046. {
  12047. //Update
  12048. //* Create merged SQL statement */
  12049. 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);
  12050. /* Execute SQL statement */
  12051. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12052. if( ret != SQLITE_OK ){
  12053. printf("SQL error: %s\n", zErrMsg);
  12054. //sqlite3_free(zErrMsg);
  12055. //sqlite3_free(sql);
  12056. return isSuccess;
  12057. }
  12058. DEBUG_INFO("Successfully operation done \n");
  12059. isSuccess = TRUE;
  12060. }
  12061. return isSuccess;
  12062. }
  12063. int GetOcppServerURL()
  12064. {
  12065. int result = FALSE;
  12066. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12067. memset(OcppHost, 0, sizeof(OcppHost));
  12068. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12069. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12070. {
  12071. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12072. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12073. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12074. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12075. result = TRUE;
  12076. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12077. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12078. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12079. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12080. goto End;
  12081. }
  12082. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12083. {
  12084. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12085. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12086. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12087. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12088. result = TRUE;
  12089. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12090. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12091. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12092. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12093. goto End;
  12094. }
  12095. else
  12096. {
  12097. strcpy(OcppHost,"");
  12098. }
  12099. End:
  12100. return result;
  12101. }
  12102. int GetOcppPath()
  12103. {
  12104. int result = FALSE;
  12105. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12106. {
  12107. if(OcppTempPath == NULL)
  12108. {
  12109. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12110. }
  12111. else
  12112. {
  12113. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12114. }
  12115. result = TRUE;
  12116. goto End;
  12117. }
  12118. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12119. {
  12120. if(OcppTempPath == NULL)
  12121. {
  12122. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12123. }
  12124. else
  12125. {
  12126. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12127. }
  12128. result = TRUE;
  12129. goto End;
  12130. }
  12131. else
  12132. {
  12133. strcpy(OcppPath,"");
  12134. }
  12135. End:
  12136. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12137. return result;
  12138. }
  12139. int GetOcppPort()
  12140. {
  12141. return OcppPort;
  12142. }
  12143. int GetOcppConnStatus(void)
  12144. {
  12145. return ShmOCPP16Data->OcppConnStatus;
  12146. }
  12147. void SetOcppConnStatus(uint8_t status)
  12148. {
  12149. ShmOCPP16Data->OcppConnStatus = status;
  12150. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12151. if(status == FALSE)
  12152. {
  12153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12154. {
  12155. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12156. }
  12157. else
  12158. {
  12159. SystemInitial = AC_QUANTITY;
  12160. }
  12161. }
  12162. }
  12163. int GetHeartBeatWithNOResponse(void)
  12164. {
  12165. return HeartBeatWithNOResponse;
  12166. }
  12167. void SetHeartBeatWithNOResponse(void)
  12168. {
  12169. HeartBeatWithNOResponse = 0;
  12170. }
  12171. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12172. /*
  12173. src 源字串的首地址(buf的地址)
  12174. separator 指定的分割字元
  12175. dest 接收子字串的陣列
  12176. num 分割後子字串的個數
  12177. */
  12178. char *pNext;
  12179. int count = 0;
  12180. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12181. return;
  12182. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12183. return;
  12184. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12185. while(pNext != NULL) {
  12186. *dest++ = pNext;
  12187. ++count;
  12188. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12189. }
  12190. *num = count;
  12191. }
  12192. int GetTransactionId(int gunindex, unsigned char idTag[])
  12193. {
  12194. char ch;
  12195. FILE *fptr1;
  12196. int temptransactionId;
  12197. char str[100]={0};
  12198. temptransactionId = 0;
  12199. /*------ Read the file ----------------*/
  12200. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12201. ch=fgetc(fptr1);
  12202. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12203. rewind(fptr1);
  12204. if(ch!=EOF)
  12205. {
  12206. // printf("%c",ch);
  12207. while (fgets(str, 100, fptr1) != NULL)
  12208. {
  12209. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12210. if(str[0]=='\0')
  12211. {
  12212. break;
  12213. }
  12214. char *revbuf[8] = {0}; //存放分割後的子字串
  12215. int num = 0;//分割後子字串的個數
  12216. printf(" Now the content of the file 44444 is : \n");
  12217. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12218. printf(" Now the content of the file 5555 is : \n");
  12219. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12220. {
  12221. temptransactionId = atoi(revbuf[2]);
  12222. break;
  12223. }
  12224. }
  12225. }
  12226. fclose(fptr1);
  12227. /*------- End of reading ---------------*/
  12228. return temptransactionId;
  12229. }
  12230. void SetTransactionIdZero(int transactionId)
  12231. {
  12232. //TransactionId[gunindex] = 0;
  12233. char ch;
  12234. FILE *fptr1, *fptr2;
  12235. int temptransactionId;
  12236. char str[100]={0}, temp[] = "/Storage/OCPP/temp.txt";
  12237. printf("\n\n Delete a specific line from a file :\n");
  12238. printf("-----------------------------------------\n");
  12239. //scanf("%s",fname);
  12240. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12241. if (!fptr1)
  12242. {
  12243. printf(" File not found or unable to open the input file!!\n");
  12244. return ;
  12245. }
  12246. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12247. if (!fptr2)
  12248. {
  12249. printf("Unable to open a temporary file to write!!\n");
  12250. fclose(fptr1);
  12251. return ;
  12252. }
  12253. ch=fgetc(fptr1);
  12254. //printf(" Now the content of the file %s is : \n",fname);
  12255. rewind(fptr1);
  12256. if(ch!=EOF)
  12257. {
  12258. // copy all contents to the temporary file except the specific line
  12259. while (fgets(str, 100, fptr1) != NULL)
  12260. {
  12261. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12262. if(str[0]=='\0')
  12263. {
  12264. break;
  12265. }
  12266. char *revbuf[8] = {0}; //存放分割後的子字串
  12267. int num = 0;//分割後子字串的個數
  12268. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12269. temptransactionId = atoi(revbuf[2]);
  12270. if(transactionId != temptransactionId)
  12271. {
  12272. fprintf(fptr2, "%s", str);
  12273. }
  12274. }
  12275. }
  12276. fclose(fptr1);
  12277. fclose(fptr2);
  12278. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12279. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12280. /*------ Read the file ----------------*/
  12281. }
  12282. int InternetDisconnect(void)
  12283. {
  12284. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12285. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12286. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12287. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12288. }
  12289. void GetChargingProfileRequest(int gunindex)
  12290. {
  12291. mtrace();
  12292. //int connectorIdInt, durationInt;
  12293. //char chargingRateUnitStr[4]={0};
  12294. int tempdurationInt = 0;
  12295. int tempchargingProfileId = 0;
  12296. int tempstackLevel = 0;
  12297. int temptransactionId = 0;
  12298. float tempminChargingRateFloat = 0.0;
  12299. char tempchargingProfilePurposeStr[24]={0};
  12300. char tempchargingProfileKindStr[12]={0};
  12301. char temprecurrencyKindStr[8]={0};
  12302. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12303. char tempvalidToStr[28]={0};
  12304. int tempStartPeriodInt = 0;
  12305. float tempLimitInt = 0.0;//0.1;
  12306. int tempNumberPhasesInt=0;
  12307. char fname[200];
  12308. //char comfirmstr[20];
  12309. float MinChargingRate =0.0;
  12310. double diff_t;
  12311. struct tm tp;
  12312. FILE *fptr1;//, *fptr2;
  12313. int c = 0;
  12314. char * pch;
  12315. char *loc;
  12316. char sstr[200]={ 0 };
  12317. int n_chargingProfile = 0;
  12318. int n_SchedulePeriods = 0;
  12319. char SchedulePeriodList[10][200]={0};
  12320. char sLineWord[800]={0};
  12321. char word[1000]={0};
  12322. int confirmPeriods = 0;
  12323. struct StructProfile ChargePointMaxProfile;
  12324. struct StructProfile TxDefaultProfile;
  12325. struct StructProfile TxProfile;
  12326. struct StructProfile TxDefaultProfiletemp[2]={0};
  12327. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12328. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12329. struct StructChargingProfile TxProfile_TEMP={0};
  12330. int TxDefaultProfileFileIsNull=FALSE;
  12331. int ChargePointMaxProfileIsNull=FALSE;
  12332. int TxProfileIsNull=FALSE;
  12333. // int CompositeSceduleIndex = 0;
  12334. char ChargePointMaxProfileScheduleStr[30]={0};
  12335. char TxDefaultProfileScheduleStr[30]={0};
  12336. char TxProfileScheduleStr[30]={0};
  12337. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12338. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12339. memset(&TxProfile,0,sizeof(struct StructProfile));
  12340. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12341. DEBUG_INFO("GetChargingProfileRequest\n");
  12342. //*****************************ChargePointMaxProfile******************************************/
  12343. strcpy(fname, ChargePointMaxProfile_JSON);
  12344. ChargePointMaxProfileIsNull=TRUE;
  12345. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12346. {
  12347. fptr1 = fopen(fname, "r");
  12348. int c;
  12349. c = fgetc(fptr1);
  12350. //DEBUG_INFO("c:%d\n",c);
  12351. rewind(fptr1);
  12352. if(c == EOF)
  12353. {
  12354. DEBUG_INFO("\n End of file reached.");
  12355. ChargePointMaxProfileIsNull=TRUE;
  12356. fclose(fptr1);
  12357. }
  12358. else
  12359. {
  12360. ChargePointMaxProfileIsNull=FALSE;
  12361. while(fscanf(fptr1, "%s", word) != EOF)
  12362. {
  12363. if(strcmp(word, "chargingProfileId") == 0)
  12364. {
  12365. n_chargingProfile = n_chargingProfile + 1;
  12366. }
  12367. }
  12368. rewind(fptr1);
  12369. //search Charging Profile Element
  12370. int i = 0;
  12371. int j = 0;
  12372. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12373. //***********chargingProfileId**************/
  12374. c = 0;
  12375. loc = strstr(sLineWord, "chargingProfileId");
  12376. //DEBUG_INFO("loc=%s\n",loc);
  12377. memset(sstr ,0, sizeof(sstr) );
  12378. if(loc != NULL)
  12379. {
  12380. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12381. {
  12382. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12383. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12384. c++;
  12385. }
  12386. sstr[c] = '\0';
  12387. tempchargingProfileId = atoi(sstr);
  12388. }
  12389. else
  12390. {
  12391. tempchargingProfileId = 0;
  12392. }
  12393. //***********stackLevel**************/
  12394. c = 0;
  12395. loc = strstr(sLineWord, "stackLevel");
  12396. //DEBUG_INFO("loc=%s\n",loc);
  12397. memset(sstr ,0, sizeof(sstr) );
  12398. if(loc != NULL)
  12399. {
  12400. while (loc[2+strlen("stackLevel")+c] != '\"')
  12401. {
  12402. sstr[c] = loc[2+strlen("stackLevel")+c];
  12403. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12404. c++;
  12405. }
  12406. sstr[c] = '\0';
  12407. tempstackLevel = atoi(sstr);
  12408. }
  12409. else
  12410. {
  12411. tempstackLevel = 0;
  12412. }
  12413. //***********chargingProfilePurpose **************/
  12414. c = 0;
  12415. loc = strstr(sLineWord, "chargingProfilePurpose");
  12416. //DEBUG_INFO("loc=%s\n",loc);
  12417. memset(sstr ,0, sizeof(sstr) );
  12418. if(loc != NULL)
  12419. {
  12420. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12421. {
  12422. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12423. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12424. c++;
  12425. }
  12426. sstr[c] = '\0';
  12427. strcpy(tempchargingProfilePurposeStr,sstr);
  12428. }
  12429. else
  12430. {
  12431. strcpy(tempchargingProfilePurposeStr,"");
  12432. }
  12433. //***********chargingProfileKind **************/
  12434. c = 0;
  12435. loc = strstr(sLineWord, "chargingProfileKind");
  12436. //DEBUG_INFO("loc=%s\n",loc);
  12437. memset(sstr ,0, sizeof(sstr) );
  12438. if(loc != NULL)
  12439. {
  12440. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12441. {
  12442. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12443. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12444. c++;
  12445. }
  12446. sstr[c] = '\0';
  12447. strcpy(tempchargingProfileKindStr,sstr);
  12448. }
  12449. else
  12450. {
  12451. strcpy(tempchargingProfileKindStr,"");
  12452. }
  12453. //***********recurrencyKind **************/
  12454. c = 0;
  12455. loc = strstr(sLineWord, "recurrencyKind");
  12456. //DEBUG_INFO("loc=%s\n",loc);
  12457. memset(sstr ,0, sizeof(sstr) );
  12458. if(loc != NULL)
  12459. {
  12460. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12461. {
  12462. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12463. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12464. c++;
  12465. }
  12466. sstr[c] = '\0';
  12467. strcpy(temprecurrencyKindStr,sstr);
  12468. }
  12469. else
  12470. {
  12471. strcpy(temprecurrencyKindStr,"");
  12472. }
  12473. //***********validFrom**************/
  12474. c = 0;
  12475. loc = strstr(sLineWord, "validFrom");
  12476. //DEBUG_INFO("loc=%s\n",loc);
  12477. memset(sstr ,0, sizeof(sstr) );
  12478. if(loc != NULL)
  12479. {
  12480. while (loc[3+strlen("validFrom")+c] != '\"')
  12481. {
  12482. sstr[c] = loc[3+strlen("validFrom")+c];
  12483. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12484. c++;
  12485. }
  12486. sstr[c] = '\0';
  12487. strcpy(tempvalidFromStr,sstr);
  12488. }
  12489. else
  12490. {
  12491. strcpy(tempvalidFromStr,"");
  12492. }
  12493. //***********validTo **************/
  12494. c = 0;
  12495. loc = strstr(sLineWord, "validTo");
  12496. //DEBUG_INFO("loc=%s\n",loc);
  12497. memset(sstr ,0, sizeof(sstr) );
  12498. if(loc != NULL)
  12499. {
  12500. while (loc[3+strlen("validTo")+c] != '\"')
  12501. {
  12502. sstr[c] = loc[3+strlen("validTo")+c];
  12503. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12504. c++;
  12505. }
  12506. sstr[c] = '\0';
  12507. strcpy(tempvalidToStr,sstr);
  12508. }
  12509. else
  12510. {
  12511. strcpy(tempvalidToStr,"");
  12512. }
  12513. //***********validFrom**************/
  12514. c = 0;
  12515. loc = strstr(sLineWord, "validFrom");
  12516. if(loc != NULL)
  12517. {
  12518. memset(sstr ,0, sizeof(sstr) );
  12519. while (loc[3+strlen("validFrom")+c] != '\"')
  12520. {
  12521. sstr[c] = loc[3+strlen("validFrom")+c];
  12522. c++;
  12523. }
  12524. sstr[c] = '\0';
  12525. strcpy(tempvalidFromStr,sstr);
  12526. }
  12527. else
  12528. {
  12529. strcpy(tempvalidFromStr,"");
  12530. }
  12531. //***********validTo **************/
  12532. c = 0;
  12533. loc = strstr(sLineWord, "validTo");
  12534. if(loc != NULL)
  12535. {
  12536. memset(sstr ,0, sizeof(sstr) );
  12537. while (loc[3+strlen("validTo")+c] != '\"')
  12538. {
  12539. sstr[c] = loc[3+strlen("validTo")+c];
  12540. c++;
  12541. }
  12542. sstr[c] = '\0';
  12543. strcpy(tempvalidToStr,sstr);
  12544. }
  12545. else
  12546. {
  12547. strcpy(tempvalidToStr,"");
  12548. }
  12549. //***********duration**************/
  12550. c = 0;
  12551. loc = strstr(sLineWord, "duration");
  12552. if(loc != NULL)
  12553. {
  12554. memset(sstr ,0, sizeof(sstr) );
  12555. while (loc[2+strlen("duration")+c] != ',')
  12556. {
  12557. sstr[c] = loc[2+strlen("duration")+c];
  12558. c++;
  12559. }
  12560. sstr[c] = '\0';
  12561. tempdurationInt = atoi(sstr);
  12562. }
  12563. else
  12564. {
  12565. tempdurationInt = 0;
  12566. }
  12567. //**********startSchedule**********/
  12568. c = 0;
  12569. loc = strstr(sLineWord, "startSchedule");
  12570. memset(sstr ,0, sizeof(sstr) );
  12571. while (loc[3+strlen("startSchedule")+c] != '\"')
  12572. {
  12573. sstr[c] = loc[3+strlen("startSchedule")+c];
  12574. c++;
  12575. }
  12576. sstr[c] = '\0';
  12577. strcpy(tempstartScheduleStr, sstr);
  12578. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12579. //**********chargingRateUnit**********/
  12580. c = 0;
  12581. loc = strstr(sLineWord, "chargingRateUnit");
  12582. memset(sstr ,0, sizeof(sstr) );
  12583. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12584. {
  12585. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12586. c++;
  12587. }
  12588. sstr[c] = '\0';
  12589. strcpy(tempchargingRateUnitStr, sstr);
  12590. //**********minChargingRate*******/
  12591. c = 0;
  12592. loc = strstr(sLineWord, "minChargingRate");
  12593. if(loc != NULL)
  12594. {
  12595. memset(sstr ,0, sizeof(sstr) );
  12596. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12597. {
  12598. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12599. c++;
  12600. }
  12601. sstr[c] = '\0';
  12602. tempminChargingRateFloat = atof(sstr);
  12603. }
  12604. else
  12605. {
  12606. tempminChargingRateFloat = 0.0;
  12607. }
  12608. //
  12609. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12610. tp.tm_isdst = -1;
  12611. time_t utc = mktime(&tp);
  12612. time_t t = time(NULL);
  12613. diff_t = difftime(t, utc);
  12614. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12615. //parsing strings to words
  12616. i = 0;
  12617. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12618. loc = loc+3+strlen("chargingSchedulePeriod");
  12619. pch = strtok(loc ,"{");
  12620. while (pch != NULL)
  12621. {
  12622. strcpy(SchedulePeriodList[i], pch);
  12623. pch = strtok (NULL, "{");
  12624. i = i + 1;
  12625. }
  12626. n_SchedulePeriods = i;
  12627. for(int i=0;i<n_SchedulePeriods;i++)
  12628. {
  12629. //*************startPeriod****************/
  12630. c = 0;
  12631. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12632. memset(sstr ,0, sizeof(sstr) );
  12633. while (loc[strlen("startPeriod")+2+c] != ',')
  12634. {
  12635. sstr[c] = loc[strlen("startPeriod")+2+c];
  12636. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12637. c++;
  12638. }
  12639. sstr[c] = '\0';
  12640. tempStartPeriodInt = atoi(sstr);
  12641. //*************limit****************/
  12642. c = 0;
  12643. loc = strstr(SchedulePeriodList[i], "limit");
  12644. memset(sstr ,0, sizeof(sstr) );
  12645. while (loc[strlen("limit")+2+c] != ',')
  12646. {
  12647. sstr[c] = loc[strlen("limit")+2+c];
  12648. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12649. c++;
  12650. }
  12651. sstr[c] = '\0';
  12652. tempLimitInt = atof(sstr);
  12653. //*************numberPhases****************/
  12654. c = 0;
  12655. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12656. memset(sstr ,0, sizeof(sstr) );
  12657. while (loc[strlen("numberPhases")+2+c] != '}')
  12658. {
  12659. sstr[c] = loc[strlen("numberPhases")+2+c];
  12660. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12661. c++;
  12662. }
  12663. sstr[c] = '\0';
  12664. tempNumberPhasesInt = atoi(sstr);
  12665. if(j == 0)
  12666. {
  12667. ChargePointMaxProfile.Duration = tempdurationInt;
  12668. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12669. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12670. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12671. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12672. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12673. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12674. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12675. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12676. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12677. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12678. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12679. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12680. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12681. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12682. }
  12683. }
  12684. if(MinChargingRate < tempminChargingRateFloat)
  12685. {
  12686. MinChargingRate = tempminChargingRateFloat;
  12687. }
  12688. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12689. if(confirmPeriods < n_SchedulePeriods)
  12690. {
  12691. confirmPeriods = n_SchedulePeriods;
  12692. }
  12693. j = j + 1;
  12694. }
  12695. fclose(fptr1);
  12696. }
  12697. }// the end of access file ChargePointMaxProfile
  12698. //****************************TxDefaultProfile************************************************/
  12699. switch(gunindex + 1)
  12700. {
  12701. case 0:
  12702. strcpy(fname, TxDefaultProfile_0_JSON );
  12703. break;
  12704. case 1:
  12705. strcpy(fname, TxDefaultProfile_1_JSON );
  12706. break;
  12707. case 2:
  12708. strcpy(fname, TxDefaultProfile_2_JSON );
  12709. break;
  12710. default:
  12711. strcpy(fname, TxDefaultProfile_1_JSON );
  12712. break;
  12713. }
  12714. TxDefaultProfileFileIsNull=TRUE;
  12715. if((access(fname,F_OK))!=-1)
  12716. {
  12717. fptr1 = fopen(fname, "r");
  12718. c = 0;
  12719. c = fgetc(fptr1);
  12720. //DEBUG_INFO("c:%d\n",c);
  12721. rewind(fptr1);
  12722. if(c == EOF)
  12723. {
  12724. DEBUG_INFO("\n End of file reached.");
  12725. TxDefaultProfileFileIsNull=TRUE;
  12726. fclose(fptr1);
  12727. }
  12728. else
  12729. {
  12730. TxDefaultProfileFileIsNull=FALSE;
  12731. while(fscanf(fptr1, "%s", word) != EOF)
  12732. {
  12733. if(strcmp(word, "chargingProfileId") == 0)
  12734. {
  12735. n_chargingProfile = n_chargingProfile + 1;
  12736. }
  12737. }
  12738. rewind(fptr1);
  12739. //search Charging Profile Element
  12740. int i = 0;
  12741. int j = 0;
  12742. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12743. #if 0
  12744. /***********connectorId****************/
  12745. c = 0;
  12746. loc = strstr(sLineWord, "connectorId");
  12747. memset(sstr ,0, sizeof(sstr) );
  12748. while (loc[strlen("connectorId")+2+c] != ',')
  12749. {
  12750. sstr[c] = loc[strlen("connectorId")+2+c];
  12751. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12752. c++;
  12753. }
  12754. sstr[c] = '\0';
  12755. tempconnectorIdInt = atoi(sstr);
  12756. #endif
  12757. //***********chargingProfileId**************/
  12758. c = 0;
  12759. loc = strstr(sLineWord, "chargingProfileId");
  12760. //DEBUG_INFO("loc=%s\n",loc);
  12761. memset(sstr ,0, sizeof(sstr) );
  12762. if(loc != NULL)
  12763. {
  12764. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12765. {
  12766. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12767. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12768. c++;
  12769. }
  12770. sstr[c] = '\0';
  12771. tempchargingProfileId = atoi(sstr);
  12772. }
  12773. else
  12774. {
  12775. tempchargingProfileId = 0;
  12776. }
  12777. //***********stackLevel**************/
  12778. c = 0;
  12779. loc = strstr(sLineWord, "stackLevel");
  12780. //DEBUG_INFO("loc=%s\n",loc);
  12781. memset(sstr ,0, sizeof(sstr) );
  12782. if(loc != NULL)
  12783. {
  12784. while (loc[2+strlen("stackLevel")+c] != '\"')
  12785. {
  12786. sstr[c] = loc[2+strlen("stackLevel")+c];
  12787. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12788. c++;
  12789. }
  12790. sstr[c] = '\0';
  12791. tempstackLevel = atoi(sstr);
  12792. }
  12793. else
  12794. {
  12795. tempstackLevel = 0;
  12796. }
  12797. //***********chargingProfilePurpose **************/
  12798. c = 0;
  12799. loc = strstr(sLineWord, "chargingProfilePurpose");
  12800. //DEBUG_INFO("loc=%s\n",loc);
  12801. memset(sstr ,0, sizeof(sstr) );
  12802. if(loc != NULL)
  12803. {
  12804. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12805. {
  12806. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12807. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12808. c++;
  12809. }
  12810. sstr[c] = '\0';
  12811. strcpy(tempchargingProfilePurposeStr,sstr);
  12812. }
  12813. else
  12814. {
  12815. strcpy(tempchargingProfilePurposeStr,"");
  12816. }
  12817. //***********chargingProfileKind **************/
  12818. c = 0;
  12819. loc = strstr(sLineWord, "chargingProfileKind");
  12820. //DEBUG_INFO("loc=%s\n",loc);
  12821. memset(sstr ,0, sizeof(sstr) );
  12822. if(loc != NULL)
  12823. {
  12824. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12825. {
  12826. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12827. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12828. c++;
  12829. }
  12830. sstr[c] = '\0';
  12831. strcpy(tempchargingProfileKindStr,sstr);
  12832. }
  12833. else
  12834. {
  12835. strcpy(tempchargingProfileKindStr,"");
  12836. }
  12837. //***********recurrencyKind **************/
  12838. c = 0;
  12839. loc = strstr(sLineWord, "recurrencyKind");
  12840. //DEBUG_INFO("loc=%s\n",loc);
  12841. memset(sstr ,0, sizeof(sstr) );
  12842. if(loc != NULL)
  12843. {
  12844. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12845. {
  12846. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12847. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12848. c++;
  12849. }
  12850. sstr[c] = '\0';
  12851. strcpy(temprecurrencyKindStr,sstr);
  12852. }
  12853. else
  12854. {
  12855. strcpy(temprecurrencyKindStr,"");
  12856. }
  12857. //***********validFrom**************/
  12858. c = 0;
  12859. loc = strstr(sLineWord, "validFrom");
  12860. if(loc != NULL)
  12861. {
  12862. memset(sstr ,0, sizeof(sstr) );
  12863. while (loc[3+strlen("validFrom")+c] != '\"')
  12864. {
  12865. sstr[c] = loc[3+strlen("validFrom")+c];
  12866. c++;
  12867. }
  12868. sstr[c] = '\0';
  12869. strcpy(tempvalidFromStr,sstr);
  12870. }
  12871. else
  12872. {
  12873. strcpy(tempvalidFromStr,"");
  12874. }
  12875. //***********validTo **************/
  12876. c = 0;
  12877. loc = strstr(sLineWord, "validTo");
  12878. if(loc != NULL)
  12879. {
  12880. memset(sstr ,0, sizeof(sstr) );
  12881. while (loc[3+strlen("validTo")+c] != '\"')
  12882. {
  12883. sstr[c] = loc[3+strlen("validTo")+c];
  12884. c++;
  12885. }
  12886. sstr[c] = '\0';
  12887. strcpy(tempvalidToStr,sstr);
  12888. }
  12889. else
  12890. {
  12891. strcpy(tempvalidToStr,"");
  12892. }
  12893. //***********duration**************/
  12894. c = 0;
  12895. loc = strstr(sLineWord, "duration");
  12896. if(loc != NULL)
  12897. {
  12898. memset(sstr ,0, sizeof(sstr) );
  12899. while (loc[2+strlen("duration")+c] != ',')
  12900. {
  12901. sstr[c] = loc[2+strlen("duration")+c];
  12902. c++;
  12903. }
  12904. sstr[c] = '\0';
  12905. tempdurationInt = atoi(sstr);
  12906. }
  12907. else
  12908. {
  12909. tempdurationInt = 0;
  12910. }
  12911. //**********startSchedule**********/
  12912. c = 0;
  12913. loc = strstr(sLineWord, "startSchedule");
  12914. memset(sstr ,0, sizeof(sstr) );
  12915. while (loc[3+strlen("startSchedule")+c] != '\"')
  12916. {
  12917. sstr[c] = loc[3+strlen("startSchedule")+c];
  12918. c++;
  12919. }
  12920. sstr[c] = '\0';
  12921. strcpy(tempstartScheduleStr, sstr);
  12922. strcpy(TxDefaultProfileScheduleStr, sstr);
  12923. //**********chargingRateUnit**********/
  12924. c = 0;
  12925. loc = strstr(sLineWord, "chargingRateUnit");
  12926. memset(sstr ,0, sizeof(sstr) );
  12927. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12928. {
  12929. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12930. c++;
  12931. }
  12932. sstr[c] = '\0';
  12933. strcpy(tempchargingRateUnitStr, sstr);
  12934. //**********minChargingRate*******/
  12935. c = 0;
  12936. loc = strstr(sLineWord, "minChargingRate");
  12937. if(loc != NULL)
  12938. {
  12939. memset(sstr ,0, sizeof(sstr) );
  12940. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12941. {
  12942. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12943. c++;
  12944. }
  12945. sstr[c] = '\0';
  12946. tempminChargingRateFloat = atof(sstr);
  12947. }
  12948. else
  12949. {
  12950. tempminChargingRateFloat = 0.0;
  12951. }
  12952. //
  12953. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12954. tp.tm_isdst = -1;
  12955. time_t utc = mktime(&tp);
  12956. time_t t = time(NULL);
  12957. diff_t = difftime(t, utc);
  12958. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12959. //parsing strings to words
  12960. i = 0;
  12961. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12962. loc = loc+3+strlen("chargingSchedulePeriod");
  12963. pch = strtok(loc ,"{");
  12964. while (pch != NULL)
  12965. {
  12966. strcpy(SchedulePeriodList[i], pch);
  12967. pch = strtok (NULL, "{");
  12968. i = i + 1;
  12969. }
  12970. n_SchedulePeriods = i;
  12971. for(int i=0;i<n_SchedulePeriods;i++)
  12972. {
  12973. //*************startPeriod****************/
  12974. c = 0;
  12975. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12976. memset(sstr ,0, sizeof(sstr) );
  12977. while (loc[strlen("startPeriod")+2+c] != ',')
  12978. {
  12979. sstr[c] = loc[strlen("startPeriod")+2+c];
  12980. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12981. c++;
  12982. }
  12983. sstr[c] = '\0';
  12984. tempStartPeriodInt = atoi(sstr);
  12985. //*************limit****************/
  12986. c = 0;
  12987. loc = strstr(SchedulePeriodList[i], "limit");
  12988. memset(sstr ,0, sizeof(sstr) );
  12989. while (loc[strlen("limit")+2+c] != ',')
  12990. {
  12991. sstr[c] = loc[strlen("limit")+2+c];
  12992. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12993. c++;
  12994. }
  12995. sstr[c] = '\0';
  12996. tempLimitInt = atof(sstr);
  12997. //*************numberPhases****************/
  12998. c = 0;
  12999. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13000. memset(sstr ,0, sizeof(sstr) );
  13001. while (loc[strlen("numberPhases")+2+c] != '}')
  13002. {
  13003. sstr[c] = loc[strlen("numberPhases")+2+c];
  13004. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13005. c++;
  13006. }
  13007. sstr[c] = '\0';
  13008. tempNumberPhasesInt = atoi(sstr);
  13009. if(j == 0)
  13010. {
  13011. TxDefaultProfile.Duration = tempdurationInt;
  13012. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13013. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13014. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13015. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13016. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13017. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13018. TxDefaultProfile_TEMP.TransactionId = 0;
  13019. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13020. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13021. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13022. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13023. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13024. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13025. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13026. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13027. }
  13028. else
  13029. {
  13030. //other stack level charging Profile
  13031. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13032. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13033. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13034. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13035. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13036. }
  13037. }
  13038. if(MinChargingRate < tempminChargingRateFloat)
  13039. {
  13040. MinChargingRate = tempminChargingRateFloat;
  13041. }
  13042. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13043. if(confirmPeriods < n_SchedulePeriods)
  13044. confirmPeriods = n_SchedulePeriods;
  13045. j = j + 1;
  13046. }
  13047. fclose(fptr1);
  13048. //Stacking Charging Profiles
  13049. for(int l=0; l <(j-1) ;l++)
  13050. {
  13051. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13052. {
  13053. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13054. {
  13055. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13056. {
  13057. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13058. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13059. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13060. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13061. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13062. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13063. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13064. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13065. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13066. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13067. }
  13068. else
  13069. {
  13070. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13071. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13072. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13073. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13074. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13075. }
  13076. }
  13077. }
  13078. }
  13079. //end of Stacking Charging Profiles
  13080. }
  13081. }// the end of ACCESS TxDefaultProfile
  13082. //****************************TxProfile************************************************/
  13083. switch(gunindex + 1)
  13084. {
  13085. case 0:
  13086. break;
  13087. case 1:
  13088. strcpy(fname, TxProfile_1_JSON );
  13089. break;
  13090. case 2:
  13091. strcpy(fname, TxProfile_2_JSON );
  13092. break;
  13093. default:
  13094. strcpy(fname, TxProfile_1_JSON );
  13095. break;
  13096. }
  13097. TxProfileIsNull=TRUE;
  13098. if((access(fname,F_OK))!=-1)
  13099. {
  13100. fptr1 = fopen(fname, "r");
  13101. c = 0;
  13102. c = fgetc(fptr1);
  13103. //DEBUG_INFO("c:%d\n",c);
  13104. rewind(fptr1);
  13105. if(c == EOF)
  13106. {
  13107. DEBUG_INFO("\n End of file reached.");
  13108. TxProfileIsNull=TRUE;
  13109. fclose(fptr1);
  13110. }
  13111. else
  13112. {
  13113. TxProfileIsNull=FALSE;
  13114. while(fscanf(fptr1, "%s", word) != EOF)
  13115. {
  13116. if(strcmp(word, "chargingProfileId") == 0)
  13117. {
  13118. n_chargingProfile = n_chargingProfile + 1;
  13119. }
  13120. }
  13121. rewind(fptr1);
  13122. //search Charging Profile Element
  13123. int i= 0;
  13124. int j= 0;
  13125. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13126. #if 0
  13127. /***********connectorId****************/
  13128. c = 0;
  13129. loc = strstr(sLineWord, "connectorId");
  13130. memset(sstr ,0, sizeof(sstr) );
  13131. while (loc[strlen("connectorId")+2+c] != ',')
  13132. {
  13133. sstr[c] = loc[strlen("connectorId")+2+c];
  13134. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13135. c++;
  13136. }
  13137. sstr[c] = '\0';
  13138. tempconnectorIdInt = atoi(sstr);
  13139. #endif
  13140. //***********chargingProfileId**************/
  13141. c = 0;
  13142. loc = strstr(sLineWord, "chargingProfileId");
  13143. memset(sstr ,0, sizeof(sstr) );
  13144. if(loc != NULL)
  13145. {
  13146. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13147. {
  13148. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13149. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13150. c++;
  13151. }
  13152. sstr[c] = '\0';
  13153. tempchargingProfileId = atoi(sstr);
  13154. }
  13155. else
  13156. {
  13157. tempchargingProfileId = 0;
  13158. }
  13159. //***********transactionId **************/
  13160. c = 0;
  13161. loc = strstr(sLineWord, "transactionId");
  13162. //DEBUG_INFO("loc=%s\n",loc);
  13163. memset(sstr ,0, sizeof(sstr) );
  13164. if(loc != NULL)
  13165. {
  13166. while (loc[2+strlen("transactionId")+c] != '\"')
  13167. {
  13168. sstr[c] = loc[2+strlen("transactionId")+c];
  13169. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13170. c++;
  13171. }
  13172. sstr[c] = '\0';
  13173. temptransactionId = atoi(sstr);
  13174. }
  13175. else
  13176. {
  13177. temptransactionId = 0;
  13178. }
  13179. //***********stackLevel**************/
  13180. c = 0;
  13181. loc = strstr(sLineWord, "stackLevel");
  13182. //DEBUG_INFO("loc=%s\n",loc);
  13183. memset(sstr ,0, sizeof(sstr) );
  13184. if(loc != NULL)
  13185. {
  13186. while (loc[2+strlen("stackLevel")+c] != '\"')
  13187. {
  13188. sstr[c] = loc[2+strlen("stackLevel")+c];
  13189. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13190. c++;
  13191. }
  13192. sstr[c] = '\0';
  13193. tempstackLevel = atoi(sstr);
  13194. }
  13195. else
  13196. {
  13197. tempstackLevel = 0;
  13198. }
  13199. //***********chargingProfilePurpose **************/
  13200. c = 0;
  13201. loc = strstr(sLineWord, "chargingProfilePurpose");
  13202. //DEBUG_INFO("loc=%s\n",loc);
  13203. memset(sstr ,0, sizeof(sstr) );
  13204. if(loc != NULL)
  13205. {
  13206. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13207. {
  13208. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13209. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13210. c++;
  13211. }
  13212. sstr[c] = '\0';
  13213. strcpy(tempchargingProfilePurposeStr,sstr);
  13214. }
  13215. else
  13216. {
  13217. strcpy(tempchargingProfilePurposeStr,"");
  13218. }
  13219. //***********chargingProfileKind **************/
  13220. c = 0;
  13221. loc = strstr(sLineWord, "chargingProfileKind");
  13222. //DEBUG_INFO("loc=%s\n",loc);
  13223. memset(sstr ,0, sizeof(sstr) );
  13224. if(loc != NULL)
  13225. {
  13226. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13227. {
  13228. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13229. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13230. c++;
  13231. }
  13232. sstr[c] = '\0';
  13233. strcpy(tempchargingProfileKindStr,sstr);
  13234. }
  13235. else
  13236. {
  13237. strcpy(tempchargingProfileKindStr,"");
  13238. }
  13239. //***********recurrencyKind **************/
  13240. c = 0;
  13241. loc = strstr(sLineWord, "recurrencyKind");
  13242. //DEBUG_INFO("loc=%s\n",loc);
  13243. memset(sstr ,0, sizeof(sstr) );
  13244. if(loc != NULL)
  13245. {
  13246. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13247. {
  13248. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13249. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13250. c++;
  13251. }
  13252. sstr[c] = '\0';
  13253. strcpy(temprecurrencyKindStr,sstr);
  13254. }
  13255. else
  13256. {
  13257. strcpy(temprecurrencyKindStr,"");
  13258. }
  13259. //***********validFrom**************/
  13260. c = 0;
  13261. loc = strstr(sLineWord, "validFrom");
  13262. if(loc != NULL)
  13263. {
  13264. memset(sstr ,0, sizeof(sstr) );
  13265. while (loc[3+strlen("validFrom")+c] != '\"')
  13266. {
  13267. sstr[c] = loc[3+strlen("validFrom")+c];
  13268. c++;
  13269. }
  13270. sstr[c] = '\0';
  13271. strcpy(tempvalidFromStr,sstr);
  13272. }
  13273. else
  13274. {
  13275. strcpy(tempvalidFromStr,"");
  13276. }
  13277. //***********validTo**************/
  13278. c = 0;
  13279. loc = strstr(sLineWord, "validTo");
  13280. if(loc != NULL)
  13281. {
  13282. memset(sstr ,0, sizeof(sstr) );
  13283. while (loc[3+strlen("validTo")+c] != '\"')
  13284. {
  13285. sstr[c] = loc[3+strlen("validTo")+c];
  13286. c++;
  13287. }
  13288. sstr[c] = '\0';
  13289. strcpy(tempvalidToStr,sstr);
  13290. }
  13291. else
  13292. {
  13293. strcpy(tempvalidToStr,"");
  13294. }
  13295. //***********duration**************/
  13296. c = 0;
  13297. loc = strstr(sLineWord, "duration");
  13298. //DEBUG_INFO("loc=%s\n",loc);
  13299. memset(sstr ,0, sizeof(sstr) );
  13300. if(loc != NULL)
  13301. {
  13302. while (loc[2+strlen("duration")+c] != '\"')
  13303. {
  13304. sstr[c] = loc[2+strlen("duration")+c];
  13305. c++;
  13306. }
  13307. sstr[c] = '\0';
  13308. tempdurationInt = atoi(sstr);
  13309. }
  13310. else
  13311. {
  13312. tempdurationInt = 0;
  13313. }
  13314. //**********startSchedule**********/
  13315. c = 0;
  13316. loc = strstr(sLineWord, "startSchedule");
  13317. memset(sstr ,0, sizeof(sstr) );
  13318. while (loc[3+strlen("startSchedule")+c] != '\"')
  13319. {
  13320. sstr[c] = loc[3+strlen("startSchedule")+c];
  13321. c++;
  13322. }
  13323. sstr[c] = '\0';
  13324. strcpy(tempstartScheduleStr, sstr);
  13325. strcpy(TxProfileScheduleStr, sstr);
  13326. //**********chargingRateUnit**********/
  13327. c = 0;
  13328. loc = strstr(sLineWord, "chargingRateUnit");
  13329. memset(sstr ,0, sizeof(sstr) );
  13330. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13331. {
  13332. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13333. c++;
  13334. }
  13335. sstr[c] = '\0';
  13336. strcpy(tempchargingRateUnitStr, sstr);
  13337. //**********minChargingRate*******/
  13338. c = 0;
  13339. loc = strstr(sLineWord, "minChargingRate");
  13340. if(loc != NULL)
  13341. {
  13342. memset(sstr ,0, sizeof(sstr) );
  13343. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13344. {
  13345. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13346. c++;
  13347. }
  13348. sstr[c] = '\0';
  13349. tempminChargingRateFloat = atof(sstr);
  13350. }
  13351. else
  13352. {
  13353. tempminChargingRateFloat = 0.0;
  13354. }
  13355. //
  13356. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13357. tp.tm_isdst = -1;
  13358. time_t utc = mktime(&tp);
  13359. time_t t = time(NULL);
  13360. diff_t = difftime(t, utc);
  13361. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13362. //parsing strings to words
  13363. i = 0;
  13364. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13365. loc = loc+3+strlen("chargingSchedulePeriod");
  13366. pch = strtok(loc ,"{");
  13367. while (pch != NULL)
  13368. {
  13369. strcpy(SchedulePeriodList[i], pch);
  13370. pch = strtok (NULL, "{");
  13371. i = i + 1;
  13372. }
  13373. n_SchedulePeriods = i;
  13374. for(int i=0;i<n_SchedulePeriods;i++)
  13375. {
  13376. //*************startPeriod****************/
  13377. c = 0;
  13378. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13379. memset(sstr ,0, sizeof(sstr) );
  13380. while (loc[strlen("startPeriod")+2+c] != ',')
  13381. {
  13382. sstr[c] = loc[strlen("startPeriod")+2+c];
  13383. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13384. c++;
  13385. }
  13386. sstr[c] = '\0';
  13387. tempStartPeriodInt = atoi(sstr);
  13388. //*************limit****************/
  13389. c = 0;
  13390. loc = strstr(SchedulePeriodList[i], "limit");
  13391. memset(sstr ,0, sizeof(sstr) );
  13392. while (loc[strlen("limit")+2+c] != ',')
  13393. {
  13394. sstr[c] = loc[strlen("limit")+2+c];
  13395. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13396. c++;
  13397. }
  13398. sstr[c] = '\0';
  13399. tempLimitInt = atof(sstr);
  13400. //*************numberPhases****************/
  13401. c = 0;
  13402. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13403. memset(sstr ,0, sizeof(sstr) );
  13404. while (loc[strlen("numberPhases")+2+c] != '}')
  13405. {
  13406. sstr[c] = loc[strlen("numberPhases")+2+c];
  13407. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13408. c++;
  13409. }
  13410. sstr[c] = '\0';
  13411. tempNumberPhasesInt = atoi(sstr);
  13412. //TxProfile.Duration = durationInt;
  13413. TxProfile.TotalPeriod = n_SchedulePeriods;
  13414. TxProfile.Period[i].Limit = tempLimitInt;
  13415. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13416. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13417. }
  13418. if(MinChargingRate < tempminChargingRateFloat)
  13419. {
  13420. MinChargingRate = tempminChargingRateFloat;
  13421. }
  13422. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13423. if(confirmPeriods < n_SchedulePeriods)
  13424. confirmPeriods = n_SchedulePeriods;
  13425. if(j == 0)
  13426. {
  13427. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13428. TxProfile_TEMP.StackLevel = tempstackLevel;
  13429. TxProfile_TEMP.TransactionId = 0;
  13430. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13431. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13432. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13433. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13434. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13435. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13436. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13437. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13438. }
  13439. }
  13440. fclose(fptr1);
  13441. }
  13442. }// the end of ACCESS TxProfile
  13443. //CompositeSchedule
  13444. int period=0;
  13445. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13446. {
  13447. //TxProfile
  13448. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13449. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13450. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13451. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13452. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13453. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13454. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13455. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13456. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13457. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13458. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13459. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13460. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13461. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13462. {
  13463. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13464. {
  13465. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13466. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13467. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13468. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13469. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13470. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13471. period = period + 1;
  13472. }
  13473. else
  13474. {
  13475. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13476. {
  13477. }
  13478. else
  13479. {
  13480. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13481. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13482. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13483. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13484. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13485. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13486. period = period + 1;
  13487. }
  13488. }
  13489. }
  13490. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13491. {
  13492. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13493. {
  13494. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13495. {
  13496. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13497. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13498. }
  13499. else
  13500. {
  13501. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13502. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13503. }
  13504. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13505. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13506. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13507. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13508. period = period + 1;
  13509. }
  13510. }
  13511. }
  13512. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13513. {
  13514. //TxDefaultProfile
  13515. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13516. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13517. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13518. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13519. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13520. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13521. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13522. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13523. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13524. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13525. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13526. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13527. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13528. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13529. {
  13530. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13531. {
  13532. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13533. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13534. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13535. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13536. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13537. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13538. period = period + 1;
  13539. }
  13540. else
  13541. {
  13542. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13543. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13544. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13545. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13546. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13547. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13548. period = period + 1;
  13549. }
  13550. }
  13551. }
  13552. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13553. {
  13554. //TxDefaultProfile
  13555. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13556. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13557. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13558. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13559. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13560. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13561. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13562. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13563. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13564. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13565. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13566. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13567. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13568. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13569. {
  13570. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13571. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13572. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13573. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13574. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13575. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13576. period = period + 1;
  13577. }
  13578. }
  13579. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13580. {
  13581. //ChargePointMaxProfile
  13582. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13583. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13584. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13585. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13586. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13587. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13588. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13589. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13590. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13591. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13592. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13593. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13594. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13595. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13596. {
  13597. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13598. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13599. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13600. period = period + 1;
  13601. }
  13602. }
  13603. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13604. {
  13605. //TxProfile
  13606. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13607. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13608. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13609. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13610. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13611. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13612. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13613. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13614. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13615. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13616. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13617. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13618. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13619. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13620. {
  13621. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13622. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13623. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13624. }
  13625. }
  13626. confirmPeriods = period;
  13627. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13628. 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,"
  13629. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13630. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13631. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13632. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13633. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13634. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13635. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13636. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13637. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13638. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13639. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13640. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13641. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13642. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13643. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13644. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13645. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13646. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13647. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13648. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13649. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13650. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13651. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13652. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13653. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13654. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13655. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13656. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13657. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13658. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13659. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13660. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13661. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13662. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13663. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13664. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13665. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13666. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13667. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13668. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13669. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13670. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13671. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13672. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13673. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13674. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13675. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13676. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13677. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13678. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13679. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13680. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13681. }
  13682. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13683. {
  13684. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13685. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13686. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13687. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13688. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13689. }
  13690. int GetWebSocketPingInterval(void)
  13691. {
  13692. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13693. }
  13694. void LWS_Send(char * str)
  13695. {
  13696. //=====================================================
  13697. // Check InternetConn 0: disconnected, 1: connected
  13698. //====================================================
  13699. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13700. {
  13701. DEBUG_INFO("\n offline now !!!\n");
  13702. return;
  13703. }
  13704. pthread_mutex_lock(&lock);
  13705. memset(SendBuffer,0,SendBufLen);
  13706. sprintf((char *)SendBuffer, "%s", str);
  13707. pthread_mutex_unlock(&lock);
  13708. lws_callback_on_writable(wsi_client);
  13709. lws_service(context, 10000);//timeout_ms
  13710. }