MessageHandler.c 597 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "define.h"
  24. #include "SystemLogMessage.h"
  25. //#include "config.h"
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <stdlib.h>
  29. /*for sendfile()*/
  30. #include <sys/sendfile.h>
  31. /*for O_RDONLY*/
  32. #include <fcntl.h>
  33. #include "sqlite3.h"
  34. #include <arpa/inet.h>
  35. //#define _GNU_SOURCE
  36. #include <time.h>
  37. #include "MessageHandler.h"
  38. #include <assert.h>
  39. #include <pthread.h>
  40. #include <mcheck.h>
  41. #define PASS 1
  42. #define FAIL -1
  43. #define FALSE 0
  44. #define TRUE 1 // Option 1
  45. //ChargePointMaxProfile
  46. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  47. //TxDefaultProfile
  48. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  49. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  50. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  51. //TxProfile
  52. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  53. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  54. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  55. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  56. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  57. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  58. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  59. //===================================
  60. // Define CP State constant
  61. //===================================
  62. #define CP_STATE_UNKNOWN 0
  63. #define CP_STATE_A 1
  64. #define CP_STATE_B 2
  65. #define CP_STATE_C 3
  66. #define CP_STATE_D 4
  67. #define CP_STATE_E 5
  68. #define CP_STATE_F 6
  69. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  70. struct StatusCodeData *ShmStatusCodeData;
  71. struct PsuData *ShmPsuData ;
  72. struct OCPP16Data *ShmOCPP16Data;
  73. // define Macro
  74. #define SystemLogMessage
  75. // OCPP Message Type
  76. #define MESSAGE_TYPE_CALL 2
  77. #define MESSAGE_TYPE_CALLRESULT 3
  78. #define MESSAGE_TYPE_CALLERROR 4
  79. //
  80. #define server_cycle_Status 120
  81. #define MACROSTR(k) #k
  82. //ConfigurationMaxKeys
  83. #define GetConfigurationMaxKeysNUM 43
  84. //char guid[37];
  85. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  86. char queuedata[2600]={0};
  87. //===============================
  88. // Configuration: unknownkey
  89. //===============================
  90. static char unknownkey[10][20]={0};
  91. static int UnknownKeynum = 0;
  92. //===============================
  93. // Gun Total Numbers
  94. //===============================
  95. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  96. static int gunTotalNumber=0;
  97. //===============================
  98. // Local List Version
  99. //===============================
  100. static int localversion=0;
  101. static char idTagAuthorization[32]={0};
  102. //===============================
  103. // OCPP Path
  104. //===============================
  105. extern char OcppPath[160];
  106. extern char OcppProtocol[10];
  107. extern char OcppHost[50];
  108. extern char OcppTempPath[50];
  109. int OcppPort=0;
  110. //===============================
  111. // OCPP sign variable
  112. //===============================
  113. int server_sign = FALSE;
  114. int server_pending = FALSE;
  115. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  116. int BootNotificationInterval = 0;
  117. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  118. //===============================
  119. // OCPP auth variable
  120. //===============================
  121. int authenrequest = FALSE;
  122. int authorizeRetryTimes = 0; //number of Retry times
  123. //===============================
  124. // OCPP StartTransaction transactionId variables
  125. //===============================
  126. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  127. //===============================
  128. // OCPP other variables
  129. //===============================
  130. int isUpdateRequest = FALSE;
  131. static int HeartBeatWaitTime = 10;
  132. static int FirstHeartBeat = 0;
  133. static int FirmwareStatusNotificationStatus = 3; // Idle
  134. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  135. static char CurrentChargingProfileScheduleStr[30]={0};
  136. //========================================
  137. // OCPP status/previous related variables
  138. //========================================
  139. static int GunStatusInterval = 10;
  140. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  141. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  142. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  143. static int GbPreviousSystemStatus[GB_QUANTITY];
  144. static int AcPreviousSystemStatus[AC_QUANTITY];
  145. int TransactionMessageAttemptsValue = 0;
  146. int TransactionMessageRetryIntervalValue = 0;
  147. static struct OCPPAuthLocalElemet
  148. {
  149. int listVersionInt;
  150. char idTagstr[20];
  151. char parentIdTag[20];
  152. char expiryDate[30];
  153. char idTagstatus[16];
  154. }idTagQuery;
  155. //=============================================
  156. // OCPP HeartBeat Response Not Receive Counts
  157. //============================================
  158. static int HeartBeatWithNOResponse = 0;
  159. static int HeartBeatCountPerHour = 0;
  160. extern struct lws *wsi_client;
  161. extern struct lws_context *context;
  162. extern unsigned char SendBuffer[4096];
  163. extern int SendBufLen;
  164. extern char *random_uuid( char buf[37] );
  165. extern void split(char **arr, char *str, const char *del);
  166. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  167. extern pthread_mutex_t mutex1;
  168. extern struct Charger_Info Charger;
  169. extern sqlite3 *db;
  170. int TransactionMessageAttemptsGet(void);
  171. int TransactionMessageRetryIntervalGet(void);
  172. int GetOcppConnStatus(void);
  173. void SetOcppConnStatus(uint8_t status);
  174. int updateSetting(char *key, char *value);
  175. int setKeyValue(char *key, char *value);
  176. void OCPP_get_TableAuthlocalAllData(void);
  177. void processUnkownKey(void);
  178. struct StructOCPPMeterValue
  179. {
  180. unsigned char TimeStamp[28];
  181. struct StructSampledValue SampledValue[10];
  182. };
  183. struct ClientTime
  184. {
  185. unsigned int Heartbeat;
  186. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  187. unsigned int StartTransaction;
  188. unsigned int StopTransaction;
  189. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  190. }clientTime;
  191. typedef union
  192. {
  193. //Operations Initiated by Central System
  194. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  195. struct
  196. {
  197. //CsMsgValue[0]
  198. unsigned char StatusNotificationReq :1; //bit 0,
  199. unsigned char StatusNotificationConf :1; //bit 0,
  200. unsigned char :6; //bit 2~7
  201. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  202. }CpinitiateMsg;
  203. CpinitiateMsg cpinitateMsg;
  204. //==========================================
  205. // Init all Enumeration & Mapping String
  206. //==========================================
  207. /*ChargePointErrorCode*/
  208. typedef enum {
  209. ConnectorLockFailure,
  210. EVCommunicationError,
  211. GroundFailure,
  212. HighTemperature,
  213. InternalError,
  214. LocalListConflict,
  215. NoError,
  216. OtherError,
  217. OverCurrentFailure,
  218. OverVoltage,
  219. PowerMeterFailure,
  220. PowerSwitchFailure,
  221. ReaderFailure,
  222. ResetFailure,
  223. UnderVoltage,
  224. WeakSignal
  225. } ChargePointErrorCode;
  226. #if 0
  227. static char *ChargePointErrorCodeStr[] = {
  228. MACROSTR(ConnectorLockFailure),
  229. MACROSTR(EVCommunicationError),
  230. MACROSTR(GroundFailure),
  231. MACROSTR(HighTemperature),
  232. MACROSTR(InternalError),
  233. MACROSTR(LocalListConflict),
  234. MACROSTR(NoError),
  235. MACROSTR(OtherError),
  236. MACROSTR(OverCurrentFailure),
  237. MACROSTR(OverVoltage),
  238. MACROSTR(PowerMeterFailure),
  239. MACROSTR(PowerSwitchFailure),
  240. MACROSTR(ReaderFailure),
  241. MACROSTR(ResetFailure),
  242. MACROSTR(UnderVoltage),
  243. MACROSTR(WeakSignal)
  244. };
  245. #endif
  246. /*ChargePointStatus*/
  247. typedef enum {
  248. Available =0,
  249. Preparing,
  250. Charging,
  251. SuspendedEVSE,
  252. SuspendedEV,
  253. Finishing,
  254. Reserved,
  255. Unavailable,
  256. Faulted
  257. } ChargePointStatus;
  258. static char * ChargePointStatusStr[] = {
  259. MACROSTR(Available),
  260. MACROSTR(Preparing),
  261. MACROSTR(Charging),
  262. MACROSTR(SuspendedEVSE),
  263. MACROSTR(SuspendedEV),
  264. MACROSTR(Finishing),
  265. MACROSTR(Reserved),
  266. MACROSTR(Unavailable),
  267. MACROSTR(Faulted)
  268. };
  269. /*AvailabilityType*/
  270. typedef enum {
  271. RegistrationStatus_Accepted,
  272. RegistrationStatus_Pending,
  273. RegistrationStatus_Rejected
  274. } RegistrationStatus;
  275. static char *RegistrationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Pending),
  278. MACROSTR(Rejected)
  279. };
  280. /*AvailabilityType*/
  281. typedef enum {
  282. Inoperative,
  283. Operative
  284. } AvailabilityType;
  285. static char *AvailabilityTypeStr[] = {
  286. MACROSTR(Inoperative),
  287. MACROSTR(Operative)
  288. };
  289. /*AvailabilityStatus*/
  290. typedef enum {
  291. Accepted,
  292. Rejected,
  293. Scheduled
  294. } AvailabilityStatus;
  295. static char *AvailabilityStatusStr[] = {
  296. MACROSTR(Accepted),
  297. MACROSTR(Rejected),
  298. MACROSTR(Scheduled)
  299. };
  300. /*ConfigurationStatus*/
  301. typedef enum {
  302. ConfigurationStatus_Accepted,
  303. ConfigurationStatus_Rejected,
  304. RebootRequired,
  305. NotSupported
  306. } ConfigurationStatus;
  307. static char *ConfigurationStatusStr[] = {
  308. MACROSTR(Accepted),
  309. MACROSTR(Rejected),
  310. MACROSTR(RebootRequired),
  311. MACROSTR(NotSupported)
  312. };
  313. /*ClearCacheStatus*/
  314. typedef enum {
  315. ClearCacheStatus_Accepted,
  316. ClearCacheStatus_Rejected
  317. } ClearCacheStatus;
  318. static char *ClearCacheStatusStr[] = {
  319. MACROSTR(Accepted),
  320. MACROSTR(Rejected)
  321. };
  322. /*ChargingProfilePurposeType*/
  323. typedef enum {
  324. ChargePointMaxProfile,
  325. TxDefaultProfile,
  326. TxProfile
  327. } ChargingProfilePurposeType;
  328. static char *ChargingProfilePurposeTypeStr[] = {
  329. MACROSTR(ChargePointMaxProfile),
  330. MACROSTR(TxDefaultProfile),
  331. MACROSTR(TxProfile)
  332. };
  333. /*ChargingProfileStatus*/
  334. typedef enum {
  335. ChargingProfileStatus_Accepted,
  336. ChargingProfileStatus_Rejected,
  337. ChargingProfileStatus_NotSupported
  338. } ChargingProfileStatus;
  339. static char *ChargingProfileStatusStr[] = {
  340. MACROSTR(Accepted),
  341. MACROSTR(Rejected),
  342. MACROSTR(NotSupported)
  343. };
  344. /*ClearChargingProfileStatus*/
  345. typedef enum {
  346. ClearChargingProfileStatus_Accepted,
  347. ClearChargingProfileStatus_Unknown
  348. } ClearChargingProfileStatus;
  349. static char *ClearChargingProfileStatusStr[] = {
  350. MACROSTR(Accepted),
  351. MACROSTR(Unknown)
  352. };
  353. /*GetCompositeScheduleStatus*/
  354. typedef enum {
  355. GetCompositeScheduleStatus_Accepted,
  356. GetCompositeScheduleStatus_Rejected
  357. } GetCompositeScheduleStatus;
  358. static char *GetCompositeScheduleStatusStr[] = {
  359. MACROSTR(Accepted),
  360. MACROSTR(Rejected)
  361. };
  362. /*ChargingRateUnitType*/
  363. typedef enum {
  364. ChargingRateUnitType_W,
  365. ChargingRateUnitType_A
  366. } ChargingRateUnitType;
  367. /*AuthorizationStatus*/
  368. typedef enum {
  369. AuthorizationStatus_Accepted ,
  370. AuthorizationStatus_Blocked ,
  371. AuthorizationStatus_Expired ,
  372. AuthorizationStatus_Invalid ,
  373. AuthorizationStatus_ConcurrentTx
  374. } AuthorizationStatus;
  375. /*UpdateType*/
  376. typedef enum {
  377. Differential ,
  378. Full
  379. } UpdateType;
  380. static char *UpdateTypeStr[] = {
  381. MACROSTR(Differential),
  382. MACROSTR(Full)
  383. };
  384. /*UpdateStatus*/
  385. typedef enum {
  386. UpdateStatus_Accepted ,
  387. UpdateStatus_Failed ,
  388. UpdateStatus_NotSupported ,
  389. UpdateStatus_VersionMismatch
  390. } UpdateStatus;
  391. static char *UpdateStatusStr[] = {
  392. MACROSTR(Accepted),
  393. MACROSTR(Failed),
  394. MACROSTR(NotSupported),
  395. MACROSTR(VersionMismatch)
  396. };
  397. /*RemoteStartStopStatus*/
  398. typedef enum {
  399. RemoteStartStopStatus_Accepted,
  400. RemoteStartStopStatus_Rejected
  401. } RemoteStartStopStatus;
  402. static char *RemoteStartStopStatusStr[] = {
  403. MACROSTR(Accepted),
  404. MACROSTR(Rejected)
  405. };
  406. /*ReservationStatus*/
  407. typedef enum {
  408. ReservationStatus_Accepted,
  409. ReservationStatus_Faulted,
  410. ReservationStatus_Occupied,
  411. ReservationStatus_Rejected,
  412. ReservationStatus_Unavailable
  413. } ReservationStatus;
  414. static char *ReservationStatusStr[] = {
  415. MACROSTR(Accepted),
  416. MACROSTR(Faulted),
  417. MACROSTR(Occupied),
  418. MACROSTR(Rejected),
  419. MACROSTR(Unavailable)
  420. };
  421. /*ResetType*/
  422. typedef enum {
  423. Hard,
  424. Soft
  425. } ResetType;
  426. static char *ResetTypeStr[] = {
  427. MACROSTR(Hard),
  428. MACROSTR(Soft)
  429. };
  430. /*ResetStatus*/
  431. typedef enum {
  432. ResetStatus_Accepted,
  433. ResetStatus_Rejected
  434. } ResetStatus;
  435. static char *ResetStatusStr[] = {
  436. MACROSTR(Accepted),
  437. MACROSTR(Rejected)
  438. };
  439. /*DiagnosticsStatus*/
  440. typedef enum {
  441. DiagnosticsStatus_Idle,
  442. DiagnosticsStatus_Uploaded,
  443. DiagnosticsStatus_UploadFailed,
  444. DiagnosticsStatus_Uploading
  445. } DiagnosticsStatus;
  446. static char * DiagnosticsStatusStr[] = {
  447. MACROSTR(Idle),
  448. MACROSTR(Uploaded),
  449. MACROSTR(UploadFailed),
  450. MACROSTR(Uploading)
  451. };
  452. /*FirmwareStatus*/
  453. typedef enum {
  454. FirmwareStatus_Downloaded,
  455. FirmwareStatus_DownloadFailed,
  456. FirmwareStatus_Downloading,
  457. FirmwareStatus_Idle,
  458. FirmwareStatus_InstallationFailed,
  459. FirmwareStatus_Installing,
  460. FirmwareStatus_Installed
  461. } FirmwareStatus;
  462. static char * FirmwareStatusStr[] = {
  463. MACROSTR(Downloaded),
  464. MACROSTR(DownloadFailed),
  465. MACROSTR(Downloading),
  466. MACROSTR(Idle),
  467. MACROSTR(InstallationFailed),
  468. MACROSTR(Installing),
  469. MACROSTR(Installed)
  470. };
  471. /*MessageTrigger*/
  472. typedef enum {
  473. BootNotification,
  474. DiagnosticsStatusNotification,
  475. FirmwareStatusNotification,
  476. Heartbeat,
  477. MeterValues,
  478. StatusNotification
  479. } MessageTrigger;
  480. static char * MessageTriggerStr[] = {
  481. MACROSTR(BootNotification),
  482. MACROSTR(DiagnosticsStatusNotification),
  483. MACROSTR(FirmwareStatusNotification),
  484. MACROSTR(Heartbeat),
  485. MACROSTR(MeterValues),
  486. MACROSTR(StatusNotification)
  487. };
  488. /*TriggerMessageStatus*/
  489. typedef enum {
  490. TriggerMessageStatus_Accepted ,
  491. TriggerMessageStatus_Rejected ,
  492. TriggerMessageStatus_NotImplemented
  493. } TriggerMessageStatus;
  494. static char * TriggerMessageStatusStr[] = {
  495. MACROSTR(Accepted),
  496. MACROSTR(Rejected),
  497. MACROSTR(NotImplemented)
  498. };
  499. /*UnlockStatus*/
  500. typedef enum {
  501. Unlocked,
  502. UnlockFailed,
  503. UnlockStatus_NotSupported
  504. } UnlockStatus;
  505. static char * UnlockStatusStr[] = {
  506. MACROSTR(Unlocked),
  507. MACROSTR(UnlockFailed),
  508. MACROSTR(NotSupported)
  509. };
  510. /*StopTransactionReason*/
  511. typedef enum {
  512. EmergencyStop,
  513. EVDisconnected,
  514. HardReset,
  515. Local,
  516. Other,
  517. PowerLoss,
  518. Reboot,
  519. Remote,
  520. SoftReset,
  521. UnlockCommand,
  522. DeAuthorized
  523. } StopTransactionReason;
  524. #if 0
  525. static char * StopTransactionReasonStr[] = {
  526. MACROSTR(EmergencyStop),
  527. MACROSTR(EVDisconnected),
  528. MACROSTR(HardReset),
  529. MACROSTR(Local),
  530. MACROSTR(Other),
  531. MACROSTR(PowerLoss),
  532. MACROSTR(Reboot),
  533. MACROSTR(Remote),
  534. MACROSTR(SoftReset),
  535. MACROSTR(UnlockCommand),
  536. MACROSTR(DeAuthorized)
  537. };
  538. #endif
  539. /*CancelReservationStatus*/
  540. typedef enum {
  541. CancelReservationStatus_Accepted,
  542. CancelReservationStatus_Rejected
  543. } CancelReservationStatus;
  544. static char * CancelReservationStatusStr[] = {
  545. MACROSTR(Accepted),
  546. MACROSTR(Rejected)
  547. };
  548. /*ReadingContext*/
  549. typedef enum {
  550. ReadingContext_Interruption_Begin,
  551. ReadingContext_Interruption_End,
  552. ReadingContext_Other,
  553. ReadingContext_Sample_Clock,
  554. ReadingContext_Sample_Periodic ,
  555. ReadingContext_Transaction_Begin ,
  556. ReadingContext_Transaction_End,
  557. ReadingContext_Trigger
  558. } ReadingContext;
  559. static char * ReadingContextStr[] = {
  560. MACROSTR(Interruption.Begin),
  561. MACROSTR(Interruption.End),
  562. MACROSTR(Other),
  563. MACROSTR(Sample.Clock),
  564. MACROSTR(Sample.Periodic),
  565. MACROSTR(Transaction.Begin),
  566. MACROSTR(Transaction.End),
  567. MACROSTR(Trigger)
  568. };
  569. /*ValueFormat*/
  570. typedef enum {
  571. Raw,
  572. SignedData
  573. } ValueFormat;
  574. static char * ValueFormatStr[] = {
  575. MACROSTR(Raw),
  576. MACROSTR(SignedData)
  577. };
  578. /*Measurand*/
  579. typedef enum {
  580. Current_Export ,
  581. Current_Import,
  582. Current_Offered,
  583. Energy_Active_Export_Register,
  584. Energy_Active_Import_Register,
  585. Energy_Reactive_Export_Register,
  586. Energy_Reactive_Import_Register,
  587. Energy_Active_Export_Interval,
  588. Energy_Active_Import_Interval,
  589. Energy_Reactive_Export_Interval,
  590. Energy_Reactive_Import_Interval,
  591. Frequency,
  592. Power_Active_Export ,
  593. Power_Active_Import,
  594. Power_Factor,
  595. Power_Offered,
  596. Power_Reactive_Export,
  597. Power_Reactive_Import,
  598. RPM,
  599. SoC,
  600. Temperature ,
  601. Voltage
  602. } Measurand;
  603. static char * MeasurandStr[] = {
  604. MACROSTR(Current.Export),
  605. MACROSTR(Current.Import),
  606. MACROSTR(Current.Offered),
  607. MACROSTR(Energy.Active.Export.Register),
  608. MACROSTR(Energy.Active.Import.Register),
  609. MACROSTR(Energy.Reactive.Export.Register),
  610. MACROSTR(Energy.Reactive.Import.Register),
  611. MACROSTR(Energy.Active.Export.Interval),
  612. MACROSTR(Energy.Active.Import.Interval),
  613. MACROSTR(Energy.Reactive.Export.Interval),
  614. MACROSTR(Energy.Reactive.Import.Interval),
  615. MACROSTR(Frequency),
  616. MACROSTR(Power.Active.Export),
  617. MACROSTR(Power.Active.Import),
  618. MACROSTR(Power.Factor),
  619. MACROSTR(Power.Offered),
  620. MACROSTR(Power.Reactive.ExportMACROSTR),
  621. MACROSTR(Power.Reactive.Import),
  622. MACROSTR(RPM),
  623. MACROSTR(SoC),
  624. MACROSTR(Temperature),
  625. MACROSTR(Voltage)
  626. };
  627. /*Location*/
  628. typedef enum {
  629. Location_Body,
  630. Location_Cable,
  631. Location_EV,
  632. Location_Inlet ,
  633. Location_Outlet
  634. } Location;
  635. static char * LocationStr[] = {
  636. MACROSTR(Body),
  637. MACROSTR(Cable),
  638. MACROSTR(EV),
  639. MACROSTR(Inlet),
  640. MACROSTR(Outlet)
  641. };
  642. /*Phase*/
  643. typedef enum {
  644. L1,
  645. L2,
  646. L3,
  647. N,
  648. L1_N,
  649. L2_N,
  650. L3_N,
  651. L1_L2,
  652. L2_L3,
  653. L3_L1
  654. } Phase;
  655. static char * PhaseStr[] = {
  656. MACROSTR(L1),
  657. MACROSTR(L2),
  658. MACROSTR(L3),
  659. MACROSTR(N),
  660. MACROSTR(L1-N),
  661. MACROSTR(L2-N),
  662. MACROSTR(L3-N),
  663. MACROSTR(L1-L2),
  664. MACROSTR(L2-L3),
  665. MACROSTR(L3-L1)
  666. };
  667. /*UnitOfMeasure*/
  668. typedef enum {
  669. UnitOfMeasure_Wh,
  670. UnitOfMeasure_kWh ,
  671. UnitOfMeasure_varh ,
  672. UnitOfMeasure_kvarh ,
  673. UnitOfMeasure_W ,
  674. UnitOfMeasure_kW ,
  675. UnitOfMeasure_VA ,
  676. UnitOfMeasure_kVA ,
  677. UnitOfMeasure_var ,
  678. UnitOfMeasure_kvar ,
  679. UnitOfMeasure_A ,
  680. UnitOfMeasure_V ,
  681. UnitOfMeasure_Celsius ,
  682. UnitOfMeasure_Fahrenheit ,
  683. UnitOfMeasure_K ,
  684. UnitOfMeasure_Percent
  685. } UnitOfMeasure;
  686. static char * UnitOfMeasureStr[] = {
  687. MACROSTR(Wh),
  688. MACROSTR(kWh),
  689. MACROSTR(varh),
  690. MACROSTR(kvarh),
  691. MACROSTR(W),
  692. MACROSTR(kW),
  693. MACROSTR(VA),
  694. MACROSTR(kVA),
  695. MACROSTR(var),
  696. MACROSTR(kvar),
  697. MACROSTR(A),
  698. MACROSTR(V),
  699. MACROSTR(Celsius),
  700. MACROSTR(Fahrenheit),
  701. MACROSTR(K),
  702. MACROSTR(Percent)
  703. };
  704. #if 0
  705. /*Configuration enum*/
  706. enum CoreProfile {
  707. AllowOfflineTxForUnknownId=0,
  708. AuthorizationCacheEnabled,
  709. AuthorizeRemoteTxRequests,
  710. BlinkRepeat,
  711. ClockAlignedDataInterval,
  712. ConnectionTimeOut,
  713. GetConfigurationMaxKeys,
  714. HeartbeatInterval,
  715. LightIntensity,
  716. LocalAuthorizeOffline,
  717. LocalPreAuthorize,
  718. MaxEnergyOnInvalidId,
  719. MeterValuesAlignedData,
  720. MeterValuesAlignedDataMaxLength,
  721. MeterValuesSampledData,
  722. MeterValuesSampledDataMaxLength,
  723. MeterValueSampleInterval,
  724. MinimumStatusDuration,
  725. NumberOfConnectors,
  726. ResetRetries,
  727. ConnectorPhaseRotation,
  728. ConnectorPhaseRotationMaxLength,
  729. StopTransactionOnEVSideDisconnect,
  730. StopTransactionOnInvalidId,
  731. StopTxnAlignedData,
  732. StopTxnAlignedDataMaxLength,
  733. StopTxnSampledData,
  734. StopTxnSampledDataMaxLength,
  735. SupportedFeatureProfiles,
  736. SupportedFeatureProfilesMaxLength,
  737. TransactionMessageAttempts,
  738. TransactionMessageRetryInterval,
  739. UnlockConnectorOnEVSideDisconnect,
  740. WebSocketPingInterval,
  741. _CoreProfile_CNT
  742. };
  743. #endif
  744. enum LocalAuthListManagementProfile{
  745. LocalAuthListEnabled=0,
  746. LocalAuthListMaxLength,
  747. SendLocalListMaxLength,
  748. _LocalAuthListManagementProfile_CNT
  749. };
  750. enum ReservationProfile{
  751. ReserveConnectorZeroSupported
  752. };
  753. enum SmartChargingProfile{
  754. ChargeProfileMaxStackLevel,
  755. ChargingScheduleAllowedChargingRateUnit,
  756. ChargingScheduleMaxPeriods,
  757. ConnectorSwitch3to1PhaseSupported,
  758. MaxChargingProfilesInstalled
  759. };
  760. enum ChargerSystemStatus{
  761. ChargerSystemStatus_Booting,
  762. ChargerSystemStatus_Idle,
  763. ChargerSystemStatus_Authorizing,
  764. ChargerSystemStatus_Preparing,
  765. ChargerSystemStatus_Charging,
  766. ChargerSystemStatus_Terminating,
  767. ChargerSystemStatus_Alarm,
  768. ChargerSystemStatus_Fault
  769. };
  770. enum GetConfigurationKey {
  771. GetConfiguration_AllowOfflineTxForUnknownId=0,
  772. GetConfiguration_AuthorizationCacheEnabled,
  773. GetConfiguration_AuthorizeRemoteTxRequests,
  774. GetConfiguration_BlinkRepeat,
  775. GetConfiguration_ClockAlignedDataInterval,
  776. GetConfiguration_ConnectionTimeOut,
  777. GetConfiguration_GetConfigurationMaxKeys,
  778. GetConfiguration_HeartbeatInterval,
  779. GetConfiguration_LightIntensity,
  780. GetConfiguration_LocalAuthorizeOffline,
  781. GetConfiguration_LocalPreAuthorize,
  782. GetConfiguration_MaxEnergyOnInvalidId,
  783. GetConfiguration_MeterValuesAlignedData,
  784. GetConfiguration_MeterValuesAlignedDataMaxLength,
  785. GetConfiguration_MeterValuesSampledData,
  786. GetConfiguration_MeterValuesSampledDataMaxLength,
  787. GetConfiguration_MeterValueSampleInterval,
  788. GetConfiguration_MinimumStatusDuration,
  789. GetConfiguration_NumberOfConnectors,
  790. GetConfiguration_ResetRetries,
  791. GetConfiguration_ConnectorPhaseRotation,
  792. GetConfiguration_ConnectorPhaseRotationMaxLength,
  793. GetConfiguration_StopTransactionOnEVSideDisconnect,
  794. GetConfiguration_StopTransactionOnInvalidId,
  795. GetConfiguration_StopTxnAlignedData,
  796. GetConfiguration_StopTxnAlignedDataMaxLength,
  797. GetConfiguration_StopTxnSampledData,
  798. GetConfiguration_StopTxnSampledDataMaxLength,
  799. GetConfiguration_SupportedFeatureProfiles,
  800. GetConfiguration_SupportedFeatureProfilesMaxLength,
  801. GetConfiguration_TransactionMessageAttempts,
  802. GetConfiguration_TransactionMessageRetryInterval,
  803. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  804. GetConfiguration_WebSocketPingInterval,
  805. GetConfiguration_LocalAuthListEnabled,
  806. GetConfiguration_LocalAuthListMaxLength,
  807. GetConfiguration_SendLocalListMaxLength,
  808. GetConfiguration_ReserveConnectorZeroSupported,
  809. GetConfiguration_ChargeProfileMaxStackLevel,
  810. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  811. GetConfiguration_ChargingScheduleMaxPeriods,
  812. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  813. GetConfiguration_MaxChargingProfilesInstalled,
  814. };
  815. //GetConfiguration Array
  816. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  817. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  818. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  819. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  820. //==========================================
  821. // Init all share memory
  822. //==========================================
  823. int InitShareMemory()
  824. {
  825. int result = PASS;
  826. int MeterSMId;
  827. //creat ShmSysConfigAndInfo
  828. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  829. {
  830. #ifdef SystemLogMessage
  831. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  832. #endif
  833. result = FAIL;
  834. }
  835. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  836. {
  837. #ifdef SystemLogMessage
  838. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  839. #endif
  840. result = FAIL;
  841. }
  842. else
  843. {}
  844. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  845. {
  846. #ifdef SystemLogMessage
  847. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  848. #endif
  849. result = FAIL;
  850. }
  851. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else
  859. {}
  860. //creat ShmPsuData
  861. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  862. {
  863. #ifdef SystemLogMessage
  864. DEBUG_ERROR("shmget ShmPsuData NG\n");
  865. #endif
  866. result = FAIL;
  867. }
  868. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmat ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else
  876. {}
  877. //creat ShmOCPP16Data
  878. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  879. {
  880. #ifdef SystemLogMessage
  881. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  882. #endif
  883. result = FAIL;
  884. }
  885. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else
  893. {}
  894. /****************************** For Initial Settings************************************************/
  895. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  896. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  897. {
  898. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  899. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  900. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  901. }
  902. // Charger PRE_SYS_MODE
  903. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  904. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  905. clientTime.Heartbeat=time((time_t*)NULL);
  906. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  907. {
  908. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  909. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  910. }
  911. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  912. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  913. // allocate Configuration memory address
  914. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  915. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  916. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  917. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  919. {
  920. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  921. DEBUG_INFO("DC ...\n");
  922. }
  923. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  924. {
  925. SystemInitial = AC_QUANTITY;
  926. DEBUG_INFO("AC ...\n");
  927. }
  928. //Status Setting
  929. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  930. {
  931. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  932. }
  933. for (int index = 0; index < CCS_QUANTITY; index++)
  934. {
  935. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  936. }
  937. for (int index = 0; index < GB_QUANTITY; index++)
  938. {
  939. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  940. }
  941. for (int index = 0; index < AC_QUANTITY; index++)
  942. {
  943. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  944. }
  945. return result;
  946. }
  947. int ProcessShareMemory()
  948. {
  949. if(InitShareMemory() == FAIL)
  950. {
  951. #ifdef SystemLogMessage
  952. DEBUG_ERROR("InitShareMemory NG\n");
  953. #endif
  954. if(ShmStatusCodeData!=NULL)
  955. {
  956. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  957. }
  958. sleep(5);
  959. return FAIL;
  960. }
  961. return PASS;
  962. }
  963. //---------------------------------------------
  964. // new:
  965. // enum SYSTEM_STATUS
  966. // {
  967. // SYS_MODE_BOOTING = 0,
  968. // SYS_MODE_IDLE = 1,
  969. // SYS_MODE_AUTHORIZING = 2,
  970. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  971. // SYS_MODE_REASSIGN = 4,
  972. // SYS_MODE_PREPARING = 5,
  973. // SYS_MODE_PREPARE_FOR_EV = 6,
  974. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  975. // SYS_MODE_CHARGING = 8,
  976. // SYS_MODE_TERMINATING = 9,
  977. // SYS_MODE_COMPLETE = 10,
  978. // SYS_MODE_ALARM = 11,
  979. // SYS_MODE_FAULT = 12,
  980. // SYS_MODE_RESERVATION = 13,
  981. // SYS_MODE_BOOKING = 14,
  982. // SYS_MODE_MAINTAIN = 15,
  983. // SYS_MODE_DEBUG = 16,
  984. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  985. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  986. // SYS_MODE_UPDATE = 19
  987. // };
  988. //
  989. //
  990. //-----------------------------------------
  991. void CheckSystemValue(void)
  992. {
  993. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  994. int IdleModeCnt = 0;
  995. char filenmae[100]={0};
  996. char str[100]={0};
  997. //===============================
  998. // send Heartbeat
  999. //===============================
  1000. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1001. {
  1002. printf("Heartbeat !!!\n");
  1003. //parameter for test
  1004. sendHeartbeatRequest(0);
  1005. //==============================================
  1006. // Reset Waiting Time
  1007. //==============================================
  1008. clientTime.Heartbeat=time((time_t*)NULL);
  1009. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1010. }
  1011. //==============================================
  1012. // Update firmware request
  1013. //==============================================
  1014. if(isUpdateRequest == TRUE )
  1015. {
  1016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1017. {
  1018. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1019. {
  1020. //check SystemStatus
  1021. /*************************DC*******************************/
  1022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1023. {
  1024. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1025. {
  1026. IdleModeCnt = IdleModeCnt + 1;
  1027. }
  1028. }
  1029. for (int index = 0; index < CCS_QUANTITY; index++)
  1030. {
  1031. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1032. {
  1033. IdleModeCnt = IdleModeCnt + 1;
  1034. }
  1035. }
  1036. for (int index = 0; index < GB_QUANTITY; index++)
  1037. {
  1038. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1039. {
  1040. IdleModeCnt = IdleModeCnt + 1;
  1041. }
  1042. }
  1043. }
  1044. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1045. {
  1046. isUpdateRequest = FALSE;
  1047. }
  1048. }
  1049. else
  1050. {
  1051. /*************************AC*******************************/
  1052. for (int index = 0; index < AC_QUANTITY; index++)
  1053. {
  1054. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1055. {
  1056. IdleModeCnt = IdleModeCnt + 1;
  1057. }
  1058. }
  1059. if(IdleModeCnt == AC_QUANTITY)
  1060. {
  1061. isUpdateRequest = FALSE;
  1062. }
  1063. }
  1064. }
  1065. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1066. {
  1067. //===============================
  1068. // CSU Trigger Reset Conf
  1069. //===============================
  1070. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1071. {
  1072. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1073. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1074. {
  1075. server_sign = FALSE;
  1076. }
  1077. }
  1078. //===============================
  1079. // CSU Trigger Authorize Request
  1080. //===============================
  1081. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1082. {
  1083. sendAuthorizeRequest(0);
  1084. authorizeRetryTimes = authorizeRetryTimes + 1;
  1085. // authenrequest = TRUE
  1086. if(authorizeRetryTimes < 3)
  1087. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1088. }
  1089. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1090. {
  1091. authorizeRetryTimes = 0;
  1092. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1093. server_sign = FALSE;
  1094. }
  1095. 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))
  1096. {
  1097. sendAuthorizeRequest(0);
  1098. }
  1099. //===============================
  1100. // CSU Trigger Smart Charging Profilw
  1101. //===============================
  1102. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1103. {
  1104. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1105. GetChargingProfileRequest(gun_index);
  1106. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1107. }
  1108. //==============================================
  1109. // Charger start transaction
  1110. //==============================================
  1111. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1112. {
  1113. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1114. sendStartTransactionRequest(gun_index);
  1115. clientTime.StartTransaction = time((time_t*)NULL);
  1116. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1117. }
  1118. //==============================================
  1119. // Charger stop transaction
  1120. //==============================================
  1121. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1122. {
  1123. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1124. sendStopTransactionRequest(gun_index);
  1125. clientTime.StopTransaction = time((time_t*)NULL);
  1126. }
  1127. //==============================================
  1128. // Charger status report
  1129. //==============================================
  1130. /* Check Mode Change */
  1131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1132. {
  1133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1134. {
  1135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1136. {
  1137. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1138. {
  1139. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1140. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1141. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1142. statusModeChage[gun_index] = TRUE;
  1143. }
  1144. }
  1145. }
  1146. for (int index = 0; index < CCS_QUANTITY; index++)
  1147. {
  1148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1149. {
  1150. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1151. {
  1152. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1153. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1154. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1155. statusModeChage[gun_index] = TRUE;
  1156. }
  1157. }
  1158. }
  1159. for (int index = 0; index < GB_QUANTITY; index++)
  1160. {
  1161. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1162. {
  1163. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1164. {
  1165. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1166. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1167. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1168. statusModeChage[gun_index] = TRUE;
  1169. }
  1170. }
  1171. }
  1172. }
  1173. else //AC
  1174. {
  1175. for (int index = 0; index < AC_QUANTITY; index++)
  1176. {
  1177. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1178. {
  1179. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1180. {
  1181. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1182. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1183. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1184. statusModeChage[gun_index] = TRUE;
  1185. }
  1186. }
  1187. }// END OF FOR
  1188. }// END OF ELSE
  1189. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1190. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1191. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1192. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1193. {
  1194. if(SystemInitial != 0)
  1195. SystemInitial = SystemInitial -1;
  1196. sendStatusNotificationRequest(gun_index);
  1197. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1198. statusModeChage[gun_index] = FALSE;
  1199. }
  1200. //==============================================
  1201. // Meter report
  1202. //==============================================
  1203. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1204. {
  1205. //check Transaction active
  1206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1207. {
  1208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1209. {
  1210. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1211. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1212. {
  1213. meterValueSend[gun_index] =1;
  1214. }
  1215. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1216. {
  1217. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1218. if((access(filenmae,F_OK))!=-1)
  1219. {
  1220. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1221. sprintf(str,"rm -f %s",filenmae);
  1222. system(str);
  1223. }
  1224. }
  1225. }// End for CHAdeMO
  1226. for (int index = 0; index < CCS_QUANTITY; index++)
  1227. {
  1228. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1229. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1230. {
  1231. meterValueSend[gun_index] =1;
  1232. }
  1233. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1234. {
  1235. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1236. if((access(filenmae,F_OK))!=-1)
  1237. {
  1238. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1239. sprintf(str,"rm -f %s",filenmae);
  1240. system(str);
  1241. }
  1242. }
  1243. } // End for CCS
  1244. for (int index = 0; index < GB_QUANTITY; index++)
  1245. {
  1246. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1247. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1248. {
  1249. meterValueSend[gun_index] =1;
  1250. }
  1251. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1252. {
  1253. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1254. if((access(filenmae,F_OK))!=-1)
  1255. {
  1256. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1257. sprintf(str,"rm -f %s",filenmae);
  1258. system(str);
  1259. }
  1260. }
  1261. }// End for GB
  1262. }
  1263. else
  1264. {
  1265. for (int index = 0; index < AC_QUANTITY; index++)
  1266. {
  1267. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1268. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1269. {
  1270. meterValueSend[gun_index] =1;
  1271. }
  1272. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1273. {
  1274. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1275. if((access(filenmae,F_OK))!=-1)
  1276. {
  1277. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1278. sprintf(str,"rm -f %s",filenmae);
  1279. system(str);
  1280. }
  1281. }
  1282. }//End for AC
  1283. }//END OF ELSE
  1284. // sleep(1);
  1285. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1286. if(meterValueSend[gun_index] == 1)
  1287. sendMeterValuesRequest(gun_index);
  1288. }
  1289. //==============================================
  1290. // Check Connector reserved
  1291. //==============================================
  1292. //===============================
  1293. // Check if Reserve is expired
  1294. //===============================
  1295. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1296. {
  1297. double diff_t;
  1298. struct tm tp;
  1299. // current time
  1300. time_t t = time(NULL);
  1301. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1302. tp.tm_isdst = -1;
  1303. time_t utc = mktime(&tp);
  1304. diff_t = difftime(utc, t);
  1305. if(diff_t <= 0)
  1306. {
  1307. DEBUG_INFO("reserve expired !!! \n");
  1308. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1309. }
  1310. }//END OF Check if Reserve is expired
  1311. //==========================================
  1312. // csu trigger FirmwareStatusNotificationReq
  1313. //==========================================
  1314. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1315. {
  1316. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1317. }
  1318. //==========================================
  1319. // csu trigger CancelReservationConf
  1320. //==========================================
  1321. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1322. {
  1323. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1324. }
  1325. //==========================================
  1326. // csu trigger ChangeAvailabilityConf
  1327. //==========================================
  1328. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1329. {
  1330. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1331. }
  1332. //==========================================
  1333. // csu trigger UnlockConnectorConf
  1334. //==========================================
  1335. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1336. {
  1337. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1338. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1339. }
  1340. //==========================================
  1341. // csu trigger ReserveNowConf
  1342. //==========================================
  1343. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1344. {
  1345. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1346. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1347. }
  1348. //==========================================
  1349. // csu trigger DataTransferReq
  1350. //==========================================
  1351. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1352. {
  1353. sendDataTransferRequest(gun_index);
  1354. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1355. }
  1356. }
  1357. }
  1358. //==========================================
  1359. // send request routine
  1360. //==========================================
  1361. int sendAuthorizeRequest(int gun_index)
  1362. {
  1363. mtrace();
  1364. int result = FAIL;
  1365. char message[100]={0};
  1366. char guid[37];
  1367. char tempdata[65]={0};
  1368. DEBUG_INFO("sendAuthorizeRequest \n");
  1369. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1370. //Local Authorize
  1371. 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)))
  1372. {
  1373. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1374. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1375. {
  1376. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1377. {
  1378. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1379. }
  1380. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1381. {
  1382. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1383. }
  1384. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1385. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1386. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1387. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1388. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1389. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1390. authorizeRetryTimes = 0;
  1391. return result;
  1392. }
  1393. else
  1394. {
  1395. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1396. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1397. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1398. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1399. result = PASS;
  1400. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1401. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1402. authorizeRetryTimes = 0;
  1403. return result;
  1404. }
  1405. }
  1406. //initailize struct Authorize
  1407. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1408. //get data from shared memory
  1409. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1410. random_uuid(guid);
  1411. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1412. LWS_Send(message);
  1413. sprintf(tempdata, "Authorize,%d", gun_index);
  1414. if(hashmap_operation(0, guid, tempdata) == 1)
  1415. {
  1416. result = PASS;
  1417. DEBUG_ERROR("Authorize mapItem pass\n");
  1418. }
  1419. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1420. return result;
  1421. }
  1422. int sendBootNotificationRequest(void)
  1423. {
  1424. mtrace();
  1425. int result = FAIL;
  1426. char message[500]={0}, payload[700]={0};
  1427. char guid[37]={0};
  1428. char tempdata[65]={0};
  1429. int IsGunCharging = FALSE;
  1430. //check Transaction active
  1431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1432. {
  1433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1434. {
  1435. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1436. {
  1437. IsGunCharging = TRUE;
  1438. }
  1439. }
  1440. for (int index = 0; index < CCS_QUANTITY; index++)
  1441. {
  1442. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1443. {
  1444. IsGunCharging = TRUE;
  1445. }
  1446. }
  1447. for (int index = 0; index < GB_QUANTITY; index++)
  1448. {
  1449. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1450. {
  1451. IsGunCharging = TRUE;
  1452. }
  1453. }
  1454. }
  1455. else
  1456. {
  1457. for (int index = 0; index < AC_QUANTITY; index++)
  1458. {
  1459. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1460. {
  1461. IsGunCharging = TRUE;
  1462. }
  1463. }
  1464. }
  1465. if(IsGunCharging == TRUE)
  1466. {
  1467. server_sign = TRUE;
  1468. return result;
  1469. }
  1470. // Fill BootNotification fields
  1471. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1472. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1473. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1474. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1475. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1476. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1477. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1478. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1479. ShmOCPP16Data->ChargeBoxId
  1480. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1481. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1482. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1483. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1484. ,ShmOCPP16Data->BootNotification.CpIccid
  1485. ,ShmOCPP16Data->BootNotification.CpImsi
  1486. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1487. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1488. random_uuid(guid);
  1489. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1490. LWS_Send(message);
  1491. sprintf(tempdata, "BootNotification,0");
  1492. 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*/)
  1493. {
  1494. result = PASS;
  1495. }
  1496. memset(queuedata, 0, sizeof(queuedata));
  1497. strcpy(queuedata,message);
  1498. return result;
  1499. }
  1500. int sendDataTransferRequest(int gun_index)
  1501. {
  1502. mtrace();
  1503. char message[1000]={0};
  1504. char guid[37]={0};
  1505. char tempdata[65]={0};
  1506. int result = FAIL;
  1507. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1508. random_uuid(guid);
  1509. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1510. MESSAGE_TYPE_CALL,
  1511. guid,
  1512. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1513. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1514. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1515. LWS_Send(message);
  1516. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1517. 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*/)
  1518. {
  1519. result = PASS;
  1520. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1521. }
  1522. return result;
  1523. }
  1524. int sendDiagnosticsStatusNotificationRequest(char *status)
  1525. {
  1526. mtrace();
  1527. int result = FAIL;
  1528. char message[110]={0};
  1529. char guid[37]={0};
  1530. char tempdata[65]={0};
  1531. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1532. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1533. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1534. random_uuid(guid);
  1535. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1536. LWS_Send(message);
  1537. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1538. if(hashmap_operation(0, guid, tempdata) == 1)
  1539. {
  1540. result = PASS;
  1541. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1542. }
  1543. //#ifdef SystemLogMessage
  1544. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1545. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1546. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1547. //#endif
  1548. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1549. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1550. //record status
  1551. if(strcmp(status,"Idle")==0)
  1552. {
  1553. DiagnosticsStatusNotificationStatus = 0;
  1554. }
  1555. else if(strcmp(status,"Uploaded")==0)
  1556. {
  1557. DiagnosticsStatusNotificationStatus = 1;
  1558. }
  1559. else if(strcmp(status,"UploadFailed")==0)
  1560. {
  1561. DiagnosticsStatusNotificationStatus = 2;
  1562. }
  1563. else if(strcmp(status,"Uploading")==0)
  1564. {
  1565. DiagnosticsStatusNotificationStatus = 3;
  1566. }
  1567. return result;
  1568. }
  1569. int sendFirmwareStatusNotificationRequest(char *status)
  1570. {
  1571. mtrace();
  1572. int result = FAIL;
  1573. char message[110]={0};
  1574. char guid[37]={0};
  1575. char tempdata[65]={0};
  1576. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1577. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1578. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1579. random_uuid(guid);
  1580. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1581. LWS_Send(message);
  1582. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1583. 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*/)
  1584. {
  1585. result = PASS;
  1586. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1587. }
  1588. //#ifdef SystemLogMessage
  1589. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1590. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1591. //#endif
  1592. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1593. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1594. //record status
  1595. if(strcmp(status,"Downloaded")==0)
  1596. {
  1597. FirmwareStatusNotificationStatus = 0;
  1598. }
  1599. else if(strcmp(status,"DownloadFailed")==0)
  1600. {
  1601. FirmwareStatusNotificationStatus = 1;
  1602. }
  1603. else if(strcmp(status,"Downloading")==0)
  1604. {
  1605. FirmwareStatusNotificationStatus = 2;
  1606. }
  1607. else if(strcmp(status,"Idle")==0)
  1608. {
  1609. FirmwareStatusNotificationStatus = 3;
  1610. }
  1611. else if(strcmp(status,"InstallationFailed")==0)
  1612. {
  1613. FirmwareStatusNotificationStatus = 4;
  1614. }
  1615. else if(strcmp(status,"Installing")==0)
  1616. {
  1617. FirmwareStatusNotificationStatus = 5;
  1618. }
  1619. else if(strcmp(status,"Installed")==0)
  1620. {
  1621. FirmwareStatusNotificationStatus = 6;
  1622. }
  1623. return result;
  1624. }
  1625. int sendHeartbeatRequest(int gun_index)
  1626. {
  1627. mtrace();
  1628. int result = FAIL;
  1629. char message[80]={0};
  1630. char guid[37]={0};
  1631. char tempdata[65]={0};
  1632. random_uuid(guid);
  1633. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1634. , MESSAGE_TYPE_CALL
  1635. , guid );
  1636. LWS_Send(message);
  1637. sprintf(tempdata, "Heartbeat,%d", 0);
  1638. 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*/)
  1639. {
  1640. result = PASS;
  1641. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1642. }
  1643. return result;
  1644. }
  1645. int sendStartTransactionRequest(int gun_index)
  1646. {
  1647. mtrace();
  1648. int result = FAIL;
  1649. char message[250]={0};
  1650. char guid[37]={0};
  1651. struct timeval tmnow;
  1652. struct tm *tm;
  1653. char buf[28];//, usec_buf[6];
  1654. char tempdata[65]={0};
  1655. DEBUG_INFO("sendStartTransactionRequest...");
  1656. gettimeofday(&tmnow, NULL);
  1657. time_t t;
  1658. t = time(NULL);
  1659. /*UTC time and date*/
  1660. tm = gmtime(&t);
  1661. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1662. #if 0 // remove temporally
  1663. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1664. strcat(buf,".");
  1665. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1666. strcat(buf,usec_buf);
  1667. #endif
  1668. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1669. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1670. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1672. {
  1673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1674. {
  1675. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1676. {
  1677. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1678. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1679. }
  1680. }
  1681. for (int index = 0; index < CCS_QUANTITY; index++)
  1682. {
  1683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1684. {
  1685. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1686. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1687. }
  1688. }
  1689. for (int index = 0; index < GB_QUANTITY; index++)
  1690. {
  1691. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1692. {
  1693. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1694. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1695. }
  1696. }
  1697. }
  1698. else
  1699. {
  1700. for (int index = 0; index < AC_QUANTITY; index++)
  1701. {
  1702. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1703. {
  1704. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1705. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1706. }
  1707. }
  1708. }//END OF ELSE
  1709. random_uuid(guid);
  1710. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1711. , MESSAGE_TYPE_CALL
  1712. , guid
  1713. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1714. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1715. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1716. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1717. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1718. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1719. 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*/)
  1720. {
  1721. result = PASS;
  1722. }
  1723. strcpy(queuedata, message);
  1724. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1725. LWS_Send(message);
  1726. #if 0
  1727. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1728. 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*/)
  1729. {
  1730. result = PASS;
  1731. }
  1732. strcpy(queuedata, message);
  1733. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1734. #endif
  1735. //#ifdef SystemLogMessage
  1736. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1737. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1738. //#endif
  1739. return result;
  1740. }
  1741. int sendStatusNotificationRequest(int gun_index)
  1742. {
  1743. mtrace();
  1744. int result = FAIL;
  1745. char message[600]={0};
  1746. char guid[37];
  1747. int currentStatus = 0;
  1748. struct timeval tmnow;
  1749. struct tm *tm;
  1750. char buf[28];//, usec_buf[6];
  1751. char tempdata[65]={0};
  1752. gettimeofday(&tmnow, NULL);
  1753. time_t t;
  1754. t = time(NULL);
  1755. /*UTC time and date*/
  1756. tm = gmtime(&t);
  1757. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1758. #if 0 // remove temporally
  1759. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1760. strcat(buf,".");
  1761. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1762. strcat(buf,usec_buf);
  1763. #endif
  1764. printf("%s",buf);
  1765. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1766. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1767. // it's option
  1768. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1769. /*
  1770. enum _SYSTEM_STATUS
  1771. {
  1772. S_BOOTING = 0,
  1773. S_IDLE, = 1
  1774. S_AUTHORIZING, =2
  1775. S_REASSIGN_CHECK, =3
  1776. S_REASSIGN, =4
  1777. S_PRECHARGE, =5
  1778. S_PREPARING_FOR_EV, =6
  1779. S_PREPARING_FOR_EVSE, =7
  1780. S_CHARGING, =8
  1781. S_TERMINATING, =9
  1782. S_COMPLETE, =10
  1783. S_ALARM, =11
  1784. S_FAULT =12
  1785. }
  1786. */
  1787. //check Transaction active
  1788. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1789. {
  1790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1791. {
  1792. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1793. {
  1794. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1795. {
  1796. currentStatus = 1; //OCPP Status: Preparing
  1797. }
  1798. else
  1799. {
  1800. currentStatus = 0; //OCPP Status: Available
  1801. }
  1802. }
  1803. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1804. {
  1805. currentStatus = 1; //OCPP Status: Preparing
  1806. }
  1807. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1808. {
  1809. currentStatus = 2; //OCPP Status: Charging
  1810. }
  1811. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1812. {
  1813. currentStatus = 5; //OCPP Status: Finishing
  1814. }
  1815. 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
  1816. {
  1817. currentStatus = 4; //OCPP Status: SuspendedEV
  1818. }
  1819. 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
  1820. {
  1821. currentStatus = 7; //OCPP Status: Unavailable
  1822. }
  1823. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1824. {
  1825. currentStatus = 8; //OCPP Status: Faulted
  1826. }
  1827. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1828. {
  1829. currentStatus = 6; //OCPP Status: Reserved
  1830. }
  1831. }//end of for CHAdeMO_QUANTITY
  1832. for (int index = 0; index < CCS_QUANTITY; index++)
  1833. {
  1834. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1835. {
  1836. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1837. {
  1838. currentStatus = 1; //OCPP Status: Preparing
  1839. }
  1840. else
  1841. {
  1842. currentStatus = 0; //OCPP Status: Available
  1843. }
  1844. }
  1845. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1846. {
  1847. currentStatus = 1; //OCPP Status: Preparing
  1848. }
  1849. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1850. {
  1851. currentStatus = 2; //OCPP Status: Charging
  1852. }
  1853. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1854. {
  1855. currentStatus = 5; //OCPP Status: Finishing
  1856. }
  1857. 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
  1858. {
  1859. currentStatus = 4; //OCPP Status: SuspendedEV
  1860. }
  1861. 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
  1862. {
  1863. currentStatus = 7; //OCPP Status : Unavailable
  1864. }
  1865. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1866. {
  1867. currentStatus = 8; //OCPP Status: Faulted
  1868. }
  1869. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1870. {
  1871. currentStatus = 6; //OCPP Status: Reserved
  1872. }
  1873. }
  1874. for (int index = 0; index < GB_QUANTITY; index++)
  1875. {
  1876. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1877. {
  1878. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1879. {
  1880. currentStatus = 1; //OCPP Status: Preparing
  1881. }
  1882. else
  1883. {
  1884. currentStatus = 0; //OCPP Status: Available
  1885. }
  1886. }
  1887. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1888. {
  1889. currentStatus = 1; //OCPP Status: Preparing
  1890. }
  1891. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1892. {
  1893. currentStatus = 2; //OCPP Status: Charging
  1894. }
  1895. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1896. {
  1897. currentStatus = 5; //OCPP Status: Finishing
  1898. }
  1899. 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
  1900. {
  1901. currentStatus = 4; //OCPP Status: SuspendedEV
  1902. }
  1903. 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
  1904. {
  1905. currentStatus = 7; //OCPP Status: Unavailable
  1906. }
  1907. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1908. {
  1909. currentStatus = 8; //OCPP Status: Faulted
  1910. }
  1911. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1912. {
  1913. currentStatus = 6; //OCPP Status: Reserved
  1914. }
  1915. }
  1916. }
  1917. else
  1918. {
  1919. for (int index = 0; index < AC_QUANTITY; index++)
  1920. {
  1921. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1922. {
  1923. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  1924. {
  1925. currentStatus = 1; //OCPP Status: Preparing
  1926. }
  1927. else
  1928. {
  1929. currentStatus = 0; //OCPP Status: Available
  1930. }
  1931. }
  1932. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1933. {
  1934. currentStatus = 1; //OCPP Status: Preparing
  1935. }
  1936. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1937. {
  1938. currentStatus = 2; //OCPP Status: Charging
  1939. }
  1940. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1941. {
  1942. currentStatus = 5; //OCPP Status: Finishing
  1943. }
  1944. 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
  1945. {
  1946. currentStatus = 4; //OCPP Status: SuspendedEV
  1947. }
  1948. 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
  1949. {
  1950. currentStatus = 7; //OCPP Status: Unavailable
  1951. }
  1952. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1953. {
  1954. currentStatus = 8; //OCPP Status: Faulted
  1955. }
  1956. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1957. {
  1958. currentStatus = 6; //OCPP Status: Reserved
  1959. }
  1960. }//end of for AC_QUANTITY
  1961. }//END OF ELSE
  1962. //it's option
  1963. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1964. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1965. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1966. random_uuid(guid);
  1967. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1968. , MESSAGE_TYPE_CALL
  1969. , guid
  1970. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1971. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1972. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1973. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1974. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1975. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1976. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1977. LWS_Send(message);
  1978. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1979. 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*/)
  1980. {
  1981. //DEBUG_ERROR("statusNotification mapitem pass");
  1982. result = PASS;
  1983. }
  1984. return result;
  1985. }
  1986. int sendStopTransactionRequest(int gun_index)
  1987. {
  1988. mtrace();
  1989. int result = FAIL;
  1990. //char message[1500]={0};
  1991. char guid[37]={0};
  1992. char tempdata[65]={0};
  1993. //int idx_sample=0;
  1994. DEBUG_ERROR("sendStopTransactionRequest \n");
  1995. memset(queuedata, 0, sizeof(queuedata));
  1996. //ENERGY_ACTIVE_IMPORT_REGISTER
  1997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1998. {
  1999. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2000. {
  2001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2002. {
  2003. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2004. }
  2005. }// END OF CHAdeMO_QUANTITY
  2006. for (int index = 0; index < CCS_QUANTITY; index++)
  2007. {
  2008. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2009. {
  2010. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2011. }
  2012. }// END OF CCS_QUANTITY
  2013. for (int index = 0; index < GB_QUANTITY; index++)
  2014. {
  2015. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2016. {
  2017. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2018. }
  2019. }// END OF GB_QUANTITY
  2020. }
  2021. else
  2022. {
  2023. for (int index = 0; index < AC_QUANTITY; index++)
  2024. {
  2025. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2026. {
  2027. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2028. }
  2029. }// END OF AC_QUANTITY
  2030. }//END OF ELSE
  2031. //Stop Transaction Time
  2032. struct timeval tmnow;
  2033. struct tm *tm;
  2034. char buf[28];//, usec_buf[6];
  2035. gettimeofday(&tmnow, NULL);
  2036. time_t t;
  2037. t = time(NULL);
  2038. /*UTC time and date*/
  2039. tm = gmtime(&t);
  2040. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2042. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2043. random_uuid(guid);
  2044. /***********************************transactionData******************************************************/
  2045. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2047. //=================================
  2048. // Transaction_Begin
  2049. //=================================
  2050. // Energy.Active.Export.Interval
  2051. //idx_sample=0;
  2052. 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
  2053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2055. 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*/]);
  2056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2057. {
  2058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2059. }
  2060. else
  2061. {
  2062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2063. }
  2064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2066. //=================================
  2067. // Transaction_End
  2068. //=================================
  2069. //Current.Export
  2070. //idx_sample=1;
  2071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2072. {
  2073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2074. {
  2075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2076. {
  2077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2078. }
  2079. }
  2080. for (int index = 0; index < CCS_QUANTITY; index++)
  2081. {
  2082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2083. {
  2084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2085. }
  2086. }
  2087. for (int index = 0; index < GB_QUANTITY; index++)
  2088. {
  2089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2090. {
  2091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2092. }
  2093. }
  2094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2095. }
  2096. else
  2097. {
  2098. for (int index = 0; index < AC_QUANTITY; index++)
  2099. {
  2100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2101. {
  2102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2103. }
  2104. }
  2105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2106. }// END FOR AC ELSE
  2107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2110. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2113. //Energy.Active.Export.Interval
  2114. //idx_sample=2;
  2115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2116. {
  2117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2118. {
  2119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2120. {
  2121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2122. }
  2123. }
  2124. for (int index = 0; index < CCS_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2127. {
  2128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2129. }
  2130. }
  2131. for (int index = 0; index < GB_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2134. {
  2135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2136. }
  2137. }
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2139. }
  2140. else
  2141. {
  2142. for (int index = 0; index < AC_QUANTITY; index++)
  2143. {
  2144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2145. {
  2146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2147. }
  2148. }
  2149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2150. }// END FOR AC ELSE
  2151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2154. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2157. //Power.Active.Export
  2158. //idx_sample=3;
  2159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2160. {
  2161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2162. {
  2163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2164. {
  2165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2166. }
  2167. }
  2168. for (int index = 0; index < CCS_QUANTITY; index++)
  2169. {
  2170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2171. {
  2172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2173. }
  2174. }
  2175. for (int index = 0; index < GB_QUANTITY; index++)
  2176. {
  2177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2178. {
  2179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2180. }
  2181. }
  2182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2183. }
  2184. else
  2185. {
  2186. for (int index = 0; index < AC_QUANTITY; index++)
  2187. {
  2188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2189. {
  2190. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2191. }
  2192. }
  2193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2194. }// END FOR AC ELSE
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2198. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2201. //Voltage
  2202. //idx_sample=4;
  2203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2204. {
  2205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2206. {
  2207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2208. {
  2209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2210. }
  2211. }
  2212. for (int index = 0; index < CCS_QUANTITY; index++)
  2213. {
  2214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2215. {
  2216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2217. }
  2218. }
  2219. for (int index = 0; index < GB_QUANTITY; index++)
  2220. {
  2221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2222. {
  2223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2224. }
  2225. }
  2226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2227. }
  2228. else
  2229. {
  2230. for (int index = 0; index < AC_QUANTITY; index++)
  2231. {
  2232. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2233. {
  2234. 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
  2235. }
  2236. }
  2237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2238. }// END FOR AC ELSE
  2239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2242. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2245. //SoC
  2246. //idx_sample=5;
  2247. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2248. {
  2249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2250. {
  2251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2252. {
  2253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2254. }
  2255. }
  2256. for (int index = 0; index < CCS_QUANTITY; index++)
  2257. {
  2258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2259. {
  2260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2261. }
  2262. }
  2263. for (int index = 0; index < GB_QUANTITY; index++)
  2264. {
  2265. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2266. {
  2267. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2268. }
  2269. }
  2270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2276. } // END FOR DC CASE
  2277. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2278. {
  2279. 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\"}]}]}]"
  2280. ,MESSAGE_TYPE_CALL
  2281. ,guid
  2282. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2283. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2286. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2287. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2288. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2289. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2290. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2291. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2292. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2293. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2294. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2295. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2298. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2330. );
  2331. }
  2332. else
  2333. {
  2334. 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\"}]}]}]"
  2335. ,MESSAGE_TYPE_CALL
  2336. ,guid
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2342. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2378. );
  2379. }
  2380. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2381. if(hashmap_operation(0, guid, tempdata) == 1)
  2382. {
  2383. result = PASS;
  2384. DEBUG_INFO("StopTransaction mapitem pass\n");
  2385. }
  2386. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2387. LWS_Send(queuedata);
  2388. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2389. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2390. {
  2391. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2392. }
  2393. #if 0
  2394. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2395. if(hashmap_operation(0, guid, tempdata) == 1)
  2396. {
  2397. result = PASS;
  2398. DEBUG_INFO("StopTransaction mapitem pass\n");
  2399. }
  2400. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2401. #endif
  2402. //for test
  2403. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2404. return result;
  2405. }
  2406. int sendMeterValuesRequest(int gun_index)
  2407. {
  2408. mtrace();
  2409. int result = FAIL;
  2410. // char message[1500]={0};
  2411. char guid[37]={0};
  2412. //int idx_sample=0;
  2413. //int length = 0;
  2414. char tempdata[65]={0};
  2415. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2416. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2417. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2418. {
  2419. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2420. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2421. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2422. return result;
  2423. }
  2424. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2425. {
  2426. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2427. }
  2428. memset(queuedata, 0, sizeof(queuedata));
  2429. //set value
  2430. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2431. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2432. random_uuid(guid);
  2433. //UTC Date time
  2434. struct timeval tmnow;
  2435. struct tm *tm;
  2436. char buf[28];//, usec_buf[6];
  2437. gettimeofday(&tmnow, NULL);
  2438. time_t t;
  2439. t = time(NULL);
  2440. /*UTC time and date*/
  2441. tm = gmtime(&t);
  2442. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2444. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2445. //idx_sample=0;
  2446. //********************************(1)Current.Export************************************************/
  2447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2448. {
  2449. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2450. {
  2451. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2452. {
  2453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2454. }
  2455. }
  2456. for (int index = 0; index < CCS_QUANTITY; index++)
  2457. {
  2458. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2459. {
  2460. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2461. }
  2462. }
  2463. for (int index = 0; index < GB_QUANTITY; index++)
  2464. {
  2465. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2466. {
  2467. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2468. }
  2469. }
  2470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2471. }
  2472. else
  2473. {
  2474. for (int index = 0; index < AC_QUANTITY; index++)
  2475. {
  2476. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2477. {
  2478. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2479. }
  2480. }
  2481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2482. }// END FOR AC ELSE
  2483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2486. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2489. //idx_sample=1;
  2490. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2492. {
  2493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2494. {
  2495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2496. {
  2497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2498. }
  2499. }
  2500. for (int index = 0; index < CCS_QUANTITY; index++)
  2501. {
  2502. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2503. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2504. {
  2505. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2507. }
  2508. }
  2509. for (int index = 0; index < GB_QUANTITY; index++)
  2510. {
  2511. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2512. {
  2513. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2514. }
  2515. }
  2516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2517. }
  2518. else
  2519. {
  2520. for (int index = 0; index < AC_QUANTITY; index++)
  2521. {
  2522. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2523. {
  2524. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2525. }
  2526. }
  2527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2528. }//END FOR AC ELSE
  2529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2532. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2533. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2535. //idx_sample=2;
  2536. //********************************(4)Power.Active.Export************************************************/
  2537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2538. {
  2539. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2540. {
  2541. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2542. {
  2543. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2544. }
  2545. }
  2546. for (int index = 0; index < CCS_QUANTITY; index++)
  2547. {
  2548. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2549. {
  2550. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2551. }
  2552. }
  2553. for (int index = 0; index < GB_QUANTITY; index++)
  2554. {
  2555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2556. {
  2557. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2558. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2559. }
  2560. }
  2561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2562. }
  2563. else
  2564. {
  2565. for (int index = 0; index < AC_QUANTITY; index++)
  2566. {
  2567. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2568. {
  2569. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2570. }
  2571. }
  2572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2573. }// END FOR AC ELSE
  2574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2577. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2580. //idx_sample=3;
  2581. //***********************************************(5)VOLTAGE******************************************************/
  2582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2583. {
  2584. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2585. {
  2586. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2587. {
  2588. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2589. }
  2590. }
  2591. for (int index = 0; index < CCS_QUANTITY; index++)
  2592. {
  2593. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2594. {
  2595. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2596. }
  2597. }
  2598. for (int index = 0; index < GB_QUANTITY; index++)
  2599. {
  2600. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2601. {
  2602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2603. }
  2604. }
  2605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2606. }
  2607. else
  2608. {
  2609. for (int index = 0; index < AC_QUANTITY; index++)
  2610. {
  2611. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2612. {
  2613. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2614. }
  2615. }
  2616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2617. }//END FOR AC ELSE
  2618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2619. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2620. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2621. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2624. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2625. {
  2626. //idx_sample=4;
  2627. //sampledValue = NULL;
  2628. //***********************************************(6)SOC******************************************************/
  2629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2630. {
  2631. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2632. {
  2633. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2634. }
  2635. }
  2636. for (int index = 0; index < CCS_QUANTITY; index++)
  2637. {
  2638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2639. {
  2640. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2641. }
  2642. }
  2643. for (int index = 0; index < GB_QUANTITY; index++)
  2644. {
  2645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2646. {
  2647. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2648. }
  2649. }
  2650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2656. }
  2657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2658. {
  2659. 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\"}]}]}]"
  2660. ,MESSAGE_TYPE_CALL
  2661. ,guid
  2662. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2663. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2664. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2700. );
  2701. }
  2702. else
  2703. {
  2704. 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\"}]}]}]"
  2705. ,MESSAGE_TYPE_CALL
  2706. ,guid
  2707. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2708. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2709. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2738. );
  2739. }
  2740. // Put request guid to hash map
  2741. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2742. 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*/)
  2743. {
  2744. result = PASS;
  2745. DEBUG_INFO("MeterValues mapitem pass\n");
  2746. }
  2747. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2748. LWS_Send(queuedata);
  2749. #if 0
  2750. // Put request guid to hash map
  2751. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2752. 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*/)
  2753. {
  2754. result = PASS;
  2755. DEBUG_INFO("MeterValues mapitem pass\n");
  2756. }
  2757. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2758. #endif
  2759. return result;
  2760. }
  2761. //==========================================
  2762. // send confirm routine
  2763. //==========================================
  2764. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2765. {
  2766. mtrace();
  2767. int result = FAIL;
  2768. char message[100]={0};
  2769. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2770. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2771. LWS_Send(message);
  2772. result = TRUE;
  2773. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2774. return result;
  2775. }
  2776. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2777. {
  2778. mtrace();
  2779. int result = FAIL;
  2780. char message[100]={0};
  2781. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2782. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2783. LWS_Send(message);
  2784. result = TRUE;
  2785. return result;
  2786. }
  2787. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2788. {
  2789. mtrace();
  2790. int result = FAIL;
  2791. char message[100]={0};
  2792. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2793. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2794. LWS_Send(message);
  2795. result = TRUE;
  2796. return result;
  2797. }
  2798. int sendClearCacheConfirmation(char *uuid,char *payload)
  2799. {
  2800. mtrace();
  2801. int result = FAIL;
  2802. char message[500]={0};
  2803. // int count = 0;
  2804. // int gun_index = 0;
  2805. // char guid[37];
  2806. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2807. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2808. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2809. LWS_Send(message);
  2810. return result;
  2811. }
  2812. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2813. {
  2814. mtrace();
  2815. int result = FAIL;
  2816. char message[500]={0};
  2817. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2818. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2819. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2820. LWS_Send(message);
  2821. return result;
  2822. }
  2823. int sendDataTransferConfirmation(char *uuid,char *payload)
  2824. {
  2825. mtrace();
  2826. char statusStr[20]={0};
  2827. char dataStr[10]={0};
  2828. char sstr[20]={0};
  2829. int c = 0;
  2830. char *loc;
  2831. int result = FAIL;
  2832. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2833. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2834. /**********************status**************************/
  2835. loc = strstr(payload, "status");
  2836. memset(sstr ,0, sizeof(sstr) );
  2837. c = 0;
  2838. while (loc[3+strlen("status")+c] != '\"')
  2839. {
  2840. sstr[c] = loc[3+strlen("status")+c];
  2841. c++;
  2842. }
  2843. sstr[c] = '\0';
  2844. strcpy(statusStr, sstr);
  2845. /**********************data**************************/
  2846. loc = strstr(payload, "data");
  2847. memset(sstr ,0, sizeof(sstr) );
  2848. c = 0;
  2849. while (loc[3+strlen("data")+c] != '\"')
  2850. {
  2851. sstr[c] = loc[3+strlen("data")+c];
  2852. c++;
  2853. }
  2854. sstr[c] = '\0';
  2855. strcpy(dataStr, sstr);
  2856. return result;
  2857. }
  2858. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2859. {
  2860. mtrace();
  2861. int result = FAIL;
  2862. char message[1000]={0};
  2863. double diff_f = 0.0;
  2864. int diff_i = 0;
  2865. int diffSeconds = 0;
  2866. struct tm tp;
  2867. int TimeZero = FALSE;
  2868. int CompositeScheduleIndex = 0;
  2869. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2870. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2871. {
  2872. TimeZero = TRUE;
  2873. }
  2874. else
  2875. {
  2876. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2877. }
  2878. if(TimeZero == FALSE)
  2879. {
  2880. tp.tm_isdst = -1;
  2881. time_t utc = mktime(&tp);
  2882. time_t t = time(NULL);
  2883. diff_f = difftime(t, utc);
  2884. diff_i = (int)diff_f;
  2885. diffSeconds = diff_i % 86400;//86400 seconds/day
  2886. }
  2887. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2888. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2889. #if 0 //remove temporally
  2890. 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}"
  2891. ,MESSAGE_TYPE_CALLRESULT
  2892. ,uuid
  2893. ,payload
  2894. ,connectorIdInt
  2895. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2896. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2897. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2898. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2899. #endif
  2900. if(nPeriod == 0)
  2901. {
  2902. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2903. ,MESSAGE_TYPE_CALLRESULT
  2904. ,uuid
  2905. ,payload
  2906. ,connectorIdInt
  2907. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2908. }
  2909. else
  2910. {
  2911. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2912. ,MESSAGE_TYPE_CALLRESULT
  2913. ,uuid
  2914. ,payload
  2915. ,connectorIdInt
  2916. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2917. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2918. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2919. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2920. int len = nPeriod;
  2921. //Last Period StartPriod is less than diffSeconds
  2922. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2923. {
  2924. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2925. , 0
  2926. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2927. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2928. }
  2929. else
  2930. {
  2931. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2932. {
  2933. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2934. {
  2935. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2936. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2937. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2938. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2939. }
  2940. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2941. {
  2942. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2943. , (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*/))
  2944. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2945. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2946. }
  2947. }
  2948. }
  2949. sprintf(message + strlen(message), "]}}]");
  2950. }
  2951. LWS_Send(message);
  2952. result = TRUE;
  2953. return result;
  2954. }
  2955. int sendGetConfigurationConfirmation(char *uuid)
  2956. {
  2957. mtrace();
  2958. int result = FAIL;
  2959. int MaxKeySupported = 0;
  2960. int sentConfigurationNumber= 0;
  2961. int sentunConfigurationNumber= 0;
  2962. char message[4000]={0};
  2963. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2964. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2965. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2966. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  2967. ,MESSAGE_TYPE_CALLRESULT
  2968. ,uuid );
  2969. //configuration key
  2970. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2971. {
  2972. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2973. {
  2974. if (sentConfigurationNumber == 0)
  2975. {
  2976. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2977. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2978. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2979. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2980. }
  2981. else
  2982. {
  2983. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2984. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2985. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2986. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2987. }
  2988. sentConfigurationNumber = sentConfigurationNumber + 1;
  2989. }
  2990. }
  2991. sprintf(message + strlen(message), "]");
  2992. if(UnknownKeynum != 0)
  2993. {
  2994. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2995. //unkown key
  2996. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2997. {
  2998. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2999. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3000. if(sentunConfigurationNumber == 0)
  3001. {
  3002. sprintf(message + strlen(message), "\"%s\""
  3003. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3004. }
  3005. else
  3006. {
  3007. sprintf(message + strlen(message), ",\"%s\""
  3008. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3009. }
  3010. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3011. }
  3012. sprintf(message + strlen(message), "]");
  3013. }
  3014. sprintf(message + strlen(message), "}]");
  3015. LWS_Send(message);
  3016. return result;
  3017. }
  3018. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3019. {
  3020. mtrace();
  3021. int result = FAIL;
  3022. char message[400]={0};
  3023. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3024. if(strcmp(payload,"")==0)
  3025. {
  3026. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3027. }
  3028. else
  3029. {
  3030. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3031. }
  3032. LWS_Send(message);
  3033. result = TRUE;
  3034. return result;
  3035. }
  3036. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3037. {
  3038. mtrace();
  3039. int result = FAIL;
  3040. char message[80]={0};
  3041. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3042. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3043. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3044. LWS_Send(message);
  3045. result = TRUE;
  3046. return result;
  3047. }
  3048. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3049. {
  3050. mtrace();
  3051. int result = FAIL;
  3052. char message[80]={0};
  3053. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3054. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3055. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3056. LWS_Send(message);
  3057. result = TRUE;
  3058. return result;
  3059. }
  3060. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3061. {
  3062. mtrace();
  3063. int result = FAIL;
  3064. char message[80]={0};
  3065. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3066. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3067. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3068. LWS_Send(message);
  3069. result = TRUE;
  3070. return result;
  3071. }
  3072. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3073. {
  3074. mtrace();
  3075. int result = FAIL;
  3076. char message[80]={0};
  3077. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3078. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3079. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3080. LWS_Send(message);
  3081. result = TRUE;
  3082. return result;
  3083. }
  3084. int sendResetConfirmation(char *uuid,char *payload)
  3085. {
  3086. mtrace();
  3087. int result = FAIL;
  3088. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3089. char message[80]={0};
  3090. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3091. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3092. LWS_Send(message);
  3093. result = TRUE;
  3094. return result;
  3095. }
  3096. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3097. {
  3098. mtrace();
  3099. int result = FAIL;
  3100. char message[500]={0};
  3101. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3102. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3103. LWS_Send(message);
  3104. result = TRUE;
  3105. return result;
  3106. }
  3107. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3108. {
  3109. mtrace();
  3110. int result = FAIL;
  3111. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3112. char message[80]={0};
  3113. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3114. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3115. LWS_Send(message);
  3116. result = TRUE;
  3117. return result;
  3118. }
  3119. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3120. {
  3121. mtrace();
  3122. int result = FAIL;
  3123. char message[80]={0};
  3124. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3125. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3126. LWS_Send(message);
  3127. result = TRUE;
  3128. return result;
  3129. }
  3130. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3131. {
  3132. mtrace();
  3133. int result = FAIL;
  3134. char message[80]={0};
  3135. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3136. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3137. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3138. LWS_Send(message);
  3139. result = TRUE;
  3140. return result;
  3141. }
  3142. int sendUpdateFirmwareConfirmation(char *uuid)
  3143. {
  3144. mtrace();
  3145. int result = FAIL;
  3146. char message[60]={0};
  3147. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3148. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3149. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3150. LWS_Send(message);
  3151. result = TRUE;
  3152. return result;
  3153. }
  3154. //==========================================
  3155. // send CallError routine
  3156. //==========================================
  3157. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3158. {
  3159. mtrace();
  3160. //int result = FAIL;
  3161. char message[220]={0};
  3162. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3163. #ifdef SystemLogMessage
  3164. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3165. uniqueId, action, errorCode, errorDescription);
  3166. #endif
  3167. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3168. LWS_Send(message);
  3169. //result = TRUE;
  3170. }
  3171. //==========================================
  3172. // Handle server request routine Start
  3173. //==========================================
  3174. #define GUN_NUM 1
  3175. int handleCancelReservationRequest(char *uuid, char *payload)
  3176. {
  3177. mtrace();
  3178. int result = FAIL;
  3179. int gunNO = 0;
  3180. int reservationIdInt =0;
  3181. char comfirmstr[20];
  3182. int c = 0;
  3183. char *loc;
  3184. char sstr[100]={0};
  3185. DEBUG_INFO("handle CancelReservationRequest\n");
  3186. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3187. c = 0;
  3188. loc = strstr(payload, "reservationId");
  3189. memset(sstr ,0, sizeof(sstr) );
  3190. while (loc[strlen("reservationId")+2+c] != '}')
  3191. {
  3192. sstr[c] = loc[strlen("reservationId")+2+c];
  3193. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3194. c++;
  3195. }
  3196. sstr[c] = '\0';
  3197. reservationIdInt = atoi(sstr);
  3198. memset(comfirmstr, 0, sizeof comfirmstr);
  3199. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3200. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3201. //check Transaction active
  3202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3203. {
  3204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3205. {
  3206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3207. {
  3208. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3209. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3210. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3211. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3212. goto end;
  3213. }
  3214. }
  3215. for (int index = 0; index < CCS_QUANTITY; index++)
  3216. {
  3217. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3218. {
  3219. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3220. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3221. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3222. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3223. goto end;
  3224. }
  3225. }
  3226. for (int index = 0; index < GB_QUANTITY; index++)
  3227. {
  3228. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3229. {
  3230. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3231. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3232. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3233. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3234. goto end;
  3235. }
  3236. }
  3237. }
  3238. else
  3239. {
  3240. for (int index = 0; index < AC_QUANTITY; index++)
  3241. {
  3242. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3243. {
  3244. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3245. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3246. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3247. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3248. goto end;
  3249. }
  3250. }
  3251. }// END FOR AC ELSE
  3252. //The reservationId does NOT match the reservationId
  3253. sendCancelReservationConfirmation(uuid, comfirmstr);
  3254. end:
  3255. // Fill in ocpp packet uuid
  3256. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3257. return result;
  3258. }
  3259. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3260. {
  3261. mtrace();
  3262. int result = FAIL;
  3263. int gunIndex = 0;
  3264. char sstr[90]={0};
  3265. char typeStr[16]={0};
  3266. char comfirmstr[20];
  3267. int specificId = FALSE;
  3268. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3269. char *loc;
  3270. //int intervalInt = 0;
  3271. int c = 0;
  3272. /*** connectorId ****/
  3273. c = 0;
  3274. loc = strstr(payload, "connectorId");
  3275. memset(sstr ,0, sizeof(sstr) );
  3276. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3277. {
  3278. sstr[c] = loc[strlen("connectorId")+2+c];
  3279. c++;
  3280. }
  3281. sstr[c] = '\0';
  3282. gunIndex = atoi(sstr);
  3283. /***type ****/
  3284. loc = strstr(payload, "type");
  3285. memset(sstr ,0, sizeof(sstr) );
  3286. c = 0;
  3287. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3288. {
  3289. sstr[c] = loc[3+strlen("type")+c];
  3290. c++;
  3291. }
  3292. sstr[c] = '\0';
  3293. strcpy(typeStr, sstr);
  3294. if(gunIndex != 0)
  3295. {
  3296. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3297. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3298. }
  3299. else
  3300. {
  3301. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3302. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3303. }
  3304. memset(comfirmstr, 0, sizeof comfirmstr);
  3305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3306. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3307. {
  3308. specificId = TRUE;
  3309. }
  3310. if(specificId == FALSE)
  3311. goto end;
  3312. if(gunIndex != 0)
  3313. {
  3314. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3315. }
  3316. else
  3317. {
  3318. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3319. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3320. }
  3321. /*
  3322. enum SYSTEM_STATUS
  3323. {
  3324. SYS_MODE_BOOTING = 0,
  3325. SYS_MODE_IDLE = 1,
  3326. SYS_MODE_AUTHORIZING = 2,
  3327. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3328. SYS_MODE_REASSIGN = 4,
  3329. SYS_MODE_PREPARING = 5,
  3330. SYS_MODE_PREPARE_FOR_EV = 6,
  3331. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3332. SYS_MODE_CHARGING = 8,
  3333. SYS_MODE_TERMINATING = 9,
  3334. SYS_MODE_COMPLETE = 10,
  3335. SYS_MODE_ALARM = 11,
  3336. SYS_MODE_FAULT = 12,
  3337. SYS_MODE_RESERVATION = 13,
  3338. SYS_MODE_BOOKING = 14,
  3339. SYS_MODE_MAINTAIN = 15,
  3340. SYS_MODE_DEBUG = 16,
  3341. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3342. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3343. SYS_MODE_UPDATE = 19
  3344. };
  3345. */
  3346. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3347. {
  3348. //check Transaction active
  3349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3350. {
  3351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3352. {
  3353. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3354. {
  3355. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3356. {
  3357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3358. }
  3359. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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 CHAdeMO_QUANTITY
  3370. for (int index = 0; index < CCS_QUANTITY; index++)
  3371. {
  3372. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3373. {
  3374. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3375. {
  3376. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3377. }
  3378. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3379. {
  3380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3381. }
  3382. else
  3383. {
  3384. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3385. }
  3386. goto end;
  3387. }
  3388. }//END FOR CCS_QUANTITY
  3389. for (int index = 0; index < GB_QUANTITY; index++)
  3390. {
  3391. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3392. {
  3393. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3394. {
  3395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3396. }
  3397. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3398. {
  3399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3400. }
  3401. else
  3402. {
  3403. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3404. }
  3405. goto end;
  3406. }
  3407. }// END FOR GB_QUANTITY
  3408. }
  3409. else
  3410. {
  3411. for (int index = 0; index < AC_QUANTITY; index++)
  3412. {
  3413. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3414. {
  3415. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3416. {
  3417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3418. }
  3419. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3420. {
  3421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3422. }
  3423. else
  3424. {
  3425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3426. }
  3427. goto end;
  3428. }
  3429. }//END FOR AC_QUANTITY
  3430. }// END FOR AC ELSE
  3431. }//END FOR AvailabilityTypeStr[Inoperative]
  3432. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3433. {
  3434. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3435. //check Transaction active
  3436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3437. {
  3438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3439. {
  3440. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3441. {
  3442. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3443. goto end;
  3444. }
  3445. }//END FOR CHAdeMO_QUANTITY
  3446. for (int index = 0; index < CCS_QUANTITY; index++)
  3447. {
  3448. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3449. {
  3450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3451. goto end;
  3452. }
  3453. }//END FOR CCS_QUANTITY
  3454. for (int index = 0; index < GB_QUANTITY; index++)
  3455. {
  3456. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3457. {
  3458. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3460. goto end;
  3461. }
  3462. }// END FOR GB_QUANTITY
  3463. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3464. }
  3465. else
  3466. {
  3467. for (int index = 0; index < AC_QUANTITY; index++)
  3468. {
  3469. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3470. {
  3471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3472. goto end;
  3473. }
  3474. }//END FOR CHAdeMO_QUANTITY
  3475. }//END FOR AC ELSE
  3476. }//END FOR AvailabilityTypeStr[Operative]
  3477. end:
  3478. if(gunIndex != 0)
  3479. {
  3480. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3481. }
  3482. else
  3483. {
  3484. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3485. }
  3486. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3487. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3488. return result;
  3489. }
  3490. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3491. {
  3492. mtrace();
  3493. int result = FAIL;
  3494. char sstr[100]={0};
  3495. char keystr[40]={0};
  3496. char valuestr[100]={0};
  3497. char *loc;
  3498. int c = 0;
  3499. char comfirmstr[20]={0};
  3500. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3501. /***key ****/
  3502. loc = strstr(payload, "key");
  3503. memset(sstr ,0, sizeof(sstr) );
  3504. c = 0;
  3505. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3506. {
  3507. sstr[c] = loc[3+strlen("key")+c];
  3508. c++;
  3509. }
  3510. sstr[c] = '\0';
  3511. strcpy(keystr, sstr);
  3512. //DEBUG_INFO( "keystr=%s\n",keystr);
  3513. /***value ****/
  3514. loc = strstr(payload, "value");
  3515. memset(sstr ,0, sizeof(sstr) );
  3516. c = 0;
  3517. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3518. {
  3519. sstr[c] = loc[3+strlen("value")+c];
  3520. c++;
  3521. }
  3522. sstr[c] = '\0';
  3523. strcpy(valuestr, sstr);
  3524. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3525. if((uuid==NULL) || (payload ==NULL) )
  3526. {
  3527. #ifdef Debug
  3528. DEBUG_INFO("payload is null\n");
  3529. #endif
  3530. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3531. }
  3532. else
  3533. {
  3534. int status = setKeyValue(keystr, valuestr);
  3535. switch(status)
  3536. {
  3537. case ConfigurationStatus_Accepted:
  3538. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3539. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3540. StoreConfigurationTable();
  3541. break;
  3542. case ConfigurationStatus_Rejected:
  3543. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3544. break;
  3545. case RebootRequired:
  3546. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3547. StoreConfigurationTable();
  3548. break;
  3549. case NotSupported:
  3550. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3551. break;
  3552. default:
  3553. break;
  3554. }
  3555. }
  3556. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3557. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3558. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3559. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3560. {
  3561. ChageWebSocketPingInterval(atoi(valuestr));
  3562. }
  3563. return result;
  3564. }
  3565. int handleClearCacheRequest(char *uuid, char *payload)
  3566. {
  3567. mtrace();
  3568. int result = FAIL;
  3569. char comfirmstr[20];
  3570. int fd;
  3571. char rmFileCmd[100]={0};
  3572. struct stat stats;
  3573. DEBUG_INFO("handle ClearCacheRequest\n");
  3574. stat("/Storage/OCPP", &stats);
  3575. // Check for directory existence
  3576. if (S_ISDIR(stats.st_mode) == 1)
  3577. {
  3578. //DEBUG_ERROR("\n OCPP directory exist \n");
  3579. }
  3580. else
  3581. {
  3582. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3583. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3584. system(rmFileCmd);
  3585. }
  3586. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3587. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3588. {
  3589. DEBUG_INFO("AuthorizationCache file exist.\n");
  3590. }
  3591. else
  3592. {
  3593. DEBUG_INFO("AuthorizationCache file not exist\n");
  3594. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3595. if(log == NULL)
  3596. {
  3597. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3598. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3599. goto end;
  3600. }
  3601. else
  3602. {
  3603. fclose(log);
  3604. }
  3605. }
  3606. fd = open(AuthorizationCache_JSON,O_RDWR);
  3607. if(fd < 0)
  3608. {
  3609. DEBUG_INFO("open AuthorizationCache file failed\n");
  3610. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3611. }
  3612. else
  3613. {
  3614. DEBUG_INFO("open AuthorizationCache file successful\n");
  3615. //* 清空? 件 */
  3616. ftruncate(fd,0);
  3617. //* ? 新设置? 件? 移??*/
  3618. lseek(fd,0,SEEK_SET);
  3619. close(fd);
  3620. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3621. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3622. }
  3623. end:
  3624. sendClearCacheConfirmation(uuid, comfirmstr);
  3625. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3626. return result;
  3627. }
  3628. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3629. {
  3630. mtrace();
  3631. int result = FAIL;
  3632. int resultRename;
  3633. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3634. char chargingProfilePurposeStr[26]={0};
  3635. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3636. char tempchargingProfilePurposeStr[26]={0};
  3637. char sstr[160]={0};//sstr[200]={ 0 };
  3638. char str[100]={0};
  3639. int c = 0;
  3640. //int i = 0;
  3641. //char * pch;
  3642. char *loc;
  3643. char fname[200]={0};
  3644. char comfirmstr[20]={0};
  3645. char word[1600]={0};
  3646. int clearflag = FALSE;
  3647. int chargingProfileIdIsNULL = FALSE;
  3648. int connectorIsNULL = FALSE;
  3649. int chargingProfilePurposeIsNULL = FALSE;
  3650. int stackLevelIsNULL = FALSE;
  3651. //int GotoEnd = FALSE;
  3652. FILE *fptr1, *fptr2;
  3653. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3654. int n_chargingProfile=0;
  3655. int isEmptyFile = FALSE;
  3656. char sLineWord[1600]={0};
  3657. char chargingProfiles[10][100]={0};
  3658. int ChargeProfileCount = 0;
  3659. char ch;
  3660. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3661. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3662. //***id ****/
  3663. c = 0;
  3664. loc = strstr(payload, "id");
  3665. memset(sstr ,0, sizeof(sstr) );
  3666. if(loc == NULL)
  3667. {
  3668. chargingProfileIdIsNULL = TRUE;
  3669. }
  3670. else
  3671. {
  3672. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3673. {
  3674. sstr[c] = loc[strlen("id")+2+c];
  3675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3676. c++;
  3677. }
  3678. sstr[c] = '\0';
  3679. chargingProfileIdInt = atoi(sstr);
  3680. }
  3681. //***connectorId ****/
  3682. c=0;
  3683. loc = strstr(payload, "connectorId");
  3684. memset(sstr ,0, sizeof(sstr) );
  3685. if(loc == NULL)
  3686. {
  3687. connectorIsNULL = TRUE;
  3688. }
  3689. else
  3690. {
  3691. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3692. {
  3693. sstr[c] = loc[strlen("connectorId")+2+c];
  3694. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3695. c++;
  3696. }
  3697. sstr[c] = '\0';
  3698. connectorIdInt = atoi(sstr);
  3699. }
  3700. //***chargingProfilePurpose ****/
  3701. loc = strstr(payload, "chargingProfilePurpose");
  3702. memset(sstr ,0, sizeof(sstr) );
  3703. c = 0;
  3704. if(loc == NULL)
  3705. {
  3706. chargingProfilePurposeIsNULL = TRUE;
  3707. }
  3708. else
  3709. {
  3710. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3711. {
  3712. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3713. c++;
  3714. }
  3715. sstr[c] = '\0';
  3716. strcpy(chargingProfilePurposeStr, sstr);
  3717. }
  3718. //***stackLevel ****/
  3719. c=0;
  3720. loc = strstr(payload, "stackLevel");
  3721. memset(sstr ,0, sizeof(sstr) );
  3722. if(loc == NULL)
  3723. {
  3724. stackLevelIsNULL = TRUE;
  3725. }
  3726. else
  3727. {
  3728. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3729. {
  3730. sstr[c] = loc[strlen("stackLevel")+2+c];
  3731. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3732. c++;
  3733. }
  3734. sstr[c] = '\0';
  3735. stackLevelInt = atoi(sstr);
  3736. }
  3737. if(connectorIsNULL == FALSE)
  3738. {
  3739. switch(connectorIdInt)
  3740. {
  3741. case 0:
  3742. if(chargingProfilePurposeIsNULL == TRUE)
  3743. {
  3744. int l = 0;
  3745. strcpy(fname, ChargePointMaxProfile_JSON);
  3746. if((access(fname,F_OK))!=-1)
  3747. {
  3748. strcpy(chargingProfiles[l], fname);
  3749. l = l + 1;
  3750. }
  3751. strcpy(fname, TxDefaultProfile_0_JSON);
  3752. if((access(fname,F_OK))!=-1)
  3753. {
  3754. strcpy(chargingProfiles[l], fname);
  3755. l = l + 1;
  3756. }
  3757. ChargeProfileCount = l;
  3758. }
  3759. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3760. {
  3761. strcpy(fname, ChargePointMaxProfile_JSON);
  3762. if((access(fname,F_OK))!=-1)
  3763. {
  3764. strcpy(chargingProfiles[0], fname);
  3765. ChargeProfileCount = 1;
  3766. }
  3767. }
  3768. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3769. {
  3770. strcpy(fname, TxDefaultProfile_0_JSON);
  3771. if((access(fname,F_OK))!=-1)
  3772. {
  3773. strcpy(chargingProfiles[0], fname);
  3774. ChargeProfileCount = 1;
  3775. }
  3776. }
  3777. break;
  3778. default:
  3779. if(chargingProfilePurposeIsNULL == TRUE)
  3780. {
  3781. int m = 0;
  3782. memset(fname, 0, sizeof fname);
  3783. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3784. if((access(fname,F_OK))!=-1)
  3785. {
  3786. strcpy(chargingProfiles[m], fname);
  3787. m = m + 1;
  3788. }
  3789. memset(fname, 0, sizeof fname);
  3790. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3791. if((access(fname,F_OK))!=-1)
  3792. {
  3793. strcpy(chargingProfiles[m], fname);
  3794. m = m + 1;
  3795. }
  3796. ChargeProfileCount = m;
  3797. }
  3798. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3799. {
  3800. //strcpy(fname, TxDefaultProfile_1_JSON);
  3801. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3802. if((access(fname,F_OK))!=-1)
  3803. {
  3804. strcpy(chargingProfiles[0], fname);
  3805. ChargeProfileCount = 1;
  3806. }
  3807. }
  3808. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3809. {
  3810. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3811. if((access(fname,F_OK))!=-1)
  3812. {
  3813. strcpy(chargingProfiles[0], fname);
  3814. ChargeProfileCount = 1;
  3815. }
  3816. //strcpy(fname, TxProfile_1_JSON);
  3817. }
  3818. //strcpy(fname, ChargePointMaxProfile_JSON );
  3819. break;
  3820. }
  3821. }
  3822. else // Check all Charging Profiles
  3823. {
  3824. int i = 0;
  3825. char fnametemp[200]={0};
  3826. ChargeProfileCount = 0;
  3827. //Check ChargePointMaxProfile.json exit
  3828. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3829. {
  3830. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3831. i = i + 1;
  3832. }
  3833. //Check TxDefaultProfile_0.json exit
  3834. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3835. {
  3836. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3837. i = i + 1;
  3838. }
  3839. //Check TxDefaultProfile_%d.json
  3840. for(int j=1; j <= gunTotalNumber; j++)
  3841. {
  3842. memset(fnametemp, 0, sizeof fnametemp);
  3843. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3844. if((access(fnametemp,F_OK))!=-1)
  3845. {
  3846. strcpy(chargingProfiles[i], fnametemp);
  3847. i = i + 1;
  3848. }
  3849. }
  3850. //Check TxProfile_%d.json
  3851. for(int j=1; j <= gunTotalNumber; j++)
  3852. {
  3853. memset(fnametemp, 0, sizeof fnametemp);
  3854. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3855. if((access(fnametemp,F_OK))!=-1)
  3856. {
  3857. strcpy(chargingProfiles[i], fnametemp);
  3858. i = i + 1;
  3859. }
  3860. }
  3861. ChargeProfileCount = i;
  3862. }// End connectorIsNULL is TRUE
  3863. if(ChargeProfileCount == 0)
  3864. {
  3865. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3866. goto end;
  3867. }
  3868. #if 0
  3869. fptr1 = fopen(fname, "r");
  3870. if (!fptr1)
  3871. {
  3872. //file not exist
  3873. DEBUG_INFO("Unable to open the input file!!\n");
  3874. fptr1 = fopen(fname, "w+");
  3875. }
  3876. fclose(fptr1);
  3877. #endif
  3878. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3879. {
  3880. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3881. goto end;
  3882. }
  3883. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3884. {
  3885. memset(str, 0, sizeof str);
  3886. // clear temp file
  3887. sprintf(str,"rm -f %s",temp);
  3888. system(str);
  3889. for(int k=0; k < ChargeProfileCount; k++)
  3890. {
  3891. memset(str, 0, sizeof str);
  3892. //clear file in C
  3893. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3894. system(str);
  3895. }
  3896. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3897. goto end;
  3898. }
  3899. else if(connectorIsNULL == TRUE)
  3900. {
  3901. for(int k=0; k < ChargeProfileCount; k++)
  3902. {
  3903. fptr1 = fopen(chargingProfiles[k], "r");
  3904. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3905. //Check Charging Profile Count
  3906. while(fscanf(fptr1, "%s", word) != EOF)
  3907. {
  3908. //DEBUG_INFO("word=%s\n",word);
  3909. if(strstr(word, "chargingProfileId")!= NULL)
  3910. {
  3911. //DEBUG_INFO("test chargingProfileId \n");
  3912. n_chargingProfile = n_chargingProfile + 1;
  3913. //DEBUG_INFO("chargingProfileId Found\n");
  3914. }
  3915. }
  3916. rewind(fptr1);
  3917. //search Charging Profile Element
  3918. //int i= 0;
  3919. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3920. {
  3921. //------------------------tempconnectorIdInt------------------------//
  3922. loc = strstr(sLineWord, "connectorId");
  3923. c = 0;
  3924. memset(sstr ,0, sizeof(sstr) );
  3925. while (loc[strlen("connectorId")+2+c] != ',')
  3926. {
  3927. sstr[c] = loc[strlen("connectorId")+2+c];
  3928. c++;
  3929. }
  3930. sstr[c] = '\0';
  3931. tempconnectorIdInt = atoi(sstr);
  3932. printf("file's gun number is %d\n", tempconnectorIdInt);
  3933. //--------------------------chargingProfileId--------------------//
  3934. c = 0;
  3935. loc = strstr(sLineWord, "chargingProfileId");
  3936. memset(sstr ,0, sizeof(sstr) );
  3937. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3938. {
  3939. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3940. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3941. c++;
  3942. }
  3943. sstr[c] = '\0';
  3944. tempchargingProfileIdInt = atoi(sstr);
  3945. //stackLevel
  3946. c = 0;
  3947. loc = strstr(sLineWord, "stackLevel");
  3948. memset(sstr ,0, sizeof(sstr) );
  3949. while (loc[strlen("stackLevel")+2+c] != ',')
  3950. {
  3951. sstr[c] = loc[strlen("stackLevel")+2+c];
  3952. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3953. c++;
  3954. }
  3955. sstr[c] = '\0';
  3956. tempstackLevelInt = atoi(sstr);
  3957. c = 0;
  3958. loc = strstr(sLineWord, "chargingProfilePurpose");
  3959. memset(sstr ,0, sizeof(sstr) );
  3960. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3961. {
  3962. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3963. c++;
  3964. }
  3965. sstr[c] = '\0';
  3966. strcpy(tempchargingProfilePurposeStr, sstr);
  3967. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  3968. {
  3969. //------- not write to fptr2-------//
  3970. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3971. //clearflag = TRUE;
  3972. }
  3973. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  3974. {
  3975. //------- not write to fptr2-------//
  3976. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3977. }
  3978. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  3979. {
  3980. //------- not write to fptr2-------//
  3981. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3982. }
  3983. else
  3984. {
  3985. fprintf(fptr2, sLineWord);//writing data into file
  3986. }
  3987. memset(sLineWord, 0, sizeof sLineWord);
  3988. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3989. if(clearflag == TRUE)
  3990. {
  3991. fclose(fptr1);
  3992. fclose(fptr2);
  3993. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3994. system(str);
  3995. // clear temp file
  3996. sprintf(str,"rm -f %s",temp);
  3997. system(str);
  3998. }
  3999. else
  4000. {
  4001. fclose(fptr1);
  4002. fclose(fptr2);
  4003. memset(str, 0, sizeof str);
  4004. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4005. system(str);
  4006. resultRename = rename(temp, chargingProfiles[k]);
  4007. if(resultRename == 0)
  4008. {
  4009. DEBUG_INFO("File ChargingProfile renamed successfully");
  4010. }
  4011. else
  4012. {
  4013. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4014. }
  4015. if(comfirmstr[0]== 0)
  4016. {
  4017. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4018. }
  4019. //Check chargingProfile is empty file
  4020. /*------ Read the file ----------------*/
  4021. fptr1=fopen(chargingProfiles[k],"r");
  4022. ch=fgetc(fptr1);
  4023. rewind(fptr1);
  4024. memset(sLineWord, 0, sizeof sLineWord);
  4025. if(ch!=EOF)
  4026. {
  4027. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4028. {
  4029. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4030. if(sLineWord[0]=='\0')
  4031. {
  4032. isEmptyFile = TRUE;
  4033. break;
  4034. }
  4035. else
  4036. {
  4037. isEmptyFile = FALSE;
  4038. break;
  4039. }
  4040. }
  4041. }
  4042. fclose(fptr1);
  4043. if(isEmptyFile == TRUE)
  4044. {
  4045. memset(str, 0, sizeof str);
  4046. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4047. system(str);
  4048. }
  4049. }
  4050. }// End of while(int k=0; k < ChargePointCount; k++)
  4051. }
  4052. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4053. {
  4054. for(int k=0; k < ChargeProfileCount; k++)
  4055. {
  4056. fptr1 = fopen(chargingProfiles[k], "r");
  4057. fptr2 = fopen(temp, "w+");
  4058. //Check Charging Profile Count
  4059. while(fscanf(fptr1, "%s", word) != EOF)
  4060. {
  4061. //DEBUG_INFO("word=%s\n",word);
  4062. if(strstr(word, "chargingProfileId")!= NULL)
  4063. {
  4064. //DEBUG_INFO("test chargingProfileId \n");
  4065. n_chargingProfile = n_chargingProfile + 1;
  4066. //DEBUG_INFO("chargingProfileId Found\n");
  4067. }
  4068. }
  4069. rewind(fptr1);
  4070. //search Charging Profile Element
  4071. //int i= 0;
  4072. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4073. {
  4074. //*************************tempconnectorIdInt*********************************/
  4075. loc = strstr(sLineWord, "connectorId");
  4076. c = 0;
  4077. memset(sstr ,0, sizeof(sstr) );
  4078. while (loc[strlen("connectorId")+2+c] != ',')
  4079. {
  4080. sstr[c] = loc[strlen("connectorId")+2+c];
  4081. c++;
  4082. }
  4083. sstr[c] = '\0';
  4084. tempconnectorIdInt = atoi(sstr);
  4085. //chargingProfileId
  4086. c = 0;
  4087. loc = strstr(sLineWord, "chargingProfileId");
  4088. memset(sstr ,0, sizeof(sstr) );
  4089. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4090. {
  4091. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4092. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4093. c++;
  4094. }
  4095. sstr[c] = '\0';
  4096. tempchargingProfileIdInt = atoi(sstr);
  4097. //stackLevel
  4098. c = 0;
  4099. loc = strstr(sLineWord, "stackLevel");
  4100. memset(sstr ,0, sizeof(sstr) );
  4101. while (loc[strlen("stackLevel")+2+c] != ',')
  4102. {
  4103. sstr[c] = loc[strlen("stackLevel")+2+c];
  4104. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4105. c++;
  4106. }
  4107. sstr[c] = '\0';
  4108. tempstackLevelInt = atoi(sstr);
  4109. c = 0;
  4110. loc = strstr(sLineWord, "chargingProfilePurpose");
  4111. memset(sstr ,0, sizeof(sstr) );
  4112. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4113. {
  4114. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4115. c++;
  4116. }
  4117. sstr[c] = '\0';
  4118. strcpy(tempchargingProfilePurposeStr, sstr);
  4119. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4120. {
  4121. //------- not write to fptr2-------//
  4122. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4123. //clearflag = TRUE;
  4124. }
  4125. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4126. {
  4127. //------- not write to fptr2-------//
  4128. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4129. }
  4130. else if(stackLevelIsNULL == TRUE)
  4131. {
  4132. //Clear Whole File
  4133. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4134. clearflag = TRUE;
  4135. break;
  4136. }
  4137. else
  4138. {
  4139. fprintf(fptr2, sLineWord);//writing data into file
  4140. }
  4141. memset(sLineWord, 0, sizeof sLineWord);
  4142. }
  4143. if(clearflag == TRUE)
  4144. {
  4145. fclose(fptr1);
  4146. fclose(fptr2);
  4147. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4148. system(str);
  4149. // clear temp file
  4150. sprintf(str,"rm -f %s",temp);
  4151. system(str);
  4152. }
  4153. else
  4154. {
  4155. fclose(fptr1);
  4156. fclose(fptr2);
  4157. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4158. system(str);
  4159. resultRename = rename(temp, chargingProfiles[k]);
  4160. if(resultRename == 0)
  4161. {
  4162. DEBUG_INFO("File ChargingProfile renamed successfully");
  4163. }
  4164. else
  4165. {
  4166. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4167. }
  4168. if(comfirmstr[0]== 0)
  4169. {
  4170. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4171. }
  4172. //Check chargingProfile is empty file
  4173. /*------ Read the file ----------------*/
  4174. fptr1=fopen(chargingProfiles[k],"r");
  4175. ch=fgetc(fptr1);
  4176. rewind(fptr1);
  4177. memset(sLineWord, 0, sizeof sLineWord);
  4178. if(ch!=EOF)
  4179. {
  4180. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4181. {
  4182. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4183. if(sLineWord[0]=='\0')
  4184. {
  4185. isEmptyFile = TRUE;
  4186. break;
  4187. }
  4188. else
  4189. {
  4190. isEmptyFile = FALSE;
  4191. break;
  4192. }
  4193. }
  4194. }
  4195. fclose(fptr1);
  4196. if(isEmptyFile == TRUE)
  4197. {
  4198. memset(str, 0, sizeof str);
  4199. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4200. system(str);
  4201. }
  4202. /*------- End of reading ---------------*/
  4203. }
  4204. } // while(int k=0; k < ChargeProfileCount; k++)
  4205. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4206. end:
  4207. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4208. return result;
  4209. }
  4210. int handleDataTransferRequest(char *uuid, char *payload)
  4211. {
  4212. mtrace();
  4213. int result = FAIL;
  4214. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4215. char tempvendorId[255]={0};
  4216. char tempmessageId[50]={0};
  4217. char tempdata[50]={0};
  4218. char sstr[160]={0};//sstr[200]={ 0 };
  4219. char message[80]={0};
  4220. int c = 0;
  4221. char *loc;
  4222. DEBUG_INFO("handle DataTransferRequest\n");
  4223. if((uuid != NULL) && (payload != NULL))
  4224. {
  4225. //===============================
  4226. // vendorId
  4227. //===============================
  4228. c = 0;
  4229. loc = strstr(payload, "vendorId");
  4230. while (loc[strlen("vendorId")+3+c] != '\"')
  4231. {
  4232. sstr[c] = loc[strlen("vendorId")+3+c];
  4233. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4234. c++;
  4235. }
  4236. sstr[c] = '\0';
  4237. strcpy(tempvendorId,sstr);
  4238. //===============================
  4239. // messageId
  4240. //===============================
  4241. memset(sstr ,0, sizeof(sstr) );
  4242. c = 0;
  4243. loc = strstr(payload, "messageId");
  4244. while (loc[strlen("messageId")+3+c] != '\"')
  4245. {
  4246. sstr[c] = loc[strlen("messageId")+3+c];
  4247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4248. c++;
  4249. }
  4250. sstr[c] = '\0';
  4251. strcpy(tempmessageId,sstr);
  4252. //===============================
  4253. // data
  4254. //===============================
  4255. memset(sstr ,0, sizeof(sstr) );
  4256. c = 0;
  4257. loc = strstr(payload, "data");
  4258. printf("loc=%s\n",loc);
  4259. while (loc[strlen("data")+3+c] != '\"')
  4260. {
  4261. sstr[c] = loc[strlen("data")+3+c];
  4262. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4263. c++;
  4264. }
  4265. sstr[c] = '\0';
  4266. strcpy(tempdata,sstr);
  4267. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4268. }
  4269. else
  4270. {
  4271. char guid[37]={0};
  4272. random_uuid(guid);
  4273. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4274. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4275. }
  4276. LWS_Send(message);
  4277. return result;
  4278. }
  4279. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4280. {
  4281. mtrace();
  4282. int result = FAIL;
  4283. int connectorIdInt, durationInt;
  4284. char chargingRateUnitStr[4]={0};
  4285. //int tempconnectorIdInt,
  4286. int tempdurationInt;
  4287. float tempminChargingRateFloat = 0.0;
  4288. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4289. int tempStartPeriodInt=0;
  4290. float tempLimitInt=0.0;//0.1;
  4291. int tempNumberPhasesInt=0;
  4292. char fname[200];
  4293. char comfirmstr[20];
  4294. //float totallimit =0.0;
  4295. float MinChargingRate =0.0;
  4296. //double diff_t;
  4297. //struct tm tp;
  4298. FILE *fptr1;
  4299. int c = 0;
  4300. //int i = 0;
  4301. char * pch;
  4302. char *loc;
  4303. char sstr[200]={ 0 };
  4304. int n_chargingProfile = 0;
  4305. int n_SchedulePeriods = 0;
  4306. char SchedulePeriodList[10][200]={0};
  4307. char sLineWord[800]={0};
  4308. //int n_periods = 0;
  4309. char word[1000]={0};
  4310. int confirmPeriods = 0;
  4311. struct StructProfile ChargePointMaxProfile;
  4312. struct StructProfile TxDefaultProfile;
  4313. struct StructProfile TxProfile;
  4314. struct StructProfile TxDefaultProfiletemp[2]={0};
  4315. int TxDefaultProfileFileIsNull=FALSE;
  4316. int ChargePointMaxProfileIsNull=FALSE;
  4317. int TxProfileIsNull=FALSE;
  4318. int CompositeSceduleIndex = 0;
  4319. char ChargePointMaxProfileScheduleStr[30]={0};
  4320. char TxDefaultProfileScheduleStr[30]={0};
  4321. char TxProfileScheduleStr[30]={0};
  4322. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4323. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4324. memset(&TxProfile,0,sizeof(struct StructProfile));
  4325. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4326. c=0;
  4327. loc = strstr(payload, "connectorId");
  4328. memset(sstr ,0, sizeof(sstr) );
  4329. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4330. {
  4331. sstr[c] = loc[strlen("connectorId")+2+c];
  4332. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4333. c++;
  4334. }
  4335. sstr[c] = '\0';
  4336. connectorIdInt = atoi(sstr);
  4337. c=0;
  4338. loc = strstr(payload, "duration");
  4339. memset(sstr ,0, sizeof(sstr) );
  4340. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4341. {
  4342. sstr[c] = loc[strlen("duration")+2+c];
  4343. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4344. c++;
  4345. }
  4346. sstr[c] = '\0';
  4347. durationInt = atoi(sstr);
  4348. c = 0;
  4349. loc = strstr(payload, "chargingRateUnit");
  4350. memset(sstr ,0, sizeof(sstr) );
  4351. if(loc == NULL)
  4352. {
  4353. }
  4354. else
  4355. {
  4356. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4357. {
  4358. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4359. c++;
  4360. }
  4361. sstr[c] = '\0';
  4362. strcpy(chargingRateUnitStr, sstr);
  4363. }
  4364. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4365. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4366. if(connectorIdInt==0) // connectorId is 0
  4367. {
  4368. //******************************ChargePointMaxProfile*****************************************************/
  4369. strcpy(fname, ChargePointMaxProfile_JSON );
  4370. char word[30]={0};
  4371. char sLineWord[1060]={0};
  4372. int n_chargingProfile=0;
  4373. ChargePointMaxProfileIsNull=TRUE;
  4374. if((access(fname,F_OK))!=-1)
  4375. {
  4376. fptr1 = fopen(fname, "r");
  4377. int c;
  4378. c = fgetc(fptr1);
  4379. //DEBUG_INFO("c:%d\n",c);
  4380. rewind(fptr1);
  4381. if(c == EOF)
  4382. {
  4383. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4384. ChargePointMaxProfileIsNull=TRUE;
  4385. fclose(fptr1);
  4386. }
  4387. else
  4388. {
  4389. ChargePointMaxProfileIsNull=FALSE;
  4390. while(fscanf(fptr1, "%s", word) != EOF)
  4391. {
  4392. if(strcmp(word, "chargingProfileId") == 0)
  4393. {
  4394. n_chargingProfile = n_chargingProfile + 1;
  4395. printf("Found\n");
  4396. }
  4397. }
  4398. rewind(fptr1);
  4399. //search Charging Profile Element
  4400. int i= 0;
  4401. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4402. #if 0
  4403. /***********connectorId****************/
  4404. c = 0;
  4405. loc = strstr(sLineWord, "connectorId");
  4406. // printf("loc=%s\n",loc);
  4407. memset(sstr ,0, sizeof(sstr) );
  4408. while (loc[strlen("connectorId")+2+c] != ',')
  4409. {
  4410. sstr[c] = loc[strlen("connectorId")+2+c];
  4411. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4412. c++;
  4413. }
  4414. sstr[c] = '\0';
  4415. tempconnectorIdInt = atoi(sstr);
  4416. #endif
  4417. //***********validFrom**************/
  4418. c = 0;
  4419. loc = strstr(sLineWord, "validFrom");
  4420. //DEBUG_INFO("loc=%s\n",loc);
  4421. memset(sstr ,0, sizeof(sstr) );
  4422. if(loc != NULL)
  4423. {
  4424. while (loc[3+strlen("validFrom")+c] != '\"')
  4425. {
  4426. sstr[c] = loc[3+strlen("validFrom")+c];
  4427. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4428. c++;
  4429. }
  4430. sstr[c] = '\0';
  4431. DEBUG_INFO("validFrom=%s\n",sstr);
  4432. strcpy(tempvalidFromStr,sstr);
  4433. }
  4434. else
  4435. {
  4436. strcpy(tempvalidFromStr,"");
  4437. }
  4438. //**********startSchedule**********/
  4439. c = 0;
  4440. loc = strstr(sLineWord, "startSchedule");
  4441. //DEBUG_INFO("loc=%s\n",loc);
  4442. memset(sstr ,0, sizeof(sstr) );
  4443. while (loc[3+strlen("startSchedule")+c] != '\"')
  4444. {
  4445. sstr[c] = loc[3+strlen("startSchedule")+c];
  4446. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4447. c++;
  4448. }
  4449. sstr[c] = '\0';
  4450. strcpy(tempstartScheduleStr, sstr);
  4451. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4452. //**********chargingRateUnit**********/
  4453. c = 0;
  4454. loc = strstr(sLineWord, "chargingRateUnit");
  4455. memset(sstr ,0, sizeof(sstr) );
  4456. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4457. {
  4458. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4459. c++;
  4460. }
  4461. sstr[c] = '\0';
  4462. strcpy(tempchargingRateUnitStr, sstr);
  4463. //**********minChargingRate*******/
  4464. c = 0;
  4465. loc = strstr(sLineWord, "minChargingRate");
  4466. //printf("loc=%s\n",loc);
  4467. if(loc != NULL)
  4468. {
  4469. memset(sstr ,0, sizeof(sstr) );
  4470. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4471. {
  4472. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4473. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4474. c++;
  4475. }
  4476. sstr[c] = '\0';
  4477. tempminChargingRateFloat = atof(sstr);
  4478. }
  4479. else
  4480. {
  4481. tempminChargingRateFloat = 0.0;
  4482. }
  4483. //
  4484. #if 0
  4485. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4486. tp.tm_isdst = -1;
  4487. time_t utc = mktime(&tp);
  4488. // current time
  4489. time_t t = time(NULL);
  4490. #endif
  4491. //diff_t = difftime(t, utc);
  4492. //parsing strings to words
  4493. i = 0;
  4494. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4495. loc = loc+3+strlen("chargingSchedulePeriod");
  4496. pch = strtok(loc ,"{");
  4497. while (pch != NULL)
  4498. {
  4499. strcpy(SchedulePeriodList[i], pch);
  4500. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4501. //printf ("%s\n",pch);
  4502. pch = strtok (NULL, "{");
  4503. i = i + 1;
  4504. }
  4505. n_SchedulePeriods = i;
  4506. for(int i=0;i<n_SchedulePeriods;i++)
  4507. {
  4508. //*************startPeriod****************/
  4509. c = 0;
  4510. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4511. memset(sstr ,0, sizeof(sstr) );
  4512. while (loc[strlen("startPeriod")+2+c] != ',')
  4513. {
  4514. sstr[c] = loc[strlen("startPeriod")+2+c];
  4515. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4516. c++;
  4517. }
  4518. sstr[c] = '\0';
  4519. tempStartPeriodInt = atoi(sstr);
  4520. //*************limit****************/
  4521. c = 0;
  4522. loc = strstr(SchedulePeriodList[i], "limit");
  4523. memset(sstr ,0, sizeof(sstr) );
  4524. while (loc[strlen("limit")+2+c] != ',')
  4525. {
  4526. sstr[c] = loc[strlen("limit")+2+c];
  4527. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4528. c++;
  4529. }
  4530. sstr[c] = '\0';
  4531. tempLimitInt = atof(sstr);
  4532. //*************numberPhases****************/
  4533. c = 0;
  4534. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4535. memset(sstr ,0, sizeof(sstr) );
  4536. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4537. {
  4538. sstr[c] = loc[strlen("numberPhases")+2+c];
  4539. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4540. c++;
  4541. }
  4542. sstr[c] = '\0';
  4543. tempNumberPhasesInt = atoi(sstr);
  4544. ChargePointMaxProfile.Duration = durationInt;
  4545. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4546. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4547. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4548. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4549. }
  4550. if(MinChargingRate < tempminChargingRateFloat)
  4551. MinChargingRate = tempminChargingRateFloat;
  4552. }
  4553. }// End of file ChargingProfile
  4554. } //THE END OF ACCESS ChargePointMaxProfile
  4555. //******************************TxDefaultProfile***********************************************/
  4556. strcpy(fname, TxDefaultProfile_0_JSON);
  4557. memset(word, 0, 30);
  4558. memset(sLineWord, 0, 1060);
  4559. //char word[30]={0};
  4560. //char sLineWord[1060]={0};
  4561. n_chargingProfile=0;
  4562. TxDefaultProfileFileIsNull=TRUE;
  4563. if((access(fname,F_OK))!=-1)
  4564. {
  4565. fptr1 = fopen(fname, "r");
  4566. c = 0;
  4567. c = fgetc(fptr1);
  4568. //DEBUG_INFO("c:%d\n",c);
  4569. rewind(fptr1);
  4570. if(c == EOF)
  4571. {
  4572. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4573. TxDefaultProfileFileIsNull=TRUE;
  4574. fclose(fptr1);
  4575. }
  4576. else
  4577. {
  4578. TxDefaultProfileFileIsNull=FALSE;
  4579. while(fscanf(fptr1, "%s", word) != EOF)
  4580. {
  4581. if(strcmp(word, "chargingProfileId") == 0)
  4582. {
  4583. n_chargingProfile = n_chargingProfile + 1;
  4584. printf("Found\n");
  4585. }
  4586. }
  4587. rewind(fptr1);
  4588. //search Charging Profile Element
  4589. int i= 0;
  4590. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4591. #if 0
  4592. /***********connectorId****************/
  4593. c = 0;
  4594. loc = strstr(sLineWord, "connectorId");
  4595. // printf("loc=%s\n",loc);
  4596. memset(sstr ,0, sizeof(sstr) );
  4597. while (loc[strlen("connectorId")+2+c] != ',')
  4598. {
  4599. sstr[c] = loc[strlen("connectorId")+2+c];
  4600. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4601. c++;
  4602. }
  4603. sstr[c] = '\0';
  4604. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4605. tempconnectorIdInt = atoi(sstr);
  4606. #endif
  4607. //***********validFrom**************/
  4608. c = 0;
  4609. loc = strstr(sLineWord, "validFrom");
  4610. //DEBUG_INFO("loc=%s\n",loc);
  4611. memset(sstr ,0, sizeof(sstr) );
  4612. if(loc != NULL)
  4613. {
  4614. while (loc[3+strlen("validFrom")+c] != '\"')
  4615. {
  4616. sstr[c] = loc[3+strlen("validFrom")+c];
  4617. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4618. c++;
  4619. }
  4620. sstr[c] = '\0';
  4621. DEBUG_INFO("validFrom=%s\n",sstr);
  4622. strcpy(tempvalidFromStr,sstr);
  4623. }
  4624. else
  4625. {
  4626. strcpy(tempvalidFromStr,"");
  4627. }
  4628. //**********startSchedule**********/
  4629. c = 0;
  4630. loc = strstr(sLineWord, "startSchedule");
  4631. //DEBUG_INFO("loc=%s\n",loc);
  4632. memset(sstr ,0, sizeof(sstr) );
  4633. while (loc[3+strlen("startSchedule")+c] != '\"')
  4634. {
  4635. sstr[c] = loc[3+strlen("startSchedule")+c];
  4636. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4637. c++;
  4638. }
  4639. sstr[c] = '\0';
  4640. strcpy(tempstartScheduleStr, sstr);
  4641. strcpy(TxDefaultProfileScheduleStr, sstr);
  4642. DEBUG_INFO(" debug 3-1\n");
  4643. //**********chargingRateUnit**********/
  4644. c = 0;
  4645. loc = strstr(sLineWord, "chargingRateUnit");
  4646. memset(sstr ,0, sizeof(sstr) );
  4647. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4648. {
  4649. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4650. c++;
  4651. }
  4652. sstr[c] = '\0';
  4653. strcpy(tempchargingRateUnitStr, sstr);
  4654. //**********minChargingRate*******/
  4655. c = 0;
  4656. loc = strstr(sLineWord, "minChargingRate");
  4657. //printf("loc=%s\n",loc);
  4658. if(loc != NULL)
  4659. {
  4660. memset(sstr ,0, sizeof(sstr) );
  4661. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4662. {
  4663. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4664. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4665. c++;
  4666. }
  4667. sstr[c] = '\0';
  4668. tempminChargingRateFloat = atof(sstr);
  4669. }
  4670. else
  4671. {
  4672. tempminChargingRateFloat = 0.0;
  4673. }
  4674. #if 0
  4675. //
  4676. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4677. tp.tm_isdst = -1;
  4678. time_t utc = mktime(&tp);
  4679. // current time
  4680. time_t t = time(NULL);
  4681. //diff_t = difftime(t, utc);
  4682. #endif
  4683. //parsing strings to words
  4684. i = 0;
  4685. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4686. loc = loc+3+strlen("chargingSchedulePeriod");
  4687. pch = strtok(loc ,"{");
  4688. while (pch != NULL)
  4689. {
  4690. strcpy(SchedulePeriodList[i], pch);
  4691. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4692. //printf ("%s\n",pch);
  4693. pch = strtok (NULL, "{");
  4694. i = i + 1;
  4695. }
  4696. n_SchedulePeriods = i;
  4697. for(int i=0;i<n_SchedulePeriods;i++)
  4698. {
  4699. //*************startPeriod****************/
  4700. c = 0;
  4701. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4702. memset(sstr ,0, sizeof(sstr) );
  4703. while (loc[strlen("startPeriod")+2+c] != ',')
  4704. {
  4705. sstr[c] = loc[strlen("startPeriod")+2+c];
  4706. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4707. c++;
  4708. }
  4709. sstr[c] = '\0';
  4710. tempStartPeriodInt = atoi(sstr);
  4711. //*************limit****************/
  4712. c = 0;
  4713. loc = strstr(SchedulePeriodList[i], "limit");
  4714. memset(sstr ,0, sizeof(sstr) );
  4715. while (loc[strlen("limit")+2+c] != ',')
  4716. {
  4717. sstr[c] = loc[strlen("limit")+2+c];
  4718. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4719. c++;
  4720. }
  4721. sstr[c] = '\0';
  4722. tempLimitInt = atof(sstr);
  4723. //*************numberPhases****************/
  4724. c = 0;
  4725. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4726. memset(sstr ,0, sizeof(sstr) );
  4727. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4728. {
  4729. sstr[c] = loc[strlen("numberPhases")+2+c];
  4730. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4731. c++;
  4732. }
  4733. sstr[c] = '\0';
  4734. tempNumberPhasesInt = atoi(sstr);
  4735. TxDefaultProfile.Duration = durationInt;
  4736. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4737. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4738. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4739. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4740. }
  4741. if(MinChargingRate < tempminChargingRateFloat)
  4742. MinChargingRate = tempminChargingRateFloat;
  4743. }
  4744. }
  4745. }// the end of ACCESS TxDefaultProfile
  4746. // Composite Schedule
  4747. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4748. {
  4749. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4750. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4751. {
  4752. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4753. {
  4754. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4755. }
  4756. else
  4757. {
  4758. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4759. }
  4760. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4761. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4762. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4763. }
  4764. }
  4765. //* Define temporary variables */
  4766. struct tm *gtime;
  4767. time_t now;
  4768. char buf[28];
  4769. /* Read the current system time */
  4770. time(&now);
  4771. /* Convert the system time to GMT (now UTC) */
  4772. gtime = gmtime(&now);
  4773. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4774. // make .conf
  4775. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4776. //MaxChargingProfilesInstalled is 10
  4777. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4778. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4779. //nPeriod = 1;
  4780. if(chargingRateUnitStr[0] != 0)
  4781. {
  4782. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4783. }
  4784. else
  4785. {
  4786. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4787. }
  4788. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4789. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4790. confirmPeriods = 1;
  4791. }
  4792. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4793. {
  4794. //*****************************ChargePointMaxProfile******************************************/
  4795. strcpy(fname, ChargePointMaxProfile_JSON);
  4796. ChargePointMaxProfileIsNull=TRUE;
  4797. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4798. {
  4799. fptr1 = fopen(fname, "r");
  4800. int c;
  4801. c = fgetc(fptr1);
  4802. //DEBUG_INFO("c:%d\n",c);
  4803. rewind(fptr1);
  4804. if(c == EOF)
  4805. {
  4806. DEBUG_INFO("\n End of file reached.");
  4807. ChargePointMaxProfileIsNull=TRUE;
  4808. fclose(fptr1);
  4809. }
  4810. else
  4811. {
  4812. ChargePointMaxProfileIsNull=FALSE;
  4813. while(fscanf(fptr1, "%s", word) != EOF)
  4814. {
  4815. if(strcmp(word, "chargingProfileId") == 0)
  4816. {
  4817. n_chargingProfile = n_chargingProfile + 1;
  4818. }
  4819. }
  4820. rewind(fptr1);
  4821. //search Charging Profile Element
  4822. int i = 0;
  4823. int j = 0;
  4824. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4825. #if 0
  4826. /***********connectorId****************/
  4827. c = 0;
  4828. loc = strstr(sLineWord, "connectorId");
  4829. memset(sstr ,0, sizeof(sstr) );
  4830. while (loc[strlen("connectorId")+2+c] != ',')
  4831. {
  4832. sstr[c] = loc[strlen("connectorId")+2+c];
  4833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4834. c++;
  4835. }
  4836. sstr[c] = '\0';
  4837. tempconnectorIdInt = atoi(sstr);
  4838. #endif
  4839. //***********validFrom**************/
  4840. c = 0;
  4841. loc = strstr(sLineWord, "validFrom");
  4842. if(loc != NULL)
  4843. {
  4844. memset(sstr ,0, sizeof(sstr) );
  4845. while (loc[3+strlen("validFrom")+c] != '\"')
  4846. {
  4847. sstr[c] = loc[3+strlen("validFrom")+c];
  4848. c++;
  4849. }
  4850. sstr[c] = '\0';
  4851. strcpy(tempvalidFromStr,sstr);
  4852. }
  4853. else
  4854. {
  4855. strcpy(tempvalidFromStr,"");
  4856. }
  4857. //***********validFrom**************/
  4858. c = 0;
  4859. loc = strstr(sLineWord, "duration");
  4860. if(loc != NULL)
  4861. {
  4862. memset(sstr ,0, sizeof(sstr) );
  4863. while (loc[2+strlen("duration")+c] != ',')
  4864. {
  4865. sstr[c] = loc[2+strlen("duration")+c];
  4866. c++;
  4867. }
  4868. sstr[c] = '\0';
  4869. tempdurationInt = atoi(sstr);
  4870. }
  4871. else
  4872. {
  4873. tempdurationInt = 0;
  4874. }
  4875. //**********startSchedule**********/
  4876. c = 0;
  4877. loc = strstr(sLineWord, "startSchedule");
  4878. memset(sstr ,0, sizeof(sstr) );
  4879. while (loc[3+strlen("startSchedule")+c] != '\"')
  4880. {
  4881. sstr[c] = loc[3+strlen("startSchedule")+c];
  4882. c++;
  4883. }
  4884. sstr[c] = '\0';
  4885. strcpy(tempstartScheduleStr, sstr);
  4886. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4887. //**********chargingRateUnit**********/
  4888. c = 0;
  4889. loc = strstr(sLineWord, "chargingRateUnit");
  4890. memset(sstr ,0, sizeof(sstr) );
  4891. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4892. {
  4893. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4894. c++;
  4895. }
  4896. sstr[c] = '\0';
  4897. strcpy(tempchargingRateUnitStr, sstr);
  4898. //**********minChargingRate*******/
  4899. c = 0;
  4900. loc = strstr(sLineWord, "minChargingRate");
  4901. if(loc != NULL)
  4902. {
  4903. memset(sstr ,0, sizeof(sstr) );
  4904. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4905. {
  4906. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4907. c++;
  4908. }
  4909. sstr[c] = '\0';
  4910. tempminChargingRateFloat = atof(sstr);
  4911. }
  4912. else
  4913. {
  4914. tempminChargingRateFloat = 0.0;
  4915. }
  4916. #if 0
  4917. //
  4918. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4919. tp.tm_isdst = -1;
  4920. time_t utc = mktime(&tp);
  4921. time_t t = time(NULL);
  4922. //diff_t = difftime(t, utc);
  4923. #endif
  4924. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4925. //DEBUG_INFO(" debug 5 -1\n");
  4926. //parsing strings to words
  4927. i = 0;
  4928. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4929. loc = loc+3+strlen("chargingSchedulePeriod");
  4930. pch = strtok(loc ,"{");
  4931. while (pch != NULL)
  4932. {
  4933. strcpy(SchedulePeriodList[i], pch);
  4934. pch = strtok (NULL, "{");
  4935. i = i + 1;
  4936. }
  4937. n_SchedulePeriods = i;
  4938. for(int i=0;i<n_SchedulePeriods;i++)
  4939. {
  4940. //*************startPeriod****************/
  4941. c = 0;
  4942. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4943. memset(sstr ,0, sizeof(sstr) );
  4944. while (loc[strlen("startPeriod")+2+c] != ',')
  4945. {
  4946. sstr[c] = loc[strlen("startPeriod")+2+c];
  4947. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4948. c++;
  4949. }
  4950. sstr[c] = '\0';
  4951. tempStartPeriodInt = atoi(sstr);
  4952. //*************limit****************/
  4953. c = 0;
  4954. loc = strstr(SchedulePeriodList[i], "limit");
  4955. memset(sstr ,0, sizeof(sstr) );
  4956. while (loc[strlen("limit")+2+c] != ',')
  4957. {
  4958. sstr[c] = loc[strlen("limit")+2+c];
  4959. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4960. c++;
  4961. }
  4962. sstr[c] = '\0';
  4963. tempLimitInt = atof(sstr);
  4964. //*************numberPhases****************/
  4965. c = 0;
  4966. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4967. memset(sstr ,0, sizeof(sstr) );
  4968. while (loc[strlen("numberPhases")+2+c] != '}')
  4969. {
  4970. sstr[c] = loc[strlen("numberPhases")+2+c];
  4971. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4972. c++;
  4973. }
  4974. sstr[c] = '\0';
  4975. tempNumberPhasesInt = atoi(sstr);
  4976. if(j == 0)
  4977. {
  4978. ChargePointMaxProfile.Duration = tempdurationInt;
  4979. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4980. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4981. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4982. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4983. }
  4984. }
  4985. if(MinChargingRate < tempminChargingRateFloat)
  4986. {
  4987. MinChargingRate = tempminChargingRateFloat;
  4988. }
  4989. if(confirmPeriods < n_SchedulePeriods)
  4990. {
  4991. confirmPeriods = n_SchedulePeriods;
  4992. }
  4993. j = j + 1;
  4994. }
  4995. fclose(fptr1);
  4996. }
  4997. }// the end of access file ChargePointMaxProfile
  4998. //****************************TxDefaultProfile************************************************/
  4999. #if 0
  5000. switch(connectorIdInt)
  5001. {
  5002. case 0:
  5003. break;
  5004. case 1:
  5005. strcpy(fname, TxDefaultProfile_1_JSON );
  5006. break;
  5007. case 2:
  5008. strcpy(fname, TxDefaultProfile_2_JSON );
  5009. break;
  5010. default:
  5011. strcpy(fname, TxDefaultProfile_1_JSON );
  5012. break;
  5013. }
  5014. #endif
  5015. memset(fname, 0, sizeof fname);
  5016. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5017. TxDefaultProfileFileIsNull=TRUE;
  5018. if((access(fname,F_OK))!=-1)
  5019. {
  5020. fptr1 = fopen(fname, "r");
  5021. c = 0;
  5022. c = fgetc(fptr1);
  5023. //DEBUG_INFO("c:%d\n",c);
  5024. rewind(fptr1);
  5025. if(c == EOF)
  5026. {
  5027. DEBUG_INFO("\n End of file reached.");
  5028. TxDefaultProfileFileIsNull=TRUE;
  5029. fclose(fptr1);
  5030. }
  5031. else
  5032. {
  5033. TxDefaultProfileFileIsNull=FALSE;
  5034. while(fscanf(fptr1, "%s", word) != EOF)
  5035. {
  5036. if(strcmp(word, "chargingProfileId") == 0)
  5037. {
  5038. n_chargingProfile = n_chargingProfile + 1;
  5039. }
  5040. }
  5041. rewind(fptr1);
  5042. //search Charging Profile Element
  5043. int i = 0;
  5044. int j = 0;
  5045. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5046. //DEBUG_INFO(" 1-1\n");
  5047. #if 0
  5048. /***********connectorId****************/
  5049. c = 0;
  5050. loc = strstr(sLineWord, "connectorId");
  5051. memset(sstr ,0, sizeof(sstr) );
  5052. while (loc[strlen("connectorId")+2+c] != ',')
  5053. {
  5054. sstr[c] = loc[strlen("connectorId")+2+c];
  5055. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5056. c++;
  5057. }
  5058. sstr[c] = '\0';
  5059. tempconnectorIdInt = atoi(sstr);
  5060. #endif
  5061. //***********validFrom**************/
  5062. c = 0;
  5063. loc = strstr(sLineWord, "validFrom");
  5064. if(loc != NULL)
  5065. {
  5066. memset(sstr ,0, sizeof(sstr) );
  5067. while (loc[3+strlen("validFrom")+c] != '\"')
  5068. {
  5069. sstr[c] = loc[3+strlen("validFrom")+c];
  5070. c++;
  5071. }
  5072. sstr[c] = '\0';
  5073. strcpy(tempvalidFromStr,sstr);
  5074. }
  5075. else
  5076. {
  5077. strcpy(tempvalidFromStr,"");
  5078. }
  5079. //***********validFrom**************/
  5080. c = 0;
  5081. loc = strstr(sLineWord, "duration");
  5082. if(loc != NULL)
  5083. {
  5084. memset(sstr ,0, sizeof(sstr) );
  5085. while (loc[2+strlen("duration")+c] != ',')
  5086. {
  5087. sstr[c] = loc[2+strlen("duration")+c];
  5088. c++;
  5089. }
  5090. sstr[c] = '\0';
  5091. tempdurationInt = atoi(sstr);
  5092. }
  5093. else
  5094. {
  5095. tempdurationInt = 0;
  5096. }
  5097. //**********startSchedule**********/
  5098. c = 0;
  5099. loc = strstr(sLineWord, "startSchedule");
  5100. memset(sstr ,0, sizeof(sstr) );
  5101. while (loc[3+strlen("startSchedule")+c] != '\"')
  5102. {
  5103. sstr[c] = loc[3+strlen("startSchedule")+c];
  5104. c++;
  5105. }
  5106. sstr[c] = '\0';
  5107. strcpy(tempstartScheduleStr, sstr);
  5108. strcpy(TxDefaultProfileScheduleStr, sstr);
  5109. //**********chargingRateUnit**********/
  5110. c = 0;
  5111. loc = strstr(sLineWord, "chargingRateUnit");
  5112. memset(sstr ,0, sizeof(sstr) );
  5113. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5114. {
  5115. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5116. c++;
  5117. }
  5118. sstr[c] = '\0';
  5119. strcpy(tempchargingRateUnitStr, sstr);
  5120. //**********minChargingRate*******/
  5121. c = 0;
  5122. loc = strstr(sLineWord, "minChargingRate");
  5123. if(loc != NULL)
  5124. {
  5125. memset(sstr ,0, sizeof(sstr) );
  5126. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5127. {
  5128. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5129. c++;
  5130. }
  5131. sstr[c] = '\0';
  5132. tempminChargingRateFloat = atof(sstr);
  5133. }
  5134. else
  5135. {
  5136. tempminChargingRateFloat = 0.0;
  5137. }
  5138. #if 0
  5139. //
  5140. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5141. tp.tm_isdst = -1;
  5142. time_t utc = mktime(&tp);
  5143. time_t t = time(NULL);
  5144. //diff_t = difftime(t, utc);
  5145. #endif
  5146. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5147. //parsing strings to words
  5148. i = 0;
  5149. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5150. loc = loc+3+strlen("chargingSchedulePeriod");
  5151. pch = strtok(loc ,"{");
  5152. while (pch != NULL)
  5153. {
  5154. strcpy(SchedulePeriodList[i], pch);
  5155. pch = strtok (NULL, "{");
  5156. i = i + 1;
  5157. }
  5158. n_SchedulePeriods = i;
  5159. for(int i=0;i<n_SchedulePeriods;i++)
  5160. {
  5161. //*************startPeriod****************/
  5162. c = 0;
  5163. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5164. memset(sstr ,0, sizeof(sstr) );
  5165. while (loc[strlen("startPeriod")+2+c] != ',')
  5166. {
  5167. sstr[c] = loc[strlen("startPeriod")+2+c];
  5168. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5169. c++;
  5170. }
  5171. sstr[c] = '\0';
  5172. tempStartPeriodInt = atoi(sstr);
  5173. //*************limit****************/
  5174. c = 0;
  5175. loc = strstr(SchedulePeriodList[i], "limit");
  5176. memset(sstr ,0, sizeof(sstr) );
  5177. while (loc[strlen("limit")+2+c] != ',')
  5178. {
  5179. sstr[c] = loc[strlen("limit")+2+c];
  5180. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5181. c++;
  5182. }
  5183. sstr[c] = '\0';
  5184. tempLimitInt = atof(sstr);
  5185. //*************numberPhases****************/
  5186. c = 0;
  5187. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5188. memset(sstr ,0, sizeof(sstr) );
  5189. while (loc[strlen("numberPhases")+2+c] != '}')
  5190. {
  5191. sstr[c] = loc[strlen("numberPhases")+2+c];
  5192. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5193. c++;
  5194. }
  5195. sstr[c] = '\0';
  5196. tempNumberPhasesInt = atoi(sstr);
  5197. if(j == 0)
  5198. {
  5199. TxDefaultProfile.Duration = tempdurationInt;
  5200. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5201. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5202. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5203. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5204. }
  5205. else
  5206. {
  5207. //other stack level charging Profile
  5208. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5209. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5210. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5211. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5212. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5213. }
  5214. }
  5215. if(MinChargingRate < tempminChargingRateFloat)
  5216. MinChargingRate = tempminChargingRateFloat;
  5217. if(confirmPeriods < n_SchedulePeriods)
  5218. confirmPeriods = n_SchedulePeriods;
  5219. j = j + 1;
  5220. //DEBUG_INFO(" 1-2\n");
  5221. }
  5222. fclose(fptr1);
  5223. //Stacking Charging Profiles
  5224. for(int l=0; l <(j-1) ;l++)
  5225. {
  5226. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5227. {
  5228. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5229. {
  5230. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5231. {
  5232. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5233. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5234. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5235. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5236. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5237. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5238. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5239. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5240. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5241. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5242. }
  5243. else
  5244. {
  5245. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5246. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5247. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5248. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5249. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5250. }
  5251. }
  5252. }
  5253. }
  5254. //end of Stacking Charging Profiles
  5255. }
  5256. }// the end of ACCESS TxDefaultProfile
  5257. //****************************TxProfile************************************************/
  5258. #if 0
  5259. switch(connectorIdInt)
  5260. {
  5261. case 0:
  5262. break;
  5263. case 1:
  5264. strcpy(fname, TxProfile_1_JSON );
  5265. break;
  5266. case 2:
  5267. strcpy(fname, TxProfile_2_JSON );
  5268. break;
  5269. default:
  5270. strcpy(fname, TxProfile_1_JSON );
  5271. break;
  5272. }
  5273. #endif
  5274. memset(fname, 0, sizeof fname);
  5275. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5276. TxProfileIsNull=TRUE;
  5277. if((access(fname,F_OK))!=-1)
  5278. {
  5279. fptr1 = fopen(fname, "r");
  5280. c = 0;
  5281. c = fgetc(fptr1);
  5282. //DEBUG_INFO("c:%d\n",c);
  5283. rewind(fptr1);
  5284. if(c == EOF)
  5285. {
  5286. DEBUG_INFO("\n End of file reached.");
  5287. TxProfileIsNull=TRUE;
  5288. fclose(fptr1);
  5289. }
  5290. else
  5291. {
  5292. TxProfileIsNull=FALSE;
  5293. while(fscanf(fptr1, "%s", word) != EOF)
  5294. {
  5295. if(strcmp(word, "chargingProfileId") == 0)
  5296. {
  5297. n_chargingProfile = n_chargingProfile + 1;
  5298. }
  5299. }
  5300. rewind(fptr1);
  5301. //search Charging Profile Element
  5302. int i= 0;
  5303. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5304. #if 0
  5305. /***********connectorId****************/
  5306. c = 0;
  5307. loc = strstr(sLineWord, "connectorId");
  5308. memset(sstr ,0, sizeof(sstr) );
  5309. while (loc[strlen("connectorId")+2+c] != ',')
  5310. {
  5311. sstr[c] = loc[strlen("connectorId")+2+c];
  5312. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5313. c++;
  5314. }
  5315. sstr[c] = '\0';
  5316. tempconnectorIdInt = atoi(sstr);
  5317. #endif
  5318. //***********validFrom**************/
  5319. c = 0;
  5320. loc = strstr(sLineWord, "validFrom");
  5321. if(loc != NULL)
  5322. {
  5323. memset(sstr ,0, sizeof(sstr) );
  5324. while (loc[3+strlen("validFrom")+c] != '\"')
  5325. {
  5326. sstr[c] = loc[3+strlen("validFrom")+c];
  5327. c++;
  5328. }
  5329. sstr[c] = '\0';
  5330. strcpy(tempvalidFromStr,sstr);
  5331. }
  5332. else
  5333. {
  5334. strcpy(tempvalidFromStr,"");
  5335. }
  5336. //**********startSchedule**********/
  5337. c = 0;
  5338. loc = strstr(sLineWord, "startSchedule");
  5339. memset(sstr ,0, sizeof(sstr) );
  5340. while (loc[3+strlen("startSchedule")+c] != '\"')
  5341. {
  5342. sstr[c] = loc[3+strlen("startSchedule")+c];
  5343. c++;
  5344. }
  5345. sstr[c] = '\0';
  5346. strcpy(tempstartScheduleStr, sstr);
  5347. strcpy(TxProfileScheduleStr, sstr);
  5348. //**********chargingRateUnit**********/
  5349. c = 0;
  5350. loc = strstr(sLineWord, "chargingRateUnit");
  5351. memset(sstr ,0, sizeof(sstr) );
  5352. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5353. {
  5354. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5355. c++;
  5356. }
  5357. sstr[c] = '\0';
  5358. strcpy(tempchargingRateUnitStr, sstr);
  5359. //**********minChargingRate*******/
  5360. c = 0;
  5361. loc = strstr(sLineWord, "minChargingRate");
  5362. if(loc != NULL)
  5363. {
  5364. memset(sstr ,0, sizeof(sstr) );
  5365. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5366. {
  5367. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5368. c++;
  5369. }
  5370. sstr[c] = '\0';
  5371. tempminChargingRateFloat = atof(sstr);
  5372. }
  5373. else
  5374. {
  5375. tempminChargingRateFloat = 0.0;
  5376. }
  5377. #if 0
  5378. //
  5379. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5380. tp.tm_isdst = -1;
  5381. time_t utc = mktime(&tp);
  5382. time_t t = time(NULL);
  5383. //diff_t = difftime(t, utc);
  5384. #endif
  5385. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5386. //parsing strings to words
  5387. i = 0;
  5388. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5389. loc = loc+3+strlen("chargingSchedulePeriod");
  5390. pch = strtok(loc ,"{");
  5391. while (pch != NULL)
  5392. {
  5393. strcpy(SchedulePeriodList[i], pch);
  5394. pch = strtok (NULL, "{");
  5395. i = i + 1;
  5396. }
  5397. n_SchedulePeriods = i;
  5398. for(int i=0;i<n_SchedulePeriods;i++)
  5399. {
  5400. //*************startPeriod****************/
  5401. c = 0;
  5402. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5403. memset(sstr ,0, sizeof(sstr) );
  5404. while (loc[strlen("startPeriod")+2+c] != ',')
  5405. {
  5406. sstr[c] = loc[strlen("startPeriod")+2+c];
  5407. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5408. c++;
  5409. }
  5410. sstr[c] = '\0';
  5411. tempStartPeriodInt = atoi(sstr);
  5412. //*************limit****************/
  5413. c = 0;
  5414. loc = strstr(SchedulePeriodList[i], "limit");
  5415. memset(sstr ,0, sizeof(sstr) );
  5416. while (loc[strlen("limit")+2+c] != ',')
  5417. {
  5418. sstr[c] = loc[strlen("limit")+2+c];
  5419. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5420. c++;
  5421. }
  5422. sstr[c] = '\0';
  5423. tempLimitInt = atof(sstr);
  5424. //*************numberPhases****************/
  5425. c = 0;
  5426. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5427. memset(sstr ,0, sizeof(sstr) );
  5428. while (loc[strlen("numberPhases")+2+c] != '}')
  5429. {
  5430. sstr[c] = loc[strlen("numberPhases")+2+c];
  5431. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5432. c++;
  5433. }
  5434. sstr[c] = '\0';
  5435. tempNumberPhasesInt = atoi(sstr);
  5436. TxProfile.Duration = durationInt;
  5437. TxProfile.TotalPeriod = n_SchedulePeriods;
  5438. TxProfile.Period[i].Limit = tempLimitInt;
  5439. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5440. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5441. }
  5442. if(MinChargingRate < tempminChargingRateFloat)
  5443. MinChargingRate = tempminChargingRateFloat;
  5444. if(confirmPeriods < n_SchedulePeriods)
  5445. confirmPeriods = n_SchedulePeriods;
  5446. }
  5447. fclose(fptr1);
  5448. }
  5449. }// the end of ACCESS TxProfile
  5450. //CompositeSchedule
  5451. int period=0;
  5452. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5453. {
  5454. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5455. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5456. {
  5457. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5458. {
  5459. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5460. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5461. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5462. period = period + 1;
  5463. }
  5464. else
  5465. {
  5466. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5467. {
  5468. }
  5469. else
  5470. {
  5471. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5472. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5473. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5474. period = period + 1;
  5475. }
  5476. }
  5477. }
  5478. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5479. {
  5480. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5481. {
  5482. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5483. {
  5484. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5485. }
  5486. else
  5487. {
  5488. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5489. }
  5490. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5491. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5492. period = period + 1;
  5493. }
  5494. }
  5495. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5496. {
  5497. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5498. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5499. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5500. period = period + 1;
  5501. }
  5502. }
  5503. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5504. {
  5505. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5506. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5507. {
  5508. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5509. {
  5510. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5511. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5512. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5513. period = period + 1;
  5514. }
  5515. else
  5516. {
  5517. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5518. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5519. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5520. period = period + 1;
  5521. }
  5522. }
  5523. }
  5524. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5525. {
  5526. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5527. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5528. {
  5529. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5530. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5531. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5532. period = period + 1;
  5533. }
  5534. }
  5535. confirmPeriods = period;
  5536. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5537. //* Define temporary variables */
  5538. struct tm *gtime;
  5539. time_t now;
  5540. char buf[28];
  5541. //* Read the current system time */
  5542. time(&now);
  5543. //* Convert the system time to GMT (now UTC) */
  5544. gtime = gmtime(&now);
  5545. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5546. // make .conf
  5547. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5548. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5549. //DEBUG_INFO(" debug 11\n");
  5550. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5551. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5552. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5553. }
  5554. else
  5555. {
  5556. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5557. }
  5558. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5559. return result;
  5560. }
  5561. int handleGetConfigurationRequest(char *uuid, char *payload)
  5562. {
  5563. mtrace();
  5564. int result = FAIL;
  5565. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5566. //struct json_object *jsonitem;
  5567. int MaxKeySupported = 0;
  5568. int n_keys = 0;
  5569. char requestKey[43][50]={0};
  5570. char search[]="[";
  5571. char sstr[500]={ 0 };
  5572. //int pos;
  5573. int l, c = 0;
  5574. int i = 0;
  5575. char *delim = "\",\"";
  5576. char * pch;
  5577. char *loc = strstr(payload, search);
  5578. //********************* Parsing String ***********************************/
  5579. if(loc == NULL) {
  5580. DEBUG_INFO("no key match in Configuration \n");
  5581. }
  5582. else {
  5583. //pos = loc - payload;
  5584. l = strlen(loc)-4;
  5585. while (c < l)
  5586. {
  5587. sstr[c] = loc[c+2];
  5588. c++;
  5589. }
  5590. sstr[c] = '\0';
  5591. //parsing strings to words
  5592. pch = strtok(sstr,delim);
  5593. if(pch == NULL)
  5594. {
  5595. strcpy(requestKey[0], sstr);
  5596. }
  5597. else
  5598. {
  5599. while (pch != NULL)
  5600. {
  5601. strcpy(requestKey[i], pch);
  5602. pch = strtok (NULL, delim);
  5603. i = i + 1;
  5604. }
  5605. n_keys = i;
  5606. }
  5607. }
  5608. UnknownKeynum = 0;
  5609. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5610. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5611. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5612. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5613. if(n_keys != 0)
  5614. {
  5615. for(int i=0;i<n_keys;i++)
  5616. {
  5617. getKeyValue(requestKey[i]);
  5618. //json_object_put(jsonitem);
  5619. }
  5620. }
  5621. else
  5622. {
  5623. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5624. getKeyValue("");
  5625. }
  5626. processUnkownKey();
  5627. sendGetConfigurationConfirmation(uuid);
  5628. return result;
  5629. }
  5630. static char fnamePlusPath[100]={0};
  5631. static char fnamePWithNoPath[60]={0};
  5632. void checkUploadLog(void)
  5633. {
  5634. FILE *fp;
  5635. /* Open the command for reading. */
  5636. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5637. if (fp == NULL) {
  5638. printf("Failed to run command\n" );
  5639. exit(1);
  5640. }
  5641. int ftppathlen = 0;
  5642. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5643. int i = 0;
  5644. /* Read the output a line at a time - output it. */
  5645. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5646. if(i==0)
  5647. {
  5648. ftppathlen = strlen(fnamePlusPath);
  5649. printf("%s\n", fnamePlusPath);
  5650. fnamePlusPath[ftppathlen]='\0';
  5651. break;
  5652. }
  5653. i= i+1;
  5654. }
  5655. /* close */
  5656. pclose(fp);
  5657. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5658. {
  5659. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5660. {
  5661. fnamePlusPath[k]='\0';
  5662. }
  5663. }
  5664. i=1;
  5665. //char fname[60]={0};
  5666. while(i < ftppathlen)
  5667. {
  5668. int len=ftppathlen-i;
  5669. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5670. {
  5671. printf("compare '/' all right\n");
  5672. break;
  5673. }
  5674. i=i+1;
  5675. }
  5676. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5677. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5678. fnamePWithNoPath[i+1] = '\0';
  5679. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5680. {
  5681. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5682. {
  5683. fnamePWithNoPath[j]='\0';
  5684. }
  5685. }
  5686. FILE* fp1 = fopen(fnamePlusPath, "r");
  5687. if (fp1)
  5688. {
  5689. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5690. // file exists
  5691. fclose(fp1);
  5692. }
  5693. else
  5694. {
  5695. // file doesn't exist
  5696. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5697. }
  5698. }
  5699. static char GetDiagnosticspayloadData[300]={0};
  5700. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5701. {
  5702. mtrace();
  5703. int result = FAIL;
  5704. pthread_t t; // pthread 變數
  5705. system("exec /root/logPackTools 'log' 6");
  5706. #if 0
  5707. //char buffer [128];
  5708. time (&rawtime);
  5709. //printf("%ld\n", rawtime);
  5710. timeinfo = localtime (&rawtime);
  5711. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5712. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5713. if((access(fnamePlusPath,F_OK))!=-1)
  5714. {
  5715. DEBUG_INFO("fnamePlusPath exist.\n");
  5716. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5717. }
  5718. else
  5719. {
  5720. DEBUG_INFO("fnamePlusPath not exist!\n");
  5721. }
  5722. #endif
  5723. checkUploadLog();
  5724. memset(GetDiagnosticspayloadData, 0, 300);
  5725. strcpy(GetDiagnosticspayloadData, payload);
  5726. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5727. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5728. return result;
  5729. }
  5730. void* GetDiagnosticsProcess(void* data)
  5731. {
  5732. pthread_detach(pthread_self());
  5733. mtrace();
  5734. int retriesInt=0, retryIntervalInt=0;
  5735. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5736. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5737. 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};
  5738. int port=0;
  5739. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5740. int c = 0;
  5741. char *loc;
  5742. int isSuccess = FALSE;
  5743. char ftpbuf[200]={0};
  5744. //char temp[100]={0};
  5745. char * pch;
  5746. // [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"}]
  5747. char str[300]={ 0 };
  5748. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5749. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5750. DEBUG_INFO("GetDiagnosticsProcess\n");
  5751. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5752. //****************location*******************/
  5753. c = 0;
  5754. memset(sstr ,0, sizeof(sstr) );
  5755. loc = strstr(str, "location");
  5756. while (loc[3+strlen("location")+c] != '\"')
  5757. {
  5758. sstr[c] = loc[3+strlen("location")+c];
  5759. c++;
  5760. }
  5761. sstr[c] = '\0';
  5762. strcpy(locationstr,sstr);
  5763. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5764. if(strcmp(locationstr,"")==0)
  5765. {
  5766. DEBUG_INFO("location is <Empty>!\n");
  5767. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5768. goto end;
  5769. }
  5770. //****************retries*******************/
  5771. c = 0;
  5772. loc = strstr(str, "retries");
  5773. if(loc == NULL)
  5774. {
  5775. retriesIsNULL = TRUE;
  5776. }
  5777. else
  5778. {
  5779. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5780. {
  5781. sstr[c] = loc[strlen("retries")+2+c];
  5782. c++;
  5783. }
  5784. sstr[c] = '\0';
  5785. retriesInt = atoi(sstr);
  5786. }
  5787. if(retriesIsNULL == TRUE)
  5788. {
  5789. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5790. }
  5791. //****************retryInterval*******************/
  5792. c = 0;
  5793. loc = strstr(str, "retryInterval");
  5794. if(loc == NULL)
  5795. {
  5796. retryIntervalIsNULL = TRUE;
  5797. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5798. }
  5799. else
  5800. {
  5801. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5802. {
  5803. sstr[c] = loc[strlen("retryInterval")+2+c];
  5804. c++;
  5805. }
  5806. sstr[c] = '\0';
  5807. retryIntervalInt = atoi(sstr);
  5808. }
  5809. //****************startTime*******************/
  5810. c = 0;
  5811. memset(sstr ,0, sizeof(sstr) );
  5812. loc = strstr(str, "startTime");
  5813. if(loc == NULL)
  5814. {
  5815. startTimeIsNULL = TRUE;
  5816. }
  5817. else
  5818. {
  5819. while (loc[3+strlen("startTime")+c] != '\"')
  5820. {
  5821. sstr[c] = loc[3+strlen("startTime")+c];
  5822. c++;
  5823. }
  5824. sstr[c] = '\0';
  5825. strcpy(startTimestr,sstr);
  5826. }
  5827. //****************stopTime*******************/
  5828. c = 0;
  5829. memset(sstr ,0, sizeof(sstr) );
  5830. loc = strstr(str, "stopTime");
  5831. if(loc == NULL)
  5832. {
  5833. stopTimeIsNULL = TRUE;
  5834. }
  5835. else
  5836. {
  5837. while (loc[3+strlen("stopTime")+c] != '\"')
  5838. {
  5839. sstr[c] = loc[3+strlen("stopTime")+c];
  5840. c++;
  5841. }
  5842. sstr[c] = '\0';
  5843. strcpy(stopTimestr,sstr);
  5844. }
  5845. memset(protocol, 0, sizeof(protocol));
  5846. memset(user, 0, sizeof(user) );
  5847. memset(password, 0, sizeof(password));
  5848. memset(host, 0, sizeof(host));
  5849. memset(path, 0, sizeof(path));
  5850. memset(ftppath, 0, sizeof(ftppath));
  5851. memset(host1, 0, sizeof(host1));
  5852. memset(path1, 0, sizeof(path1));
  5853. /*location: ftp://user:password@host:port/path*/
  5854. #if 0
  5855. time_t rawtime;
  5856. struct tm * timeinfo;
  5857. //char buffer [128];
  5858. time (&rawtime);
  5859. //printf("%ld\n", rawtime);
  5860. timeinfo = localtime (&rawtime);
  5861. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5862. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5863. #endif
  5864. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5865. if((access(fnamePlusPath,F_OK))!=-1)
  5866. {
  5867. DEBUG_INFO("fnamePlusPath exist.\n");
  5868. }
  5869. else
  5870. {
  5871. DEBUG_INFO("fnamePlusPath not exist!\n");
  5872. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5873. goto end;
  5874. }
  5875. pch=strchr(locationstr,'@');
  5876. if(pch==NULL)
  5877. {
  5878. sscanf(locationstr,
  5879. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5880. protocol, host, &port, path);
  5881. strcpy(user,"anonymous");
  5882. strcpy(password,"");
  5883. }
  5884. else
  5885. {
  5886. //DEBUG_INFO("pch=%s\n", pch);
  5887. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5888. protocol, user, password, host, &port, path);
  5889. }
  5890. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5891. {
  5892. DEBUG_INFO("protocol is not ftp/http ! \n");
  5893. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5894. goto end;
  5895. }
  5896. if(strncmp(locationstr,"http", 4) == 0)
  5897. {
  5898. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  5899. sprintf(ftppath,"/%s", path);
  5900. do{
  5901. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5902. sleep(retryIntervalInt);
  5903. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5904. if(!isSuccess)
  5905. {
  5906. DEBUG_INFO("Diagnostics fail.\n");
  5907. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5908. }
  5909. else
  5910. {
  5911. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5912. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5913. }
  5914. }
  5915. else
  5916. {
  5917. sscanf(host,"%[^/]%s",host1, path1);
  5918. sprintf(ftppath,"%s", path1);
  5919. int ftppathlen=strlen(ftppath);
  5920. int i=1;
  5921. char filenametemp[50];
  5922. while(i < ftppathlen)
  5923. {
  5924. int len=ftppathlen-i;
  5925. if(ftppath[len]== 47) // '/' ascll code: 47
  5926. {
  5927. DEBUG_INFO("find '/' all right\n");
  5928. break;
  5929. }
  5930. i=i+1;
  5931. }
  5932. memset(filenametemp, 0, sizeof(filenametemp));
  5933. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5934. filenametemp[i+1] = 0;
  5935. memset(ftpbuf, 0, sizeof(ftpbuf));
  5936. if(port == 0)
  5937. port = 21;
  5938. do{
  5939. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5940. sleep(retryIntervalInt);
  5941. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5942. if(!isSuccess)
  5943. {
  5944. DEBUG_INFO("Diagnostics fail.\n");
  5945. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5946. }
  5947. else
  5948. {
  5949. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5950. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5951. }
  5952. }
  5953. end:
  5954. DiagnosticsStatusNotificationStatus = 0; //Idle
  5955. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5956. }
  5957. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5958. {
  5959. mtrace();
  5960. int result = FAIL;
  5961. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5962. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5963. {
  5964. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5965. localversion = -1;
  5966. }
  5967. else
  5968. {
  5969. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5970. OCPP_getListVerion();
  5971. }
  5972. //from db.OCPP_getListVerion
  5973. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5974. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5975. sendGetLocalListVersionConfirmation(uuid,"");
  5976. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5977. return result;
  5978. }
  5979. int handleRemoteStartRequest(char *uuid, char *payload)
  5980. {
  5981. mtrace();
  5982. int result = FAIL;
  5983. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5984. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5985. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5986. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5987. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5988. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5989. int chargingSchedulePeriodCount = 0;
  5990. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5991. int c = 0;
  5992. char *loc;
  5993. char comfirmstr[20]={0};
  5994. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5995. if(server_pending == TRUE)
  5996. {
  5997. return 0;
  5998. }
  5999. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6000. //**********connectorId****************/
  6001. c = 0;
  6002. memset(sstr ,0, sizeof(sstr) );
  6003. loc = strstr(payload, "connectorId");
  6004. if(loc == NULL)
  6005. {
  6006. connectorIdIsNULL = TRUE;
  6007. }
  6008. else
  6009. {
  6010. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6011. {
  6012. sstr[c] = loc[strlen("connectorId")+2+c];
  6013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6014. c++;
  6015. }
  6016. sstr[c] = '\0';
  6017. connectorIdInt = atoi(sstr);
  6018. }
  6019. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6020. {
  6021. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6022. goto end;
  6023. }
  6024. //****************idTag*******************/
  6025. c = 0;
  6026. memset(sstr ,0, sizeof(sstr) );
  6027. loc = strstr(payload, "idTag");
  6028. while (loc[3+strlen("idTag")+c] != '\"')
  6029. {
  6030. sstr[c] = loc[3+strlen("idTag")+c];
  6031. c++;
  6032. }
  6033. sstr[c] = '\0';
  6034. strcpy(idTagstr,sstr);
  6035. //****************chargingProfile*******************/
  6036. c = 0;
  6037. memset(sstr ,0, sizeof(sstr) );
  6038. loc = strstr(payload, "chargingProfile");
  6039. if(loc == NULL)
  6040. {
  6041. chargingProfileIsNULL = TRUE;
  6042. }
  6043. else
  6044. {
  6045. //****************chargingProfileId*******************/
  6046. c=0;
  6047. loc = strstr(payload, "chargingProfileId");
  6048. memset(sstr ,0, sizeof(sstr) );
  6049. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6050. {
  6051. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6052. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6053. c++;
  6054. }
  6055. sstr[c] = '\0';
  6056. chargingProfileIdInt = atoi(sstr);
  6057. //****************transactionId*******************/
  6058. loc = strstr(payload, "transactionId");
  6059. if(loc == NULL)
  6060. {
  6061. transactionIdIsNULL = TRUE;
  6062. }
  6063. else
  6064. {
  6065. c=0;
  6066. memset(sstr ,0, sizeof(sstr) );
  6067. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6068. {
  6069. sstr[c] = loc[strlen("transactionId")+2+c];
  6070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6071. c++;
  6072. }
  6073. sstr[c] = '\0';
  6074. transactionIdInt = atoi(sstr);
  6075. }
  6076. //****************stackLevel*******************/
  6077. c=0;
  6078. loc = strstr(payload, "stackLevel");
  6079. memset(sstr ,0, sizeof(sstr) );
  6080. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6081. {
  6082. sstr[c] = loc[strlen("stackLevel")+2+c];
  6083. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6084. c++;
  6085. }
  6086. sstr[c] = '\0';
  6087. stackLevelInt = atoi(sstr);
  6088. //****************chargingProfilePurpose*******************/
  6089. c = 0;
  6090. memset(sstr ,0, sizeof(sstr) );
  6091. loc = strstr(payload, "chargingProfilePurpose");
  6092. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6093. {
  6094. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6095. c++;
  6096. }
  6097. sstr[c] = '\0';
  6098. strcpy(chargingProfilePurposestr,sstr);
  6099. //****************chargingProfileKind*******************/
  6100. c = 0;
  6101. memset(sstr ,0, sizeof(sstr) );
  6102. loc = strstr(payload, "chargingProfileKind");
  6103. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6104. {
  6105. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6106. c++;
  6107. }
  6108. sstr[c] = '\0';
  6109. strcpy(chargingProfileKindstr,sstr);
  6110. //****************recurrencyKind*******************/
  6111. loc = strstr(payload, "recurrencyKind");
  6112. if(loc == NULL)
  6113. {
  6114. recurrencyKindIsNULL = TRUE;
  6115. }
  6116. else
  6117. {
  6118. c = 0;
  6119. memset(sstr ,0, sizeof(sstr) );
  6120. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6121. {
  6122. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6123. c++;
  6124. }
  6125. sstr[c] = '\0';
  6126. strcpy(recurrencyKindstr,sstr);
  6127. }
  6128. //****************validFrom*******************/
  6129. loc = strstr(payload, "validFrom");
  6130. if(loc == NULL)
  6131. {
  6132. validFromIsNULL = TRUE;
  6133. }
  6134. else
  6135. {
  6136. c = 0;
  6137. memset(sstr ,0, sizeof(sstr) );
  6138. while (loc[3+strlen("validFrom")+c] != '\"')
  6139. {
  6140. sstr[c] = loc[3+strlen("validFrom")+c];
  6141. c++;
  6142. }
  6143. sstr[c] = '\0';
  6144. strcpy(validFromstr,sstr);
  6145. }
  6146. //****************validTo*******************/
  6147. loc = strstr(payload, "validTo");
  6148. if(loc == NULL)
  6149. {
  6150. validToIsNULL = TRUE;
  6151. }
  6152. else
  6153. {
  6154. c = 0;
  6155. memset(sstr ,0, sizeof(sstr) );
  6156. while (loc[3+strlen("validTo")+c] != '\"')
  6157. {
  6158. sstr[c] = loc[3+strlen("validTo")+c];
  6159. c++;
  6160. }
  6161. sstr[c] = '\0';
  6162. strcpy(validTostr,sstr);
  6163. }
  6164. //****************chargingSchedule*******************/
  6165. loc = strstr(payload, "chargingSchedule");
  6166. if(loc != NULL)
  6167. {
  6168. //****************duration*******************/
  6169. loc = strstr(payload, "duration");
  6170. if(loc == NULL)
  6171. {
  6172. durationIsNULL = TRUE;
  6173. }
  6174. else
  6175. {
  6176. c=0;
  6177. memset(sstr ,0, sizeof(sstr) );
  6178. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6179. {
  6180. sstr[c] = loc[strlen("duration")+2+c];
  6181. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6182. c++;
  6183. }
  6184. sstr[c] = '\0';
  6185. durationInt = atoi(sstr);
  6186. }
  6187. //****************startSchedule******************/
  6188. loc = strstr(payload, "startSchedule");
  6189. if(loc == NULL)
  6190. {
  6191. startScheduleIsNULL = TRUE;
  6192. }
  6193. else
  6194. {
  6195. c = 0;
  6196. memset(sstr ,0, sizeof(sstr) );
  6197. while (loc[3+strlen("startSchedule")+c] != '\"')
  6198. {
  6199. sstr[c] = loc[3+strlen("startSchedule")+c];
  6200. c++;
  6201. }
  6202. sstr[c] = '\0';
  6203. strcpy(startSchedulestr,sstr);
  6204. }
  6205. //****************chargingRateUnit*******************/
  6206. c = 0;
  6207. memset(sstr ,0, sizeof(sstr) );
  6208. loc = strstr(payload, "chargingRateUnit");
  6209. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6210. {
  6211. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6212. c++;
  6213. }
  6214. sstr[c] = '\0';
  6215. strcpy(chargingRateUnitstr,sstr);
  6216. //****************minChargingRate*******************/
  6217. loc = strstr(payload, "minChargingRate");
  6218. if(loc == NULL)
  6219. {
  6220. minChargingRateIsNULL = TRUE;
  6221. }
  6222. else
  6223. {
  6224. c=0;
  6225. memset(sstr ,0, sizeof(sstr) );
  6226. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6227. {
  6228. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6229. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6230. c++;
  6231. }
  6232. sstr[c] = '\0';
  6233. minChargingRateflaot = atof(sstr);
  6234. }
  6235. //****************chargingSchedulePeriod count*******************/
  6236. int what_len = strlen("startPeriod");
  6237. char *where = payload;
  6238. while ((where = strstr(where, "startPeriod"))) {
  6239. where += what_len;
  6240. chargingSchedulePeriodCount++;
  6241. }
  6242. where = payload;
  6243. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6244. {
  6245. //****************startPeriod*******************/
  6246. c=0;
  6247. loc = strstr(where, "startPeriod");
  6248. memset(sstr ,0, sizeof(sstr) );
  6249. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6250. {
  6251. sstr[c] = loc[strlen("startPeriod")+2+c];
  6252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6253. c++;
  6254. }
  6255. sstr[c] = '\0';
  6256. startPeriodInt[periodNums] = atoi(sstr);
  6257. //****************limit*******************/
  6258. c=0;
  6259. loc = strstr(where, "limit");
  6260. memset(sstr ,0, sizeof(sstr) );
  6261. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6262. {
  6263. sstr[c] = loc[strlen("limit")+2+c];
  6264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6265. c++;
  6266. }
  6267. sstr[c] = '\0';
  6268. limitflaot[periodNums] = atof(sstr);
  6269. //****************numberPhases*******************/
  6270. loc = strstr(where, "numberPhases");
  6271. if(loc == NULL)
  6272. {
  6273. numberPhasesIsNULL = TRUE;
  6274. }
  6275. else
  6276. {
  6277. c=0;
  6278. memset(sstr ,0, sizeof(sstr) );
  6279. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6280. {
  6281. sstr[c] = loc[strlen("numberPhases")+2+c];
  6282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6283. c++;
  6284. }
  6285. sstr[c] = '\0';
  6286. numberPhasesInt[periodNums] = atoi(sstr);
  6287. }
  6288. where = loc;
  6289. }
  6290. }
  6291. }
  6292. /*
  6293. enum _SYSTEM_STATUS
  6294. {
  6295. S_BOOTING = 0,
  6296. S_IDLE, = 1
  6297. S_AUTHORIZING, =2
  6298. S_REASSIGN_CHECK, =3
  6299. S_REASSIGN, =4
  6300. S_PRECHARGE, =5
  6301. S_PREPARING_FOR_EV, =6
  6302. S_PREPARING_FOR_EVSE, =7
  6303. S_CHARGING, =8
  6304. S_TERMINATING, =9
  6305. S_COMPLETE, =10
  6306. S_ALARM, =11
  6307. S_FAULT =12
  6308. }
  6309. */
  6310. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6311. {
  6312. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6313. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6314. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6315. //check Transaction active
  6316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6317. {
  6318. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6319. {
  6320. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6321. {
  6322. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6323. {
  6324. //Reserved
  6325. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6326. }
  6327. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6328. {
  6329. //Reserved
  6330. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6331. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6332. goto end;
  6333. }
  6334. else
  6335. {
  6336. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6337. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6338. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6339. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6340. {
  6341. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6342. goto end;
  6343. }
  6344. }//END FOR ELSE
  6345. }
  6346. }// END FOR CHAdeMO_QUANTITY
  6347. for (int index = 0; index < CCS_QUANTITY; index++)
  6348. {
  6349. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6350. {
  6351. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6352. {
  6353. //Reserved
  6354. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6355. }
  6356. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6357. {
  6358. //Reserved
  6359. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6360. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6361. goto end;
  6362. }
  6363. else
  6364. {
  6365. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6366. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6367. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6368. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6369. {
  6370. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6371. goto end;
  6372. }
  6373. }// END FOR ELSE
  6374. }
  6375. }// END FOR CCS_QUANTITY
  6376. for (int index = 0; index < GB_QUANTITY; index++)
  6377. {
  6378. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6379. {
  6380. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6381. {
  6382. //Reserved
  6383. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6384. }
  6385. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6386. {
  6387. //Reserved
  6388. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6389. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6390. goto end;
  6391. }
  6392. else
  6393. {
  6394. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6395. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6396. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6397. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6398. {
  6399. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6400. goto end;
  6401. }
  6402. }// END FOR ELSE
  6403. }
  6404. } // END FOR GB_QUANTITY
  6405. }
  6406. else
  6407. {
  6408. for (int index = 0; index < AC_QUANTITY; index++)
  6409. {
  6410. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6411. {
  6412. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6413. {
  6414. //Reserved
  6415. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6416. }
  6417. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6418. {
  6419. //Reserved
  6420. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6421. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6422. goto end;
  6423. }
  6424. else
  6425. {
  6426. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6427. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6428. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6429. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6430. {
  6431. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6432. goto end;
  6433. }
  6434. }//END FOR ELSE
  6435. }
  6436. }// END FOR AC_QUANTITY
  6437. }
  6438. if(chargingProfileIsNULL == FALSE)
  6439. {
  6440. //ChargingProfile
  6441. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6442. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6443. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6444. if(recurrencyKindIsNULL == FALSE) //OPTION
  6445. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6446. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6447. if(transactionIdIsNULL == FALSE) // OPTION
  6448. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6449. if(validFromIsNULL == FALSE) // OPTION
  6450. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6451. if(validToIsNULL == FALSE) //OPTION
  6452. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6453. //ChargingSchedule
  6454. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6455. if(durationIsNULL == FALSE) //OPTION
  6456. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6457. if(minChargingRateIsNULL == FALSE) //OPTION
  6458. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6459. if(startScheduleIsNULL == FALSE) //OPTION
  6460. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6461. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6462. {
  6463. //ChargingSchedulePeriod
  6464. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6465. if(numberPhasesIsNULL == FALSE)
  6466. {
  6467. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6468. }
  6469. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6470. }
  6471. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6472. {
  6473. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6474. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6475. //memset idTag
  6476. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6477. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6478. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6479. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6480. }
  6481. else
  6482. {
  6483. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6484. }
  6485. }
  6486. else
  6487. {
  6488. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6489. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6490. //memset idTag
  6491. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6492. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6493. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6494. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6495. }
  6496. }
  6497. else
  6498. {
  6499. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6500. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6501. }
  6502. end:
  6503. if(connectorIdIsNULL == FALSE)
  6504. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6505. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6506. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6507. //OCPP send RemoteStartConfirmation by first.
  6508. sendRemoteStartConfirmation(uuid, comfirmstr);
  6509. return result;
  6510. }
  6511. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6512. {
  6513. mtrace();
  6514. int result = FAIL;
  6515. int match = FALSE;
  6516. int GunNO = 0;
  6517. int transactionIdInt=0;
  6518. int transactionIdIsNULL= FALSE;
  6519. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6520. int c = 0;
  6521. char *loc;
  6522. char comfirmstr[20];
  6523. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6524. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6525. if(server_pending == TRUE)
  6526. {
  6527. return 0;
  6528. }
  6529. c=0;
  6530. loc = strstr(payload, "transactionId");
  6531. if(loc == NULL)
  6532. {
  6533. transactionIdIsNULL= TRUE;
  6534. }
  6535. else
  6536. {
  6537. memset(sstr ,0, sizeof(sstr) );
  6538. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6539. {
  6540. sstr[c] = loc[strlen("transactionId")+2+c];
  6541. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6542. c++;
  6543. }
  6544. sstr[c] = '\0';
  6545. transactionIdInt = atoi(sstr);
  6546. }
  6547. if(transactionIdIsNULL == FALSE)
  6548. {
  6549. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6550. {
  6551. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6552. {
  6553. //check Transaction active
  6554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6555. {
  6556. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6557. {
  6558. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6559. {
  6560. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6561. {
  6562. match = TRUE;
  6563. GunNO = gun_index;
  6564. }
  6565. }
  6566. }// END FOR CHAdeMO_QUANTITY
  6567. for (int index = 0; index < CCS_QUANTITY; index++)
  6568. {
  6569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6570. {
  6571. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6572. {
  6573. match = TRUE;
  6574. GunNO = gun_index;
  6575. }
  6576. }
  6577. }// END FOR CCS_QUANTITY
  6578. for (int index = 0; index < GB_QUANTITY; index++)
  6579. {
  6580. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6581. {
  6582. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6583. {
  6584. match = TRUE;
  6585. GunNO = gun_index;
  6586. }
  6587. }
  6588. }// END FOR GB_QUANTITY
  6589. }
  6590. else
  6591. {
  6592. for (int index = 0; index < AC_QUANTITY; index++)
  6593. {
  6594. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6595. {
  6596. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6597. {
  6598. match = TRUE;
  6599. GunNO = gun_index;
  6600. }
  6601. }
  6602. }// END FOR CHAdeMO_QUANTITY
  6603. }// END FOR AC ELSE
  6604. }// CHECK IF ResponseTransactionId == transactionIdInt
  6605. }//END FOR
  6606. if( match == TRUE)
  6607. {
  6608. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6609. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6610. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6611. }
  6612. else
  6613. {
  6614. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6615. }
  6616. }
  6617. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6618. return result;
  6619. }
  6620. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6621. {
  6622. mtrace();
  6623. int result = FAIL;
  6624. int connectorIdInt=0, reservationIdInt=0;
  6625. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6626. char comfirmstr[20]={0};
  6627. char sstr[180]={ 0 };
  6628. int c = 0;
  6629. char *loc;
  6630. //char *ptr;
  6631. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6632. //***(1)connectorId ****/
  6633. c=0;
  6634. loc = strstr(payload, "connectorId");
  6635. memset(sstr ,0, sizeof(sstr) );
  6636. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6637. {
  6638. sstr[c] = loc[strlen("connectorId")+2+c];
  6639. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6640. c++;
  6641. }
  6642. sstr[c] = '\0';
  6643. connectorIdInt = atoi(sstr);
  6644. //***(2)expiryDate ****/
  6645. loc = strstr(payload, "expiryDate");
  6646. memset(sstr ,0, sizeof(sstr) );
  6647. c = 0;
  6648. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6649. {
  6650. sstr[c] = loc[3+strlen("expiryDate")+c];
  6651. c++;
  6652. }
  6653. sstr[c] = '\0';
  6654. strcpy(expiryDatestr, sstr);
  6655. //***(3)idTag ****/
  6656. loc = strstr(payload, "idTag");
  6657. memset(sstr ,0, sizeof(sstr) );
  6658. c = 0;
  6659. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6660. {
  6661. sstr[c] = loc[3+strlen("idTag")+c];
  6662. c++;
  6663. }
  6664. sstr[c] = '\0';
  6665. strcpy(idTagstr, sstr);
  6666. //***(4)parentIdTag ****/
  6667. loc = strstr(payload, "parentIdTag");
  6668. memset(sstr ,0, sizeof(sstr) );
  6669. c = 0;
  6670. if(loc == NULL)
  6671. {
  6672. strcpy(parentIdTagstr, "");
  6673. }
  6674. else
  6675. {
  6676. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6677. {
  6678. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6679. c++;
  6680. }
  6681. sstr[c] = '\0';
  6682. strcpy(parentIdTagstr, sstr);
  6683. }
  6684. //***(5)reservationId ****/
  6685. c=0;
  6686. loc = strstr(payload, "reservationId");
  6687. memset(sstr ,0, sizeof(sstr) );
  6688. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6689. {
  6690. sstr[c] = loc[strlen("reservationId")+2+c];
  6691. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6692. c++;
  6693. }
  6694. sstr[c] = '\0';
  6695. reservationIdInt = atoi(sstr);
  6696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6697. /*
  6698. enum SYSTEM_STATUS
  6699. {
  6700. SYS_MODE_BOOTING = 0,
  6701. SYS_MODE_IDLE = 1,
  6702. SYS_MODE_AUTHORIZING = 2,
  6703. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6704. SYS_MODE_REASSIGN = 4,
  6705. SYS_MODE_PREPARING = 5,
  6706. SYS_MODE_PREPARE_FOR_EV = 6,
  6707. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6708. SYS_MODE_CHARGING = 8,
  6709. SYS_MODE_TERMINATING = 9,
  6710. SYS_MODE_COMPLETE = 10,
  6711. SYS_MODE_ALARM = 11,
  6712. SYS_MODE_FAULT = 12,
  6713. SYS_MODE_RESERVATION = 13,
  6714. SYS_MODE_BOOKING = 14,
  6715. SYS_MODE_MAINTAIN = 15,
  6716. SYS_MODE_DEBUG = 16,
  6717. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6718. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6719. SYS_MODE_UPDATE = 19
  6720. };
  6721. */
  6722. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6723. {
  6724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6725. goto end;
  6726. }
  6727. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6728. {
  6729. //check Transaction active
  6730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6731. {
  6732. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6733. {
  6734. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6735. {
  6736. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6737. {
  6738. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6739. {
  6740. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6741. {
  6742. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6744. }
  6745. 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'))
  6746. {
  6747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6748. }
  6749. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6750. {
  6751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6752. }
  6753. else
  6754. {
  6755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6756. }
  6757. }
  6758. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6759. {
  6760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6761. }
  6762. }
  6763. else
  6764. {
  6765. //replace reservation
  6766. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6768. }
  6769. }
  6770. } // END FOR CHAdeMO_QUANTITY
  6771. for (int index = 0; index < CCS_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6774. {
  6775. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6776. {
  6777. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6778. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6779. {
  6780. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6781. {
  6782. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6784. }
  6785. 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'))
  6786. {
  6787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6788. }
  6789. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6790. {
  6791. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6792. }
  6793. else
  6794. {
  6795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6796. }
  6797. }
  6798. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6799. {
  6800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6801. }
  6802. }
  6803. else
  6804. {
  6805. //replace reservation
  6806. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6807. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6808. }
  6809. }
  6810. } // END FOR CCS_QUANTITY
  6811. for (int index = 0; index < GB_QUANTITY; index++)
  6812. {
  6813. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6814. {
  6815. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6816. {
  6817. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6818. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6819. {
  6820. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6821. {
  6822. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6823. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6824. }
  6825. 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'))
  6826. {
  6827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6828. }
  6829. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6830. {
  6831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6832. }
  6833. else
  6834. {
  6835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6836. }
  6837. }
  6838. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6839. {
  6840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6841. }
  6842. }
  6843. else
  6844. {
  6845. //replace reservation
  6846. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6848. }
  6849. }
  6850. }// END FOR GB_QUANTITY
  6851. }
  6852. else
  6853. {
  6854. for (int index = 0; index < AC_QUANTITY; index++)
  6855. {
  6856. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6857. {
  6858. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6859. {
  6860. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6861. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6862. {
  6863. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6864. {
  6865. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6867. }
  6868. 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'))
  6869. {
  6870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6871. }
  6872. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6873. {
  6874. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6875. }
  6876. else
  6877. {
  6878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6879. }
  6880. }
  6881. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6882. {
  6883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6884. }
  6885. }
  6886. else
  6887. {
  6888. //replace reservation
  6889. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6891. }
  6892. }
  6893. } // END FOR AC_QUANTITY
  6894. }//END FOR AC ELSE
  6895. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6896. }
  6897. else if(connectorIdInt == 0)
  6898. {
  6899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6900. {
  6901. //check Transaction active
  6902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6903. {
  6904. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6905. {
  6906. 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'))
  6907. {
  6908. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6909. goto end;
  6910. }
  6911. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6912. {
  6913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6914. goto end;
  6915. }
  6916. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6917. {
  6918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6919. goto end;
  6920. }
  6921. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6922. {
  6923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6924. goto end;
  6925. }
  6926. }
  6927. }// END FOR CHAdeMO_QUANTITY
  6928. for (int index = 0; index < CCS_QUANTITY; index++)
  6929. {
  6930. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6931. {
  6932. 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'))
  6933. {
  6934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6935. }
  6936. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6937. {
  6938. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6939. }
  6940. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6941. {
  6942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6943. }
  6944. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6945. {
  6946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6947. }
  6948. }
  6949. } // END FOR CCS_QUANTITY
  6950. for (int index = 0; index < GB_QUANTITY; index++)
  6951. {
  6952. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6953. {
  6954. 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'))
  6955. {
  6956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6957. }
  6958. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6959. {
  6960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6961. }
  6962. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6963. {
  6964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6965. }
  6966. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6967. {
  6968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6969. }
  6970. }
  6971. } // END FOR GB_QUANTITY
  6972. }
  6973. else
  6974. {
  6975. for (int index = 0; index < AC_QUANTITY; index++)
  6976. {
  6977. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6978. {
  6979. 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'))
  6980. {
  6981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6982. goto end;
  6983. }
  6984. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6985. {
  6986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6987. goto end;
  6988. }
  6989. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6990. {
  6991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6992. goto end;
  6993. }
  6994. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6995. {
  6996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6997. goto end;
  6998. }
  6999. }
  7000. }// END FOR AC_QUANTITY
  7001. }
  7002. //The connectorId is 0
  7003. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7005. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7006. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7007. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7008. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7009. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7010. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7011. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7012. result = TRUE;
  7013. return result;
  7014. }
  7015. else
  7016. {
  7017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7018. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7019. }
  7020. if(strcmp(comfirmstr,"Accepted") == 0)
  7021. {
  7022. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7023. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7024. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7025. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7026. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7027. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7028. result = TRUE;
  7029. return result;
  7030. }
  7031. end:
  7032. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7033. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7034. return result;
  7035. }
  7036. int handleResetRequest(char *uuid, char *payload)
  7037. {
  7038. mtrace();
  7039. int result = FAIL;
  7040. char sstr[10]={0};
  7041. char typestr[10]={0};
  7042. char comfirmstr[20]={0};
  7043. int c = 0;
  7044. char *loc;
  7045. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7046. DEBUG_INFO("handleResetRequest ...\n");
  7047. loc = strstr(payload, "type");
  7048. memset(sstr ,0, sizeof(sstr) );
  7049. c = 0;
  7050. while (loc[3+strlen("type")+c] != '\"')
  7051. {
  7052. sstr[c] = loc[3+strlen("type")+c];
  7053. c++;
  7054. }
  7055. sstr[c] = '\0';
  7056. strcpy(typestr,sstr);
  7057. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7058. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7059. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7060. {
  7061. //check Transaction active
  7062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7063. {
  7064. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7065. {
  7066. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7067. {
  7068. //0: unplug, 1: Plug-in
  7069. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7070. }
  7071. }
  7072. for (int index = 0; index < CCS_QUANTITY; index++)
  7073. {
  7074. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7075. {
  7076. //0: unplug, 1: Plug-in
  7077. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7078. }
  7079. }
  7080. for (int index = 0; index < GB_QUANTITY; index++)
  7081. {
  7082. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7083. {
  7084. //0: unplug, 1: Plug-in
  7085. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7086. }
  7087. }
  7088. }
  7089. else
  7090. {
  7091. for (int index = 0; index < AC_QUANTITY; index++)
  7092. {
  7093. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7094. {
  7095. //0: unplug, 1: Plug-in
  7096. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7097. }
  7098. }
  7099. }// END FOR AC ELSE
  7100. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7101. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7102. result = TRUE;
  7103. return result;
  7104. }
  7105. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7106. {
  7107. //check Transaction active
  7108. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7109. {
  7110. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7111. {
  7112. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7113. {
  7114. //0: unplug, 1: Plug-in
  7115. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7116. }
  7117. }
  7118. for (int index = 0; index < CCS_QUANTITY; index++)
  7119. {
  7120. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7121. {
  7122. //0: unplug, 1: Plug-in
  7123. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7124. }
  7125. }
  7126. for (int index = 0; index < GB_QUANTITY; index++)
  7127. {
  7128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7129. {
  7130. //0: unplug, 1: Plug-in
  7131. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7132. }
  7133. }
  7134. }
  7135. else
  7136. {
  7137. for (int index = 0; index < AC_QUANTITY; index++)
  7138. {
  7139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7140. {
  7141. //0: unplug, 1: Plug-in
  7142. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7143. }
  7144. }
  7145. }// END FOR AC ELSE
  7146. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7147. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7148. result = TRUE;
  7149. return result;
  7150. }
  7151. else
  7152. {
  7153. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7154. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7155. goto errorend;
  7156. }
  7157. errorend:
  7158. sendResetConfirmation(uuid, comfirmstr);
  7159. return result;
  7160. }
  7161. int handleSendLocalListRequest(char *uuid, char *payload)
  7162. {
  7163. mtrace();
  7164. int result = FAIL;
  7165. int listVersionInt;
  7166. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7167. char listsearch[]="listVersion";
  7168. char updateTypesearch[]="updateType";
  7169. char localAuthorizationListsearch[]="localAuthorizationList";
  7170. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7171. char CardList[500][160]={0};
  7172. char updateTypestr[15]={0};
  7173. char idTagstr[20]={0};
  7174. char parentIdTag[20]={0};
  7175. char expiryDate[30]={0};
  7176. char idTagstatus[16]={0};
  7177. int c = 0;
  7178. int i = 0;
  7179. char *delim1 = "}";
  7180. char * pch;
  7181. char *loc;
  7182. //char *ptr;
  7183. char comfirmstr[20];
  7184. //int n_localAuthorizations = 0;
  7185. int checkState_Faulted = FALSE;
  7186. DEBUG_INFO("handleSendLocalListRequest\n");
  7187. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7188. {
  7189. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7190. goto end;
  7191. }
  7192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7193. {
  7194. //check Charge Point state
  7195. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7196. {
  7197. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7198. {
  7199. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7200. }
  7201. }
  7202. for (int index = 0; index < CCS_QUANTITY; index++)
  7203. {
  7204. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7205. {
  7206. checkState_Faulted = TRUE; //OCPP Status
  7207. }
  7208. }
  7209. for (int index = 0; index < GB_QUANTITY; index++)
  7210. {
  7211. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7212. {
  7213. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7214. }
  7215. }
  7216. }
  7217. else
  7218. {
  7219. //check Charge Point state
  7220. for (int index = 0; index < AC_QUANTITY; index++)
  7221. {
  7222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7223. {
  7224. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7225. }
  7226. }
  7227. }// END FOR AC ELSE
  7228. if(checkState_Faulted == TRUE)
  7229. {
  7230. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7231. goto end;
  7232. }
  7233. //listVersion
  7234. c = 0;
  7235. loc = strstr(payload, listsearch);
  7236. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7237. {
  7238. sstr[c] = loc[strlen("listVersion")+2+c];
  7239. c++;
  7240. }
  7241. sstr[c] = '\0';
  7242. listVersionInt = atoi(sstr);
  7243. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7244. //updateType
  7245. loc = strstr(payload, updateTypesearch);
  7246. c = 0;
  7247. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7248. {
  7249. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7250. c++;
  7251. }
  7252. sstr[c] = '\0';
  7253. strcpy(updateTypestr, sstr);
  7254. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7255. //localAuthorizationList
  7256. memset(sstr ,0, sizeof(sstr) );
  7257. loc = strstr(payload, localAuthorizationListsearch);
  7258. if(loc != NULL) // localAuthorizationList is not NULL
  7259. {
  7260. //Check UpdateType
  7261. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7262. {
  7263. //Local list full update
  7264. printf("Local list full update.\n");
  7265. OCPP_cleanLocalList();
  7266. }
  7267. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7268. {
  7269. //Local list different update
  7270. printf("Local list different update.\n");
  7271. OCPP_getListVerion();
  7272. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7273. {
  7274. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7275. goto end;
  7276. }
  7277. }
  7278. else
  7279. {
  7280. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7281. goto end;
  7282. }
  7283. c = 0;
  7284. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7285. {
  7286. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7287. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7288. c++;
  7289. }
  7290. sstr[c] = '\0';
  7291. //DEBUG_INFO("sstr=%s\n", sstr);
  7292. //parsing strings to words
  7293. i = 0;
  7294. pch = strtok(sstr,delim1);
  7295. while (pch != NULL)
  7296. {
  7297. strcpy(CardList[i], pch);
  7298. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7299. pch = strtok (NULL, delim1);
  7300. i = i + 1;
  7301. }
  7302. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7303. //local Authorizations List Numbers
  7304. //n_localAuthorizations = i;
  7305. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7306. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7307. c= 0;
  7308. while(c < i)
  7309. {
  7310. //Search "IdToken"
  7311. memset(sstr ,0, sizeof(sstr) );
  7312. loc = strstr(CardList[c], "idTag");
  7313. int j = 0;
  7314. while (loc[3+strlen("idTag")+j] != '\"')
  7315. {
  7316. sstr[j] = loc[3+strlen("idTag")+j];
  7317. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7318. j++;
  7319. }
  7320. sstr[j] = '\0';
  7321. strcpy(idTagstr, sstr);
  7322. DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7323. //Search "expiryDate"
  7324. memset(sstr ,0, sizeof(sstr) );
  7325. loc = strstr(CardList[c], "expiryDate");
  7326. j = 0;
  7327. if(loc != NULL)
  7328. {
  7329. while (loc[3+strlen("expiryDate")+j] != '\"')
  7330. {
  7331. sstr[j] = loc[3+strlen("expiryDate")+j];
  7332. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7333. j++;
  7334. }
  7335. sstr[j] = '\0';
  7336. strcpy(expiryDate, sstr);
  7337. }
  7338. else
  7339. {
  7340. strcpy(expiryDate, "");
  7341. }
  7342. DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7343. //Search "parentIdTag"
  7344. memset(sstr ,0, sizeof(sstr) );
  7345. loc = strstr(CardList[c], "parentIdTag");
  7346. j = 0;
  7347. if(loc != NULL)
  7348. {
  7349. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7350. {
  7351. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7352. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7353. j++;
  7354. }
  7355. sstr[j] = '\0';
  7356. strcpy(parentIdTag, sstr);
  7357. }
  7358. else
  7359. {
  7360. strcpy(parentIdTag, "");
  7361. }
  7362. DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7363. //Search "status"
  7364. memset(sstr ,0, sizeof(sstr) );
  7365. loc = strstr(CardList[c], "status");
  7366. j = 0;
  7367. while (loc[3+strlen("status")+j] != '\"')
  7368. {
  7369. sstr[j] = loc[3+strlen("status")+j];
  7370. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7371. j++;
  7372. }
  7373. sstr[j] = '\0';
  7374. strcpy(idTagstatus, sstr);
  7375. DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7376. OCPP_getIdTag(idTagstr);
  7377. //OCPP_getIdTag("test"); For Test
  7378. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7379. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7380. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7381. {
  7382. //Local list full update
  7383. DEBUG_INFO("Local list full update.\n");
  7384. // update list
  7385. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7386. //DEBUG_INFO("Local list full update. 1\n");
  7387. //OCPP_get_TableAuthlocalAllData();
  7388. //DEBUG_INFO("Local list full update. 2\n");
  7389. }
  7390. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7391. {
  7392. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7393. {
  7394. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7395. }
  7396. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7397. {
  7398. OCPP_deleteIdTag(idTagstr);
  7399. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7400. //OCPP_deleteIdTag(idTagstr);
  7401. }
  7402. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7403. {
  7404. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7405. }
  7406. }
  7407. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7408. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7409. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7410. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7411. c++;
  7412. }
  7413. }
  7414. else
  7415. {
  7416. //Check UpdateType
  7417. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7418. {
  7419. //Local list full update
  7420. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7421. OCPP_cleanLocalList();
  7422. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7423. goto end;
  7424. }
  7425. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7426. {
  7427. //Local list different update
  7428. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7429. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7430. goto end;
  7431. }
  7432. }
  7433. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7434. end:
  7435. sendSendLocalListConfirmation(uuid, comfirmstr);
  7436. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7437. return result;
  7438. }
  7439. #define MAX 200
  7440. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7441. {
  7442. mtrace();
  7443. int result = FAIL;
  7444. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7445. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7446. char chargingProfilePurposeStr[30]={0};
  7447. char chargingProfileKindStr[16]={0};
  7448. char recurrencyKindStr[10]={0};
  7449. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7450. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7451. int chargingSchedulePeriodCount = 0;
  7452. //int updateflag = FALSE;
  7453. char comfirmstr[20]={0};
  7454. int meet= FALSE;
  7455. char sstr[10]={0};
  7456. int c = 0;
  7457. char *loc;
  7458. FILE *fptr1;//, *fptr2;
  7459. //int lno=0;//, linectr = 0;
  7460. //int modifyflag = FALSE;
  7461. char filename[MAX]={0};
  7462. char tempfile[] = "/Storage/OCPP/temp.json";
  7463. //int resultRename=0;
  7464. char rmFileCmd[50]={0};
  7465. char tempchargingProfilePurposeStr[30]={0};
  7466. char word[1600]={0};
  7467. int n_chargingProfile = 0;
  7468. //[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}}}]
  7469. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7470. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7471. //*********************connectorId***************************/
  7472. loc = strstr(payload, "connectorId");
  7473. c = 0;
  7474. memset(sstr ,0, sizeof(sstr) );
  7475. while (loc[strlen("connectorId")+2+c] != ',')
  7476. {
  7477. sstr[c] = loc[strlen("connectorId")+2+c];
  7478. c++;
  7479. }
  7480. sstr[c] = '\0';
  7481. connectorIdInt = atoi(sstr);
  7482. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7483. {
  7484. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7485. }
  7486. else
  7487. {
  7488. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7489. }
  7490. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7491. //*********************chargingProfileId***************************/
  7492. loc = strstr(payload, "chargingProfileId");
  7493. c = 0;
  7494. memset(sstr ,0, sizeof(sstr) );
  7495. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7496. {
  7497. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7498. c++;
  7499. }
  7500. sstr[c] = '\0';
  7501. chargingProfileIdInt = atoi(sstr);
  7502. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7503. {
  7504. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7505. }
  7506. else
  7507. {
  7508. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7509. }
  7510. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7511. //*********************transactionId***************************/
  7512. loc = strstr(payload, "transactionId");
  7513. if(loc != NULL)
  7514. {
  7515. c = 0;
  7516. memset(sstr ,0, sizeof(sstr) );
  7517. while (loc[strlen("transactionId")+2+c] != ',')
  7518. {
  7519. sstr[c] = loc[strlen("transactionId")+2+c];
  7520. c++;
  7521. }
  7522. sstr[c] = '\0';
  7523. transactionIdInt = atoi(sstr);
  7524. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7525. {
  7526. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7527. }
  7528. else
  7529. {
  7530. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7531. }
  7532. }
  7533. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7534. //*********************stackLevel***************************/
  7535. loc = strstr(payload, "stackLevel");
  7536. c = 0;
  7537. memset(sstr ,0, sizeof(sstr) );
  7538. while (loc[strlen("stackLevel")+2+c] != ',')
  7539. {
  7540. sstr[c] = loc[strlen("stackLevel")+2+c];
  7541. c++;
  7542. }
  7543. sstr[c] = '\0';
  7544. stackLevelInt = atoi(sstr);
  7545. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7546. {
  7547. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7548. }
  7549. else
  7550. {
  7551. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7552. }
  7553. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7554. //*********************chargingProfilePurpose***************************/
  7555. loc = strstr(payload, "chargingProfilePurpose");
  7556. c = 0;
  7557. memset(sstr ,0, sizeof(sstr) );
  7558. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7559. {
  7560. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7561. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7562. c++;
  7563. }
  7564. sstr[c] = '\0';
  7565. strcpy(chargingProfilePurposeStr,sstr);
  7566. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7567. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7568. {
  7569. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7570. }
  7571. else
  7572. {
  7573. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7574. }
  7575. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7576. //*********************chargingProfileKind***************************/
  7577. loc = strstr(payload, "chargingProfileKind");
  7578. c = 0;
  7579. memset(sstr ,0, sizeof(sstr) );
  7580. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7581. {
  7582. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7583. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7584. c++;
  7585. }
  7586. sstr[c] = '\0';
  7587. strcpy(chargingProfileKindStr,sstr);
  7588. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7589. {
  7590. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7591. }
  7592. else
  7593. {
  7594. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7595. }
  7596. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7597. //*********************recurrencyKind***************************/
  7598. loc = strstr(payload, "recurrencyKind");
  7599. if(loc != NULL)
  7600. {
  7601. c = 0;
  7602. memset(sstr ,0, sizeof(sstr) );
  7603. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7604. {
  7605. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7606. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7607. c++;
  7608. }
  7609. sstr[c] = '\0';
  7610. strcpy(recurrencyKindStr,sstr);
  7611. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7612. {
  7613. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7614. }
  7615. else
  7616. {
  7617. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7618. }
  7619. }
  7620. else
  7621. {
  7622. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7623. {
  7624. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7625. }
  7626. else
  7627. {
  7628. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7629. }
  7630. }
  7631. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7632. //*********************validFrom***************************/
  7633. loc = strstr(payload, "validFrom");
  7634. if(loc != NULL)
  7635. {
  7636. c = 0;
  7637. memset(sstr ,0, sizeof(sstr) );
  7638. while (loc[3+strlen("validFrom")+c] != '\"')
  7639. {
  7640. sstr[c] = loc[3+strlen("validFrom")+c];
  7641. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7642. c++;
  7643. }
  7644. sstr[c] = '\0';
  7645. strcpy(validFromStr,sstr);
  7646. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7647. {
  7648. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7649. }
  7650. else
  7651. {
  7652. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7653. }
  7654. }
  7655. else
  7656. {
  7657. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7658. {
  7659. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7660. }
  7661. else
  7662. {
  7663. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7664. }
  7665. }
  7666. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7667. //*********************validTo***************************/
  7668. loc = strstr(payload, "validTo");
  7669. if(loc != NULL)
  7670. {
  7671. c = 0;
  7672. memset(sstr ,0, sizeof(sstr) );
  7673. while (loc[3+strlen("validTo")+c] != '\"')
  7674. {
  7675. sstr[c] = loc[3+strlen("validTo")+c];
  7676. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7677. c++;
  7678. }
  7679. sstr[c] = '\0';
  7680. strcpy(validToStr,sstr);
  7681. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7682. {
  7683. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7684. }
  7685. else
  7686. {
  7687. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7688. }
  7689. }
  7690. else
  7691. {
  7692. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7693. {
  7694. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7695. }
  7696. else
  7697. {
  7698. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7699. }
  7700. }
  7701. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7702. //*********************duration***************************/
  7703. loc = strstr(payload, "duration");
  7704. if(loc != NULL)
  7705. {
  7706. c = 0;
  7707. memset(sstr ,0, sizeof(sstr) );
  7708. while (loc[strlen("duration")+2+c] != ',')
  7709. {
  7710. sstr[c] = loc[strlen("duration")+2+c];
  7711. c++;
  7712. }
  7713. sstr[c] = '\0';
  7714. durationInt = atoi(sstr);
  7715. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7716. {
  7717. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7718. }
  7719. else
  7720. {
  7721. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7722. }
  7723. }
  7724. else
  7725. {
  7726. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7727. {
  7728. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7729. }
  7730. else
  7731. {
  7732. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7733. }
  7734. }
  7735. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7736. //*********************startSchedule***************************/
  7737. loc = strstr(payload, "startSchedule");
  7738. if(loc != NULL)
  7739. {
  7740. c = 0;
  7741. memset(sstr ,0, sizeof(sstr) );
  7742. while (loc[3+strlen("startSchedule")+c] != '\"')
  7743. {
  7744. sstr[c] = loc[3+strlen("startSchedule")+c];
  7745. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7746. c++;
  7747. }
  7748. sstr[c] = '\0';
  7749. strcpy(startScheduleStr,sstr);
  7750. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7751. {
  7752. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7753. }
  7754. else
  7755. {
  7756. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7757. }
  7758. }
  7759. else
  7760. {
  7761. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7762. {
  7763. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7764. }
  7765. else
  7766. {
  7767. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7768. }
  7769. }
  7770. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7771. //*********************chargingRateUnit***************************/
  7772. loc = strstr(payload, "chargingRateUnit");
  7773. if(loc != NULL)
  7774. {
  7775. c = 0;
  7776. memset(sstr ,0, sizeof(sstr) );
  7777. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7778. {
  7779. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7780. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7781. c++;
  7782. }
  7783. sstr[c] = '\0';
  7784. strcpy(chargingRateUnitStr,sstr);
  7785. #if 0
  7786. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7787. {
  7788. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7789. goto end;
  7790. }
  7791. #endif
  7792. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7793. {
  7794. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7795. }
  7796. else
  7797. {
  7798. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7799. }
  7800. }
  7801. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7802. //****************chargingSchedulePeriod count start*******************/
  7803. int what_len = strlen("startPeriod");
  7804. char tempChargingProfile[1000]={0};
  7805. strcpy(tempChargingProfile,(const char*)payload);
  7806. char *where = tempChargingProfile;
  7807. if (what_len)
  7808. {
  7809. while ((where = strstr(where, "startPeriod"))) {
  7810. where += what_len;
  7811. chargingSchedulePeriodCount++;
  7812. }
  7813. }
  7814. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  7815. {
  7816. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7817. goto end;
  7818. }
  7819. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7820. //where = payload;
  7821. int templength = 0;
  7822. //int searchstart = 0;
  7823. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7824. {
  7825. //****************startPeriod*******************/
  7826. c=0;
  7827. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7828. memset(sstr ,0, sizeof(sstr) );
  7829. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7830. {
  7831. sstr[c] = loc[strlen("startPeriod")+2+c];
  7832. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7833. c++;
  7834. }
  7835. sstr[c] = '\0';
  7836. startPeriodInt[periodNums] = atoi(sstr);
  7837. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7838. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7839. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7840. {
  7841. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7842. }
  7843. else
  7844. {
  7845. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7846. }
  7847. templength = strlen("startPeriod")+2+c;
  7848. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7849. //****************limit*******************/
  7850. c=0;
  7851. loc = strstr(tempChargingProfile + templength, "limit");
  7852. memset(sstr ,0, sizeof(sstr) );
  7853. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7854. {
  7855. sstr[c] = loc[strlen("limit")+2+c];
  7856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7857. c++;
  7858. }
  7859. sstr[c] = '\0';
  7860. limitflaot[periodNums] = atof(sstr);
  7861. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7862. {
  7863. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7864. }
  7865. else
  7866. {
  7867. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7868. }
  7869. templength = templength + strlen("limit")+2+c;
  7870. //****************numberPhases*******************/
  7871. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7872. if(loc != NULL)
  7873. {
  7874. c=0;
  7875. memset(sstr ,0, sizeof(sstr) );
  7876. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7877. {
  7878. sstr[c] = loc[strlen("numberPhases")+2+c];
  7879. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7880. c++;
  7881. }
  7882. sstr[c] = '\0';
  7883. numberPhasesInt[periodNums] = atoi(sstr);
  7884. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7885. {
  7886. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7887. }
  7888. else
  7889. {
  7890. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7891. }
  7892. templength = templength + strlen("numberPhases")+2+c;
  7893. }
  7894. //where = loc;
  7895. }
  7896. //****************chargingSchedulePeriod count end*******************/
  7897. //*********************minChargingRate***************************/
  7898. loc = strstr(payload, "minChargingRate");
  7899. if(loc != NULL)
  7900. {
  7901. c = 0;
  7902. memset(sstr ,0, sizeof(sstr) );
  7903. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7904. {
  7905. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7906. c++;
  7907. }
  7908. sstr[c] = '\0';
  7909. minChargingRateFloat = atof(sstr);
  7910. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7911. {
  7912. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7913. }
  7914. else
  7915. {
  7916. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7917. }
  7918. }
  7919. else
  7920. {
  7921. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7922. {
  7923. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7924. }
  7925. else
  7926. {
  7927. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7928. }
  7929. }
  7930. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7931. {
  7932. //printf("set chargingProfile 1-2\n");
  7933. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7934. if(connectorIdInt != 0)
  7935. {
  7936. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7937. goto end;
  7938. }
  7939. strcpy(filename, ChargePointMaxProfile_JSON );
  7940. fptr1 = fopen(filename, "r");
  7941. if (!fptr1)
  7942. {
  7943. //file not exist
  7944. DEBUG_INFO("Unable to open the input file!!\n");
  7945. fptr1 = fopen(filename, "w+");
  7946. }
  7947. else
  7948. {
  7949. //Check Charging Profile Count
  7950. while(fscanf(fptr1, "%s", word) != EOF)
  7951. {
  7952. //DEBUG_INFO("word=%s\n",word);
  7953. if(strstr(word, "chargingProfileId")!= NULL)
  7954. {
  7955. //DEBUG_INFO("test chargingProfileId \n");
  7956. n_chargingProfile = n_chargingProfile + 1;
  7957. //DEBUG_INFO("chargingProfileId Found\n");
  7958. }
  7959. }
  7960. }
  7961. fclose(fptr1);
  7962. }
  7963. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7964. {
  7965. //printf("set chargingProfile 1-3\n");
  7966. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7967. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7968. {
  7969. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7970. goto end;
  7971. }
  7972. #if 0
  7973. switch(connectorIdInt)
  7974. {
  7975. case 0:
  7976. strcpy(filename, TxDefaultProfile_0_JSON );
  7977. break;
  7978. case 1:
  7979. strcpy(filename, TxDefaultProfile_1_JSON );
  7980. break;
  7981. case 2:
  7982. strcpy(filename, TxDefaultProfile_2_JSON );
  7983. break;
  7984. default:
  7985. strcpy(filename, TxDefaultProfile_0_JSON );
  7986. break;
  7987. }
  7988. #endif
  7989. memset(filename, 0, sizeof filename);
  7990. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7991. fptr1 = fopen(filename, "r");
  7992. if (!fptr1)
  7993. {
  7994. //file not exist
  7995. //DEBUG_INFO("Unable to open the input file!!\n");
  7996. fptr1 = fopen(filename, "w+");
  7997. }
  7998. else
  7999. {
  8000. //Check Charging Profile Count
  8001. while(fscanf(fptr1, "%s", word) != EOF)
  8002. {
  8003. //DEBUG_INFO("word=%s\n",word);
  8004. if(strstr(word, "chargingProfileId")!= NULL)
  8005. {
  8006. //DEBUG_INFO("test chargingProfileId \n");
  8007. n_chargingProfile = n_chargingProfile + 1;
  8008. //DEBUG_INFO("chargingProfileId Found\n");
  8009. }
  8010. }
  8011. }
  8012. fclose(fptr1);
  8013. }
  8014. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8015. {
  8016. //printf("set chargingProfile 1-4\n");
  8017. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8018. //check Transaction active
  8019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8020. {
  8021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8022. {
  8023. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8024. {
  8025. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8026. {
  8027. meet = TRUE;
  8028. break;
  8029. }
  8030. }
  8031. }
  8032. }
  8033. for (int index = 0; index < CCS_QUANTITY; index++)
  8034. {
  8035. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8036. {
  8037. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8038. {
  8039. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8040. {
  8041. meet = TRUE;
  8042. break;
  8043. }
  8044. }
  8045. }
  8046. }
  8047. for (int index = 0; index < GB_QUANTITY; index++)
  8048. {
  8049. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8050. {
  8051. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8052. {
  8053. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8054. {
  8055. meet = TRUE;
  8056. break;
  8057. }
  8058. }
  8059. }
  8060. }
  8061. if(meet == FALSE)
  8062. {
  8063. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8064. goto end;
  8065. }
  8066. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8067. {
  8068. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8069. goto end;
  8070. }
  8071. #if 0
  8072. switch(connectorIdInt)
  8073. {
  8074. case 0:
  8075. break;
  8076. case 1:
  8077. strcpy(filename, TxProfile_1_JSON);
  8078. break;
  8079. case 2:
  8080. strcpy(filename, TxProfile_2_JSON);
  8081. break;
  8082. default:
  8083. strcpy(filename, TxProfile_1_JSON);
  8084. break;
  8085. }
  8086. #endif
  8087. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8088. fptr1 = fopen(filename, "r");
  8089. if (!fptr1)
  8090. {
  8091. //file not exist
  8092. DEBUG_INFO("Unable to open the input file!!\n");
  8093. fptr1 = fopen(filename, "w+");
  8094. }
  8095. else
  8096. {
  8097. //Check Charging Profile Count
  8098. while(fscanf(fptr1, "%s", word) != EOF)
  8099. {
  8100. //DEBUG_INFO("word=%s\n",word);
  8101. if(strstr(word, "chargingProfileId")!= NULL)
  8102. {
  8103. //DEBUG_INFO("test chargingProfileId \n");
  8104. n_chargingProfile = n_chargingProfile + 1;
  8105. //DEBUG_INFO("chargingProfileId Found\n");
  8106. }
  8107. }
  8108. }
  8109. fclose(fptr1);
  8110. }
  8111. // Check ChargeProfileMaxStackLevel
  8112. if(n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8113. {
  8114. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8115. goto end;
  8116. }
  8117. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8118. {
  8119. int i = 0;
  8120. char fnametemp[200]={0};
  8121. n_chargingProfile = 0;
  8122. //Check ChargePointMaxProfile.json exit
  8123. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8124. {
  8125. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8126. //Check Charging Profile Count
  8127. while(fscanf(fptr1, "%s", word) != EOF)
  8128. {
  8129. //DEBUG_INFO("word=%s\n",word);
  8130. if(strstr(word, "chargingProfileId")!= NULL)
  8131. {
  8132. //DEBUG_INFO("test chargingProfileId \n");
  8133. n_chargingProfile = n_chargingProfile + 1;
  8134. i = i + 1;
  8135. //DEBUG_INFO("chargingProfileId Found\n");
  8136. }
  8137. memset(word, 0, sizeof word);
  8138. }
  8139. fclose(fptr1);
  8140. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8141. }
  8142. //Check TxDefaultProfile_0.json exit
  8143. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8144. {
  8145. i = 0;
  8146. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8147. //Check Charging Profile Count
  8148. while(fscanf(fptr1, "%s", word) != EOF)
  8149. {
  8150. //DEBUG_INFO("word=%s\n",word);
  8151. if(strstr(word, "chargingProfileId")!= NULL)
  8152. {
  8153. //DEBUG_INFO("test chargingProfileId \n");
  8154. n_chargingProfile = n_chargingProfile + 1;
  8155. i = i + 1;
  8156. //DEBUG_INFO("chargingProfileId Found\n");
  8157. }
  8158. memset(word, 0, sizeof word);
  8159. }
  8160. fclose(fptr1);
  8161. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8162. }
  8163. //Check TxDefaultProfile_%d.json
  8164. for(int j=1; j <= gunTotalNumber; j++)
  8165. {
  8166. memset(fnametemp, 0, sizeof fnametemp);
  8167. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8168. if((access(fnametemp,F_OK))!=-1)
  8169. {
  8170. i = 0;
  8171. fptr1 = fopen(fnametemp, "r");
  8172. //Check Charging Profile Count
  8173. while(fscanf(fptr1, "%s", word) != EOF)
  8174. {
  8175. //DEBUG_INFO("word=%s\n",word);
  8176. if(strstr(word, "chargingProfileId")!= NULL)
  8177. {
  8178. //DEBUG_INFO("test chargingProfileId \n");
  8179. n_chargingProfile = n_chargingProfile + 1;
  8180. i = i + 1;
  8181. //DEBUG_INFO("chargingProfileId Found\n");
  8182. }
  8183. memset(word, 0, sizeof word);
  8184. }
  8185. fclose(fptr1);
  8186. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8187. }
  8188. }
  8189. //Check TxProfile_%d.json
  8190. for(int j=1; j <= gunTotalNumber; j++)
  8191. {
  8192. memset(fnametemp, 0, sizeof fnametemp);
  8193. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8194. if((access(fnametemp,F_OK))!=-1)
  8195. {
  8196. i = 0;
  8197. fptr1 = fopen(fnametemp, "r");
  8198. //Check Charging Profile Count
  8199. while(fscanf(fptr1, "%s", word) != EOF)
  8200. {
  8201. //DEBUG_INFO("word=%s\n",word);
  8202. if(strstr(word, "chargingProfileId")!= NULL)
  8203. {
  8204. //DEBUG_INFO("test chargingProfileId \n");
  8205. n_chargingProfile = n_chargingProfile + 1;
  8206. i = i + 1;
  8207. //DEBUG_INFO("chargingProfileId Found\n");
  8208. }
  8209. memset(word, 0, sizeof word);
  8210. }
  8211. fclose(fptr1);
  8212. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8213. }
  8214. }
  8215. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8216. {
  8217. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8218. goto end;
  8219. }
  8220. }
  8221. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8222. //**********************************Write to File********************************************************/
  8223. FILE *infile;
  8224. FILE *outfile;
  8225. // open file for writing
  8226. infile = fopen (filename, "r");
  8227. outfile = fopen (tempfile, "w");
  8228. int d =0;
  8229. d = fgetc(infile);
  8230. //DEBUG_INFO("d:%d\n",d);
  8231. rewind(infile);
  8232. //*检测到文件结束标识返回1,否则返回0。*/
  8233. if(d == EOF)
  8234. {
  8235. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8236. fprintf(outfile,"%s\n",payload);
  8237. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8238. fclose(infile);
  8239. fclose(outfile);
  8240. sprintf(rmFileCmd,"rm -f %s",filename);
  8241. system(rmFileCmd);
  8242. rename(tempfile, filename);
  8243. #if 0
  8244. resultRename = rename(tempfile, filename);
  8245. if(resultRename == 0)
  8246. {
  8247. DEBUG_INFO("File chargingProfile renamed successfully");
  8248. }
  8249. else
  8250. {
  8251. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8252. }
  8253. #endif
  8254. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8255. //system(rmFileCmd);
  8256. }
  8257. else
  8258. {
  8259. char buf[1000]={0};
  8260. int ChargingProfileAdded = FALSE;
  8261. while (fgets(buf, sizeof(buf), infile) != NULL)
  8262. {
  8263. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8264. //*************************tempconnectorIdInt*********************************/
  8265. loc = strstr(buf, "connectorId");
  8266. c = 0;
  8267. memset(sstr ,0, sizeof(sstr) );
  8268. while (loc[strlen("connectorId")+2+c] != ',')
  8269. {
  8270. sstr[c] = loc[strlen("connectorId")+2+c];
  8271. c++;
  8272. }
  8273. sstr[c] = '\0';
  8274. tempconnectorIdInt = atoi(sstr);
  8275. //*************************tempchargingProfileIdInt*********************************/
  8276. loc = strstr(buf, "chargingProfileId");
  8277. c = 0;
  8278. memset(sstr ,0, sizeof(sstr) );
  8279. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8280. {
  8281. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8282. c++;
  8283. }
  8284. sstr[c] = '\0';
  8285. tempchargingProfileIdInt = atoi(sstr);
  8286. //*************************tempstackLevelInt*********************************/
  8287. loc = strstr(buf, "stackLevel");
  8288. c = 0;
  8289. memset(sstr ,0, sizeof(sstr) );
  8290. while (loc[strlen("stackLevel")+2+c] != ',')
  8291. {
  8292. sstr[c] = loc[strlen("stackLevel")+2+c];
  8293. c++;
  8294. }
  8295. sstr[c] = '\0';
  8296. tempstackLevelInt = atoi(sstr);
  8297. //*************************tempchargingProfilePurposeStr*********************************/
  8298. loc = strstr(payload, "chargingProfilePurpose");
  8299. c = 0;
  8300. memset(sstr ,0, sizeof(sstr) );
  8301. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8302. {
  8303. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8304. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8305. c++;
  8306. }
  8307. sstr[c] = '\0';
  8308. strcpy(tempchargingProfilePurposeStr,sstr);
  8309. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8310. {
  8311. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8312. {
  8313. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8314. if(ChargingProfileAdded == FALSE)
  8315. {
  8316. fprintf(outfile,"%s\n",payload);
  8317. ChargingProfileAdded = TRUE;
  8318. }
  8319. }
  8320. else
  8321. {
  8322. if(tempstackLevelInt < stackLevelInt)
  8323. {
  8324. if(ChargingProfileAdded == FALSE)
  8325. {
  8326. fprintf(outfile,"%s\n",payload);
  8327. ChargingProfileAdded = TRUE;
  8328. fprintf(outfile,"%s\n",buf);
  8329. }
  8330. else
  8331. {
  8332. fprintf(outfile,"%s\n",buf);
  8333. }
  8334. }
  8335. else
  8336. {
  8337. if(ChargingProfileAdded == FALSE)
  8338. {
  8339. fprintf(outfile,"%s\n",buf);
  8340. fprintf(outfile,"%s\n",payload);
  8341. ChargingProfileAdded = TRUE;
  8342. }
  8343. else
  8344. {
  8345. fprintf(outfile,"%s\n",buf);
  8346. }
  8347. }
  8348. }
  8349. }
  8350. else
  8351. {
  8352. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8353. {
  8354. if(ChargingProfileAdded == FALSE)
  8355. {
  8356. fprintf(outfile,"%s\n",payload);
  8357. ChargingProfileAdded = TRUE;
  8358. fprintf(outfile,"%s\n",buf);
  8359. }
  8360. else
  8361. {
  8362. fprintf(outfile,"%s\n",buf);
  8363. }
  8364. }
  8365. else if(tempstackLevelInt < stackLevelInt)
  8366. {
  8367. if(ChargingProfileAdded == FALSE)
  8368. {
  8369. fprintf(outfile,"%s\n",payload);
  8370. ChargingProfileAdded = TRUE;
  8371. fprintf(outfile,"%s\n",buf);
  8372. }
  8373. else
  8374. {
  8375. fprintf(outfile,"%s\n",buf);
  8376. }
  8377. }
  8378. else
  8379. {
  8380. if(ChargingProfileAdded == FALSE)
  8381. {
  8382. fprintf(outfile,"%s\n",buf);
  8383. fprintf(outfile,"%s\n",payload);
  8384. ChargingProfileAdded = TRUE;
  8385. }
  8386. else
  8387. {
  8388. fprintf(outfile,"%s\n",buf);
  8389. }
  8390. }
  8391. }
  8392. } // end of while loop
  8393. fclose(infile);
  8394. fclose(outfile);
  8395. sprintf(rmFileCmd,"rm -f %s",filename);
  8396. system(rmFileCmd);
  8397. rename(tempfile, filename);
  8398. #if 0
  8399. resultRename = rename(tempfile, filename);
  8400. if(resultRename == 0)
  8401. {
  8402. DEBUG_INFO("File chargingProfile renamed successfully");
  8403. }
  8404. else
  8405. {
  8406. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8407. }
  8408. #endif
  8409. result = TRUE;
  8410. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8411. }
  8412. end:
  8413. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8414. return result;
  8415. return result;
  8416. }
  8417. int handleTriggerMessageRequest(char *uuid, char *payload)
  8418. {
  8419. mtrace();
  8420. int result = FAIL;
  8421. int connectorIdIsNULL = FALSE;
  8422. int connectorIdInt =0;
  8423. char sstr[40]={0};
  8424. char requestedMessagestr[40]={0};
  8425. char comfirmstr[20]={0};
  8426. int c = 0;
  8427. char *loc;
  8428. DEBUG_INFO("handleTriggerMessageRequest\n");
  8429. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8430. c = 0;
  8431. loc = strstr(payload, "requestedMessage");
  8432. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8433. {
  8434. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8435. c++;
  8436. }
  8437. sstr[c] = '\0';
  8438. strcpy(requestedMessagestr, sstr);
  8439. c = 0;
  8440. loc = strstr(payload, "connectorId");
  8441. if(loc == NULL)
  8442. {
  8443. connectorIdIsNULL = TRUE;
  8444. }
  8445. else
  8446. {
  8447. memset(sstr ,0, sizeof(sstr) );
  8448. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8449. {
  8450. sstr[c] = loc[strlen("connectorId")+2+c];
  8451. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8452. c++;
  8453. }
  8454. sstr[c] = '\0';
  8455. connectorIdInt = atoi(sstr);
  8456. }
  8457. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8458. {
  8459. //connectorIdInt = json_object_get_int(connectorId);
  8460. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8461. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8462. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8463. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8464. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8465. }
  8466. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8467. {
  8468. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8469. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8470. return TRUE;
  8471. }
  8472. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8473. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8474. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8475. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8476. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8477. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8478. {
  8479. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8480. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8481. return TRUE;
  8482. }
  8483. else
  8484. {
  8485. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8486. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8487. }
  8488. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8489. {
  8490. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8491. {
  8492. FirmwareStatusNotificationStatus = 3;
  8493. }
  8494. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8495. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8496. }
  8497. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8498. {
  8499. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8500. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8501. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8502. }
  8503. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8504. {
  8505. sendBootNotificationRequest();
  8506. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8507. }
  8508. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8509. {
  8510. sendHeartbeatRequest(connectorIdInt);
  8511. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8512. }
  8513. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8514. {
  8515. if(connectorIdIsNULL == FALSE)
  8516. {
  8517. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8518. {
  8519. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8520. sendMeterValuesRequest(connectorIdInt -1);
  8521. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8522. }
  8523. }
  8524. else
  8525. {
  8526. for(int idx=0;idx< gunTotalNumber;idx++)
  8527. {
  8528. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8529. sendMeterValuesRequest(idx);
  8530. }
  8531. }
  8532. }
  8533. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8534. {
  8535. if(connectorIdIsNULL == FALSE)
  8536. {
  8537. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8538. {
  8539. sendStatusNotificationRequest(connectorIdInt -1);
  8540. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8541. }
  8542. }
  8543. else
  8544. {
  8545. for(int idx=0;idx< gunTotalNumber;idx++)
  8546. sendStatusNotificationRequest(idx);
  8547. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8548. }
  8549. }
  8550. return result;
  8551. }
  8552. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8553. {
  8554. mtrace();
  8555. int result = FAIL;
  8556. char sstr[6]={0};
  8557. int connectorIdInt =0;
  8558. char comfirmstr[20]={0};
  8559. int c = 0;
  8560. char *loc;
  8561. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8562. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8563. c = 0;
  8564. loc = strstr(payload, "connectorId");
  8565. memset(sstr ,0, sizeof(sstr) );
  8566. while (loc[strlen("connectorId")+2+c] != '}')
  8567. {
  8568. sstr[c] = loc[strlen("connectorId")+2+c];
  8569. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8570. c++;
  8571. }
  8572. sstr[c] = '\0';
  8573. connectorIdInt = atoi(sstr);
  8574. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8575. if(gunTotalNumber == 0)
  8576. {
  8577. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8578. goto end;
  8579. }
  8580. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8581. {
  8582. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8583. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8584. goto end;
  8585. }
  8586. else
  8587. {
  8588. //check Transaction active
  8589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8590. {
  8591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8592. {
  8593. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8594. {
  8595. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8596. }
  8597. }
  8598. for (int index = 0; index < CCS_QUANTITY; index++)
  8599. {
  8600. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8601. {
  8602. //stop Transaction
  8603. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8604. }
  8605. }
  8606. for (int index = 0; index < GB_QUANTITY; index++)
  8607. {
  8608. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8609. {
  8610. //stop Transaction
  8611. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8612. }
  8613. }
  8614. }
  8615. else
  8616. {
  8617. for (int index = 0; index < AC_QUANTITY; index++)
  8618. {
  8619. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8620. {
  8621. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8622. }
  8623. }
  8624. }// END FOR AC ELSE
  8625. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8626. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8627. result = TRUE;
  8628. return result;
  8629. }
  8630. end:
  8631. //json_object_put(obj); --- remove temporally
  8632. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8633. return result;
  8634. }
  8635. static char UpdateFirmwarepayloadData[300]={0};
  8636. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8637. {
  8638. mtrace();
  8639. int result = FAIL;
  8640. pthread_t t;
  8641. sendUpdateFirmwareConfirmation(uuid);
  8642. memset(UpdateFirmwarepayloadData, 0, 300);
  8643. strcpy(UpdateFirmwarepayloadData, payload);
  8644. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8645. ////pthread_join(t, NULL); //
  8646. //pthread_detach(t);
  8647. //sendUpdateFirmwareConfirmation(uuid);
  8648. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8649. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8650. return result;
  8651. }
  8652. void *UpdateFirmwareProcess(void *data)
  8653. {
  8654. pthread_detach(pthread_self());
  8655. mtrace();
  8656. int retriesInt =0, retryIntervalInt=0;
  8657. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8658. int port=0;
  8659. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8660. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8661. //char comfirmstr[20];
  8662. int isSuccess = 0;
  8663. char ftpbuf[200];
  8664. char temp[100];
  8665. char * pch;
  8666. int retriesISNULL=FALSE;
  8667. int retryInterval=FALSE;
  8668. int c = 0;
  8669. //int i = 0;
  8670. char *loc;
  8671. char sstr[300]={ 0 };
  8672. char str[300]={ 0 };
  8673. //char *str = (char*) data; // ? ?輸入資 ?
  8674. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8675. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8676. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8677. //***************location **************/
  8678. loc = strstr(str, "location");
  8679. memset(sstr ,0, sizeof(sstr) );
  8680. c = 0;
  8681. while (loc[3+strlen("location")+c] != '\"')
  8682. {
  8683. sstr[c] = loc[3+strlen("location")+c];
  8684. c++;
  8685. }
  8686. sstr[c] = '\0';
  8687. strcpy(locationstr, sstr);
  8688. //***************retries**************/
  8689. c = 0;
  8690. loc = strstr(str, "retries");
  8691. if(loc == NULL)
  8692. {
  8693. retriesISNULL=TRUE;
  8694. }
  8695. else
  8696. {
  8697. memset(sstr ,0, sizeof(sstr) );
  8698. while (loc[strlen("retries")+2+c] != ',')
  8699. {
  8700. sstr[c] = loc[strlen("retries")+2+c];
  8701. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8702. c++;
  8703. }
  8704. sstr[c] = '\0';
  8705. }
  8706. if(retriesISNULL == FALSE)
  8707. {
  8708. retriesInt = atoi(sstr);
  8709. }
  8710. //***************retrieveDate **************/
  8711. loc = strstr(str, "retrieveDate");
  8712. memset(sstr ,0, sizeof(sstr) );
  8713. c = 0;
  8714. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8715. {
  8716. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8717. c++;
  8718. }
  8719. sstr[c] = '\0';
  8720. strcpy(retrieveDatestr, sstr);
  8721. //***************retryInterval **************/
  8722. c = 0;
  8723. loc = strstr(str, "retryInterval");
  8724. memset(sstr ,0, sizeof(sstr) );
  8725. if(loc == NULL)
  8726. {
  8727. retryInterval=TRUE;
  8728. }
  8729. else
  8730. {
  8731. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8732. {
  8733. sstr[c] = loc[strlen("retryInterval")+2+c];
  8734. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8735. c++;
  8736. }
  8737. sstr[c] = '\0';
  8738. }
  8739. if(retryInterval==FALSE)
  8740. {
  8741. retryIntervalInt = atoi(sstr);
  8742. }
  8743. memset(ftppath, 0, sizeof(ftppath));
  8744. memset(path, 0, sizeof(path));
  8745. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8746. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8747. if(strncmp(locationstr,"http", 4) == 0)
  8748. {
  8749. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8750. protocol, host, path);
  8751. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8752. // protocol, user, password, host, path);
  8753. sprintf(ftppath,"/%s", path);
  8754. //DEBUG_INFO("protocol =%s\n",protocol);
  8755. //DEBUG_INFO("host =%s\n",host);
  8756. //DEBUG_INFO("path =%s\n",path);
  8757. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8758. int ftppathlen=strlen(ftppath);
  8759. int i=1;
  8760. char filenametemp[50];
  8761. while(i < ftppathlen)
  8762. {
  8763. int len=ftppathlen-i;
  8764. if(ftppath[len]== 47) // '/' ascll code: 47
  8765. {
  8766. DEBUG_INFO("compare '/' all right\n");
  8767. break;
  8768. }
  8769. i=i+1;
  8770. }
  8771. memset(filenametemp, 0, sizeof(filenametemp));
  8772. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8773. filenametemp[i+1] = 0;
  8774. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8775. do{
  8776. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8777. sleep(retryIntervalInt);
  8778. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8779. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8780. if(!isSuccess)
  8781. {
  8782. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8783. }
  8784. else
  8785. {
  8786. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8787. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8788. isUpdateRequest = TRUE;
  8789. }
  8790. }
  8791. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8792. {
  8793. memset(ftpbuf, 0, sizeof(ftpbuf));
  8794. memset(temp, 0, sizeof(temp));
  8795. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8796. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8797. int ftppathlen=strlen(ftpbuf);
  8798. int i=1;
  8799. char filenametemp[50];
  8800. while(i < ftppathlen)
  8801. {
  8802. int len=ftppathlen-i;
  8803. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8804. {
  8805. DEBUG_INFO(" compare '/' all right\n");
  8806. break;
  8807. }
  8808. i=i+1;
  8809. }
  8810. memset(filenametemp, 0, sizeof(filenametemp));
  8811. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8812. filenametemp[i+1] = 0;
  8813. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8814. pch=strchr(temp,'@');
  8815. if(pch==NULL)
  8816. {
  8817. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8818. protocol, host, &port, path);
  8819. strcpy(user,"anonymous");
  8820. strcpy(password,"");
  8821. }
  8822. else
  8823. {
  8824. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8825. protocol, user, password, host, &port, path);
  8826. }
  8827. sscanf(host,"%[^/]%s",host1, path1);
  8828. sprintf(ftppath,"%s", path1);
  8829. //DEBUG_INFO("protocol =%s\n",protocol);
  8830. //DEBUG_INFO("user =%s\n",user);
  8831. //DEBUG_INFO("password =%s\n",password);
  8832. //DEBUG_INFO("host1 =%s\n",host1);
  8833. //DEBUG_INFO("port =%d\n",port);
  8834. //DEBUG_INFO("path1 =%s\n",path1);
  8835. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8836. //ftpFile(host, user, password, port, ftppath, fname);
  8837. //download firmware pthred
  8838. if(port == 0)
  8839. {
  8840. port = 21;
  8841. }
  8842. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8843. do{
  8844. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8845. sleep(retryIntervalInt);
  8846. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8847. if(!isSuccess)
  8848. {
  8849. //BulldogUtil.sleepMs(interval*1000);
  8850. DEBUG_INFO("Update firmware request and download file fail.\n");
  8851. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8852. }
  8853. else
  8854. {
  8855. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8856. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8857. isUpdateRequest = TRUE;
  8858. }
  8859. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8860. }
  8861. else
  8862. {
  8863. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8864. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8865. }
  8866. pthread_exit(NULL);
  8867. }
  8868. //==========================================
  8869. // Handle server response routine
  8870. //==========================================
  8871. void handleAuthorizeResponse(char *payload, int gun_index)
  8872. {
  8873. mtrace();
  8874. char expiryDatestr[30]={0};
  8875. char parentIdTagstr[20]={0};
  8876. char statusstr[20]={0};
  8877. char expiryDatestrtemp[30]={0};
  8878. char parentIdTagstrtemp[20]={0};
  8879. char IdTagstrtemp[20]={0};
  8880. char statusstrtemp[20]={0};
  8881. int expiryDateISNULL=FALSE;
  8882. int parentIdTagISNULL=FALSE;
  8883. char sstr[160]={ 0 };
  8884. char* filename = AuthorizationCache_JSON;
  8885. char tempfile[] = "/Storage/OCPP/temp.json";
  8886. int c = 0;
  8887. char *loc;
  8888. int resultRename=0;
  8889. int responseIdTagInfoAsZero= 0;
  8890. char rmFileCmd[50]={0};
  8891. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8892. //***********expiryDate*************/
  8893. loc = strstr(payload, "expiryDate");
  8894. memset(sstr ,0, sizeof(sstr) );
  8895. c = 0;
  8896. if(loc == NULL)
  8897. {
  8898. expiryDateISNULL = TRUE;
  8899. }
  8900. else
  8901. {
  8902. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8903. {
  8904. sstr[c] = loc[3+strlen("expiryDate")+c];
  8905. c++;
  8906. }
  8907. sstr[c] = '\0';
  8908. strcpy(expiryDatestr, sstr);
  8909. }
  8910. //***********parentIdTag*************/
  8911. loc = strstr(payload, "parentIdTag");
  8912. memset(sstr ,0, sizeof(sstr) );
  8913. c = 0;
  8914. if(loc == NULL)
  8915. {
  8916. parentIdTagISNULL = TRUE;
  8917. }
  8918. else
  8919. {
  8920. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8921. {
  8922. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8923. c++;
  8924. }
  8925. sstr[c] = '\0';
  8926. strcpy(parentIdTagstr, sstr);
  8927. }
  8928. //***********status*************/
  8929. loc = strstr(payload, "status");
  8930. memset(sstr ,0, sizeof(sstr) );
  8931. c = 0;
  8932. while (loc[3+strlen("status")+c] != '\"')
  8933. {
  8934. sstr[c] = loc[3+strlen("status")+c];
  8935. c++;
  8936. }
  8937. sstr[c] = '\0';
  8938. strcpy(statusstr, sstr);
  8939. if(expiryDateISNULL == FALSE)
  8940. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8941. if(parentIdTagISNULL == FALSE)
  8942. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8943. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8944. //Update idTag information to authorization cache if supproted
  8945. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8946. {
  8947. if((access(filename,F_OK))!=-1)
  8948. {
  8949. printf("AuthorizationCache exist.\n");
  8950. }
  8951. else
  8952. {
  8953. printf("AuthorizationCache not exist\n");
  8954. FILE *log = fopen(filename, "w+");
  8955. if(log == NULL)
  8956. {
  8957. printf("log is NULL\n");
  8958. goto out;
  8959. }
  8960. else
  8961. {
  8962. fclose(log);
  8963. }
  8964. }
  8965. FILE *infile;
  8966. FILE *outfile;
  8967. // open file for writing
  8968. infile = fopen (filename, "r");
  8969. outfile = fopen (tempfile, "w");
  8970. //*检测到文件结束标识返回1,否则返回0。*/
  8971. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8972. int c;
  8973. c = fgetc(infile);
  8974. //DEBUG_INFO("c:%d\n",c);
  8975. rewind(infile);
  8976. if(c == EOF)
  8977. {
  8978. DEBUG_INFO("Orignal File is NULL\n");
  8979. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8980. {
  8981. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8982. }
  8983. else
  8984. {
  8985. strcpy(expiryDatestrtemp, "");
  8986. }
  8987. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8988. {
  8989. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8990. }
  8991. else
  8992. {
  8993. //write Authorize IdTag
  8994. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8995. }
  8996. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8997. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8998. fclose(infile);
  8999. fclose(outfile);
  9000. sprintf(rmFileCmd,"rm -f %s",filename);
  9001. system(rmFileCmd);
  9002. resultRename = rename(tempfile, filename);
  9003. if(resultRename == 0)
  9004. {
  9005. printf("File renamed successfully");
  9006. }
  9007. else
  9008. {
  9009. printf("Error: unable to rename the file");
  9010. }
  9011. }
  9012. else
  9013. {
  9014. char buf[160]={0};
  9015. while (fgets(buf, sizeof(buf), infile) != NULL)
  9016. {
  9017. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9018. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9019. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9020. memset(statusstr, 0, sizeof(statusstrtemp));
  9021. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9022. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9023. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9024. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9025. //------------------IdTag-----------------------
  9026. loc = strstr(buf, "idTag");
  9027. memset(sstr ,0, sizeof(sstr) );
  9028. c = 0;
  9029. while (loc[3+strlen("idTag")+c] != '\"')
  9030. {
  9031. sstr[c] = loc[3+strlen("idTag")+c];
  9032. c++;
  9033. }
  9034. sstr[c] = '\0';
  9035. strcpy(IdTagstrtemp,sstr);
  9036. //*********************expiryDate***************/
  9037. loc = strstr(buf, "expiryDate");
  9038. memset(sstr ,0, sizeof(sstr) );
  9039. c = 0;
  9040. while (loc[3+strlen("expiryDate")+c] != '\"')
  9041. {
  9042. sstr[c] = loc[3+strlen("expiryDate")+c];
  9043. c++;
  9044. }
  9045. sstr[c] = '\0';
  9046. strcpy(expiryDatestr,sstr);
  9047. //*********************parentIdTag***************/
  9048. loc = strstr(buf, "parentIdTag");
  9049. memset(sstr ,0, sizeof(sstr) );
  9050. c = 0;
  9051. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9052. {
  9053. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9054. c++;
  9055. }
  9056. sstr[c] = '\0';
  9057. strcpy(parentIdTagstr,sstr);
  9058. //*********************status***************/
  9059. loc = strstr(buf, "status");
  9060. memset(sstr ,0, sizeof(sstr) );
  9061. c = 0;
  9062. while (loc[3+strlen("status")+c] != '\"')
  9063. {
  9064. sstr[c] = loc[3+strlen("status")+c];
  9065. c++;
  9066. }
  9067. sstr[c] = '\0';
  9068. strcpy(statusstr,sstr);
  9069. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9070. {
  9071. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9072. responseIdTagInfoAsZero = 1;
  9073. }
  9074. else
  9075. {
  9076. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9077. }
  9078. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9079. {
  9080. //modify item
  9081. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9082. {
  9083. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9084. }
  9085. else
  9086. {
  9087. strcpy(expiryDatestrtemp, "");
  9088. }
  9089. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9090. {
  9091. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9092. }
  9093. else
  9094. {
  9095. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9096. }
  9097. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9098. }
  9099. else
  9100. {
  9101. //wrie original item
  9102. strcpy(expiryDatestrtemp, expiryDatestr);
  9103. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9104. strcpy(statusstrtemp, statusstr);
  9105. }
  9106. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9107. }
  9108. fclose(infile);
  9109. fclose(outfile);
  9110. sprintf(rmFileCmd,"rm -f %s",filename);
  9111. system(rmFileCmd);
  9112. resultRename = rename(tempfile, filename);
  9113. if(resultRename == 0)
  9114. {
  9115. DEBUG_INFO("File renamed successfully");
  9116. }
  9117. else
  9118. {
  9119. DEBUG_INFO("Error: unable to rename the file");
  9120. }
  9121. }
  9122. }
  9123. out:
  9124. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9125. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9126. authorizeRetryTimes = 0;
  9127. }
  9128. void handleBootNotificationResponse(char *payload, int gun_index)
  9129. {
  9130. mtrace();
  9131. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9132. char statusStr[12]={0};
  9133. char currentTimeStr[30]={0};
  9134. char *loc;
  9135. int intervalInt = 0;
  9136. int c = 0;
  9137. //double diff_t;
  9138. struct tm tp;
  9139. char buf[28]={0};
  9140. char timebuf[50]={0};
  9141. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9142. //*** interval ****/
  9143. c = 0;
  9144. loc = strstr(payload, "interval");
  9145. //printf("loc=%s\n",loc);
  9146. memset(sstr ,0, sizeof(sstr) );
  9147. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9148. {
  9149. sstr[c] = loc[strlen("interval")+2+c];
  9150. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9151. c++;
  9152. }
  9153. sstr[c] = '\0';
  9154. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9155. intervalInt = atoi(sstr);
  9156. //***status ****/
  9157. loc = strstr(payload, "status");
  9158. memset(sstr ,0, sizeof(sstr) );
  9159. c = 0;
  9160. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9161. {
  9162. sstr[c] = loc[3+strlen("status")+c];
  9163. c++;
  9164. }
  9165. sstr[c] = '\0';
  9166. strcpy(statusStr, sstr);
  9167. //***currentTime ****/
  9168. loc = strstr(payload, "currentTime");
  9169. //printf("loc=%s\n",loc);
  9170. memset(sstr ,0, sizeof(sstr) );
  9171. c = 0;
  9172. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9173. {
  9174. sstr[c] = loc[3+strlen("currentTime")+c];
  9175. c++;
  9176. }
  9177. sstr[c] = '\0';
  9178. strcpy(currentTimeStr, sstr);
  9179. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9180. HeartBeatWaitTime = BootNotificationInterval;
  9181. clientTime.Heartbeat=time((time_t*)NULL);
  9182. //write back to ShmOCPP16Data->BootNotification
  9183. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9184. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9185. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9186. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9187. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9188. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9189. {
  9190. server_sign = TRUE;
  9191. server_pending =FALSE;
  9192. }
  9193. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9194. {
  9195. server_pending = TRUE;
  9196. }
  9197. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9198. tp.tm_isdst = -1;
  9199. //time_t utc = mktime(&tp);
  9200. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9201. memset(timebuf, 0, sizeof timebuf);
  9202. sprintf(timebuf,"date -s '%s'",buf);
  9203. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9204. system(timebuf);
  9205. //==============================================
  9206. // RTC sync
  9207. //==============================================
  9208. system("/sbin/hwclock -w --systohc");
  9209. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9210. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9211. }
  9212. void handleDataTransferResponse(char *payload, int gun_index)
  9213. {
  9214. char sstr[160]={0};//sstr[200]={ 0 };
  9215. int c = 0;
  9216. char *loc;
  9217. DEBUG_INFO("handleDataTransferResponse ...\n");
  9218. loc = strstr(payload, "status");
  9219. printf("loc=%s\n",loc);
  9220. c = 0;
  9221. while (loc[3+strlen("status")+c] != '\"')
  9222. {
  9223. sstr[c] = loc[3+strlen("status")+c];
  9224. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9225. c++;
  9226. }
  9227. sstr[c] = '\0';
  9228. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9229. }
  9230. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9231. {
  9232. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9233. //struct json_object *obj;
  9234. // obj = json_tokener_parse(payload);
  9235. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9236. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9237. //No fields are defined.
  9238. }
  9239. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9240. {
  9241. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9242. //struct json_object *obj;
  9243. // obj = json_tokener_parse(payload);
  9244. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9245. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9246. //No fields are defined.
  9247. }
  9248. void handleHeartbeatResponse(char *payload, int gun_index)
  9249. {
  9250. mtrace();
  9251. //double diff_t;
  9252. struct tm tp;
  9253. char buf[28]={0};
  9254. char timebuf[50]={0};
  9255. char sstr[30]={ 0 };
  9256. int c = 0;
  9257. char *loc;
  9258. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9259. c = 0;
  9260. loc = strstr(payload, "currentTime");
  9261. memset(sstr ,0, sizeof(sstr) );
  9262. while (loc[3+strlen("currentTime")+c] != '\"')
  9263. {
  9264. sstr[c] = loc[3+strlen("currentTime")+c];
  9265. c++;
  9266. }
  9267. sstr[c] = '\0';
  9268. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9269. // #ifdef SystemLogMessage
  9270. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9271. // #endif
  9272. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9273. tp.tm_isdst = -1;
  9274. //time_t utc = mktime(&tp);
  9275. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9276. memset(timebuf, 0, sizeof timebuf);
  9277. sprintf(timebuf,"date -s '%s'",buf);
  9278. system(timebuf);
  9279. //==============================================
  9280. // RTC sync
  9281. //==============================================
  9282. system("/sbin/hwclock -w --systohc");
  9283. if(FirstHeartBeat == 0)
  9284. {
  9285. FirstHeartBeat = 1;
  9286. }
  9287. HeartBeatWithNOResponse = 0;
  9288. //--------Print Out HeartBeat log
  9289. {
  9290. double diff_t;
  9291. struct tm tp,tp1;
  9292. // BootNotification Receive Time
  9293. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9294. tp.tm_isdst = -1;
  9295. time_t BootNotificationReceiveTime = mktime(&tp);
  9296. //HeartBeat Receive Time
  9297. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9298. tp1.tm_isdst = -1;
  9299. time_t HeartBeatReceiveTime = mktime(&tp1);
  9300. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9301. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9302. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9303. {
  9304. HeartBeatCountPerHour = (int)diff_t / 3600;
  9305. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9306. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9307. }
  9308. }
  9309. }
  9310. void handleMeterValuesResponse(char *payload, int gun_index)
  9311. {
  9312. mtrace();
  9313. //struct json_object *obj;
  9314. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9315. //No fields are defined.
  9316. }
  9317. void handleStartTransactionResponse(char *payload, int gun_index)
  9318. {
  9319. mtrace();
  9320. char sstr[28]={ 0 };
  9321. int c = 0;
  9322. char *loc;
  9323. int transactionIdInt = 0;
  9324. FILE *outfile;
  9325. char data[100]={0};
  9326. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9327. DEBUG_INFO("handleStartTransactionResponse\n");
  9328. //****************expiryDate********************/
  9329. loc = strstr(payload, "expiryDate");
  9330. if(loc == NULL)
  9331. {
  9332. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9333. }
  9334. else
  9335. {
  9336. c = 0;
  9337. memset(sstr ,0, sizeof(sstr) );
  9338. while (loc[3+strlen("expiryDate")+c] != '\"')
  9339. {
  9340. sstr[c] = loc[3+strlen("expiryDate")+c];
  9341. c++;
  9342. }
  9343. sstr[c] = '\0';
  9344. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9345. }
  9346. //****************parentIdTag********************/
  9347. loc = strstr(payload, "parentIdTag");
  9348. if(loc == NULL)
  9349. {
  9350. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9351. }
  9352. else
  9353. {
  9354. c = 0;
  9355. memset(sstr ,0, sizeof(sstr) );
  9356. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9357. {
  9358. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9359. c++;
  9360. }
  9361. sstr[c] = '\0';
  9362. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9363. }
  9364. //****************status********************/
  9365. loc = strstr(payload, "status");
  9366. if(loc == NULL)
  9367. {
  9368. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9369. }
  9370. else
  9371. {
  9372. c = 0;
  9373. memset(sstr ,0, sizeof(sstr) );
  9374. while (loc[3+strlen("status")+c] != '\"')
  9375. {
  9376. sstr[c] = loc[3+strlen("status")+c];
  9377. c++;
  9378. }
  9379. sstr[c] = '\0';
  9380. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9381. }
  9382. //****************transactionId********************/
  9383. c=0;
  9384. loc = strstr(payload, "transactionId");
  9385. memset(sstr ,0, sizeof(sstr) );
  9386. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9387. {
  9388. sstr[c] = loc[strlen("transactionId")+2+c];
  9389. c++;
  9390. }
  9391. sstr[c] = '\0';
  9392. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9393. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9394. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9395. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9396. //-----------Start : write to the Queue TransactionId file -----------------//
  9397. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9398. {
  9399. //DEBUG_INFO("QueueTransactionId exist.\n");
  9400. }
  9401. else
  9402. {
  9403. //DEBUG_INFO("QueueTransactionId not exist\n");
  9404. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9405. if(log == NULL)
  9406. {
  9407. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9408. return ;
  9409. }
  9410. else
  9411. {
  9412. fclose(log);
  9413. }
  9414. }
  9415. // open file for writing
  9416. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9417. //DEBUG_INFO("data=%s\n",data);
  9418. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9419. fputs(data, outfile);
  9420. //fputs("\n", outfile);
  9421. fclose (outfile);
  9422. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9423. TransactionId[gun_index] = transactionIdInt;
  9424. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9425. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9426. #ifdef SystemLogMessage
  9427. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9428. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9429. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9430. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9431. #endif
  9432. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  9433. {
  9434. //add Charging Record
  9435. SettingChargingRecord(gun_index, transactionIdInt);
  9436. }
  9437. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  9438. }
  9439. void handleStatusNotificationResponse(char *payload, int gun_index)
  9440. {
  9441. mtrace();
  9442. printf("handleStatusNotificationResponse\n");
  9443. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9444. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9445. }
  9446. void handleStopTransactionnResponse(char *payload, int gun_index)
  9447. {
  9448. mtrace();
  9449. char sstr[30]={ 0 };
  9450. int c = 0;
  9451. char *loc;
  9452. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9453. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9454. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9455. loc = strstr(payload, "idTagInfo");
  9456. //***********************idTagInfo************************/
  9457. if(loc != NULL)
  9458. {
  9459. //***********************expiryDate************************/
  9460. loc = strstr(payload, "expiryDate");
  9461. if(loc != NULL)
  9462. {
  9463. memset(sstr ,0, sizeof(sstr) );
  9464. c = 0;
  9465. while (loc[3+strlen("expiryDate")+c] != '\"')
  9466. {
  9467. sstr[c] = loc[3+strlen("expiryDate")+c];
  9468. c++;
  9469. }
  9470. sstr[c] = '\0';
  9471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9472. }
  9473. //***********************parentIdTag************************/
  9474. loc = strstr(payload, "parentIdTag");
  9475. if(loc != NULL)
  9476. {
  9477. memset(sstr ,0, sizeof(sstr) );
  9478. c = 0;
  9479. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9480. {
  9481. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9482. c++;
  9483. }
  9484. sstr[c] = '\0';
  9485. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9486. }
  9487. //***********************status************************/
  9488. loc = strstr(payload, "status");
  9489. memset(sstr ,0, sizeof(sstr) );
  9490. c = 0;
  9491. while (loc[3+strlen("status")+c] != '\"')
  9492. {
  9493. sstr[c] = loc[3+strlen("status")+c];
  9494. c++;
  9495. }
  9496. sstr[c] = '\0';
  9497. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9498. }
  9499. #ifdef SystemLogMessage
  9500. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9501. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9502. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9503. #endif
  9504. }
  9505. //==========================================
  9506. // Handle Error routine
  9507. //==========================================
  9508. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9509. {
  9510. mtrace();
  9511. #ifdef SystemLogMessage
  9512. DEBUG_INFO("errorCode: %s\n", errorCode);
  9513. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9514. DEBUG_INFO("errorDetails: %s\n", payload);
  9515. #endif
  9516. }
  9517. //===============================================
  9518. // Common routine
  9519. //===============================================
  9520. int initialConfigurationTable(void)
  9521. {
  9522. FILE *fp;
  9523. FILE *outfile;
  9524. char str[200]={0};
  9525. char sstr[100]={0};
  9526. int c = 0;
  9527. char *loc;
  9528. printf("initialConfigurationTable \n");
  9529. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9530. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9531. {
  9532. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9533. if(outfile == NULL) {
  9534. DEBUG_INFO("Error opening file");
  9535. return FALSE;
  9536. }
  9537. /*Core Profile*/
  9538. //AllowOfflineTxForUnknownId
  9539. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9540. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9544. //AuthorizationCacheEnabled
  9545. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9549. //AuthorizeRemoteTxRequests
  9550. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9554. //BlinkRepeat
  9555. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9559. //ClockAlignedDataInterval
  9560. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9564. //ConnectionTimeOut
  9565. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9569. //GetConfigurationMaxKeys
  9570. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9574. // HeartbeatInterval
  9575. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9579. // LightIntensity
  9580. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9584. // LocalAuthorizeOffline
  9585. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9589. // LocalPreAuthorize
  9590. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9594. // MaxEnergyOnInvalidId
  9595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9598. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9600. // MeterValuesAlignedData
  9601. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9605. // MeterValuesAlignedDataMaxLength
  9606. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9610. // MeterValuesSampledData
  9611. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9615. // MeterValuesSampledDataMaxLength
  9616. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9620. // MeterValueSampleInterval
  9621. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9625. // MinimumStatusDuration
  9626. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9630. // NumberOfConnectors
  9631. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9634. {
  9635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9636. }
  9637. else
  9638. {
  9639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9640. }
  9641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9642. // ResetRetries
  9643. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9647. // ConnectorPhaseRotation
  9648. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9652. // ConnectorPhaseRotationMaxLength
  9653. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9657. // StopTransactionOnEVSideDisconnect
  9658. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9662. // StopTransactionOnInvalidId
  9663. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9667. // StopTxnAlignedData
  9668. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9672. // StopTxnAlignedDataMaxLength
  9673. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9677. // StopTxnSampledData
  9678. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9682. // StopTxnSampledDataMaxLength
  9683. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9686. {
  9687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9688. }
  9689. else
  9690. {
  9691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9692. }
  9693. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9695. // SupportedFeatureProfiles
  9696. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9700. // SupportedFeatureProfilesMaxLength
  9701. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9705. // TransactionMessageAttempts
  9706. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9709. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9711. // TransactionMessageRetryInterval
  9712. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9715. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9717. // UnlockConnectorOnEVSideDisconnect
  9718. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9722. // WebSocketPingInterval
  9723. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9727. //* Local Auth List Management Profile*/
  9728. #if 0
  9729. //For OCTT Test Case
  9730. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9733. #endif
  9734. #if 1
  9735. //LocalAuthListEnabled
  9736. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9740. #endif
  9741. //LocalAuthListMaxLength
  9742. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9746. //SendLocalListMaxLength
  9747. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9751. //ReserveConnectorZeroSupported
  9752. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9756. //* Smart Charging Profile */
  9757. //ChargeProfileMaxStackLevel
  9758. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9762. // ChargingScheduleAllowedChargingRateUnit
  9763. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9767. // ChargingScheduleMaxPeriods
  9768. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9772. // ConnectorSwitch3to1PhaseSupported
  9773. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9777. // MaxChargingProfilesInstalled
  9778. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9782. fclose(outfile);
  9783. }
  9784. else
  9785. {
  9786. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9787. char keystr[60]={0};
  9788. char readonlystr[10]={0};
  9789. char valuestr[100]={0};
  9790. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9791. if(fp == NULL) {
  9792. DEBUG_INFO("Error opening file");
  9793. return FALSE;
  9794. }
  9795. while( fgets (str, sizeof(str), fp)!=NULL )
  9796. {
  9797. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9798. //*************************key*********************************/
  9799. loc = strstr(str, "key");
  9800. c = 0;
  9801. memset(sstr ,0, sizeof(sstr) );
  9802. while (loc[strlen("key")+3+c] != '\"')
  9803. {
  9804. sstr[c] = loc[strlen("key")+3+c];
  9805. c++;
  9806. }
  9807. sstr[c] = '\0';
  9808. strcpy(keystr,sstr);
  9809. //*************************readonly*********************************/
  9810. loc = strstr(str, "readonly");
  9811. c = 0;
  9812. memset(sstr ,0, sizeof(sstr) );
  9813. while (loc[strlen("readonly")+2+c] != ',')
  9814. {
  9815. sstr[c] = loc[strlen("readonly")+2+c];
  9816. c++;
  9817. }
  9818. sstr[c] = '\0';
  9819. strcpy(readonlystr,sstr);
  9820. //*************************value*********************************/
  9821. loc = strstr(str, "value");
  9822. c = 0;
  9823. memset(sstr ,0, sizeof(sstr) );
  9824. while (loc[strlen("value")+3+c] != '\"')
  9825. {
  9826. sstr[c] = loc[strlen("value")+3+c];
  9827. c++;
  9828. }
  9829. sstr[c] = '\0';
  9830. strcpy(valuestr,sstr);
  9831. // DEBUG_INFO("keystr=%s\n",keystr);
  9832. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9833. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9834. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9835. {
  9836. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9837. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9839. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9840. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9841. }
  9842. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9843. {
  9844. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9845. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9847. }
  9848. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9849. {
  9850. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9852. }
  9853. if(strcmp(keystr, "BlinkRepeat") == 0)
  9854. {
  9855. //Charger.BlinkRepeat = Integer.parseInt(value);
  9856. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9858. }
  9859. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9860. {
  9861. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9863. }
  9864. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9865. {
  9866. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9868. }
  9869. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9870. {
  9871. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9873. }
  9874. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9875. {
  9876. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9878. HeartBeatWaitTime = atoi(valuestr);
  9879. }
  9880. if(strcmp(keystr, "LightIntensity") == 0)
  9881. {
  9882. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9884. }
  9885. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9886. {
  9887. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9889. }
  9890. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9891. {
  9892. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9894. }
  9895. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9896. {
  9897. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9899. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9900. }
  9901. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9902. {
  9903. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9905. }
  9906. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9907. {
  9908. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9910. }
  9911. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9912. {
  9913. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9915. }
  9916. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9917. {
  9918. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9920. }
  9921. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9922. {
  9923. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9925. }
  9926. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9927. {
  9928. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9930. }
  9931. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9932. {
  9933. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9935. }
  9936. if(strcmp(keystr, "ResetRetries") == 0)
  9937. {
  9938. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9940. }
  9941. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9942. {
  9943. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9945. }
  9946. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9947. {
  9948. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9950. }
  9951. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9952. {
  9953. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9955. }
  9956. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9957. {
  9958. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9960. }
  9961. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9962. {
  9963. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9965. }
  9966. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9967. {
  9968. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9970. }
  9971. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9972. {
  9973. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9975. }
  9976. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9977. {
  9978. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9980. }
  9981. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9982. {
  9983. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9985. }
  9986. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9987. {
  9988. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9990. }
  9991. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9992. {
  9993. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9995. TransactionMessageAttemptsValue = atoi(valuestr);
  9996. }
  9997. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9998. {
  9999. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10001. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10002. }
  10003. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10004. {
  10005. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10007. }
  10008. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10009. {
  10010. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10012. }
  10013. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10014. {
  10015. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10017. }
  10018. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10019. {
  10020. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10022. }
  10023. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10024. {
  10025. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10027. }
  10028. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10029. {
  10030. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10032. }
  10033. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10034. {
  10035. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10037. }
  10038. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10039. {
  10040. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10042. }
  10043. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10044. {
  10045. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10047. }
  10048. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10049. {
  10050. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10052. }
  10053. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10054. {
  10055. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10057. }
  10058. }
  10059. fclose(fp);
  10060. }
  10061. return 0;
  10062. }
  10063. void StoreConfigurationTable(void)
  10064. {
  10065. FILE *outfile;
  10066. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10067. if(outfile == NULL)
  10068. {
  10069. DEBUG_INFO("Error opening file");
  10070. return ;
  10071. }
  10072. /*Core Profile*/
  10073. //AllowOfflineTxForUnknownId
  10074. /*
  10075. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10076. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10079. */
  10080. //DEBUG_INFO("data=%s\n",data);
  10081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10082. //AuthorizationCacheEnabled
  10083. /*
  10084. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10087. */
  10088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10089. //AuthorizeRemoteTxRequests
  10090. /*
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10094. */
  10095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10096. //BlinkRepeat
  10097. /*
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10101. */
  10102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10103. //ClockAlignedDataInterval
  10104. /*
  10105. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10108. */
  10109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10110. //ConnectionTimeOut
  10111. /*
  10112. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10115. */
  10116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10117. //GetConfigurationMaxKeys
  10118. /*
  10119. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10122. */
  10123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10124. // HeartbeatInterval
  10125. /*
  10126. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10129. */
  10130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10131. // LightIntensity
  10132. /*
  10133. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10136. */
  10137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10138. // LocalAuthorizeOffline
  10139. /*
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10143. */
  10144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10145. // LocalPreAuthorize
  10146. /*
  10147. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10150. */
  10151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10152. // MaxEnergyOnInvalidId
  10153. /*
  10154. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10157. */
  10158. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10160. // MeterValuesAlignedData
  10161. /*
  10162. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10165. */
  10166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10167. // MeterValuesAlignedDataMaxLength
  10168. /*
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10172. */
  10173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10174. // MeterValuesSampledData
  10175. /*
  10176. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10179. */
  10180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10181. // MeterValuesSampledDataMaxLength
  10182. /*
  10183. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10186. */
  10187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10188. // MeterValueSampleInterval
  10189. /*
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10193. */
  10194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10195. // MinimumStatusDuration
  10196. /*
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10200. */
  10201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10202. // NumberOfConnectors
  10203. /*
  10204. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10207. {
  10208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10209. }
  10210. else
  10211. {
  10212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10213. }
  10214. */
  10215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10216. // ResetRetries
  10217. /*
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10221. */
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10223. // ConnectorPhaseRotation
  10224. /*
  10225. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10228. */
  10229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10230. // ConnectorPhaseRotationMaxLength
  10231. /*
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10235. */
  10236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10237. // StopTransactionOnEVSideDisconnect
  10238. /*
  10239. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10242. */
  10243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10244. // StopTransactionOnInvalidId
  10245. /*
  10246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10249. */
  10250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10251. // StopTxnAlignedData
  10252. /*
  10253. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10256. */
  10257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10258. // StopTxnAlignedDataMaxLength
  10259. /*
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10263. */
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10265. // StopTxnSampledData
  10266. /*
  10267. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10270. */
  10271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10272. // StopTxnSampledDataMaxLength
  10273. /*
  10274. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10277. */
  10278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10279. // SupportedFeatureProfiles
  10280. /*
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10284. */
  10285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10286. // SupportedFeatureProfilesMaxLength
  10287. /*
  10288. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10291. */
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10293. // TransactionMessageAttempts
  10294. /*
  10295. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10298. */
  10299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10300. // TransactionMessageRetryInterval
  10301. /*
  10302. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10305. */
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10307. // UnlockConnectorOnEVSideDisconnect
  10308. /*
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10312. */
  10313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10314. // WebSocketPingInterval
  10315. /*
  10316. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10319. */
  10320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10321. //* Local Auth List Management Profile*/
  10322. //LocalAuthListEnabled
  10323. /*
  10324. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10327. */
  10328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10329. //LocalAuthListMaxLength
  10330. /*
  10331. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10334. */
  10335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10336. //SendLocalListMaxLength
  10337. /*
  10338. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10341. */
  10342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10343. //ReserveConnectorZeroSupported
  10344. /*
  10345. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10348. */
  10349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10350. //* Smart Charging Profile */
  10351. //ChargeProfileMaxStackLevel
  10352. /*
  10353. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10356. */
  10357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10358. // ChargingScheduleAllowedChargingRateUnit
  10359. /*
  10360. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10363. */
  10364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10365. // ChargingScheduleMaxPeriods
  10366. /*
  10367. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10370. */
  10371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10372. // ConnectorSwitch3to1PhaseSupported
  10373. /*
  10374. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10377. */
  10378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10379. // MaxChargingProfilesInstalled
  10380. /*
  10381. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10384. */
  10385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10386. fclose(outfile);
  10387. }
  10388. void getKeyValue(char *keyReq)
  10389. {
  10390. int isEmpty = FALSE;
  10391. int isKnowKey = FALSE;
  10392. //int unKnowIndex = 0;
  10393. DEBUG_INFO("getKeyValue \n");
  10394. DEBUG_INFO("keyReq=%s \n",keyReq);
  10395. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10396. isEmpty = TRUE;
  10397. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10398. {
  10399. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  10400. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10402. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10403. {
  10404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10405. }
  10406. else
  10407. {
  10408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10409. }
  10410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10411. isKnowKey = TRUE;
  10412. }
  10413. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10414. {
  10415. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10418. {
  10419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10420. }
  10421. else
  10422. {
  10423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10424. }
  10425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10426. isKnowKey = TRUE;
  10427. }
  10428. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10429. {
  10430. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10433. {
  10434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10435. }
  10436. else
  10437. {
  10438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10439. }
  10440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10441. isKnowKey = TRUE;
  10442. }
  10443. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10444. {
  10445. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10448. {
  10449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10450. }
  10451. else
  10452. {
  10453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10454. }
  10455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10456. isKnowKey = TRUE;
  10457. }
  10458. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10459. {
  10460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10463. {
  10464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10465. }
  10466. else
  10467. {
  10468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10469. }
  10470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10471. isKnowKey = TRUE;
  10472. }
  10473. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10474. {
  10475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10478. {
  10479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10480. }
  10481. else
  10482. {
  10483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10484. }
  10485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10486. isKnowKey = TRUE;
  10487. }
  10488. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10489. {
  10490. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10493. {
  10494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10495. }
  10496. else
  10497. {
  10498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10499. }
  10500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10501. isKnowKey = TRUE;
  10502. }
  10503. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10504. {
  10505. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10508. {
  10509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10510. }
  10511. else
  10512. {
  10513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10514. }
  10515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10516. isKnowKey = TRUE;
  10517. }
  10518. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10519. {
  10520. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10523. {
  10524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10525. }
  10526. else
  10527. {
  10528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10529. }
  10530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10531. isKnowKey = TRUE;
  10532. }
  10533. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10534. {
  10535. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10538. {
  10539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10540. }
  10541. else
  10542. {
  10543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10544. }
  10545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10546. isKnowKey = TRUE;
  10547. }
  10548. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10549. {
  10550. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10553. {
  10554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10555. }
  10556. else
  10557. {
  10558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10559. }
  10560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10561. isKnowKey = TRUE;
  10562. }
  10563. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10564. {
  10565. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10568. {
  10569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10570. }
  10571. else
  10572. {
  10573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10574. }
  10575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10576. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10577. isKnowKey = TRUE;
  10578. }
  10579. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10580. {
  10581. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10584. {
  10585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10586. }
  10587. else
  10588. {
  10589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10590. }
  10591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10592. isKnowKey = TRUE;
  10593. }
  10594. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10595. {
  10596. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10599. {
  10600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10601. }
  10602. else
  10603. {
  10604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10605. }
  10606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10607. isKnowKey = TRUE;
  10608. }
  10609. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10610. {
  10611. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10614. {
  10615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10616. }
  10617. else
  10618. {
  10619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10620. }
  10621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10622. isKnowKey = TRUE;
  10623. }
  10624. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10625. {
  10626. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10629. {
  10630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10631. }
  10632. else
  10633. {
  10634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10635. }
  10636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10637. isKnowKey = TRUE;
  10638. }
  10639. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10640. {
  10641. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10644. {
  10645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10646. }
  10647. else
  10648. {
  10649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10650. }
  10651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10652. isKnowKey = TRUE;
  10653. }
  10654. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10655. {
  10656. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10659. {
  10660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10661. }
  10662. else
  10663. {
  10664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10665. }
  10666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10667. isKnowKey = TRUE;
  10668. }
  10669. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10670. {
  10671. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10674. {
  10675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10676. }
  10677. else
  10678. {
  10679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10680. }
  10681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10682. isKnowKey = TRUE;
  10683. }
  10684. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10685. {
  10686. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10688. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10689. {
  10690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10691. }
  10692. else
  10693. {
  10694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10695. }
  10696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10697. isKnowKey = TRUE;
  10698. }
  10699. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10700. {
  10701. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10704. {
  10705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10706. }
  10707. else
  10708. {
  10709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10710. }
  10711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10712. isKnowKey = TRUE;
  10713. }
  10714. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10715. {
  10716. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10719. {
  10720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10721. }
  10722. else
  10723. {
  10724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10725. }
  10726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10727. isKnowKey = TRUE;
  10728. }
  10729. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10730. {
  10731. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10734. {
  10735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10736. }
  10737. else
  10738. {
  10739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10740. }
  10741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10742. isKnowKey = TRUE;
  10743. }
  10744. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10745. {
  10746. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10749. {
  10750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10751. }
  10752. else
  10753. {
  10754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10755. }
  10756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10757. isKnowKey = TRUE;
  10758. }
  10759. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10760. {
  10761. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10763. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10764. {
  10765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10766. }
  10767. else
  10768. {
  10769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10770. }
  10771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10772. isKnowKey = TRUE;
  10773. }
  10774. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10775. {
  10776. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10779. {
  10780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10781. }
  10782. else
  10783. {
  10784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10785. }
  10786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10787. isKnowKey = TRUE;
  10788. }
  10789. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10790. {
  10791. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10794. {
  10795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10796. }
  10797. else
  10798. {
  10799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10800. }
  10801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10802. isKnowKey = TRUE;
  10803. }
  10804. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10805. {
  10806. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10809. {
  10810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10811. }
  10812. else
  10813. {
  10814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10815. }
  10816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10817. isKnowKey = TRUE;
  10818. }
  10819. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10820. {
  10821. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10824. {
  10825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10826. }
  10827. else
  10828. {
  10829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10830. }
  10831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10832. isKnowKey = TRUE;
  10833. }
  10834. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10835. {
  10836. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10839. {
  10840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10841. }
  10842. else
  10843. {
  10844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10845. }
  10846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10847. isKnowKey = TRUE;
  10848. }
  10849. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10850. {
  10851. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10854. {
  10855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10856. }
  10857. else
  10858. {
  10859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10860. }
  10861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10862. isKnowKey = TRUE;
  10863. }
  10864. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10865. {
  10866. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10869. {
  10870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10871. }
  10872. else
  10873. {
  10874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10875. }
  10876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10877. isKnowKey = TRUE;
  10878. }
  10879. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10880. {
  10881. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10884. {
  10885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10886. }
  10887. else
  10888. {
  10889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10890. }
  10891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10892. isKnowKey = TRUE;
  10893. }
  10894. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10895. {
  10896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10899. {
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10901. }
  10902. else
  10903. {
  10904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10905. }
  10906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10907. isKnowKey = TRUE;
  10908. }
  10909. #if 0
  10910. //For OCTT Test Case
  10911. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10912. {
  10913. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10915. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10916. {
  10917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10918. }
  10919. else
  10920. {
  10921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10922. }
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10924. isKnowKey = TRUE;
  10925. }
  10926. #endif
  10927. #if 1
  10928. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10932. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10935. }
  10936. else
  10937. {
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10939. }
  10940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10941. isKnowKey = TRUE;
  10942. }
  10943. #endif
  10944. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10945. {
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10948. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10949. {
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10951. }
  10952. else
  10953. {
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10955. }
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10957. isKnowKey = TRUE;
  10958. }
  10959. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10960. {
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10963. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10964. {
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10966. }
  10967. else
  10968. {
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10970. }
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10972. isKnowKey = TRUE;
  10973. }
  10974. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10975. {
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10978. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10979. {
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10981. }
  10982. else
  10983. {
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10985. }
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10987. isKnowKey = TRUE;
  10988. }
  10989. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10990. {
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10993. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10994. {
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10996. }
  10997. else
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11000. }
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11002. isKnowKey = TRUE;
  11003. }
  11004. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11005. {
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11008. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11009. {
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11011. }
  11012. else
  11013. {
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11015. }
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11017. isKnowKey = TRUE;
  11018. }
  11019. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11020. {
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11023. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11024. {
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11026. }
  11027. else
  11028. {
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11030. }
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11032. isKnowKey = TRUE;
  11033. }
  11034. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11035. {
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11038. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11039. {
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11041. }
  11042. else
  11043. {
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11045. }
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11047. isKnowKey = TRUE;
  11048. }
  11049. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11050. {
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11053. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11054. {
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11056. }
  11057. else
  11058. {
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11060. }
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11062. isKnowKey = TRUE;
  11063. }
  11064. //=========================================================
  11065. if(!isEmpty && !isKnowKey)
  11066. {
  11067. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11068. strcpy(unknownkey[UnknownKeynum], keyReq);
  11069. UnknownKeynum = UnknownKeynum + 1;
  11070. }
  11071. }
  11072. void processUnkownKey(void)
  11073. {
  11074. DEBUG_INFO("processUnkownKey\n");
  11075. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11076. for(int index=0; index < UnknownKeynum; index++)
  11077. {
  11078. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11079. {
  11080. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11081. }
  11082. }
  11083. }
  11084. int setKeyValue(char *key, char *value)
  11085. {
  11086. int isSuccess = NotSupported;
  11087. int check_ascii=0;
  11088. char str[10]={0};
  11089. #ifdef Debug
  11090. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11091. #endif
  11092. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11093. {
  11094. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11096. {
  11097. strcpy(str, (const char*)value);
  11098. for(int i = 0; str[i]; i++){
  11099. str[i] = tolower(str[i]);
  11100. }
  11101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11102. isSuccess = ConfigurationStatus_Accepted;
  11103. }
  11104. else
  11105. {
  11106. isSuccess = ConfigurationStatus_Rejected;
  11107. }
  11108. }
  11109. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11110. {
  11111. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11113. {
  11114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  11115. isSuccess = ConfigurationStatus_Accepted;
  11116. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11117. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11118. }
  11119. else
  11120. {
  11121. isSuccess = ConfigurationStatus_Rejected;
  11122. }
  11123. }
  11124. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11125. {
  11126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11127. {
  11128. strcpy(str, (const char*)value);
  11129. for(int i = 0; str[i]; i++)
  11130. {
  11131. str[i] = tolower(str[i]);
  11132. }
  11133. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11135. isSuccess = ConfigurationStatus_Accepted;
  11136. }
  11137. else
  11138. {
  11139. isSuccess = ConfigurationStatus_Rejected;
  11140. }
  11141. }
  11142. if(strcmp(key, "BlinkRepeat") == 0)
  11143. {
  11144. //Charger.BlinkRepeat = Integer.parseInt(value);
  11145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11146. {
  11147. check_ascii = value[0];
  11148. if( (check_ascii < 48) || (check_ascii > 57) )
  11149. {
  11150. isSuccess = ConfigurationStatus_Rejected;
  11151. }
  11152. else
  11153. {
  11154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11155. isSuccess = ConfigurationStatus_Accepted;
  11156. }
  11157. }
  11158. else
  11159. {
  11160. isSuccess = ConfigurationStatus_Rejected;
  11161. }
  11162. }
  11163. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11164. {
  11165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].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. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11176. isSuccess = ConfigurationStatus_Accepted;
  11177. }
  11178. }
  11179. else
  11180. {
  11181. isSuccess = ConfigurationStatus_Rejected;
  11182. }
  11183. }
  11184. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11185. {
  11186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11187. {
  11188. check_ascii = value[0];
  11189. if( (check_ascii < 48) || (check_ascii > 57) )
  11190. {
  11191. isSuccess = ConfigurationStatus_Rejected;
  11192. }
  11193. else
  11194. {
  11195. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11197. isSuccess = ConfigurationStatus_Accepted;
  11198. }
  11199. }
  11200. else
  11201. {
  11202. isSuccess = ConfigurationStatus_Rejected;
  11203. }
  11204. }
  11205. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11206. {
  11207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].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.HeartbeatInterval = Integer.parseInt(value)*1000;
  11217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11218. isSuccess = ConfigurationStatus_Accepted;
  11219. }
  11220. }
  11221. else
  11222. {
  11223. isSuccess = ConfigurationStatus_Rejected;
  11224. }
  11225. }
  11226. if(strcmp(key, "HeartbeatInterval") == 0)
  11227. {
  11228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11229. {
  11230. check_ascii = value[0];
  11231. if( (check_ascii < 48) || (check_ascii > 57) )
  11232. {
  11233. isSuccess = ConfigurationStatus_Rejected;
  11234. }
  11235. else
  11236. {
  11237. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11239. HeartBeatWaitTime = atoi(value);
  11240. isSuccess = ConfigurationStatus_Accepted;
  11241. }
  11242. }
  11243. else
  11244. {
  11245. isSuccess = ConfigurationStatus_Rejected;
  11246. }
  11247. }
  11248. if(strcmp(key, "LightIntensity") == 0)
  11249. {
  11250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11251. {
  11252. check_ascii = value[0];
  11253. if( (check_ascii < 48) || (check_ascii > 57) )
  11254. {
  11255. isSuccess = ConfigurationStatus_Rejected;
  11256. }
  11257. else
  11258. {
  11259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11260. isSuccess = ConfigurationStatus_Accepted;
  11261. }
  11262. }
  11263. else
  11264. {
  11265. isSuccess = ConfigurationStatus_Rejected;
  11266. }
  11267. }
  11268. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11269. {
  11270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11271. {
  11272. strcpy(str, (const char*)value);
  11273. for(int i = 0; str[i]; i++)
  11274. {
  11275. str[i] = tolower(str[i]);
  11276. }
  11277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11278. isSuccess = ConfigurationStatus_Accepted;
  11279. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11280. }
  11281. else
  11282. {
  11283. isSuccess = ConfigurationStatus_Rejected;
  11284. }
  11285. }
  11286. if(strcmp(key, "LocalPreAuthorize") == 0)
  11287. {
  11288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11289. {
  11290. strcpy(str, (const char*)value);
  11291. for(int i = 0; str[i]; i++)
  11292. {
  11293. str[i] = tolower(str[i]);
  11294. }
  11295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11296. isSuccess = ConfigurationStatus_Accepted;
  11297. }
  11298. else
  11299. {
  11300. isSuccess = ConfigurationStatus_Rejected;
  11301. }
  11302. }
  11303. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11304. {
  11305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11306. {
  11307. check_ascii = value[0];
  11308. if( (check_ascii < 48) || (check_ascii > 57) )
  11309. {
  11310. isSuccess = ConfigurationStatus_Rejected;
  11311. }
  11312. else
  11313. {
  11314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11315. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11316. isSuccess = ConfigurationStatus_Accepted;
  11317. }
  11318. }
  11319. else
  11320. {
  11321. isSuccess = ConfigurationStatus_Rejected;
  11322. }
  11323. }
  11324. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11325. {
  11326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11327. {
  11328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11329. isSuccess = ConfigurationStatus_Accepted;
  11330. }
  11331. else
  11332. {
  11333. isSuccess = ConfigurationStatus_Rejected;
  11334. }
  11335. }
  11336. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11337. {
  11338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11339. {
  11340. check_ascii = value[0];
  11341. if( (check_ascii < 48) || (check_ascii > 57) )
  11342. {
  11343. isSuccess = ConfigurationStatus_Rejected;
  11344. }
  11345. else
  11346. {
  11347. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11349. isSuccess = ConfigurationStatus_Accepted;
  11350. }
  11351. }
  11352. else
  11353. {
  11354. isSuccess = ConfigurationStatus_Rejected;
  11355. }
  11356. }
  11357. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11358. {
  11359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11360. {
  11361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11362. isSuccess = ConfigurationStatus_Accepted;
  11363. }
  11364. else
  11365. {
  11366. isSuccess = ConfigurationStatus_Rejected;
  11367. }
  11368. }
  11369. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11370. {
  11371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11372. {
  11373. check_ascii = value[0];
  11374. if( (check_ascii < 48) || (check_ascii > 57) )
  11375. {
  11376. isSuccess = ConfigurationStatus_Rejected;
  11377. }
  11378. else
  11379. {
  11380. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11382. isSuccess = ConfigurationStatus_Accepted;
  11383. }
  11384. }
  11385. else
  11386. {
  11387. isSuccess = ConfigurationStatus_Rejected;
  11388. }
  11389. }
  11390. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11391. {
  11392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].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. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11403. isSuccess = ConfigurationStatus_Accepted;
  11404. }
  11405. }
  11406. else
  11407. {
  11408. isSuccess = ConfigurationStatus_Rejected;
  11409. }
  11410. }
  11411. if(strcmp(key, "MinimumStatusDuration") == 0)
  11412. {
  11413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11414. {
  11415. check_ascii = value[0];
  11416. if( (check_ascii < 48) || (check_ascii > 57) )
  11417. {
  11418. isSuccess = ConfigurationStatus_Rejected;
  11419. }
  11420. else
  11421. {
  11422. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11424. isSuccess = ConfigurationStatus_Accepted;
  11425. }
  11426. }
  11427. else
  11428. {
  11429. isSuccess = ConfigurationStatus_Rejected;
  11430. }
  11431. }
  11432. if(strcmp(key, "NumberOfConnectors") == 0)
  11433. {
  11434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11435. {
  11436. check_ascii = value[0];
  11437. if( (check_ascii < 48) || (check_ascii > 57) )
  11438. {
  11439. isSuccess = ConfigurationStatus_Rejected;
  11440. }
  11441. else
  11442. {
  11443. //Charger.ResetRetries = Integer.parseInt(value);
  11444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11445. isSuccess = ConfigurationStatus_Accepted;
  11446. }
  11447. }
  11448. else
  11449. {
  11450. isSuccess = ConfigurationStatus_Rejected;
  11451. }
  11452. }
  11453. if(strcmp(key, "ResetRetries") == 0)
  11454. {
  11455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11456. {
  11457. check_ascii = value[0];
  11458. if( (check_ascii < 48) || (check_ascii > 57) )
  11459. {
  11460. isSuccess = ConfigurationStatus_Rejected;
  11461. }
  11462. else
  11463. {
  11464. //Charger.ResetRetries = Integer.parseInt(value);
  11465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11466. isSuccess = ConfigurationStatus_Accepted;
  11467. }
  11468. }
  11469. else
  11470. {
  11471. isSuccess = ConfigurationStatus_Rejected;
  11472. }
  11473. }
  11474. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11475. {
  11476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11477. {
  11478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11479. isSuccess = ConfigurationStatus_Accepted;
  11480. }
  11481. else
  11482. {
  11483. isSuccess = ConfigurationStatus_Rejected;
  11484. }
  11485. }
  11486. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11487. {
  11488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11489. {
  11490. check_ascii = value[0];
  11491. if( (check_ascii < 48) || (check_ascii > 57) )
  11492. {
  11493. isSuccess = ConfigurationStatus_Rejected;
  11494. }
  11495. else
  11496. {
  11497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11498. isSuccess = ConfigurationStatus_Accepted;
  11499. }
  11500. }
  11501. else
  11502. {
  11503. isSuccess = ConfigurationStatus_Rejected;
  11504. }
  11505. }
  11506. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11507. {
  11508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11509. {
  11510. strcpy(str, (const char*)value);
  11511. for(int i = 0; str[i]; i++)
  11512. {
  11513. str[i] = tolower(str[i]);
  11514. }
  11515. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11517. isSuccess = ConfigurationStatus_Accepted;
  11518. }
  11519. else
  11520. {
  11521. isSuccess = ConfigurationStatus_Rejected;
  11522. }
  11523. }
  11524. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11525. {
  11526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11527. {
  11528. strcpy(str, (const char*)value);
  11529. for(int i = 0; str[i]; i++)
  11530. {
  11531. str[i] = tolower(str[i]);
  11532. }
  11533. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11535. isSuccess = ConfigurationStatus_Accepted;
  11536. }
  11537. else
  11538. {
  11539. isSuccess = ConfigurationStatus_Rejected;
  11540. }
  11541. }
  11542. if(strcmp(key, "StopTxnAlignedData") == 0)
  11543. {
  11544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11545. {
  11546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11547. isSuccess = ConfigurationStatus_Accepted;
  11548. }
  11549. else
  11550. {
  11551. isSuccess = ConfigurationStatus_Rejected;
  11552. }
  11553. }
  11554. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11555. {
  11556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11557. {
  11558. check_ascii = value[0];
  11559. if( (check_ascii < 48) || (check_ascii > 57) )
  11560. {
  11561. isSuccess = ConfigurationStatus_Rejected;
  11562. }
  11563. else
  11564. {
  11565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11566. isSuccess = ConfigurationStatus_Accepted;
  11567. }
  11568. }
  11569. else
  11570. {
  11571. isSuccess = ConfigurationStatus_Rejected;
  11572. }
  11573. }
  11574. if(strcmp(key, "StopTxnSampledData") == 0)
  11575. {
  11576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11577. {
  11578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11579. isSuccess = ConfigurationStatus_Accepted;
  11580. }
  11581. else
  11582. {
  11583. isSuccess = ConfigurationStatus_Rejected;
  11584. }
  11585. }
  11586. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11587. {
  11588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11589. {
  11590. check_ascii = value[0];
  11591. if( (check_ascii < 48) || (check_ascii > 57) )
  11592. {
  11593. isSuccess = ConfigurationStatus_Rejected;
  11594. }
  11595. else
  11596. {
  11597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11598. isSuccess = ConfigurationStatus_Accepted;
  11599. }
  11600. }
  11601. else
  11602. {
  11603. isSuccess = ConfigurationStatus_Rejected;
  11604. }
  11605. }
  11606. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11607. {
  11608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11609. {
  11610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11611. isSuccess = ConfigurationStatus_Accepted;
  11612. }
  11613. else
  11614. {
  11615. isSuccess = ConfigurationStatus_Rejected;
  11616. }
  11617. }
  11618. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11619. {
  11620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11621. {
  11622. check_ascii = value[0];
  11623. if( (check_ascii < 48) || (check_ascii > 57) )
  11624. {
  11625. isSuccess = ConfigurationStatus_Rejected;
  11626. }
  11627. else
  11628. {
  11629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11630. isSuccess = ConfigurationStatus_Accepted;
  11631. }
  11632. }
  11633. else
  11634. {
  11635. isSuccess = ConfigurationStatus_Rejected;
  11636. }
  11637. }
  11638. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11639. {
  11640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11641. {
  11642. check_ascii = value[0];
  11643. if( (check_ascii < 48) || (check_ascii > 57) )
  11644. {
  11645. isSuccess = ConfigurationStatus_Rejected;
  11646. }
  11647. else
  11648. {
  11649. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11651. TransactionMessageAttemptsValue = atoi(value);
  11652. isSuccess = ConfigurationStatus_Accepted;
  11653. }
  11654. }
  11655. else
  11656. {
  11657. isSuccess = ConfigurationStatus_Rejected;
  11658. }
  11659. }
  11660. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11661. {
  11662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11663. {
  11664. check_ascii = value[0];
  11665. if( (check_ascii < 48) || (check_ascii > 57) )
  11666. {
  11667. isSuccess = ConfigurationStatus_Rejected;
  11668. }
  11669. else
  11670. {
  11671. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11673. TransactionMessageRetryIntervalValue = atoi(value);
  11674. isSuccess = ConfigurationStatus_Accepted;
  11675. }
  11676. }
  11677. else
  11678. {
  11679. isSuccess = ConfigurationStatus_Rejected;
  11680. }
  11681. }
  11682. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11683. {
  11684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11685. {
  11686. strcpy(str, (const char*)value);
  11687. for(int i = 0; str[i]; i++)
  11688. {
  11689. str[i] = tolower(str[i]);
  11690. }
  11691. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11693. isSuccess = ConfigurationStatus_Accepted;
  11694. }
  11695. else
  11696. {
  11697. isSuccess = ConfigurationStatus_Rejected;
  11698. }
  11699. }
  11700. if(strcmp(key, "WebSocketPingInterval") == 0)
  11701. {
  11702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11703. {
  11704. check_ascii = value[0];
  11705. if( (check_ascii < 48) || (check_ascii > 57) )
  11706. {
  11707. isSuccess = ConfigurationStatus_Rejected;
  11708. }
  11709. else
  11710. {
  11711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11712. isSuccess = ConfigurationStatus_Accepted;
  11713. }
  11714. }
  11715. else
  11716. {
  11717. isSuccess = ConfigurationStatus_Rejected;
  11718. }
  11719. }
  11720. #if 0
  11721. //For OCPP Test Case
  11722. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11723. {
  11724. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11725. {
  11726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11727. isSuccess = ConfigurationStatus_Accepted;
  11728. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11729. }
  11730. else
  11731. {
  11732. isSuccess = ConfigurationStatus_Rejected;
  11733. }
  11734. }
  11735. #endif
  11736. #if 1
  11737. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11738. {
  11739. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11740. {
  11741. strcpy(str, (const char*)value);
  11742. for(int i = 0; str[i]; i++)
  11743. {
  11744. str[i] = tolower(str[i]);
  11745. }
  11746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11747. isSuccess = ConfigurationStatus_Accepted;
  11748. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11749. }
  11750. else
  11751. {
  11752. isSuccess = ConfigurationStatus_Rejected;
  11753. }
  11754. }
  11755. #endif
  11756. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11757. {
  11758. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11759. {
  11760. check_ascii = value[0];
  11761. if( (check_ascii < 48) || (check_ascii > 57) )
  11762. {
  11763. isSuccess = ConfigurationStatus_Rejected;
  11764. }
  11765. else
  11766. {
  11767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11768. isSuccess = ConfigurationStatus_Accepted;
  11769. }
  11770. }
  11771. else
  11772. {
  11773. isSuccess = ConfigurationStatus_Rejected;
  11774. }
  11775. }
  11776. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11777. {
  11778. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11779. {
  11780. check_ascii = value[0];
  11781. if( (check_ascii < 48) || (check_ascii > 57) )
  11782. {
  11783. isSuccess = ConfigurationStatus_Rejected;
  11784. }
  11785. else
  11786. {
  11787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11788. isSuccess = ConfigurationStatus_Accepted;
  11789. }
  11790. }
  11791. else
  11792. {
  11793. isSuccess = ConfigurationStatus_Rejected;
  11794. }
  11795. }
  11796. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11797. {
  11798. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11799. {
  11800. strcpy(str, (const char*)value);
  11801. for(int i = 0; str[i]; i++)
  11802. {
  11803. str[i] = tolower(str[i]);
  11804. }
  11805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11806. isSuccess = ConfigurationStatus_Accepted;
  11807. }
  11808. else
  11809. {
  11810. isSuccess = ConfigurationStatus_Rejected;
  11811. }
  11812. }
  11813. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11814. {
  11815. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11816. {
  11817. check_ascii = value[0];
  11818. if( (check_ascii < 48) || (check_ascii > 57) )
  11819. {
  11820. isSuccess = ConfigurationStatus_Rejected;
  11821. }
  11822. else
  11823. {
  11824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11825. isSuccess = ConfigurationStatus_Accepted;
  11826. }
  11827. }
  11828. else
  11829. {
  11830. isSuccess = ConfigurationStatus_Rejected;
  11831. }
  11832. }
  11833. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11834. {
  11835. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11836. {
  11837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11838. isSuccess = ConfigurationStatus_Accepted;
  11839. }
  11840. else
  11841. {
  11842. isSuccess = ConfigurationStatus_Rejected;
  11843. }
  11844. }
  11845. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11846. {
  11847. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11848. {
  11849. check_ascii = value[0];
  11850. if( (check_ascii < 48) || (check_ascii > 57) )
  11851. {
  11852. isSuccess = ConfigurationStatus_Rejected;
  11853. }
  11854. else
  11855. {
  11856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11857. isSuccess = ConfigurationStatus_Accepted;
  11858. }
  11859. }
  11860. else
  11861. {
  11862. isSuccess = ConfigurationStatus_Rejected;
  11863. }
  11864. }
  11865. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11866. {
  11867. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11868. {
  11869. strcpy(str, (const char*)value);
  11870. for(int i = 0; str[i]; i++)
  11871. {
  11872. str[i] = tolower(str[i]);
  11873. }
  11874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11875. isSuccess = ConfigurationStatus_Accepted;
  11876. }
  11877. else
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. }
  11882. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11883. {
  11884. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11885. {
  11886. check_ascii = value[0];
  11887. if( (check_ascii < 48) || (check_ascii > 57) )
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. else
  11892. {
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11894. isSuccess = ConfigurationStatus_Accepted;
  11895. }
  11896. }
  11897. else
  11898. {
  11899. isSuccess = ConfigurationStatus_Rejected;
  11900. }
  11901. }
  11902. return isSuccess;
  11903. }
  11904. int updateSetting(char *key, char *value)
  11905. {
  11906. mtrace();
  11907. int isSuccess = FALSE;
  11908. char string[1000]={0}, buffer[1000]={0};
  11909. char strtemp[50]={0};
  11910. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11911. int pos, c = 0;
  11912. char *loc;
  11913. int pos1=0;
  11914. FILE *f = fopen("/var/www/settings1", "r");
  11915. if(f == NULL)
  11916. {
  11917. #ifdef Debug
  11918. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11919. #endif
  11920. return isSuccess;
  11921. }
  11922. fseek(f, 0, SEEK_END);
  11923. long fsize = ftell(f);
  11924. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11925. fread(string, 1, fsize, f);
  11926. fclose(f);
  11927. string[fsize] = 0;
  11928. loc = strstr(string, key);
  11929. if(loc != NULL)
  11930. {
  11931. DEBUG_INFO("key exist!\n");
  11932. pos = loc - string-1;
  11933. f = fopen("/var/www/settings1", "w");
  11934. strncpy(buffer, string, pos);
  11935. fprintf(f, "%s", buffer);
  11936. memset(sstr ,0, sizeof(sstr) );
  11937. c = 0;
  11938. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11939. {
  11940. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11941. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11942. c++;
  11943. }
  11944. sstr[c] = '\0';
  11945. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11946. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11947. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11948. memset(buffer ,0, sizeof(buffer) );
  11949. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11950. //printf("buffer=%s",buffer);
  11951. fprintf(f, "%s", buffer);
  11952. fclose(f);
  11953. }
  11954. else
  11955. {
  11956. printf("key not exist!\n");
  11957. f = fopen("/var/www/settings1", "w+");
  11958. fputs(string, f);
  11959. fseek(f, -1, SEEK_CUR);
  11960. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11961. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11962. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11963. fclose(f);
  11964. }
  11965. isSuccess = TRUE;
  11966. return isSuccess;
  11967. }
  11968. int TransactionMessageAttemptsGet(void)
  11969. {
  11970. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11971. }
  11972. int FirstHeartBeatResponse(void)
  11973. {
  11974. return FirstHeartBeat;
  11975. }
  11976. int TransactionMessageRetryIntervalGet(void)
  11977. {
  11978. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11979. }
  11980. #define SA struct sockaddr
  11981. #define MAXBUF 1024
  11982. //static int m_socket_data;
  11983. //static int sockfd;
  11984. int ReadHttpStatus(int sock){
  11985. //char c;
  11986. char buff[1024]="",*ptr=buff+1;
  11987. int bytes_received, status;
  11988. DEBUG_INFO("Begin Response ..\n");
  11989. while((bytes_received = recv(sock, ptr, 1, 0))){
  11990. if(bytes_received==-1){
  11991. perror("ReadHttpStatus");
  11992. exit(1);
  11993. }
  11994. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11995. ptr++;
  11996. }
  11997. *ptr=0;
  11998. ptr=buff+1;
  11999. sscanf(ptr,"%*s %d ", &status);
  12000. DEBUG_INFO("%s\n",ptr);
  12001. DEBUG_INFO("status=%d\n",status);
  12002. DEBUG_INFO("End Response ..\n");
  12003. return (bytes_received>0)?status:0;
  12004. }
  12005. //the only filed that it parsed is 'Content-Length'
  12006. int ParseHeader(int sock){
  12007. //char c;
  12008. char buff[1024]="",*ptr=buff+4;
  12009. int bytes_received;
  12010. DEBUG_INFO("Begin HEADER ..\n");
  12011. while((bytes_received = recv(sock, ptr, 1, 0))){
  12012. if(bytes_received==-1){
  12013. perror("Parse Header");
  12014. exit(1);
  12015. }
  12016. if(
  12017. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12018. (ptr[-1]=='\r') && (*ptr=='\n' )
  12019. ) break;
  12020. ptr++;
  12021. }
  12022. *ptr=0;
  12023. ptr=buff+4;
  12024. //printf("%s",ptr);
  12025. if(bytes_received){
  12026. ptr=strstr(ptr,"Content-Length:");
  12027. if(ptr){
  12028. sscanf(ptr,"%*s %d",&bytes_received);
  12029. }else
  12030. bytes_received=-1; //unknown size
  12031. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12032. }
  12033. DEBUG_INFO("End HEADER ..\n");
  12034. return bytes_received ;
  12035. }
  12036. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12037. {
  12038. char rmFileCmd[100]={0};
  12039. char FilePath[100]={0};
  12040. char ftpbuf[200];
  12041. int systemresult;
  12042. //DEBUG_INFO("filename=%s\n",filename);
  12043. //DEBUG_INFO("url=%s\n",url);
  12044. sprintf(FilePath,"/mnt/%s",filename);
  12045. if((access(FilePath,F_OK))!=-1)
  12046. {
  12047. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12048. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12049. system(rmFileCmd);
  12050. }
  12051. memset(ftpbuf, 0, sizeof(ftpbuf));
  12052. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12053. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12054. systemresult = system(ftpbuf);
  12055. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12056. if(systemresult != 0)
  12057. {
  12058. DEBUG_INFO("http DownLoad error!\n");
  12059. return FALSE;
  12060. }
  12061. return TRUE;
  12062. }
  12063. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12064. {
  12065. char rmFileCmd[100]={0};
  12066. char FilePath[100]={0};
  12067. char ftpbuf[200];
  12068. int systemresult;
  12069. //char temp[100];
  12070. #if 0
  12071. struct hostent* server;
  12072. char *IPbuffer;
  12073. server = gethostbyname(location);
  12074. // To convert an Internet network
  12075. // address into ASCII string
  12076. IPbuffer = inet_ntoa(*((struct in_addr*)
  12077. server->h_addr_list[0]));
  12078. #endif
  12079. sprintf(FilePath,"/mnt/%s",filename);
  12080. if((access(FilePath,F_OK))!=-1)
  12081. {
  12082. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12083. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12084. system(rmFileCmd);
  12085. }
  12086. memset(ftpbuf, 0, sizeof(ftpbuf));
  12087. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12088. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12089. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12090. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12091. systemresult = system(ftpbuf);
  12092. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12093. if(systemresult != 0)
  12094. {
  12095. printf("wget error!\n");
  12096. return FALSE;
  12097. }
  12098. return TRUE;
  12099. }
  12100. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12101. {
  12102. char rmFileCmd[100]={0};
  12103. char FilePath[100]={0};
  12104. char ftpbuf[200];
  12105. char filenametemp[60]={0};
  12106. int systemresult;
  12107. //DEBUG_INFO("filename=%s\n",filename);
  12108. //DEBUG_INFO("url=%s\n",url);
  12109. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12110. if((access(FilePath,F_OK))!=-1)
  12111. {
  12112. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12113. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12114. system(rmFileCmd);
  12115. }
  12116. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12117. if(fp == NULL)
  12118. {
  12119. DEBUG_INFO("log is NULL\n");
  12120. return FALSE;
  12121. }
  12122. else
  12123. {
  12124. fprintf(fp, "%s\n", url);
  12125. sscanf(filename, "%*2[.]%s", filenametemp);
  12126. fprintf(fp, "%s\n", filenametemp);
  12127. fclose(fp);
  12128. }
  12129. memset(ftpbuf, 0, sizeof(ftpbuf));
  12130. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12131. systemresult = system(ftpbuf);
  12132. DEBUG_INFO("systemresult=%d\n",systemresult);
  12133. if(systemresult != 0)
  12134. {
  12135. DEBUG_INFO("http upload error!\n");
  12136. return FALSE;
  12137. }
  12138. return TRUE;
  12139. }
  12140. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12141. {
  12142. struct hostent* server;
  12143. char *IPbuffer;
  12144. char ftpbuf[200];
  12145. int systemresult;
  12146. // To retrieve host information
  12147. server = gethostbyname(location);
  12148. // To convert an Internet network
  12149. // address into ASCII string
  12150. IPbuffer = inet_ntoa(*((struct in_addr*)
  12151. server->h_addr_list[0]));
  12152. memset(ftpbuf, 0, sizeof(ftpbuf));
  12153. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12154. /* format : ftpput -u username -p passwd IP target source*/
  12155. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12156. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12157. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12158. systemresult = system(ftpbuf);
  12159. DEBUG_INFO("systemresult=%d\n",systemresult);
  12160. if(systemresult != 0)
  12161. {
  12162. DEBUG_INFO("ftpput error!\n");
  12163. return FALSE;
  12164. }
  12165. return TRUE;
  12166. }
  12167. int SettingChargingRecord(int target, int transactionId)
  12168. {
  12169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12170. {
  12171. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12172. {
  12173. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12174. {
  12175. addBuff(target, transactionId, 0);
  12176. return TRUE;
  12177. }
  12178. }
  12179. for (int index = 0; index < CCS_QUANTITY; index++)
  12180. {
  12181. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12182. {
  12183. addBuff(target, transactionId, 0);
  12184. return TRUE;
  12185. }
  12186. }
  12187. for (int index = 0; index < GB_QUANTITY; index++)
  12188. {
  12189. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12190. {
  12191. addBuff(target, transactionId, 0);
  12192. return TRUE;
  12193. }
  12194. }
  12195. }
  12196. else
  12197. {
  12198. for (int index = 0; index < AC_QUANTITY; index++)
  12199. {
  12200. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12201. {
  12202. addBuff(target, transactionId, 0);
  12203. return TRUE;
  12204. }
  12205. }
  12206. }
  12207. return FALSE;
  12208. }
  12209. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12210. {
  12211. int isSuccess = FALSE;
  12212. //char *query = NULL;
  12213. sqlite3_stmt *stmt;
  12214. int rc; // return code
  12215. char str[20];
  12216. sprintf(str,"%d",user_id);
  12217. 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 */
  12218. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12219. rc = sqlite3_step(stmt); /* 3 */
  12220. if (rc != SQLITE_DONE) {
  12221. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12222. goto out;
  12223. }
  12224. sqlite3_finalize(stmt);
  12225. // free(query);
  12226. out:
  12227. //----------------------
  12228. // close SQLite database
  12229. //----------------------
  12230. sqlite3_close(db);
  12231. printf("database closed.\n");
  12232. return isSuccess;
  12233. }
  12234. /**
  12235. * Place the contents of the specified file into a memory buffer
  12236. *
  12237. * @param[in] filename The path and name of the file to read
  12238. * @param[out] filebuffer A pointer to the contents in memory
  12239. * @return status 0 success, 1 on failure
  12240. */
  12241. int get_file_contents(const char* filename, char** outbuffer) {
  12242. FILE* file = NULL;
  12243. long filesize;
  12244. const int blocksize = 1;
  12245. size_t readsize;
  12246. char* filebuffer;
  12247. // Open the file
  12248. file = fopen(filename, "r");
  12249. if (NULL == file)
  12250. {
  12251. printf("'%s' not opened\n", filename);
  12252. exit(EXIT_FAILURE);
  12253. }
  12254. // Determine the file size
  12255. fseek(file, 0, SEEK_END);
  12256. filesize = ftell(file);
  12257. rewind (file);
  12258. // Allocate memory for the file contents
  12259. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12260. *outbuffer = filebuffer;
  12261. if (filebuffer == NULL)
  12262. {
  12263. fputs ("malloc out-of-memory", stderr);
  12264. exit(EXIT_FAILURE);
  12265. }
  12266. // Read in the file
  12267. readsize = fread(filebuffer, blocksize, filesize, file);
  12268. if (readsize != filesize)
  12269. {
  12270. fputs ("didn't read file completely",stderr);
  12271. exit(EXIT_FAILURE);
  12272. }
  12273. // Clean exit
  12274. fclose(file);
  12275. return EXIT_SUCCESS;
  12276. }
  12277. static int selectSqlCount = 0;
  12278. static int callback(void *data, int argc, char **argv, char **azColName){
  12279. int i;
  12280. printf("%s: ", (const char*)data);
  12281. selectSqlCount = argc;
  12282. for(i = 0; i<argc; i++){
  12283. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12284. }
  12285. printf("\n");
  12286. return 0;
  12287. }
  12288. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12289. //int i;
  12290. //printf("%s:\n", (const char*)data);
  12291. localversion = argv[5] ? atoi(argv[5]) : 0;
  12292. printf("localversion=%d\n", localversion);
  12293. return 0;
  12294. }
  12295. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12296. //int i;
  12297. //printf("%s:\n", (const char*)data);
  12298. //idTag
  12299. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12300. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12301. //parentIdTag
  12302. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12303. //expir_date
  12304. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12305. //status
  12306. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12307. //version
  12308. idTagQuery.listVersionInt = atoi(argv[5]);
  12309. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12310. return 0;
  12311. }
  12312. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12313. int i;
  12314. //printf("%s:\n", (const char*)data);
  12315. #if 1
  12316. for(i=0; i<argc; i++){
  12317. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12318. }
  12319. //printf("");
  12320. #endif
  12321. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12322. // printf("localversion=%d\n", localversion);
  12323. return 0;
  12324. }
  12325. /** sqlite3_exec的回调。
  12326. *
  12327. * 向控制台打印查询的结果。
  12328. *
  12329. * @param in data 传递给回调函数的数据。
  12330. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12331. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12332. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12333. * @return 状态码。
  12334. */
  12335. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12336. {
  12337. for (int i = 0; i < n_columns; i++)
  12338. {
  12339. DEBUG_INFO("%s/t", col_values[i]);
  12340. }
  12341. DEBUG_INFO("/n");
  12342. return 0;
  12343. }
  12344. void OCPP_getListVerion()
  12345. {
  12346. int rc = 0;
  12347. // const char* data = "Callback function called";
  12348. char sql[100];
  12349. char zErrMsg[100];
  12350. memset(sql, 0, 100);
  12351. memset(zErrMsg, 0, 100);
  12352. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12353. /* Execute SQL statement */
  12354. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12355. DEBUG_INFO("rc=%d\n",rc);
  12356. if( rc != SQLITE_OK ){
  12357. DEBUG_INFO("SQL error: %s", zErrMsg);
  12358. //sqlite3_free(zErrMsg);
  12359. }else{
  12360. DEBUG_INFO("Operation done successfully");
  12361. }
  12362. }
  12363. void OCPP_getIdTag(char idTag[])
  12364. {
  12365. int rc = 0;
  12366. // const char* data = "Callback function called";
  12367. char sql[100];
  12368. char zErrMsg[100];
  12369. memset(sql, 0, 100);
  12370. memset(zErrMsg, 0, 100);
  12371. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12372. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12373. DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12374. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12375. /* Execute SQL statement */
  12376. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12377. if( rc != SQLITE_OK ){
  12378. DEBUG_INFO("SQL error: %s", zErrMsg);
  12379. //sqlite3_free(zErrMsg);
  12380. }else{
  12381. printf("Operation done successfully");
  12382. }
  12383. //return ver;
  12384. }
  12385. void OCPP_get_TableAuthlocalAllData(void)
  12386. {
  12387. int rc = 0;
  12388. // const char* data = "Callback function called";
  12389. char sql[100];
  12390. char zErrMsg[100];
  12391. memset(sql, 0, 100);
  12392. memset(zErrMsg, 0, 100);
  12393. sprintf(sql,"select * from ocpp_auth_local ");
  12394. /* Execute SQL statement */
  12395. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12396. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12397. if( rc != SQLITE_OK ){
  12398. DEBUG_INFO("SQL error: %s", zErrMsg);
  12399. //sqlite3_free(zErrMsg);
  12400. }else{
  12401. DEBUG_INFO("Operation done successfully");
  12402. }
  12403. //return ver;
  12404. }
  12405. int OCPP_cleanLocalList()
  12406. {
  12407. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12408. char *errMsg = 0;
  12409. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12410. if (SQLITE_OK != rc)
  12411. {
  12412. DEBUG_INFO("%s\n",errMsg);
  12413. return FALSE;
  12414. }
  12415. else
  12416. {
  12417. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12418. }
  12419. return TRUE;
  12420. }
  12421. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12422. {
  12423. int isSuccess = FALSE;
  12424. int ret = 0;
  12425. //const char* data = "Callback function called";
  12426. char sql[300];
  12427. char zErrMsg[200];
  12428. memset(sql, 0, 300);
  12429. memset(zErrMsg, 0, 200);
  12430. 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);
  12431. //* Execute SQL statement */
  12432. //zErrMsg = 0;
  12433. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12434. if( ret != SQLITE_OK ){
  12435. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12436. // free(zErrMsg);
  12437. // free(sql);
  12438. return isSuccess;
  12439. }
  12440. DEBUG_INFO("successfully Insert records created\n");
  12441. isSuccess = TRUE;
  12442. return isSuccess;
  12443. }
  12444. void OCPP_deleteIdTag(char idTag[])
  12445. {
  12446. //int ver = 0;
  12447. //int isSuccess = FALSE;
  12448. int rc = 0;
  12449. char sql[100];
  12450. char zErrMsg[100];
  12451. memset(sql, 0, 100);
  12452. memset(zErrMsg, 0, 100);
  12453. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12454. //* Execute SQL statement */
  12455. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12456. if( rc != SQLITE_OK ){
  12457. DEBUG_INFO("SQL error: %s", zErrMsg);
  12458. //sqlite3_free(zErrMsg);
  12459. }else{
  12460. DEBUG_INFO("Operation done successfully");
  12461. }
  12462. }
  12463. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12464. {
  12465. int isSuccess = FALSE;
  12466. int ret = 0;
  12467. const char* data = "Callback function called";
  12468. char sql[200];
  12469. char zErrMsg[100];
  12470. memset(sql, 0, 200);
  12471. memset(zErrMsg, 0, 100);
  12472. //* selectFromTable */
  12473. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12474. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12475. //* Execute SQL statement */
  12476. selectSqlCount = 0;
  12477. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12478. if( ret != SQLITE_OK ){
  12479. printf("Error SQL: %s\n", zErrMsg);
  12480. }
  12481. printf("successfully select operation done\n");
  12482. memset(sql, 0, 200);
  12483. memset(zErrMsg, 0, 100);
  12484. if(selectSqlCount == 0)
  12485. {
  12486. //Insert
  12487. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12488. 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);
  12489. DEBUG_INFO("sql:%s\n", sql);
  12490. //* Execute SQL statement */
  12491. //zErrMsg = 0;
  12492. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12493. if( ret != SQLITE_OK ){
  12494. printf("SQL error: %s\n", zErrMsg);
  12495. return isSuccess;
  12496. }
  12497. DEBUG_INFO("successfully Insert records created\n");
  12498. isSuccess = TRUE;
  12499. }
  12500. else
  12501. {
  12502. //Update
  12503. //* Create merged SQL statement */
  12504. 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);
  12505. /* Execute SQL statement */
  12506. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12507. if( ret != SQLITE_OK ){
  12508. printf("SQL error: %s\n", zErrMsg);
  12509. //sqlite3_free(zErrMsg);
  12510. //sqlite3_free(sql);
  12511. return isSuccess;
  12512. }
  12513. DEBUG_INFO("Successfully operation done \n");
  12514. isSuccess = TRUE;
  12515. }
  12516. return isSuccess;
  12517. }
  12518. int GetOcppServerURL()
  12519. {
  12520. int result = FALSE;
  12521. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12522. memset(OcppHost, 0, sizeof(OcppHost));
  12523. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12524. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12525. {
  12526. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12527. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12528. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12529. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12530. result = TRUE;
  12531. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12532. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12533. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12534. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12535. goto End;
  12536. }
  12537. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12538. {
  12539. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12540. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12541. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12542. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12543. result = TRUE;
  12544. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12545. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12546. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12547. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12548. goto End;
  12549. }
  12550. else
  12551. {
  12552. strcpy(OcppHost,"");
  12553. }
  12554. End:
  12555. return result;
  12556. }
  12557. int GetOcppPath()
  12558. {
  12559. int result = FALSE;
  12560. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12561. {
  12562. if(OcppTempPath == NULL)
  12563. {
  12564. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12565. }
  12566. else
  12567. {
  12568. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12569. }
  12570. result = TRUE;
  12571. goto End;
  12572. }
  12573. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12574. {
  12575. if(OcppTempPath == NULL)
  12576. {
  12577. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12578. }
  12579. else
  12580. {
  12581. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12582. }
  12583. result = TRUE;
  12584. goto End;
  12585. }
  12586. else
  12587. {
  12588. strcpy(OcppPath,"");
  12589. }
  12590. End:
  12591. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12592. return result;
  12593. }
  12594. int GetOcppPort()
  12595. {
  12596. return OcppPort;
  12597. }
  12598. int GetOcppConnStatus(void)
  12599. {
  12600. return ShmOCPP16Data->OcppConnStatus;
  12601. }
  12602. void SetOcppConnStatus(uint8_t status)
  12603. {
  12604. ShmOCPP16Data->OcppConnStatus = status;
  12605. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12606. if(status == FALSE)
  12607. {
  12608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12609. {
  12610. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12611. }
  12612. else
  12613. {
  12614. SystemInitial = AC_QUANTITY;
  12615. }
  12616. }
  12617. }
  12618. int GetHeartBeatWithNOResponse(void)
  12619. {
  12620. return HeartBeatWithNOResponse;
  12621. }
  12622. void SetHeartBeatWithNOResponse(void)
  12623. {
  12624. HeartBeatWithNOResponse = 0;
  12625. }
  12626. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12627. /*
  12628. src 源字串的首地址(buf的地址)
  12629. separator 指定的分割字元
  12630. dest 接收子字串的陣列
  12631. num 分割後子字串的個數
  12632. */
  12633. char *pNext;
  12634. int count = 0;
  12635. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12636. return;
  12637. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12638. return;
  12639. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12640. while(pNext != NULL) {
  12641. *dest++ = pNext;
  12642. ++count;
  12643. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12644. }
  12645. *num = count;
  12646. }
  12647. int GetTransactionId(int gunindex, unsigned char idTag[])
  12648. {
  12649. char ch;
  12650. FILE *fptr1;
  12651. int temptransactionId;
  12652. char str[100]={0};
  12653. temptransactionId = 0;
  12654. /*------ Read the file ----------------*/
  12655. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12656. ch=fgetc(fptr1);
  12657. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12658. rewind(fptr1);
  12659. if(ch!=EOF)
  12660. {
  12661. // printf("%c",ch);
  12662. while (fgets(str, 100, fptr1) != NULL)
  12663. {
  12664. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12665. if(str[0]=='\0')
  12666. {
  12667. break;
  12668. }
  12669. char *revbuf[8] = {0}; //存放分割後的子字串
  12670. int num = 0;//分割後子字串的個數
  12671. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12672. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12673. {
  12674. temptransactionId = atoi(revbuf[2]);
  12675. break;
  12676. }
  12677. }
  12678. }
  12679. fclose(fptr1);
  12680. /*------- End of reading ---------------*/
  12681. return temptransactionId;
  12682. }
  12683. void SetTransactionIdZero(int transactionId)
  12684. {
  12685. //TransactionId[gunindex] = 0;
  12686. char ch;
  12687. FILE *fptr1, *fptr2;
  12688. int temptransactionId;
  12689. char str[100]={0}, temp[] = "/Storage/OCPP/temp.txt";
  12690. printf("\n\n Delete a specific line from a file :\n");
  12691. printf("-----------------------------------------\n");
  12692. //scanf("%s",fname);
  12693. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12694. if (!fptr1)
  12695. {
  12696. printf(" File not found or unable to open the input file!!\n");
  12697. return ;
  12698. }
  12699. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12700. if (!fptr2)
  12701. {
  12702. printf("Unable to open a temporary file to write!!\n");
  12703. fclose(fptr1);
  12704. return ;
  12705. }
  12706. ch=fgetc(fptr1);
  12707. //printf(" Now the content of the file %s is : \n",fname);
  12708. rewind(fptr1);
  12709. if(ch!=EOF)
  12710. {
  12711. // copy all contents to the temporary file except the specific line
  12712. while (fgets(str, 100, fptr1) != NULL)
  12713. {
  12714. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12715. if(str[0]=='\0')
  12716. {
  12717. break;
  12718. }
  12719. char *revbuf[8] = {0}; //存放分割後的子字串
  12720. int num = 0;//分割後子字串的個數
  12721. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12722. temptransactionId = atoi(revbuf[2]);
  12723. if(transactionId != temptransactionId)
  12724. {
  12725. fprintf(fptr2, "%s", str);
  12726. }
  12727. }
  12728. }
  12729. fclose(fptr1);
  12730. fclose(fptr2);
  12731. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12732. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12733. /*------ Read the file ----------------*/
  12734. }
  12735. int InternetDisconnect(void)
  12736. {
  12737. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12738. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12739. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12740. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12741. }
  12742. void GetChargingProfileRequest(int gunindex)
  12743. {
  12744. mtrace();
  12745. //int connectorIdInt, durationInt;
  12746. //char chargingRateUnitStr[4]={0};
  12747. int tempdurationInt = 0;
  12748. int tempchargingProfileId = 0;
  12749. int tempstackLevel = 0;
  12750. int temptransactionId = 0;
  12751. float tempminChargingRateFloat = 0.0;
  12752. char tempchargingProfilePurposeStr[24]={0};
  12753. char tempchargingProfileKindStr[12]={0};
  12754. char temprecurrencyKindStr[8]={0};
  12755. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12756. char tempvalidToStr[28]={0};
  12757. int tempStartPeriodInt = 0;
  12758. float tempLimitInt = 0.0;//0.1;
  12759. int tempNumberPhasesInt=0;
  12760. char fname[200];
  12761. //char comfirmstr[20];
  12762. float MinChargingRate =0.0;
  12763. double diff_t;
  12764. struct tm tp;
  12765. FILE *fptr1;//, *fptr2;
  12766. int c = 0;
  12767. char * pch;
  12768. char *loc;
  12769. char sstr[200]={ 0 };
  12770. int n_chargingProfile = 0;
  12771. int n_SchedulePeriods = 0;
  12772. char SchedulePeriodList[10][200]={0};
  12773. char sLineWord[1600]={0};
  12774. char word[1000]={0};
  12775. int confirmPeriods = 0;
  12776. struct StructProfile ChargePointMaxProfile;
  12777. struct StructProfile TxDefaultProfile;
  12778. struct StructProfile TxProfile;
  12779. struct StructProfile TxDefaultProfiletemp[2]={0};
  12780. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12781. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12782. struct StructChargingProfile TxProfile_TEMP={0};
  12783. int TxDefaultProfileFileIsNull=FALSE;
  12784. int ChargePointMaxProfileIsNull=FALSE;
  12785. int TxProfileIsNull=FALSE;
  12786. // int CompositeSceduleIndex = 0;
  12787. char ChargePointMaxProfileScheduleStr[30]={0};
  12788. char TxDefaultProfileScheduleStr[30]={0};
  12789. char TxProfileScheduleStr[30]={0};
  12790. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12791. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12792. memset(&TxProfile,0,sizeof(struct StructProfile));
  12793. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12794. DEBUG_INFO("GetChargingProfileRequest\n");
  12795. //*****************************ChargePointMaxProfile******************************************/
  12796. strcpy(fname, ChargePointMaxProfile_JSON);
  12797. ChargePointMaxProfileIsNull=TRUE;
  12798. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12799. {
  12800. fptr1 = fopen(fname, "r");
  12801. int c;
  12802. c = fgetc(fptr1);
  12803. //DEBUG_INFO("c:%d\n",c);
  12804. rewind(fptr1);
  12805. if(c == EOF)
  12806. {
  12807. DEBUG_INFO("\n End of file reached.");
  12808. ChargePointMaxProfileIsNull=TRUE;
  12809. fclose(fptr1);
  12810. }
  12811. else
  12812. {
  12813. ChargePointMaxProfileIsNull=FALSE;
  12814. while(fscanf(fptr1, "%s", word) != EOF)
  12815. {
  12816. if(strcmp(word, "chargingProfileId") == 0)
  12817. {
  12818. n_chargingProfile = n_chargingProfile + 1;
  12819. }
  12820. }
  12821. rewind(fptr1);
  12822. //search Charging Profile Element
  12823. int i = 0;
  12824. int j = 0;
  12825. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12826. //***********chargingProfileId**************/
  12827. c = 0;
  12828. loc = strstr(sLineWord, "chargingProfileId");
  12829. //DEBUG_INFO("loc=%s\n",loc);
  12830. memset(sstr ,0, sizeof(sstr) );
  12831. if(loc != NULL)
  12832. {
  12833. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12834. {
  12835. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12836. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12837. c++;
  12838. }
  12839. sstr[c] = '\0';
  12840. tempchargingProfileId = atoi(sstr);
  12841. }
  12842. else
  12843. {
  12844. tempchargingProfileId = 0;
  12845. }
  12846. //***********stackLevel**************/
  12847. c = 0;
  12848. loc = strstr(sLineWord, "stackLevel");
  12849. //DEBUG_INFO("loc=%s\n",loc);
  12850. memset(sstr ,0, sizeof(sstr) );
  12851. if(loc != NULL)
  12852. {
  12853. while (loc[2+strlen("stackLevel")+c] != '\"')
  12854. {
  12855. sstr[c] = loc[2+strlen("stackLevel")+c];
  12856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12857. c++;
  12858. }
  12859. sstr[c] = '\0';
  12860. tempstackLevel = atoi(sstr);
  12861. }
  12862. else
  12863. {
  12864. tempstackLevel = 0;
  12865. }
  12866. //***********chargingProfilePurpose **************/
  12867. c = 0;
  12868. loc = strstr(sLineWord, "chargingProfilePurpose");
  12869. //DEBUG_INFO("loc=%s\n",loc);
  12870. memset(sstr ,0, sizeof(sstr) );
  12871. if(loc != NULL)
  12872. {
  12873. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12874. {
  12875. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12876. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12877. c++;
  12878. }
  12879. sstr[c] = '\0';
  12880. strcpy(tempchargingProfilePurposeStr,sstr);
  12881. }
  12882. else
  12883. {
  12884. strcpy(tempchargingProfilePurposeStr,"");
  12885. }
  12886. //***********chargingProfileKind **************/
  12887. c = 0;
  12888. loc = strstr(sLineWord, "chargingProfileKind");
  12889. //DEBUG_INFO("loc=%s\n",loc);
  12890. memset(sstr ,0, sizeof(sstr) );
  12891. if(loc != NULL)
  12892. {
  12893. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12894. {
  12895. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12896. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12897. c++;
  12898. }
  12899. sstr[c] = '\0';
  12900. strcpy(tempchargingProfileKindStr,sstr);
  12901. }
  12902. else
  12903. {
  12904. strcpy(tempchargingProfileKindStr,"");
  12905. }
  12906. //***********recurrencyKind **************/
  12907. c = 0;
  12908. loc = strstr(sLineWord, "recurrencyKind");
  12909. //DEBUG_INFO("loc=%s\n",loc);
  12910. memset(sstr ,0, sizeof(sstr) );
  12911. if(loc != NULL)
  12912. {
  12913. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12914. {
  12915. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12916. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12917. c++;
  12918. }
  12919. sstr[c] = '\0';
  12920. strcpy(temprecurrencyKindStr,sstr);
  12921. }
  12922. else
  12923. {
  12924. strcpy(temprecurrencyKindStr,"");
  12925. }
  12926. //***********validFrom**************/
  12927. c = 0;
  12928. loc = strstr(sLineWord, "validFrom");
  12929. //DEBUG_INFO("loc=%s\n",loc);
  12930. memset(sstr ,0, sizeof(sstr) );
  12931. if(loc != NULL)
  12932. {
  12933. while (loc[3+strlen("validFrom")+c] != '\"')
  12934. {
  12935. sstr[c] = loc[3+strlen("validFrom")+c];
  12936. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12937. c++;
  12938. }
  12939. sstr[c] = '\0';
  12940. strcpy(tempvalidFromStr,sstr);
  12941. }
  12942. else
  12943. {
  12944. strcpy(tempvalidFromStr,"");
  12945. }
  12946. //***********validTo **************/
  12947. c = 0;
  12948. loc = strstr(sLineWord, "validTo");
  12949. //DEBUG_INFO("loc=%s\n",loc);
  12950. memset(sstr ,0, sizeof(sstr) );
  12951. if(loc != NULL)
  12952. {
  12953. while (loc[3+strlen("validTo")+c] != '\"')
  12954. {
  12955. sstr[c] = loc[3+strlen("validTo")+c];
  12956. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12957. c++;
  12958. }
  12959. sstr[c] = '\0';
  12960. strcpy(tempvalidToStr,sstr);
  12961. }
  12962. else
  12963. {
  12964. strcpy(tempvalidToStr,"");
  12965. }
  12966. //***********validFrom**************/
  12967. c = 0;
  12968. loc = strstr(sLineWord, "validFrom");
  12969. if(loc != NULL)
  12970. {
  12971. memset(sstr ,0, sizeof(sstr) );
  12972. while (loc[3+strlen("validFrom")+c] != '\"')
  12973. {
  12974. sstr[c] = loc[3+strlen("validFrom")+c];
  12975. c++;
  12976. }
  12977. sstr[c] = '\0';
  12978. strcpy(tempvalidFromStr,sstr);
  12979. }
  12980. else
  12981. {
  12982. strcpy(tempvalidFromStr,"");
  12983. }
  12984. //***********validTo **************/
  12985. c = 0;
  12986. loc = strstr(sLineWord, "validTo");
  12987. if(loc != NULL)
  12988. {
  12989. memset(sstr ,0, sizeof(sstr) );
  12990. while (loc[3+strlen("validTo")+c] != '\"')
  12991. {
  12992. sstr[c] = loc[3+strlen("validTo")+c];
  12993. c++;
  12994. }
  12995. sstr[c] = '\0';
  12996. strcpy(tempvalidToStr,sstr);
  12997. }
  12998. else
  12999. {
  13000. strcpy(tempvalidToStr,"");
  13001. }
  13002. //***********duration**************/
  13003. c = 0;
  13004. loc = strstr(sLineWord, "duration");
  13005. if(loc != NULL)
  13006. {
  13007. memset(sstr ,0, sizeof(sstr) );
  13008. while (loc[2+strlen("duration")+c] != ',')
  13009. {
  13010. sstr[c] = loc[2+strlen("duration")+c];
  13011. c++;
  13012. }
  13013. sstr[c] = '\0';
  13014. tempdurationInt = atoi(sstr);
  13015. }
  13016. else
  13017. {
  13018. tempdurationInt = 0;
  13019. }
  13020. //**********startSchedule**********/
  13021. c = 0;
  13022. loc = strstr(sLineWord, "startSchedule");
  13023. memset(sstr ,0, sizeof(sstr) );
  13024. while (loc[3+strlen("startSchedule")+c] != '\"')
  13025. {
  13026. sstr[c] = loc[3+strlen("startSchedule")+c];
  13027. c++;
  13028. }
  13029. sstr[c] = '\0';
  13030. strcpy(tempstartScheduleStr, sstr);
  13031. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13032. //**********chargingRateUnit**********/
  13033. c = 0;
  13034. loc = strstr(sLineWord, "chargingRateUnit");
  13035. memset(sstr ,0, sizeof(sstr) );
  13036. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13037. {
  13038. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13039. c++;
  13040. }
  13041. sstr[c] = '\0';
  13042. strcpy(tempchargingRateUnitStr, sstr);
  13043. //**********minChargingRate*******/
  13044. c = 0;
  13045. loc = strstr(sLineWord, "minChargingRate");
  13046. if(loc != NULL)
  13047. {
  13048. memset(sstr ,0, sizeof(sstr) );
  13049. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13050. {
  13051. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13052. c++;
  13053. }
  13054. sstr[c] = '\0';
  13055. tempminChargingRateFloat = atof(sstr);
  13056. }
  13057. else
  13058. {
  13059. tempminChargingRateFloat = 0.0;
  13060. }
  13061. //
  13062. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13063. tp.tm_isdst = -1;
  13064. time_t utc = mktime(&tp);
  13065. time_t t = time(NULL);
  13066. diff_t = difftime(t, utc);
  13067. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13068. //parsing strings to words
  13069. i = 0;
  13070. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13071. loc = loc+3+strlen("chargingSchedulePeriod");
  13072. pch = strtok(loc ,"{");
  13073. while (pch != NULL)
  13074. {
  13075. strcpy(SchedulePeriodList[i], pch);
  13076. pch = strtok (NULL, "{");
  13077. i = i + 1;
  13078. }
  13079. n_SchedulePeriods = i;
  13080. for(int i=0;i<n_SchedulePeriods;i++)
  13081. {
  13082. //*************startPeriod****************/
  13083. c = 0;
  13084. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13085. memset(sstr ,0, sizeof(sstr) );
  13086. while (loc[strlen("startPeriod")+2+c] != ',')
  13087. {
  13088. sstr[c] = loc[strlen("startPeriod")+2+c];
  13089. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13090. c++;
  13091. }
  13092. sstr[c] = '\0';
  13093. tempStartPeriodInt = atoi(sstr);
  13094. //*************limit****************/
  13095. c = 0;
  13096. loc = strstr(SchedulePeriodList[i], "limit");
  13097. memset(sstr ,0, sizeof(sstr) );
  13098. while (loc[strlen("limit")+2+c] != ',')
  13099. {
  13100. sstr[c] = loc[strlen("limit")+2+c];
  13101. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13102. c++;
  13103. }
  13104. sstr[c] = '\0';
  13105. tempLimitInt = atof(sstr);
  13106. //*************numberPhases****************/
  13107. c = 0;
  13108. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13109. memset(sstr ,0, sizeof(sstr) );
  13110. while (loc[strlen("numberPhases")+2+c] != '}')
  13111. {
  13112. sstr[c] = loc[strlen("numberPhases")+2+c];
  13113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13114. c++;
  13115. }
  13116. sstr[c] = '\0';
  13117. tempNumberPhasesInt = atoi(sstr);
  13118. if(j == 0)
  13119. {
  13120. ChargePointMaxProfile.Duration = tempdurationInt;
  13121. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13122. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13123. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13124. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13125. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13126. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13127. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13128. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13129. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13130. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13131. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13132. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13133. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13134. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13135. }
  13136. }
  13137. if(MinChargingRate < tempminChargingRateFloat)
  13138. {
  13139. MinChargingRate = tempminChargingRateFloat;
  13140. }
  13141. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13142. if(confirmPeriods < n_SchedulePeriods)
  13143. {
  13144. confirmPeriods = n_SchedulePeriods;
  13145. }
  13146. j = j + 1;
  13147. }
  13148. fclose(fptr1);
  13149. }
  13150. }// the end of access file ChargePointMaxProfile
  13151. //****************************TxDefaultProfile************************************************/
  13152. #if 0
  13153. switch(gunindex + 1)
  13154. {
  13155. case 0:
  13156. strcpy(fname, TxDefaultProfile_0_JSON );
  13157. break;
  13158. case 1:
  13159. strcpy(fname, TxDefaultProfile_1_JSON );
  13160. break;
  13161. case 2:
  13162. strcpy(fname, TxDefaultProfile_2_JSON );
  13163. break;
  13164. default:
  13165. strcpy(fname, TxDefaultProfile_1_JSON );
  13166. break;
  13167. }
  13168. #endif
  13169. memset(fname, 0, sizeof fname);
  13170. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13171. TxDefaultProfileFileIsNull=TRUE;
  13172. if((access(fname,F_OK))!=-1)
  13173. {
  13174. fptr1 = fopen(fname, "r");
  13175. c = 0;
  13176. c = fgetc(fptr1);
  13177. //DEBUG_INFO("c:%d\n",c);
  13178. rewind(fptr1);
  13179. if(c == EOF)
  13180. {
  13181. DEBUG_INFO("\n End of file reached.");
  13182. TxDefaultProfileFileIsNull=TRUE;
  13183. fclose(fptr1);
  13184. }
  13185. else
  13186. {
  13187. TxDefaultProfileFileIsNull=FALSE;
  13188. while(fscanf(fptr1, "%s", word) != EOF)
  13189. {
  13190. if(strcmp(word, "chargingProfileId") == 0)
  13191. {
  13192. n_chargingProfile = n_chargingProfile + 1;
  13193. }
  13194. }
  13195. rewind(fptr1);
  13196. //search Charging Profile Element
  13197. int i = 0;
  13198. int j = 0;
  13199. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13200. #if 0
  13201. /***********connectorId****************/
  13202. c = 0;
  13203. loc = strstr(sLineWord, "connectorId");
  13204. memset(sstr ,0, sizeof(sstr) );
  13205. while (loc[strlen("connectorId")+2+c] != ',')
  13206. {
  13207. sstr[c] = loc[strlen("connectorId")+2+c];
  13208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13209. c++;
  13210. }
  13211. sstr[c] = '\0';
  13212. tempconnectorIdInt = atoi(sstr);
  13213. #endif
  13214. //***********chargingProfileId**************/
  13215. c = 0;
  13216. loc = strstr(sLineWord, "chargingProfileId");
  13217. //DEBUG_INFO("loc=%s\n",loc);
  13218. memset(sstr ,0, sizeof(sstr) );
  13219. if(loc != NULL)
  13220. {
  13221. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13222. {
  13223. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13224. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13225. c++;
  13226. }
  13227. sstr[c] = '\0';
  13228. tempchargingProfileId = atoi(sstr);
  13229. }
  13230. else
  13231. {
  13232. tempchargingProfileId = 0;
  13233. }
  13234. //***********stackLevel**************/
  13235. c = 0;
  13236. loc = strstr(sLineWord, "stackLevel");
  13237. //DEBUG_INFO("loc=%s\n",loc);
  13238. memset(sstr ,0, sizeof(sstr) );
  13239. if(loc != NULL)
  13240. {
  13241. while (loc[2+strlen("stackLevel")+c] != '\"')
  13242. {
  13243. sstr[c] = loc[2+strlen("stackLevel")+c];
  13244. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13245. c++;
  13246. }
  13247. sstr[c] = '\0';
  13248. tempstackLevel = atoi(sstr);
  13249. }
  13250. else
  13251. {
  13252. tempstackLevel = 0;
  13253. }
  13254. //***********chargingProfilePurpose **************/
  13255. c = 0;
  13256. loc = strstr(sLineWord, "chargingProfilePurpose");
  13257. //DEBUG_INFO("loc=%s\n",loc);
  13258. memset(sstr ,0, sizeof(sstr) );
  13259. if(loc != NULL)
  13260. {
  13261. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13262. {
  13263. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13265. c++;
  13266. }
  13267. sstr[c] = '\0';
  13268. strcpy(tempchargingProfilePurposeStr,sstr);
  13269. }
  13270. else
  13271. {
  13272. strcpy(tempchargingProfilePurposeStr,"");
  13273. }
  13274. //***********chargingProfileKind **************/
  13275. c = 0;
  13276. loc = strstr(sLineWord, "chargingProfileKind");
  13277. //DEBUG_INFO("loc=%s\n",loc);
  13278. memset(sstr ,0, sizeof(sstr) );
  13279. if(loc != NULL)
  13280. {
  13281. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13282. {
  13283. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13284. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13285. c++;
  13286. }
  13287. sstr[c] = '\0';
  13288. strcpy(tempchargingProfileKindStr,sstr);
  13289. }
  13290. else
  13291. {
  13292. strcpy(tempchargingProfileKindStr,"");
  13293. }
  13294. //***********recurrencyKind **************/
  13295. c = 0;
  13296. loc = strstr(sLineWord, "recurrencyKind");
  13297. //DEBUG_INFO("loc=%s\n",loc);
  13298. memset(sstr ,0, sizeof(sstr) );
  13299. if(loc != NULL)
  13300. {
  13301. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13302. {
  13303. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13304. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13305. c++;
  13306. }
  13307. sstr[c] = '\0';
  13308. strcpy(temprecurrencyKindStr,sstr);
  13309. }
  13310. else
  13311. {
  13312. strcpy(temprecurrencyKindStr,"");
  13313. }
  13314. //***********validFrom**************/
  13315. c = 0;
  13316. loc = strstr(sLineWord, "validFrom");
  13317. if(loc != NULL)
  13318. {
  13319. memset(sstr ,0, sizeof(sstr) );
  13320. while (loc[3+strlen("validFrom")+c] != '\"')
  13321. {
  13322. sstr[c] = loc[3+strlen("validFrom")+c];
  13323. c++;
  13324. }
  13325. sstr[c] = '\0';
  13326. strcpy(tempvalidFromStr,sstr);
  13327. }
  13328. else
  13329. {
  13330. strcpy(tempvalidFromStr,"");
  13331. }
  13332. //***********validTo **************/
  13333. c = 0;
  13334. loc = strstr(sLineWord, "validTo");
  13335. if(loc != NULL)
  13336. {
  13337. memset(sstr ,0, sizeof(sstr) );
  13338. while (loc[3+strlen("validTo")+c] != '\"')
  13339. {
  13340. sstr[c] = loc[3+strlen("validTo")+c];
  13341. c++;
  13342. }
  13343. sstr[c] = '\0';
  13344. strcpy(tempvalidToStr,sstr);
  13345. }
  13346. else
  13347. {
  13348. strcpy(tempvalidToStr,"");
  13349. }
  13350. //***********duration**************/
  13351. c = 0;
  13352. loc = strstr(sLineWord, "duration");
  13353. if(loc != NULL)
  13354. {
  13355. memset(sstr ,0, sizeof(sstr) );
  13356. while (loc[2+strlen("duration")+c] != ',')
  13357. {
  13358. sstr[c] = loc[2+strlen("duration")+c];
  13359. c++;
  13360. }
  13361. sstr[c] = '\0';
  13362. tempdurationInt = atoi(sstr);
  13363. }
  13364. else
  13365. {
  13366. tempdurationInt = 0;
  13367. }
  13368. //**********startSchedule**********/
  13369. c = 0;
  13370. loc = strstr(sLineWord, "startSchedule");
  13371. memset(sstr ,0, sizeof(sstr) );
  13372. while (loc[3+strlen("startSchedule")+c] != '\"')
  13373. {
  13374. sstr[c] = loc[3+strlen("startSchedule")+c];
  13375. c++;
  13376. }
  13377. sstr[c] = '\0';
  13378. strcpy(tempstartScheduleStr, sstr);
  13379. strcpy(TxDefaultProfileScheduleStr, sstr);
  13380. //**********chargingRateUnit**********/
  13381. c = 0;
  13382. loc = strstr(sLineWord, "chargingRateUnit");
  13383. memset(sstr ,0, sizeof(sstr) );
  13384. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13385. {
  13386. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13387. c++;
  13388. }
  13389. sstr[c] = '\0';
  13390. strcpy(tempchargingRateUnitStr, sstr);
  13391. //**********minChargingRate*******/
  13392. c = 0;
  13393. loc = strstr(sLineWord, "minChargingRate");
  13394. if(loc != NULL)
  13395. {
  13396. memset(sstr ,0, sizeof(sstr) );
  13397. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13398. {
  13399. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13400. c++;
  13401. }
  13402. sstr[c] = '\0';
  13403. tempminChargingRateFloat = atof(sstr);
  13404. }
  13405. else
  13406. {
  13407. tempminChargingRateFloat = 0.0;
  13408. }
  13409. //
  13410. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13411. tp.tm_isdst = -1;
  13412. time_t utc = mktime(&tp);
  13413. time_t t = time(NULL);
  13414. diff_t = difftime(t, utc);
  13415. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13416. //parsing strings to words
  13417. i = 0;
  13418. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13419. loc = loc+3+strlen("chargingSchedulePeriod");
  13420. pch = strtok(loc ,"{");
  13421. while (pch != NULL)
  13422. {
  13423. strcpy(SchedulePeriodList[i], pch);
  13424. pch = strtok (NULL, "{");
  13425. i = i + 1;
  13426. }
  13427. n_SchedulePeriods = i;
  13428. for(int i=0;i<n_SchedulePeriods;i++)
  13429. {
  13430. //*************startPeriod****************/
  13431. c = 0;
  13432. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13433. memset(sstr ,0, sizeof(sstr) );
  13434. while (loc[strlen("startPeriod")+2+c] != ',')
  13435. {
  13436. sstr[c] = loc[strlen("startPeriod")+2+c];
  13437. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13438. c++;
  13439. }
  13440. sstr[c] = '\0';
  13441. tempStartPeriodInt = atoi(sstr);
  13442. //*************limit****************/
  13443. c = 0;
  13444. loc = strstr(SchedulePeriodList[i], "limit");
  13445. memset(sstr ,0, sizeof(sstr) );
  13446. while (loc[strlen("limit")+2+c] != ',')
  13447. {
  13448. sstr[c] = loc[strlen("limit")+2+c];
  13449. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13450. c++;
  13451. }
  13452. sstr[c] = '\0';
  13453. tempLimitInt = atof(sstr);
  13454. //*************numberPhases****************/
  13455. c = 0;
  13456. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13457. memset(sstr ,0, sizeof(sstr) );
  13458. while (loc[strlen("numberPhases")+2+c] != '}')
  13459. {
  13460. sstr[c] = loc[strlen("numberPhases")+2+c];
  13461. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13462. c++;
  13463. }
  13464. sstr[c] = '\0';
  13465. tempNumberPhasesInt = atoi(sstr);
  13466. if(j == 0)
  13467. {
  13468. TxDefaultProfile.Duration = tempdurationInt;
  13469. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13470. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13471. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13472. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13473. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13474. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13475. TxDefaultProfile_TEMP.TransactionId = 0;
  13476. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13477. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13478. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13479. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13480. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13481. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13482. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13483. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13484. }
  13485. else
  13486. {
  13487. //other stack level charging Profile
  13488. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13489. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13490. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13491. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13492. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13493. }
  13494. }
  13495. if(MinChargingRate < tempminChargingRateFloat)
  13496. {
  13497. MinChargingRate = tempminChargingRateFloat;
  13498. }
  13499. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13500. if(confirmPeriods < n_SchedulePeriods)
  13501. confirmPeriods = n_SchedulePeriods;
  13502. j = j + 1;
  13503. }
  13504. fclose(fptr1);
  13505. //Stacking Charging Profiles
  13506. for(int l=0; l <(j-1) ;l++)
  13507. {
  13508. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13509. {
  13510. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13511. {
  13512. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13513. {
  13514. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13515. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13516. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13517. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13518. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13519. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13520. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13521. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13522. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13523. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13524. }
  13525. else
  13526. {
  13527. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13528. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13529. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13530. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13531. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13532. }
  13533. }
  13534. }
  13535. }
  13536. //end of Stacking Charging Profiles
  13537. }
  13538. }// the end of ACCESS TxDefaultProfile
  13539. //****************************TxProfile************************************************/
  13540. #if 0
  13541. switch(gunindex + 1)
  13542. {
  13543. case 0:
  13544. break;
  13545. case 1:
  13546. strcpy(fname, TxProfile_1_JSON );
  13547. break;
  13548. case 2:
  13549. strcpy(fname, TxProfile_2_JSON );
  13550. break;
  13551. default:
  13552. strcpy(fname, TxProfile_1_JSON );
  13553. break;
  13554. }
  13555. #endif
  13556. memset(fname, 0, sizeof fname);
  13557. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13558. TxProfileIsNull=TRUE;
  13559. if((access(fname,F_OK))!=-1)
  13560. {
  13561. fptr1 = fopen(fname, "r");
  13562. c = 0;
  13563. c = fgetc(fptr1);
  13564. //DEBUG_INFO("c:%d\n",c);
  13565. rewind(fptr1);
  13566. if(c == EOF)
  13567. {
  13568. DEBUG_INFO("\n End of file reached.");
  13569. TxProfileIsNull=TRUE;
  13570. fclose(fptr1);
  13571. }
  13572. else
  13573. {
  13574. TxProfileIsNull=FALSE;
  13575. while(fscanf(fptr1, "%s", word) != EOF)
  13576. {
  13577. if(strcmp(word, "chargingProfileId") == 0)
  13578. {
  13579. n_chargingProfile = n_chargingProfile + 1;
  13580. }
  13581. }
  13582. rewind(fptr1);
  13583. //search Charging Profile Element
  13584. int i= 0;
  13585. int j= 0;
  13586. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13587. #if 0
  13588. /***********connectorId****************/
  13589. c = 0;
  13590. loc = strstr(sLineWord, "connectorId");
  13591. memset(sstr ,0, sizeof(sstr) );
  13592. while (loc[strlen("connectorId")+2+c] != ',')
  13593. {
  13594. sstr[c] = loc[strlen("connectorId")+2+c];
  13595. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13596. c++;
  13597. }
  13598. sstr[c] = '\0';
  13599. tempconnectorIdInt = atoi(sstr);
  13600. #endif
  13601. //***********chargingProfileId**************/
  13602. c = 0;
  13603. loc = strstr(sLineWord, "chargingProfileId");
  13604. memset(sstr ,0, sizeof(sstr) );
  13605. if(loc != NULL)
  13606. {
  13607. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13608. {
  13609. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13610. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13611. c++;
  13612. }
  13613. sstr[c] = '\0';
  13614. tempchargingProfileId = atoi(sstr);
  13615. }
  13616. else
  13617. {
  13618. tempchargingProfileId = 0;
  13619. }
  13620. //***********transactionId **************/
  13621. c = 0;
  13622. loc = strstr(sLineWord, "transactionId");
  13623. //DEBUG_INFO("loc=%s\n",loc);
  13624. memset(sstr ,0, sizeof(sstr) );
  13625. if(loc != NULL)
  13626. {
  13627. while (loc[2+strlen("transactionId")+c] != '\"')
  13628. {
  13629. sstr[c] = loc[2+strlen("transactionId")+c];
  13630. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13631. c++;
  13632. }
  13633. sstr[c] = '\0';
  13634. temptransactionId = atoi(sstr);
  13635. }
  13636. else
  13637. {
  13638. temptransactionId = 0;
  13639. }
  13640. //***********stackLevel**************/
  13641. c = 0;
  13642. loc = strstr(sLineWord, "stackLevel");
  13643. //DEBUG_INFO("loc=%s\n",loc);
  13644. memset(sstr ,0, sizeof(sstr) );
  13645. if(loc != NULL)
  13646. {
  13647. while (loc[2+strlen("stackLevel")+c] != '\"')
  13648. {
  13649. sstr[c] = loc[2+strlen("stackLevel")+c];
  13650. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13651. c++;
  13652. }
  13653. sstr[c] = '\0';
  13654. tempstackLevel = atoi(sstr);
  13655. }
  13656. else
  13657. {
  13658. tempstackLevel = 0;
  13659. }
  13660. //***********chargingProfilePurpose **************/
  13661. c = 0;
  13662. loc = strstr(sLineWord, "chargingProfilePurpose");
  13663. //DEBUG_INFO("loc=%s\n",loc);
  13664. memset(sstr ,0, sizeof(sstr) );
  13665. if(loc != NULL)
  13666. {
  13667. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13668. {
  13669. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13670. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13671. c++;
  13672. }
  13673. sstr[c] = '\0';
  13674. strcpy(tempchargingProfilePurposeStr,sstr);
  13675. }
  13676. else
  13677. {
  13678. strcpy(tempchargingProfilePurposeStr,"");
  13679. }
  13680. //***********chargingProfileKind **************/
  13681. c = 0;
  13682. loc = strstr(sLineWord, "chargingProfileKind");
  13683. //DEBUG_INFO("loc=%s\n",loc);
  13684. memset(sstr ,0, sizeof(sstr) );
  13685. if(loc != NULL)
  13686. {
  13687. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13688. {
  13689. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13690. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13691. c++;
  13692. }
  13693. sstr[c] = '\0';
  13694. strcpy(tempchargingProfileKindStr,sstr);
  13695. }
  13696. else
  13697. {
  13698. strcpy(tempchargingProfileKindStr,"");
  13699. }
  13700. //***********recurrencyKind **************/
  13701. c = 0;
  13702. loc = strstr(sLineWord, "recurrencyKind");
  13703. //DEBUG_INFO("loc=%s\n",loc);
  13704. memset(sstr ,0, sizeof(sstr) );
  13705. if(loc != NULL)
  13706. {
  13707. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13708. {
  13709. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13710. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13711. c++;
  13712. }
  13713. sstr[c] = '\0';
  13714. strcpy(temprecurrencyKindStr,sstr);
  13715. }
  13716. else
  13717. {
  13718. strcpy(temprecurrencyKindStr,"");
  13719. }
  13720. //***********validFrom**************/
  13721. c = 0;
  13722. loc = strstr(sLineWord, "validFrom");
  13723. if(loc != NULL)
  13724. {
  13725. memset(sstr ,0, sizeof(sstr) );
  13726. while (loc[3+strlen("validFrom")+c] != '\"')
  13727. {
  13728. sstr[c] = loc[3+strlen("validFrom")+c];
  13729. c++;
  13730. }
  13731. sstr[c] = '\0';
  13732. strcpy(tempvalidFromStr,sstr);
  13733. }
  13734. else
  13735. {
  13736. strcpy(tempvalidFromStr,"");
  13737. }
  13738. //***********validTo**************/
  13739. c = 0;
  13740. loc = strstr(sLineWord, "validTo");
  13741. if(loc != NULL)
  13742. {
  13743. memset(sstr ,0, sizeof(sstr) );
  13744. while (loc[3+strlen("validTo")+c] != '\"')
  13745. {
  13746. sstr[c] = loc[3+strlen("validTo")+c];
  13747. c++;
  13748. }
  13749. sstr[c] = '\0';
  13750. strcpy(tempvalidToStr,sstr);
  13751. }
  13752. else
  13753. {
  13754. strcpy(tempvalidToStr,"");
  13755. }
  13756. //***********duration**************/
  13757. c = 0;
  13758. loc = strstr(sLineWord, "duration");
  13759. //DEBUG_INFO("loc=%s\n",loc);
  13760. memset(sstr ,0, sizeof(sstr) );
  13761. if(loc != NULL)
  13762. {
  13763. while (loc[2+strlen("duration")+c] != '\"')
  13764. {
  13765. sstr[c] = loc[2+strlen("duration")+c];
  13766. c++;
  13767. }
  13768. sstr[c] = '\0';
  13769. tempdurationInt = atoi(sstr);
  13770. }
  13771. else
  13772. {
  13773. tempdurationInt = 0;
  13774. }
  13775. //**********startSchedule**********/
  13776. c = 0;
  13777. loc = strstr(sLineWord, "startSchedule");
  13778. memset(sstr ,0, sizeof(sstr) );
  13779. while (loc[3+strlen("startSchedule")+c] != '\"')
  13780. {
  13781. sstr[c] = loc[3+strlen("startSchedule")+c];
  13782. c++;
  13783. }
  13784. sstr[c] = '\0';
  13785. strcpy(tempstartScheduleStr, sstr);
  13786. strcpy(TxProfileScheduleStr, sstr);
  13787. //**********chargingRateUnit**********/
  13788. c = 0;
  13789. loc = strstr(sLineWord, "chargingRateUnit");
  13790. memset(sstr ,0, sizeof(sstr) );
  13791. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13792. {
  13793. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13794. c++;
  13795. }
  13796. sstr[c] = '\0';
  13797. strcpy(tempchargingRateUnitStr, sstr);
  13798. //**********minChargingRate*******/
  13799. c = 0;
  13800. loc = strstr(sLineWord, "minChargingRate");
  13801. if(loc != NULL)
  13802. {
  13803. memset(sstr ,0, sizeof(sstr) );
  13804. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13805. {
  13806. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13807. c++;
  13808. }
  13809. sstr[c] = '\0';
  13810. tempminChargingRateFloat = atof(sstr);
  13811. }
  13812. else
  13813. {
  13814. tempminChargingRateFloat = 0.0;
  13815. }
  13816. //
  13817. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13818. tp.tm_isdst = -1;
  13819. time_t utc = mktime(&tp);
  13820. time_t t = time(NULL);
  13821. diff_t = difftime(t, utc);
  13822. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13823. //parsing strings to words
  13824. i = 0;
  13825. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13826. loc = loc+3+strlen("chargingSchedulePeriod");
  13827. pch = strtok(loc ,"{");
  13828. while (pch != NULL)
  13829. {
  13830. strcpy(SchedulePeriodList[i], pch);
  13831. pch = strtok (NULL, "{");
  13832. i = i + 1;
  13833. }
  13834. n_SchedulePeriods = i;
  13835. for(int i=0;i<n_SchedulePeriods;i++)
  13836. {
  13837. //*************startPeriod****************/
  13838. c = 0;
  13839. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13840. memset(sstr ,0, sizeof(sstr) );
  13841. while (loc[strlen("startPeriod")+2+c] != ',')
  13842. {
  13843. sstr[c] = loc[strlen("startPeriod")+2+c];
  13844. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13845. c++;
  13846. }
  13847. sstr[c] = '\0';
  13848. tempStartPeriodInt = atoi(sstr);
  13849. //*************limit****************/
  13850. c = 0;
  13851. loc = strstr(SchedulePeriodList[i], "limit");
  13852. memset(sstr ,0, sizeof(sstr) );
  13853. while (loc[strlen("limit")+2+c] != ',')
  13854. {
  13855. sstr[c] = loc[strlen("limit")+2+c];
  13856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13857. c++;
  13858. }
  13859. sstr[c] = '\0';
  13860. tempLimitInt = atof(sstr);
  13861. //*************numberPhases****************/
  13862. c = 0;
  13863. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13864. memset(sstr ,0, sizeof(sstr) );
  13865. while (loc[strlen("numberPhases")+2+c] != '}')
  13866. {
  13867. sstr[c] = loc[strlen("numberPhases")+2+c];
  13868. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13869. c++;
  13870. }
  13871. sstr[c] = '\0';
  13872. tempNumberPhasesInt = atoi(sstr);
  13873. //TxProfile.Duration = durationInt;
  13874. TxProfile.TotalPeriod = n_SchedulePeriods;
  13875. TxProfile.Period[i].Limit = tempLimitInt;
  13876. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13877. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13878. }
  13879. if(MinChargingRate < tempminChargingRateFloat)
  13880. {
  13881. MinChargingRate = tempminChargingRateFloat;
  13882. }
  13883. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13884. if(confirmPeriods < n_SchedulePeriods)
  13885. confirmPeriods = n_SchedulePeriods;
  13886. if(j == 0)
  13887. {
  13888. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13889. TxProfile_TEMP.StackLevel = tempstackLevel;
  13890. TxProfile_TEMP.TransactionId = 0;
  13891. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13892. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13893. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13894. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13895. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13896. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13897. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13898. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13899. }
  13900. }
  13901. fclose(fptr1);
  13902. }
  13903. }// the end of ACCESS TxProfile
  13904. //CompositeSchedule
  13905. int period=0;
  13906. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13907. {
  13908. //TxProfile
  13909. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13910. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13911. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13912. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13913. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13914. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13915. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13916. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13917. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13918. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13919. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13920. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13921. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13922. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13923. {
  13924. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13925. {
  13926. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13927. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13928. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13929. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13930. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13931. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13932. period = period + 1;
  13933. }
  13934. else
  13935. {
  13936. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13937. {
  13938. }
  13939. else
  13940. {
  13941. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13942. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13943. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13944. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13945. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13946. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13947. period = period + 1;
  13948. }
  13949. }
  13950. }
  13951. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13952. {
  13953. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13954. {
  13955. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13956. {
  13957. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13958. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13959. }
  13960. else
  13961. {
  13962. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13963. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13964. }
  13965. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13966. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13967. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13968. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13969. period = period + 1;
  13970. }
  13971. }
  13972. }
  13973. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13974. {
  13975. //TxDefaultProfile
  13976. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13977. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13978. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13979. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13980. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13981. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13982. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13983. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13984. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13985. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13986. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13987. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13988. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13989. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13990. {
  13991. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13992. {
  13993. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13994. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13995. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13996. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13997. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13998. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13999. period = period + 1;
  14000. }
  14001. else
  14002. {
  14003. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14004. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14005. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14006. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14007. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14008. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14009. period = period + 1;
  14010. }
  14011. }
  14012. }
  14013. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14014. {
  14015. //TxDefaultProfile
  14016. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14017. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14018. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14019. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14020. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14021. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14022. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14023. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14024. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14025. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14026. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14027. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14028. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14029. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14030. {
  14031. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14032. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14033. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14034. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14035. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14036. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14037. period = period + 1;
  14038. }
  14039. }
  14040. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14041. {
  14042. //ChargePointMaxProfile
  14043. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14044. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14045. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14046. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14047. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14048. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14049. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14050. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14051. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14052. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14053. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14054. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14055. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14056. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  14057. {
  14058. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14059. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14060. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14061. period = period + 1;
  14062. }
  14063. }
  14064. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14065. {
  14066. //TxProfile
  14067. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14068. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14069. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14070. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14071. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14072. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14073. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14074. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14075. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14076. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14077. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14078. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14079. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14080. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14081. {
  14082. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  14083. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  14084. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  14085. }
  14086. }
  14087. confirmPeriods = period;
  14088. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14089. 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,"
  14090. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14091. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14092. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14093. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14094. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14095. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14096. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14097. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14098. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14099. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14100. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14101. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14102. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14103. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14104. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14105. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14106. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14107. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14108. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14109. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14110. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14111. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14112. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14113. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14114. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14115. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14116. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14117. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14118. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14119. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14120. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14121. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14122. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14123. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14124. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14125. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14126. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14127. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14128. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14129. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14130. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14131. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14132. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14133. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14134. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14135. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14136. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14137. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14138. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14139. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14140. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14141. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14142. }
  14143. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14144. {
  14145. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14146. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14147. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14148. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14149. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14150. }
  14151. int GetWebSocketPingInterval(void)
  14152. {
  14153. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14154. }
  14155. void LWS_Send(char * str)
  14156. {
  14157. //=====================================================
  14158. // Check InternetConn 0: disconnected, 1: connected
  14159. //====================================================
  14160. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14161. {
  14162. DEBUG_INFO("\n offline now !!!\n");
  14163. return;
  14164. }
  14165. pthread_mutex_lock(&lock);
  14166. memset(SendBuffer,0,SendBufLen);
  14167. sprintf((char *)SendBuffer, "%s", str);
  14168. pthread_mutex_unlock(&lock);
  14169. lws_callback_on_writable(wsi_client);
  14170. lws_service(context, 10000);//timeout_ms
  14171. }