MessageHandler.c 658 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000
  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 "define.h"
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <stdlib.h>
  24. /*for sendfile()*/
  25. #include <sys/sendfile.h>
  26. /*for O_RDONLY*/
  27. #include <fcntl.h>
  28. #include "sqlite3.h"
  29. #include <arpa/inet.h>
  30. #include <time.h>
  31. #include <assert.h>
  32. #include <pthread.h>
  33. #include <mcheck.h>
  34. #include "MessageHandler.h"
  35. #include "SystemLogMessage.h"
  36. #include "hashmap.h"
  37. #include "ShareMemory.h"
  38. #include "TransactionQueue.h"
  39. #define PASS 1
  40. #define FAIL -1
  41. #define FALSE 0
  42. #define TRUE 1 // Option 1
  43. //ChargePointMaxProfile
  44. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  45. //TxDefaultProfile
  46. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  47. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  48. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  49. //TxProfile
  50. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  51. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  52. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  53. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  54. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  55. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  56. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  57. //===================================
  58. // Define CP State constant
  59. //===================================
  60. #define CP_STATE_UNKNOWN 0
  61. #define CP_STATE_A 1
  62. #define CP_STATE_B 2
  63. #define CP_STATE_C 3
  64. #define CP_STATE_D 4
  65. #define CP_STATE_E 5
  66. #define CP_STATE_F 6
  67. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  68. struct StatusCodeData *ShmStatusCodeData;
  69. struct PsuData *ShmPsuData ;
  70. struct OCPP16Data *ShmOCPP16Data;
  71. // define Macro
  72. #define SystemLogMessage
  73. // OCPP Message Type
  74. #define MESSAGE_TYPE_CALL 2
  75. #define MESSAGE_TYPE_CALLRESULT 3
  76. #define MESSAGE_TYPE_CALLERROR 4
  77. //
  78. //#define server_cycle_Status 120
  79. #define MACROSTR(k) #k
  80. //ConfigurationMaxKeys
  81. #define GetConfigurationMaxKeysNUM 43
  82. //char guid[37];
  83. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  84. char queuedata[2600]={0};
  85. //=================================
  86. // StatusNotification cycle
  87. //=================================
  88. static int server_cycle_Status = 120;
  89. //===============================
  90. // Configuration: unknownkey
  91. //===============================
  92. static char unknownkey[10][20]={0};
  93. static int UnknownKeynum = 0;
  94. //===============================
  95. // Gun Total Numbers
  96. //===============================
  97. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  98. static int gunTotalNumber=0;
  99. //===============================
  100. // Local List Version
  101. //===============================
  102. static int localversion=0;
  103. static char idTagAuthorization[32]={0};
  104. //===============================
  105. // OCPP Path
  106. //===============================
  107. extern char OcppPath[160];
  108. extern char OcppProtocol[10];
  109. extern char OcppHost[50];
  110. extern char OcppTempPath[50];
  111. static int OcppPort=0;
  112. //===============================
  113. // OCPP sign variable
  114. //===============================
  115. static int server_sign = FALSE;
  116. int server_pending = FALSE;
  117. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  118. static int BootNotificationInterval = 0;
  119. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  120. //===============================
  121. // OCPP auth variable
  122. //===============================
  123. static int authorizeRetryTimes = 0; //number of Retry times
  124. //===============================
  125. // OCPP StartTransaction transactionId variables
  126. //===============================
  127. //static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  128. //===============================
  129. // OCPP other variables
  130. //===============================
  131. //int isUpdateRequest = FALSE;
  132. static int HeartBeatWaitTime = 10;
  133. static int FirstHeartBeat = 0;
  134. static int FirmwareStatusNotificationStatus = 3; // Idle
  135. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  136. static char CurrentChargingProfileScheduleStr[30]={0};
  137. //========================================
  138. // OCPP status/previous related variables
  139. //========================================
  140. static int GunStatusInterval = 10;
  141. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  142. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  143. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  144. static int GbPreviousSystemStatus[GB_QUANTITY];
  145. static int AcPreviousSystemStatus[AC_QUANTITY];
  146. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  147. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  148. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  149. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  150. static int TransactionMessageAttemptsValue = 0;
  151. static int TransactionMessageRetryIntervalValue = 0;
  152. static struct OCPPAuthLocalElemet
  153. {
  154. int listVersionInt;
  155. char idTagstr[20];
  156. char parentIdTag[20];
  157. char expiryDate[30];
  158. char idTagstatus[16];
  159. }idTagQuery;
  160. //=============================================
  161. // OCPP HeartBeat Response Not Receive Counts
  162. //============================================
  163. static int HeartBeatWithNOResponse = 0;
  164. static int HeartBeatCountPerHour = 0;
  165. extern struct lws *wsi_client;
  166. extern struct lws_context *context;
  167. extern unsigned char SendBuffer[4096];
  168. extern int SendBufLen;
  169. extern char *random_uuid( char buf[37] );
  170. extern void split(char **arr, char *str, const char *del);
  171. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  172. extern int GetTransactionQueueNum(void);
  173. extern pthread_mutex_t mutex1;
  174. extern struct Charger_Info Charger;
  175. extern sqlite3 *db;
  176. int TransactionMessageAttemptsGet(void);
  177. int TransactionMessageRetryIntervalGet(void);
  178. int GetOcppConnStatus(void);
  179. void SetOcppConnStatus(uint8_t status);
  180. int updateSetting(char *key, char *value);
  181. int setKeyValue(char *key, char *value);
  182. void OCPP_get_TableAuthlocalAllData(void);
  183. void processUnkownKey(void);
  184. struct StructOCPPMeterValue
  185. {
  186. unsigned char TimeStamp[28];
  187. struct StructSampledValue SampledValue[10];
  188. };
  189. struct ClientTime
  190. {
  191. unsigned int Heartbeat;
  192. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  193. unsigned int StartTransaction;
  194. unsigned int StopTransaction;
  195. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  196. }clientTime;
  197. typedef union
  198. {
  199. //Operations Initiated by Central System
  200. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  201. struct
  202. {
  203. //CsMsgValue[0]
  204. unsigned char StatusNotificationReq :1; //bit 0,
  205. unsigned char StatusNotificationConf :1; //bit 0,
  206. unsigned char :6; //bit 2~7
  207. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  208. }CpinitiateMsg;
  209. CpinitiateMsg cpinitateMsg;
  210. //==========================================
  211. // Init all Enumeration & Mapping String
  212. //==========================================
  213. /*ChargePointErrorCode*/
  214. typedef enum {
  215. ConnectorLockFailure,
  216. EVCommunicationError,
  217. GroundFailure,
  218. HighTemperature,
  219. InternalError,
  220. LocalListConflict,
  221. NoError,
  222. OtherError,
  223. OverCurrentFailure,
  224. OverVoltage,
  225. PowerMeterFailure,
  226. PowerSwitchFailure,
  227. ReaderFailure,
  228. ResetFailure,
  229. UnderVoltage,
  230. WeakSignal
  231. } ChargePointErrorCode;
  232. #if 0
  233. static char *ChargePointErrorCodeStr[] = {
  234. MACROSTR(ConnectorLockFailure),
  235. MACROSTR(EVCommunicationError),
  236. MACROSTR(GroundFailure),
  237. MACROSTR(HighTemperature),
  238. MACROSTR(InternalError),
  239. MACROSTR(LocalListConflict),
  240. MACROSTR(NoError),
  241. MACROSTR(OtherError),
  242. MACROSTR(OverCurrentFailure),
  243. MACROSTR(OverVoltage),
  244. MACROSTR(PowerMeterFailure),
  245. MACROSTR(PowerSwitchFailure),
  246. MACROSTR(ReaderFailure),
  247. MACROSTR(ResetFailure),
  248. MACROSTR(UnderVoltage),
  249. MACROSTR(WeakSignal)
  250. };
  251. #endif
  252. /*ChargePointStatus*/
  253. typedef enum {
  254. Available =0,
  255. Preparing,
  256. Charging,
  257. SuspendedEVSE,
  258. SuspendedEV,
  259. Finishing,
  260. Reserved,
  261. Unavailable,
  262. Faulted
  263. } ChargePointStatus;
  264. static char * ChargePointStatusStr[] = {
  265. MACROSTR(Available),
  266. MACROSTR(Preparing),
  267. MACROSTR(Charging),
  268. MACROSTR(SuspendedEVSE),
  269. MACROSTR(SuspendedEV),
  270. MACROSTR(Finishing),
  271. MACROSTR(Reserved),
  272. MACROSTR(Unavailable),
  273. MACROSTR(Faulted)
  274. };
  275. /*AvailabilityType*/
  276. typedef enum {
  277. RegistrationStatus_Accepted,
  278. RegistrationStatus_Pending,
  279. RegistrationStatus_Rejected
  280. } RegistrationStatus;
  281. static char *RegistrationStatusStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Pending),
  284. MACROSTR(Rejected)
  285. };
  286. /*AvailabilityType*/
  287. typedef enum {
  288. Inoperative,
  289. Operative
  290. } AvailabilityType;
  291. static char *AvailabilityTypeStr[] = {
  292. MACROSTR(Inoperative),
  293. MACROSTR(Operative)
  294. };
  295. /*AvailabilityStatus*/
  296. typedef enum {
  297. Accepted,
  298. Rejected,
  299. Scheduled
  300. } AvailabilityStatus;
  301. static char *AvailabilityStatusStr[] = {
  302. MACROSTR(Accepted),
  303. MACROSTR(Rejected),
  304. MACROSTR(Scheduled)
  305. };
  306. /*ConfigurationStatus*/
  307. typedef enum {
  308. ConfigurationStatus_Accepted,
  309. ConfigurationStatus_Rejected,
  310. RebootRequired,
  311. NotSupported
  312. } ConfigurationStatus;
  313. static char *ConfigurationStatusStr[] = {
  314. MACROSTR(Accepted),
  315. MACROSTR(Rejected),
  316. MACROSTR(RebootRequired),
  317. MACROSTR(NotSupported)
  318. };
  319. /*ClearCacheStatus*/
  320. typedef enum {
  321. ClearCacheStatus_Accepted,
  322. ClearCacheStatus_Rejected
  323. } ClearCacheStatus;
  324. static char *ClearCacheStatusStr[] = {
  325. MACROSTR(Accepted),
  326. MACROSTR(Rejected)
  327. };
  328. /*ChargingProfilePurposeType*/
  329. typedef enum {
  330. ChargePointMaxProfile,
  331. TxDefaultProfile,
  332. TxProfile
  333. } ChargingProfilePurposeType;
  334. static char *ChargingProfilePurposeTypeStr[] = {
  335. MACROSTR(ChargePointMaxProfile),
  336. MACROSTR(TxDefaultProfile),
  337. MACROSTR(TxProfile)
  338. };
  339. /*ChargingProfileStatus*/
  340. typedef enum {
  341. ChargingProfileStatus_Accepted,
  342. ChargingProfileStatus_Rejected,
  343. ChargingProfileStatus_NotSupported
  344. } ChargingProfileStatus;
  345. static char *ChargingProfileStatusStr[] = {
  346. MACROSTR(Accepted),
  347. MACROSTR(Rejected),
  348. MACROSTR(NotSupported)
  349. };
  350. /*ClearChargingProfileStatus*/
  351. typedef enum {
  352. ClearChargingProfileStatus_Accepted,
  353. ClearChargingProfileStatus_Unknown
  354. } ClearChargingProfileStatus;
  355. static char *ClearChargingProfileStatusStr[] = {
  356. MACROSTR(Accepted),
  357. MACROSTR(Unknown)
  358. };
  359. /*GetCompositeScheduleStatus*/
  360. typedef enum {
  361. GetCompositeScheduleStatus_Accepted,
  362. GetCompositeScheduleStatus_Rejected
  363. } GetCompositeScheduleStatus;
  364. static char *GetCompositeScheduleStatusStr[] = {
  365. MACROSTR(Accepted),
  366. MACROSTR(Rejected)
  367. };
  368. /*ChargingRateUnitType*/
  369. typedef enum {
  370. ChargingRateUnitType_W,
  371. ChargingRateUnitType_A
  372. } ChargingRateUnitType;
  373. /*AuthorizationStatus*/
  374. typedef enum {
  375. AuthorizationStatus_Accepted ,
  376. AuthorizationStatus_Blocked ,
  377. AuthorizationStatus_Expired ,
  378. AuthorizationStatus_Invalid ,
  379. AuthorizationStatus_ConcurrentTx
  380. } AuthorizationStatus;
  381. /*UpdateType*/
  382. typedef enum {
  383. Differential ,
  384. Full
  385. } UpdateType;
  386. static char *UpdateTypeStr[] = {
  387. MACROSTR(Differential),
  388. MACROSTR(Full)
  389. };
  390. /*UpdateStatus*/
  391. typedef enum {
  392. UpdateStatus_Accepted ,
  393. UpdateStatus_Failed ,
  394. UpdateStatus_NotSupported ,
  395. UpdateStatus_VersionMismatch
  396. } UpdateStatus;
  397. static char *UpdateStatusStr[] = {
  398. MACROSTR(Accepted),
  399. MACROSTR(Failed),
  400. MACROSTR(NotSupported),
  401. MACROSTR(VersionMismatch)
  402. };
  403. /*RemoteStartStopStatus*/
  404. typedef enum {
  405. RemoteStartStopStatus_Accepted,
  406. RemoteStartStopStatus_Rejected
  407. } RemoteStartStopStatus;
  408. static char *RemoteStartStopStatusStr[] = {
  409. MACROSTR(Accepted),
  410. MACROSTR(Rejected)
  411. };
  412. /*ReservationStatus*/
  413. typedef enum {
  414. ReservationStatus_Accepted,
  415. ReservationStatus_Faulted,
  416. ReservationStatus_Occupied,
  417. ReservationStatus_Rejected,
  418. ReservationStatus_Unavailable
  419. } ReservationStatus;
  420. static char *ReservationStatusStr[] = {
  421. MACROSTR(Accepted),
  422. MACROSTR(Faulted),
  423. MACROSTR(Occupied),
  424. MACROSTR(Rejected),
  425. MACROSTR(Unavailable)
  426. };
  427. /*ResetType*/
  428. typedef enum {
  429. Hard,
  430. Soft
  431. } ResetType;
  432. static char *ResetTypeStr[] = {
  433. MACROSTR(Hard),
  434. MACROSTR(Soft)
  435. };
  436. /*ResetStatus*/
  437. typedef enum {
  438. ResetStatus_Accepted,
  439. ResetStatus_Rejected
  440. } ResetStatus;
  441. static char *ResetStatusStr[] = {
  442. MACROSTR(Accepted),
  443. MACROSTR(Rejected)
  444. };
  445. /*DiagnosticsStatus*/
  446. typedef enum {
  447. DiagnosticsStatus_Idle,
  448. DiagnosticsStatus_Uploaded,
  449. DiagnosticsStatus_UploadFailed,
  450. DiagnosticsStatus_Uploading
  451. } DiagnosticsStatus;
  452. static char * DiagnosticsStatusStr[] = {
  453. MACROSTR(Idle),
  454. MACROSTR(Uploaded),
  455. MACROSTR(UploadFailed),
  456. MACROSTR(Uploading)
  457. };
  458. /*FirmwareStatus*/
  459. typedef enum {
  460. FirmwareStatus_Downloaded,
  461. FirmwareStatus_DownloadFailed,
  462. FirmwareStatus_Downloading,
  463. FirmwareStatus_Idle,
  464. FirmwareStatus_InstallationFailed,
  465. FirmwareStatus_Installing,
  466. FirmwareStatus_Installed
  467. } FirmwareStatus;
  468. static char * FirmwareStatusStr[] = {
  469. MACROSTR(Downloaded),
  470. MACROSTR(DownloadFailed),
  471. MACROSTR(Downloading),
  472. MACROSTR(Idle),
  473. MACROSTR(InstallationFailed),
  474. MACROSTR(Installing),
  475. MACROSTR(Installed)
  476. };
  477. /*MessageTrigger*/
  478. typedef enum {
  479. BootNotification,
  480. DiagnosticsStatusNotification,
  481. FirmwareStatusNotification,
  482. Heartbeat,
  483. MeterValues,
  484. StatusNotification
  485. } MessageTrigger;
  486. static char * MessageTriggerStr[] = {
  487. MACROSTR(BootNotification),
  488. MACROSTR(DiagnosticsStatusNotification),
  489. MACROSTR(FirmwareStatusNotification),
  490. MACROSTR(Heartbeat),
  491. MACROSTR(MeterValues),
  492. MACROSTR(StatusNotification)
  493. };
  494. /*TriggerMessageStatus*/
  495. typedef enum {
  496. TriggerMessageStatus_Accepted ,
  497. TriggerMessageStatus_Rejected ,
  498. TriggerMessageStatus_NotImplemented
  499. } TriggerMessageStatus;
  500. static char * TriggerMessageStatusStr[] = {
  501. MACROSTR(Accepted),
  502. MACROSTR(Rejected),
  503. MACROSTR(NotImplemented)
  504. };
  505. /*UnlockStatus*/
  506. typedef enum {
  507. Unlocked,
  508. UnlockFailed,
  509. UnlockStatus_NotSupported
  510. } UnlockStatus;
  511. static char * UnlockStatusStr[] = {
  512. MACROSTR(Unlocked),
  513. MACROSTR(UnlockFailed),
  514. MACROSTR(NotSupported)
  515. };
  516. /*StopTransactionReason*/
  517. typedef enum {
  518. EmergencyStop,
  519. EVDisconnected,
  520. HardReset,
  521. Local,
  522. Other,
  523. PowerLoss,
  524. Reboot,
  525. Remote,
  526. SoftReset,
  527. UnlockCommand,
  528. DeAuthorized
  529. } StopTransactionReason;
  530. #if 0
  531. static char * StopTransactionReasonStr[] = {
  532. MACROSTR(EmergencyStop),
  533. MACROSTR(EVDisconnected),
  534. MACROSTR(HardReset),
  535. MACROSTR(Local),
  536. MACROSTR(Other),
  537. MACROSTR(PowerLoss),
  538. MACROSTR(Reboot),
  539. MACROSTR(Remote),
  540. MACROSTR(SoftReset),
  541. MACROSTR(UnlockCommand),
  542. MACROSTR(DeAuthorized)
  543. };
  544. #endif
  545. /*CancelReservationStatus*/
  546. typedef enum {
  547. CancelReservationStatus_Accepted,
  548. CancelReservationStatus_Rejected
  549. } CancelReservationStatus;
  550. static char * CancelReservationStatusStr[] = {
  551. MACROSTR(Accepted),
  552. MACROSTR(Rejected)
  553. };
  554. /*ReadingContext*/
  555. typedef enum {
  556. ReadingContext_Interruption_Begin,
  557. ReadingContext_Interruption_End,
  558. ReadingContext_Other,
  559. ReadingContext_Sample_Clock,
  560. ReadingContext_Sample_Periodic ,
  561. ReadingContext_Transaction_Begin ,
  562. ReadingContext_Transaction_End,
  563. ReadingContext_Trigger
  564. } ReadingContext;
  565. static char * ReadingContextStr[] = {
  566. MACROSTR(Interruption.Begin),
  567. MACROSTR(Interruption.End),
  568. MACROSTR(Other),
  569. MACROSTR(Sample.Clock),
  570. MACROSTR(Sample.Periodic),
  571. MACROSTR(Transaction.Begin),
  572. MACROSTR(Transaction.End),
  573. MACROSTR(Trigger)
  574. };
  575. /*ValueFormat*/
  576. typedef enum {
  577. Raw,
  578. SignedData
  579. } ValueFormat;
  580. static char * ValueFormatStr[] = {
  581. MACROSTR(Raw),
  582. MACROSTR(SignedData)
  583. };
  584. /*Measurand*/
  585. typedef enum {
  586. Current_Export ,
  587. Current_Import,
  588. Current_Offered,
  589. Energy_Active_Export_Register,
  590. Energy_Active_Import_Register,
  591. Energy_Reactive_Export_Register,
  592. Energy_Reactive_Import_Register,
  593. Energy_Active_Export_Interval,
  594. Energy_Active_Import_Interval,
  595. Energy_Reactive_Export_Interval,
  596. Energy_Reactive_Import_Interval,
  597. Frequency,
  598. Power_Active_Export ,
  599. Power_Active_Import,
  600. Power_Factor,
  601. Power_Offered,
  602. Power_Reactive_Export,
  603. Power_Reactive_Import,
  604. RPM,
  605. SoC,
  606. Temperature ,
  607. Voltage
  608. } Measurand;
  609. static char * MeasurandStr[] = {
  610. MACROSTR(Current.Export),
  611. MACROSTR(Current.Import),
  612. MACROSTR(Current.Offered),
  613. MACROSTR(Energy.Active.Export.Register),
  614. MACROSTR(Energy.Active.Import.Register),
  615. MACROSTR(Energy.Reactive.Export.Register),
  616. MACROSTR(Energy.Reactive.Import.Register),
  617. MACROSTR(Energy.Active.Export.Interval),
  618. MACROSTR(Energy.Active.Import.Interval),
  619. MACROSTR(Energy.Reactive.Export.Interval),
  620. MACROSTR(Energy.Reactive.Import.Interval),
  621. MACROSTR(Frequency),
  622. MACROSTR(Power.Active.Export),
  623. MACROSTR(Power.Active.Import),
  624. MACROSTR(Power.Factor),
  625. MACROSTR(Power.Offered),
  626. MACROSTR(Power.Reactive.ExportMACROSTR),
  627. MACROSTR(Power.Reactive.Import),
  628. MACROSTR(RPM),
  629. MACROSTR(SoC),
  630. MACROSTR(Temperature),
  631. MACROSTR(Voltage)
  632. };
  633. /*Location*/
  634. typedef enum {
  635. Location_Body,
  636. Location_Cable,
  637. Location_EV,
  638. Location_Inlet ,
  639. Location_Outlet
  640. } Location;
  641. static char * LocationStr[] = {
  642. MACROSTR(Body),
  643. MACROSTR(Cable),
  644. MACROSTR(EV),
  645. MACROSTR(Inlet),
  646. MACROSTR(Outlet)
  647. };
  648. /*Phase*/
  649. typedef enum {
  650. L1,
  651. L2,
  652. L3,
  653. N,
  654. L1_N,
  655. L2_N,
  656. L3_N,
  657. L1_L2,
  658. L2_L3,
  659. L3_L1
  660. } Phase;
  661. static char * PhaseStr[] = {
  662. MACROSTR(L1),
  663. MACROSTR(L2),
  664. MACROSTR(L3),
  665. MACROSTR(N),
  666. MACROSTR(L1-N),
  667. MACROSTR(L2-N),
  668. MACROSTR(L3-N),
  669. MACROSTR(L1-L2),
  670. MACROSTR(L2-L3),
  671. MACROSTR(L3-L1)
  672. };
  673. /*UnitOfMeasure*/
  674. typedef enum {
  675. UnitOfMeasure_Wh,
  676. UnitOfMeasure_kWh ,
  677. UnitOfMeasure_varh ,
  678. UnitOfMeasure_kvarh ,
  679. UnitOfMeasure_W ,
  680. UnitOfMeasure_kW ,
  681. UnitOfMeasure_VA ,
  682. UnitOfMeasure_kVA ,
  683. UnitOfMeasure_var ,
  684. UnitOfMeasure_kvar ,
  685. UnitOfMeasure_A ,
  686. UnitOfMeasure_V ,
  687. UnitOfMeasure_Celsius ,
  688. UnitOfMeasure_Fahrenheit ,
  689. UnitOfMeasure_K ,
  690. UnitOfMeasure_Percent
  691. } UnitOfMeasure;
  692. static char * UnitOfMeasureStr[] = {
  693. MACROSTR(Wh),
  694. MACROSTR(kWh),
  695. MACROSTR(varh),
  696. MACROSTR(kvarh),
  697. MACROSTR(W),
  698. MACROSTR(kW),
  699. MACROSTR(VA),
  700. MACROSTR(kVA),
  701. MACROSTR(var),
  702. MACROSTR(kvar),
  703. MACROSTR(A),
  704. MACROSTR(V),
  705. MACROSTR(Celsius),
  706. MACROSTR(Fahrenheit),
  707. MACROSTR(K),
  708. MACROSTR(Percent)
  709. };
  710. #if 0
  711. /*Configuration enum*/
  712. enum CoreProfile {
  713. AllowOfflineTxForUnknownId=0,
  714. AuthorizationCacheEnabled,
  715. AuthorizeRemoteTxRequests,
  716. BlinkRepeat,
  717. ClockAlignedDataInterval,
  718. ConnectionTimeOut,
  719. GetConfigurationMaxKeys,
  720. HeartbeatInterval,
  721. LightIntensity,
  722. LocalAuthorizeOffline,
  723. LocalPreAuthorize,
  724. MaxEnergyOnInvalidId,
  725. MeterValuesAlignedData,
  726. MeterValuesAlignedDataMaxLength,
  727. MeterValuesSampledData,
  728. MeterValuesSampledDataMaxLength,
  729. MeterValueSampleInterval,
  730. MinimumStatusDuration,
  731. NumberOfConnectors,
  732. ResetRetries,
  733. ConnectorPhaseRotation,
  734. ConnectorPhaseRotationMaxLength,
  735. StopTransactionOnEVSideDisconnect,
  736. StopTransactionOnInvalidId,
  737. StopTxnAlignedData,
  738. StopTxnAlignedDataMaxLength,
  739. StopTxnSampledData,
  740. StopTxnSampledDataMaxLength,
  741. SupportedFeatureProfiles,
  742. SupportedFeatureProfilesMaxLength,
  743. TransactionMessageAttempts,
  744. TransactionMessageRetryInterval,
  745. UnlockConnectorOnEVSideDisconnect,
  746. WebSocketPingInterval,
  747. _CoreProfile_CNT
  748. };
  749. #endif
  750. enum LocalAuthListManagementProfile{
  751. LocalAuthListEnabled=0,
  752. LocalAuthListMaxLength,
  753. SendLocalListMaxLength,
  754. _LocalAuthListManagementProfile_CNT
  755. };
  756. enum ReservationProfile{
  757. ReserveConnectorZeroSupported
  758. };
  759. enum SmartChargingProfile{
  760. ChargeProfileMaxStackLevel,
  761. ChargingScheduleAllowedChargingRateUnit,
  762. ChargingScheduleMaxPeriods,
  763. ConnectorSwitch3to1PhaseSupported,
  764. MaxChargingProfilesInstalled
  765. };
  766. enum ChargerSystemStatus{
  767. ChargerSystemStatus_Booting,
  768. ChargerSystemStatus_Idle,
  769. ChargerSystemStatus_Authorizing,
  770. ChargerSystemStatus_Preparing,
  771. ChargerSystemStatus_Charging,
  772. ChargerSystemStatus_Terminating,
  773. ChargerSystemStatus_Alarm,
  774. ChargerSystemStatus_Fault
  775. };
  776. enum GetConfigurationKey {
  777. GetConfiguration_AllowOfflineTxForUnknownId=0,
  778. GetConfiguration_AuthorizationCacheEnabled,
  779. GetConfiguration_AuthorizeRemoteTxRequests,
  780. GetConfiguration_BlinkRepeat,
  781. GetConfiguration_ClockAlignedDataInterval,
  782. GetConfiguration_ConnectionTimeOut,
  783. GetConfiguration_GetConfigurationMaxKeys,
  784. GetConfiguration_HeartbeatInterval,
  785. GetConfiguration_LightIntensity,
  786. GetConfiguration_LocalAuthorizeOffline,
  787. GetConfiguration_LocalPreAuthorize,
  788. GetConfiguration_MaxEnergyOnInvalidId,
  789. GetConfiguration_MeterValuesAlignedData,
  790. GetConfiguration_MeterValuesAlignedDataMaxLength,
  791. GetConfiguration_MeterValuesSampledData,
  792. GetConfiguration_MeterValuesSampledDataMaxLength,
  793. GetConfiguration_MeterValueSampleInterval,
  794. GetConfiguration_MinimumStatusDuration,
  795. GetConfiguration_NumberOfConnectors,
  796. GetConfiguration_ResetRetries,
  797. GetConfiguration_ConnectorPhaseRotation,
  798. GetConfiguration_ConnectorPhaseRotationMaxLength,
  799. GetConfiguration_StopTransactionOnEVSideDisconnect,
  800. GetConfiguration_StopTransactionOnInvalidId,
  801. GetConfiguration_StopTxnAlignedData,
  802. GetConfiguration_StopTxnAlignedDataMaxLength,
  803. GetConfiguration_StopTxnSampledData,
  804. GetConfiguration_StopTxnSampledDataMaxLength,
  805. GetConfiguration_SupportedFeatureProfiles,
  806. GetConfiguration_SupportedFeatureProfilesMaxLength,
  807. GetConfiguration_TransactionMessageAttempts,
  808. GetConfiguration_TransactionMessageRetryInterval,
  809. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  810. GetConfiguration_WebSocketPingInterval,
  811. GetConfiguration_LocalAuthListEnabled,
  812. GetConfiguration_LocalAuthListMaxLength,
  813. GetConfiguration_SendLocalListMaxLength,
  814. GetConfiguration_ReserveConnectorZeroSupported,
  815. GetConfiguration_ChargeProfileMaxStackLevel,
  816. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  817. GetConfiguration_ChargingScheduleMaxPeriods,
  818. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  819. GetConfiguration_MaxChargingProfilesInstalled,
  820. };
  821. //GetConfiguration Array
  822. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  823. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  824. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  825. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  826. //==========================================
  827. // Init all share memory
  828. //==========================================
  829. int InitShareMemory()
  830. {
  831. int result = PASS;
  832. int MeterSMId;
  833. //creat ShmSysConfigAndInfo
  834. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  835. {
  836. #ifdef SystemLogMessage
  837. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  838. #endif
  839. result = FAIL;
  840. }
  841. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else
  849. {}
  850. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  858. {
  859. #ifdef SystemLogMessage
  860. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  861. #endif
  862. result = FAIL;
  863. }
  864. else
  865. {}
  866. //creat ShmPsuData
  867. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("shmget ShmPsuData NG\n");
  871. #endif
  872. result = FAIL;
  873. }
  874. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  875. {
  876. #ifdef SystemLogMessage
  877. DEBUG_ERROR("shmat ShmPsuData NG\n");
  878. #endif
  879. result = FAIL;
  880. }
  881. else
  882. {}
  883. //creat ShmOCPP16Data
  884. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  885. {
  886. #ifdef SystemLogMessage
  887. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  888. #endif
  889. result = FAIL;
  890. }
  891. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  892. {
  893. #ifdef SystemLogMessage
  894. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  895. #endif
  896. result = FAIL;
  897. }
  898. else
  899. {}
  900. /****************************** For Initial Settings************************************************/
  901. #if 0
  902. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  903. server_sign = FALSE;
  904. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  905. {
  906. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  907. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  908. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  909. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  910. }
  911. // Charger PRE_SYS_MODE
  912. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  913. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  914. clientTime.Heartbeat=time((time_t*)NULL);
  915. #endif
  916. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  917. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  918. // allocate Configuration memory address
  919. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  920. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  921. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  923. #if 0
  924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  925. {
  926. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  927. DEBUG_INFO("DC ...\n");
  928. }
  929. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  930. {
  931. SystemInitial = AC_QUANTITY;
  932. DEBUG_INFO("AC ...\n");
  933. }
  934. //Status / ConnectorPlugIn Setting
  935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  936. {
  937. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  938. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  939. }
  940. for (int index = 0; index < CCS_QUANTITY; index++)
  941. {
  942. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  943. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  944. }
  945. for (int index = 0; index < GB_QUANTITY; index++)
  946. {
  947. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  948. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  949. }
  950. for (int index = 0; index < AC_QUANTITY; index++)
  951. {
  952. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  953. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  954. }
  955. #endif
  956. return result;
  957. }
  958. int ProcessShareMemory()
  959. {
  960. if(InitShareMemory() == FAIL)
  961. {
  962. #ifdef SystemLogMessage
  963. DEBUG_ERROR("InitShareMemory NG\n");
  964. #endif
  965. if(ShmStatusCodeData!=NULL)
  966. {
  967. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  968. }
  969. sleep(5);
  970. return FAIL;
  971. }
  972. return PASS;
  973. }
  974. //---------------------common routine---------------------------//
  975. char * stringtrim( char * s )
  976. {
  977. char * p1 = s;
  978. char * p2 = s;
  979. while(*p1 != '\0')
  980. {
  981. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  982. {
  983. if(*p1 != ',')
  984. {
  985. p1 ++;
  986. }
  987. else
  988. {
  989. break;
  990. }
  991. }
  992. if(*p1 != ',')
  993. {
  994. * p2 ++ = *p1 ++;
  995. //printf("p2=%s\n",p2);
  996. }
  997. else
  998. {
  999. break;
  1000. }
  1001. }
  1002. *p2 = '\0';
  1003. return (s);
  1004. }
  1005. char * stringtrimspace( char * s )
  1006. {
  1007. char * p1 = s;
  1008. char * p2 = s;
  1009. while(*p1 != '\0')
  1010. {
  1011. while(*p1 == ' ') //while(*p1 == ' ' || *p1 == '\t' || *p1 == '\n' || *p1 == '\r')
  1012. {
  1013. p1 ++;
  1014. }
  1015. * p2 ++ = *p1 ++;
  1016. //printf("p2=%s\n",p2);
  1017. }
  1018. *p2 = '\0';
  1019. return (s);
  1020. }
  1021. //---------------------------------------------
  1022. // new:
  1023. // enum SYSTEM_STATUS
  1024. // {
  1025. // SYS_MODE_BOOTING = 0,
  1026. // SYS_MODE_IDLE = 1,
  1027. // SYS_MODE_AUTHORIZING = 2,
  1028. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1029. // SYS_MODE_REASSIGN = 4,
  1030. // SYS_MODE_PREPARING = 5,
  1031. // SYS_MODE_PREPARE_FOR_EV = 6,
  1032. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1033. // SYS_MODE_CHARGING = 8,
  1034. // SYS_MODE_TERMINATING = 9,
  1035. // SYS_MODE_COMPLETE = 10,
  1036. // SYS_MODE_ALARM = 11,
  1037. // SYS_MODE_FAULT = 12,
  1038. // SYS_MODE_RESERVATION = 13,
  1039. // SYS_MODE_BOOKING = 14,
  1040. // SYS_MODE_MAINTAIN = 15,
  1041. // SYS_MODE_DEBUG = 16,
  1042. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1043. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1044. // SYS_MODE_UPDATE = 19
  1045. // };
  1046. //
  1047. //
  1048. //-----------------------------------------
  1049. void CheckSystemValue(void)
  1050. {
  1051. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1052. //int IdleModeCnt = 0;
  1053. char filenmae[100]={0};
  1054. char str[100]={0};
  1055. //===============================
  1056. // send Heartbeat
  1057. //===============================
  1058. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1059. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1060. {
  1061. printf("Heartbeat !!!\n");
  1062. //parameter for test
  1063. sendHeartbeatRequest(0);
  1064. //==============================================
  1065. // Reset Waiting Time
  1066. //==============================================
  1067. clientTime.Heartbeat=time((time_t*)NULL);
  1068. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1069. }
  1070. else if((server_sign == TRUE) &&(FirstHeartBeat == 0)) // Send First HeartBeat
  1071. {
  1072. printf("FirstHeartBeat !!!\n");
  1073. //parameter for test
  1074. sendHeartbeatRequest(0);
  1075. //==============================================
  1076. // Reset Waiting Time
  1077. //==============================================
  1078. clientTime.Heartbeat=time((time_t*)NULL);
  1079. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1080. }
  1081. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1082. {
  1083. //===============================
  1084. // CSU Trigger Reset Conf
  1085. //===============================
  1086. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1087. {
  1088. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1089. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1090. {
  1091. server_sign = FALSE;
  1092. }
  1093. }
  1094. //===============================
  1095. // CSU Trigger Authorize Request
  1096. //===============================
  1097. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1098. {
  1099. sendAuthorizeRequest(0);
  1100. authorizeRetryTimes = authorizeRetryTimes + 1;
  1101. if(authorizeRetryTimes < 3)
  1102. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1103. }
  1104. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1105. {
  1106. authorizeRetryTimes = 0;
  1107. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1108. server_sign = FALSE;
  1109. }
  1110. 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))
  1111. {
  1112. sendAuthorizeRequest(0);
  1113. }
  1114. //===============================
  1115. // CSU Trigger Smart Charging Profilw
  1116. //===============================
  1117. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1118. {
  1119. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1120. GetChargingProfileRequest(gun_index);
  1121. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1122. }
  1123. //==============================================
  1124. // Charger start transaction
  1125. //==============================================
  1126. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1127. {
  1128. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1129. sendStartTransactionRequest(gun_index);
  1130. clientTime.StartTransaction = time((time_t*)NULL);
  1131. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1132. }
  1133. //==============================================
  1134. // Charger stop transaction
  1135. //==============================================
  1136. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1137. {
  1138. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1139. sendStopTransactionRequest(gun_index);
  1140. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1141. clientTime.StopTransaction = time((time_t*)NULL);
  1142. }
  1143. //==============================================
  1144. // Charger status report
  1145. //==============================================
  1146. /* Check Mode Change */
  1147. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1148. {
  1149. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1150. {
  1151. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1152. {
  1153. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1154. {
  1155. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1156. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1157. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1158. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1159. statusModeChage[gun_index] = TRUE;
  1160. }
  1161. #if 0 // for TempStopTransaction
  1162. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1163. {
  1164. checkTempStopTransaction(gun_index);
  1165. }
  1166. #endif
  1167. }
  1168. }
  1169. for (int index = 0; index < CCS_QUANTITY; index++)
  1170. {
  1171. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1172. {
  1173. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1174. {
  1175. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1176. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1177. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1178. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1179. statusModeChage[gun_index] = TRUE;
  1180. }
  1181. #if 0 // for TempStopTransaction
  1182. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1183. {
  1184. checkTempStopTransaction(gun_index);
  1185. }
  1186. #endif
  1187. }
  1188. }
  1189. for (int index = 0; index < GB_QUANTITY; index++)
  1190. {
  1191. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1192. {
  1193. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1194. {
  1195. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1196. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1197. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1198. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1199. statusModeChage[gun_index] = TRUE;
  1200. }
  1201. #if 0 // for TempStopTransaction
  1202. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1203. {
  1204. checkTempStopTransaction(gun_index);
  1205. }
  1206. #endif
  1207. }
  1208. }
  1209. }
  1210. else //AC
  1211. {
  1212. for (int index = 0; index < AC_QUANTITY; index++)
  1213. {
  1214. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1215. {
  1216. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1217. {
  1218. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1219. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1220. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1221. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1222. statusModeChage[gun_index] = TRUE;
  1223. }
  1224. #if 0 // for TempStopTransaction
  1225. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1226. {
  1227. checkTempStopTransaction(gun_index);
  1228. }
  1229. #endif
  1230. }
  1231. }// END OF FOR
  1232. }// END OF ELSE
  1233. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1234. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1235. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1236. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1237. {
  1238. if(SystemInitial != 0)
  1239. SystemInitial = SystemInitial -1;
  1240. sendStatusNotificationRequest(gun_index);
  1241. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1242. statusModeChage[gun_index] = FALSE;
  1243. }
  1244. //==============================================
  1245. // Meter report
  1246. //==============================================
  1247. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1248. {
  1249. //check Transaction active
  1250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1251. {
  1252. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1253. {
  1254. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1255. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1256. {
  1257. meterValueSend[gun_index] =1;
  1258. }
  1259. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1260. {
  1261. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1262. if((access(filenmae,F_OK))!=-1)
  1263. {
  1264. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1265. sprintf(str,"rm -f %s",filenmae);
  1266. system(str);
  1267. }
  1268. }
  1269. }// End for CHAdeMO
  1270. for (int index = 0; index < CCS_QUANTITY; index++)
  1271. {
  1272. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1273. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1274. {
  1275. meterValueSend[gun_index] =1;
  1276. }
  1277. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1278. {
  1279. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1280. if((access(filenmae,F_OK))!=-1)
  1281. {
  1282. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1283. sprintf(str,"rm -f %s",filenmae);
  1284. system(str);
  1285. }
  1286. }
  1287. } // End for CCS
  1288. for (int index = 0; index < GB_QUANTITY; index++)
  1289. {
  1290. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1291. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1292. {
  1293. meterValueSend[gun_index] =1;
  1294. }
  1295. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1296. {
  1297. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1298. if((access(filenmae,F_OK))!=-1)
  1299. {
  1300. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1301. sprintf(str,"rm -f %s",filenmae);
  1302. system(str);
  1303. }
  1304. }
  1305. }// End for GB
  1306. }
  1307. else
  1308. {
  1309. for (int index = 0; index < AC_QUANTITY; index++)
  1310. {
  1311. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1312. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1313. {
  1314. meterValueSend[gun_index] =1;
  1315. }
  1316. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1317. {
  1318. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1319. if((access(filenmae,F_OK))!=-1)
  1320. {
  1321. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1322. sprintf(str,"rm -f %s",filenmae);
  1323. system(str);
  1324. }
  1325. }
  1326. }//End for AC
  1327. }//END OF ELSE
  1328. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1329. if(meterValueSend[gun_index] == 1)
  1330. {
  1331. sendMeterValuesRequest(gun_index);
  1332. #if 0 // for TempStopTransaction
  1333. storeTempStopTransaction(gun_index);
  1334. #endif
  1335. }
  1336. }
  1337. //==============================================
  1338. // Check Connector reserved
  1339. //==============================================
  1340. //===============================
  1341. // Check if Reserve is expired
  1342. //===============================
  1343. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1344. {
  1345. double diff_t;
  1346. struct tm tp;
  1347. // current time
  1348. time_t t = time(NULL);
  1349. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1350. tp.tm_isdst = -1;
  1351. time_t utc = mktime(&tp);
  1352. diff_t = difftime(utc, t);
  1353. if(diff_t <= 0)
  1354. {
  1355. DEBUG_INFO("reserve expired !!! \n");
  1356. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1357. }
  1358. }//END OF Check if Reserve is expired
  1359. //==========================================
  1360. // csu trigger FirmwareStatusNotificationReq
  1361. //==========================================
  1362. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1363. {
  1364. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1365. }
  1366. //==========================================
  1367. // csu trigger CancelReservationConf
  1368. //==========================================
  1369. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1370. {
  1371. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1372. }
  1373. //==========================================
  1374. // csu trigger ChangeAvailabilityConf
  1375. //==========================================
  1376. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1377. {
  1378. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1379. }
  1380. //==========================================
  1381. // csu trigger UnlockConnectorConf
  1382. //==========================================
  1383. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1384. {
  1385. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1386. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1387. }
  1388. //==========================================
  1389. // csu trigger ReserveNowConf
  1390. //==========================================
  1391. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1392. {
  1393. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1394. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1395. }
  1396. //==========================================
  1397. // csu trigger DataTransferReq
  1398. //==========================================
  1399. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1400. {
  1401. sendDataTransferRequest(gun_index);
  1402. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1403. }
  1404. }
  1405. }
  1406. //==========================================
  1407. // send request routine
  1408. //==========================================
  1409. int sendAuthorizeRequest(int gun_index)
  1410. {
  1411. mtrace();
  1412. int result = FAIL;
  1413. char message[100]={0};
  1414. char guid[37];
  1415. char tempdata[65]={0};
  1416. DEBUG_INFO("sendAuthorizeRequest \n");
  1417. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1418. //Local Authorize
  1419. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1420. {
  1421. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1422. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1423. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1424. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1425. result = PASS;
  1426. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1427. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1428. authorizeRetryTimes = 0;
  1429. return result;
  1430. }
  1431. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  1432. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1433. {
  1434. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1435. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1436. {
  1437. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1438. {
  1439. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1440. }
  1441. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1442. {
  1443. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1444. }
  1445. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1446. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1447. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1448. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1449. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1450. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1451. authorizeRetryTimes = 0;
  1452. return result;
  1453. }
  1454. else
  1455. {
  1456. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1457. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1458. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1459. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1460. result = PASS;
  1461. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1462. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1463. authorizeRetryTimes = 0;
  1464. return result;
  1465. }
  1466. }
  1467. //initailize struct Authorize
  1468. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1469. //get data from shared memory
  1470. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1471. random_uuid(guid);
  1472. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1473. LWS_Send(message);
  1474. sprintf(tempdata, "Authorize,%d", gun_index);
  1475. if(hashmap_operation(0, guid, tempdata) == 1)
  1476. {
  1477. result = PASS;
  1478. DEBUG_ERROR("Authorize mapItem pass\n");
  1479. }
  1480. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1481. return result;
  1482. }
  1483. int sendBootNotificationRequest(void)
  1484. {
  1485. mtrace();
  1486. int result = FAIL;
  1487. char message[500]={0}, payload[700]={0};
  1488. char guid[37]={0};
  1489. char tempdata[65]={0};
  1490. int IsGunCharging = FALSE;
  1491. //check Transaction active
  1492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1493. {
  1494. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1495. {
  1496. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1497. {
  1498. IsGunCharging = TRUE;
  1499. }
  1500. }
  1501. for (int index = 0; index < CCS_QUANTITY; index++)
  1502. {
  1503. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1504. {
  1505. IsGunCharging = TRUE;
  1506. }
  1507. }
  1508. for (int index = 0; index < GB_QUANTITY; index++)
  1509. {
  1510. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1511. {
  1512. IsGunCharging = TRUE;
  1513. }
  1514. }
  1515. }
  1516. else
  1517. {
  1518. for (int index = 0; index < AC_QUANTITY; index++)
  1519. {
  1520. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1521. {
  1522. IsGunCharging = TRUE;
  1523. }
  1524. }
  1525. }
  1526. if(IsGunCharging == TRUE)
  1527. {
  1528. server_sign = TRUE;
  1529. return result;
  1530. }
  1531. // Fill BootNotification fields
  1532. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1533. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1534. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1535. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1536. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1537. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1538. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1539. #if 0
  1540. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1541. ShmOCPP16Data->ChargeBoxId
  1542. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1543. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1544. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1545. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1546. ,ShmOCPP16Data->BootNotification.CpIccid
  1547. ,ShmOCPP16Data->BootNotification.CpImsi
  1548. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1549. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1550. #endif
  1551. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1552. ShmOCPP16Data->ChargeBoxId
  1553. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1554. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1555. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1556. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1557. ,ShmOCPP16Data->BootNotification.CpIccid
  1558. ,ShmOCPP16Data->BootNotification.CpImsi);
  1559. random_uuid(guid);
  1560. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1561. LWS_Send(message);
  1562. sprintf(tempdata, "BootNotification,0");
  1563. 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*/)
  1564. {
  1565. result = PASS;
  1566. }
  1567. memset(queuedata, 0, sizeof(queuedata));
  1568. strcpy(queuedata,message);
  1569. return result;
  1570. }
  1571. int sendDataTransferRequest(int gun_index)
  1572. {
  1573. mtrace();
  1574. char message[1000]={0};
  1575. char guid[37]={0};
  1576. char tempdata[65]={0};
  1577. int result = FAIL;
  1578. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1579. random_uuid(guid);
  1580. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1581. MESSAGE_TYPE_CALL,
  1582. guid,
  1583. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1584. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1585. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1586. LWS_Send(message);
  1587. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1588. 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*/)
  1589. {
  1590. result = PASS;
  1591. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1592. }
  1593. return result;
  1594. }
  1595. int sendDiagnosticsStatusNotificationRequest(char *status)
  1596. {
  1597. mtrace();
  1598. int result = FAIL;
  1599. char message[110]={0};
  1600. char guid[37]={0};
  1601. char tempdata[65]={0};
  1602. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1603. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1604. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1605. random_uuid(guid);
  1606. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1607. LWS_Send(message);
  1608. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1609. if(hashmap_operation(0, guid, tempdata) == 1)
  1610. {
  1611. result = PASS;
  1612. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1613. }
  1614. //#ifdef SystemLogMessage
  1615. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1616. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1617. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1618. //#endif
  1619. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1620. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1621. //record status
  1622. if(strcmp(status,"Idle")==0)
  1623. {
  1624. DiagnosticsStatusNotificationStatus = 0;
  1625. }
  1626. else if(strcmp(status,"Uploaded")==0)
  1627. {
  1628. DiagnosticsStatusNotificationStatus = 1;
  1629. }
  1630. else if(strcmp(status,"UploadFailed")==0)
  1631. {
  1632. DiagnosticsStatusNotificationStatus = 2;
  1633. }
  1634. else if(strcmp(status,"Uploading")==0)
  1635. {
  1636. DiagnosticsStatusNotificationStatus = 3;
  1637. }
  1638. return result;
  1639. }
  1640. int sendFirmwareStatusNotificationRequest(char *status)
  1641. {
  1642. mtrace();
  1643. int result = FAIL;
  1644. char message[110]={0};
  1645. char guid[37]={0};
  1646. char tempdata[65]={0};
  1647. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1648. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1649. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1650. random_uuid(guid);
  1651. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1652. LWS_Send(message);
  1653. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1654. 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*/)
  1655. {
  1656. result = PASS;
  1657. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1658. }
  1659. //#ifdef SystemLogMessage
  1660. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1661. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1662. //#endif
  1663. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1664. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1665. //record status
  1666. if(strcmp(status,"Downloaded")==0)
  1667. {
  1668. FirmwareStatusNotificationStatus = 0;
  1669. }
  1670. else if(strcmp(status,"DownloadFailed")==0)
  1671. {
  1672. FirmwareStatusNotificationStatus = 1;
  1673. }
  1674. else if(strcmp(status,"Downloading")==0)
  1675. {
  1676. FirmwareStatusNotificationStatus = 2;
  1677. }
  1678. else if(strcmp(status,"Idle")==0)
  1679. {
  1680. FirmwareStatusNotificationStatus = 3;
  1681. }
  1682. else if(strcmp(status,"InstallationFailed")==0)
  1683. {
  1684. FirmwareStatusNotificationStatus = 4;
  1685. }
  1686. else if(strcmp(status,"Installing")==0)
  1687. {
  1688. FirmwareStatusNotificationStatus = 5;
  1689. }
  1690. else if(strcmp(status,"Installed")==0)
  1691. {
  1692. FirmwareStatusNotificationStatus = 6;
  1693. }
  1694. return result;
  1695. }
  1696. int sendHeartbeatRequest(int gun_index)
  1697. {
  1698. mtrace();
  1699. int result = FAIL;
  1700. char message[80]={0};
  1701. char guid[37]={0};
  1702. char tempdata[65]={0};
  1703. random_uuid(guid);
  1704. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1705. , MESSAGE_TYPE_CALL
  1706. , guid );
  1707. LWS_Send(message);
  1708. sprintf(tempdata, "Heartbeat,%d", 0);
  1709. 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*/)
  1710. {
  1711. result = PASS;
  1712. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1713. }
  1714. return result;
  1715. }
  1716. int sendStartTransactionRequest(int gun_index)
  1717. {
  1718. mtrace();
  1719. int result = FAIL;
  1720. char message[250]={0};
  1721. char guid[37]={0};
  1722. struct timeval tmnow;
  1723. struct tm *tm;
  1724. char buf[28];//, usec_buf[6];
  1725. char tempdata[65]={0};
  1726. DEBUG_INFO("sendStartTransactionRequest...");
  1727. gettimeofday(&tmnow, NULL);
  1728. time_t t;
  1729. t = time(NULL);
  1730. /*UTC time and date*/
  1731. tm = gmtime(&t);
  1732. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1733. #if 0 // remove temporally
  1734. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1735. strcat(buf,".");
  1736. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1737. strcat(buf,usec_buf);
  1738. #endif
  1739. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1740. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1741. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1742. // clear StartTransaction Response
  1743. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1744. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1745. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1746. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1748. {
  1749. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1750. {
  1751. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1752. {
  1753. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1754. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1755. }
  1756. }
  1757. for (int index = 0; index < CCS_QUANTITY; index++)
  1758. {
  1759. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1760. {
  1761. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1762. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1763. }
  1764. }
  1765. for (int index = 0; index < GB_QUANTITY; index++)
  1766. {
  1767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1768. {
  1769. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1770. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1771. }
  1772. }
  1773. }
  1774. else
  1775. {
  1776. for (int index = 0; index < AC_QUANTITY; index++)
  1777. {
  1778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1779. {
  1780. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1781. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1782. }
  1783. }
  1784. }//END OF ELSE
  1785. random_uuid(guid);
  1786. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1787. , MESSAGE_TYPE_CALL
  1788. , guid
  1789. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1790. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1791. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1792. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1793. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1794. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1795. 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*/)
  1796. {
  1797. result = PASS;
  1798. }
  1799. strcpy(queuedata, message);
  1800. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1801. if(GetTransactionQueueNum() == 1)
  1802. {
  1803. LWS_Send(message);
  1804. }
  1805. #if 0
  1806. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1807. 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*/)
  1808. {
  1809. result = PASS;
  1810. }
  1811. strcpy(queuedata, message);
  1812. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1813. #endif
  1814. //#ifdef SystemLogMessage
  1815. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1816. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1817. //#endif
  1818. return result;
  1819. }
  1820. int sendStatusNotificationRequest(int gun_index)
  1821. {
  1822. mtrace();
  1823. int result = FAIL;
  1824. char message[600]={0};
  1825. char guid[37];
  1826. int currentStatus = 0;
  1827. struct timeval tmnow;
  1828. struct tm *tm;
  1829. char buf[28];//, usec_buf[6];
  1830. char tempdata[65]={0};
  1831. gettimeofday(&tmnow, NULL);
  1832. time_t t;
  1833. t = time(NULL);
  1834. /*UTC time and date*/
  1835. tm = gmtime(&t);
  1836. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1837. #if 0 // remove temporally
  1838. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1839. strcat(buf,".");
  1840. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1841. strcat(buf,usec_buf);
  1842. #endif
  1843. printf("%s",buf);
  1844. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1845. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1846. // it's option
  1847. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1848. /*
  1849. enum _SYSTEM_STATUS
  1850. {
  1851. S_BOOTING = 0,
  1852. S_IDLE, = 1
  1853. S_AUTHORIZING, =2
  1854. S_REASSIGN_CHECK, =3
  1855. S_REASSIGN, =4
  1856. S_PRECHARGE, =5
  1857. S_PREPARING_FOR_EV, =6
  1858. S_PREPARING_FOR_EVSE, =7
  1859. S_CHARGING, =8
  1860. S_TERMINATING, =9
  1861. S_COMPLETE, =10
  1862. S_ALARM, =11
  1863. S_FAULT =12
  1864. }
  1865. */
  1866. //check Transaction active
  1867. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1868. {
  1869. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1870. {
  1871. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1872. {
  1873. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1874. {
  1875. currentStatus = 1; //OCPP Status: Preparing
  1876. }
  1877. else
  1878. {
  1879. currentStatus = 0; //OCPP Status: Available
  1880. }
  1881. }
  1882. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1883. {
  1884. currentStatus = 1; //OCPP Status: Preparing
  1885. }
  1886. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1887. {
  1888. currentStatus = 2; //OCPP Status: Charging
  1889. }
  1890. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1891. {
  1892. currentStatus = 5; //OCPP Status: Finishing
  1893. }
  1894. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1895. {
  1896. currentStatus = 4; //OCPP Status: SuspendedEV
  1897. }
  1898. 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
  1899. {
  1900. currentStatus = 7; //OCPP Status: Unavailable
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM,S_FAULT ---> Faulted
  1903. {
  1904. currentStatus = 8; //OCPP Status: Faulted
  1905. }
  1906. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1907. {
  1908. currentStatus = 6; //OCPP Status: Reserved
  1909. }
  1910. }//end of for CHAdeMO_QUANTITY
  1911. for (int index = 0; index < CCS_QUANTITY; index++)
  1912. {
  1913. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1914. {
  1915. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1916. {
  1917. currentStatus = 1; //OCPP Status: Preparing
  1918. }
  1919. else
  1920. {
  1921. currentStatus = 0; //OCPP Status: Available
  1922. }
  1923. }
  1924. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1925. {
  1926. currentStatus = 1; //OCPP Status: Preparing
  1927. }
  1928. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1929. {
  1930. currentStatus = 2; //OCPP Status: Charging
  1931. }
  1932. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1933. {
  1934. currentStatus = 5; //OCPP Status: Finishing
  1935. }
  1936. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //S_TERMINATING ---> SuspendedEV
  1937. {
  1938. currentStatus = 4; //OCPP Status: SuspendedEV
  1939. }
  1940. 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
  1941. {
  1942. currentStatus = 7; //OCPP Status : Unavailable
  1943. }
  1944. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM ,S_FAULT ---> Faulted
  1945. {
  1946. currentStatus = 8; //OCPP Status: Faulted
  1947. }
  1948. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1949. {
  1950. currentStatus = 6; //OCPP Status: Reserved
  1951. }
  1952. }
  1953. for (int index = 0; index < GB_QUANTITY; index++)
  1954. {
  1955. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1956. {
  1957. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1958. {
  1959. currentStatus = 1; //OCPP Status: Preparing
  1960. }
  1961. else
  1962. {
  1963. currentStatus = 0; //OCPP Status: Available
  1964. }
  1965. }
  1966. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1967. {
  1968. currentStatus = 1; //OCPP Status: Preparing
  1969. }
  1970. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1971. {
  1972. currentStatus = 2; //OCPP Status: Charging
  1973. }
  1974. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1975. {
  1976. currentStatus = 5; //OCPP Status: Finishing
  1977. }
  1978. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1979. {
  1980. currentStatus = 4; //OCPP Status: SuspendedEV
  1981. }
  1982. 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
  1983. {
  1984. currentStatus = 7; //OCPP Status: Unavailable
  1985. }
  1986. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) )) //S_ALARM ,S_FAULT ---> Faulted
  1987. {
  1988. currentStatus = 8; //OCPP Status: Faulted
  1989. }
  1990. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1991. {
  1992. currentStatus = 6; //OCPP Status: Reserved
  1993. }
  1994. }
  1995. }
  1996. else
  1997. {
  1998. for (int index = 0; index < AC_QUANTITY; index++)
  1999. {
  2000. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2001. {
  2002. 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))
  2003. {
  2004. currentStatus = 1; //OCPP Status: Preparing
  2005. }
  2006. else
  2007. {
  2008. currentStatus = 0; //OCPP Status: Available
  2009. }
  2010. }
  2011. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2012. {
  2013. currentStatus = 1; //OCPP Status: Preparing
  2014. }
  2015. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2016. {
  2017. currentStatus = 2; //OCPP Status: Charging
  2018. }
  2019. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2020. {
  2021. currentStatus = 5; //OCPP Status: Finishing
  2022. }
  2023. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  2024. {
  2025. currentStatus = 4; //OCPP Status: SuspendedEV
  2026. }
  2027. 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
  2028. {
  2029. currentStatus = 7; //OCPP Status: Unavailable
  2030. }
  2031. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM,S_FAULT ---> Faulted
  2032. {
  2033. currentStatus = 8; //OCPP Status: Faulted
  2034. }
  2035. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2036. {
  2037. currentStatus = 6; //OCPP Status: Reserved
  2038. }
  2039. }//end of for AC_QUANTITY
  2040. }//END OF ELSE
  2041. //it's option
  2042. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2043. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2044. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2045. random_uuid(guid);
  2046. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2047. , MESSAGE_TYPE_CALL
  2048. , guid
  2049. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2050. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2051. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2052. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2053. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2054. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2055. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2056. LWS_Send(message);
  2057. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2058. 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*/)
  2059. {
  2060. //DEBUG_ERROR("statusNotification mapitem pass");
  2061. result = PASS;
  2062. }
  2063. return result;
  2064. }
  2065. int sendStopTransactionRequest(int gun_index)
  2066. {
  2067. mtrace();
  2068. int result = FAIL;
  2069. //char message[1500]={0};
  2070. char guid[37]={0};
  2071. char tempdata[65]={0};
  2072. //int idx_sample=0;
  2073. DEBUG_ERROR("sendStopTransactionRequest \n");
  2074. memset(queuedata, 0, sizeof(queuedata));
  2075. //ENERGY_ACTIVE_IMPORT_REGISTER
  2076. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2077. {
  2078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2079. {
  2080. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2081. {
  2082. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2083. }
  2084. }// END OF CHAdeMO_QUANTITY
  2085. for (int index = 0; index < CCS_QUANTITY; index++)
  2086. {
  2087. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2088. {
  2089. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2090. }
  2091. }// END OF CCS_QUANTITY
  2092. for (int index = 0; index < GB_QUANTITY; index++)
  2093. {
  2094. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2095. {
  2096. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2097. }
  2098. }// END OF GB_QUANTITY
  2099. }
  2100. else
  2101. {
  2102. for (int index = 0; index < AC_QUANTITY; index++)
  2103. {
  2104. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2105. {
  2106. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2107. }
  2108. }// END OF AC_QUANTITY
  2109. }//END OF ELSE
  2110. //Stop Transaction Time
  2111. struct timeval tmnow;
  2112. struct tm *tm;
  2113. char buf[28];//, usec_buf[6];
  2114. gettimeofday(&tmnow, NULL);
  2115. time_t t;
  2116. t = time(NULL);
  2117. /*UTC time and date*/
  2118. tm = gmtime(&t);
  2119. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2121. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2122. random_uuid(guid);
  2123. /***********************************transactionData******************************************************/
  2124. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2126. //=================================
  2127. // Transaction_Begin
  2128. //=================================
  2129. // Energy.Active.Export.Interval
  2130. //idx_sample=0;
  2131. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  2132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2134. 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*/]);
  2135. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2136. {
  2137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2138. }
  2139. else
  2140. {
  2141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2142. }
  2143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2145. //=================================
  2146. // Transaction_End
  2147. //=================================
  2148. //Current.Export
  2149. //idx_sample=1;
  2150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2151. {
  2152. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2153. {
  2154. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2155. {
  2156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2157. }
  2158. }
  2159. for (int index = 0; index < CCS_QUANTITY; index++)
  2160. {
  2161. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2162. {
  2163. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2164. }
  2165. }
  2166. for (int index = 0; index < GB_QUANTITY; index++)
  2167. {
  2168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2169. {
  2170. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2171. }
  2172. }
  2173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2174. }
  2175. else
  2176. {
  2177. for (int index = 0; index < AC_QUANTITY; index++)
  2178. {
  2179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2180. {
  2181. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2182. }
  2183. }
  2184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2185. }// END FOR AC ELSE
  2186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2189. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2192. //Energy.Active.Export.Interval
  2193. //idx_sample=2;
  2194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2195. {
  2196. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2197. {
  2198. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2199. {
  2200. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2201. }
  2202. }
  2203. for (int index = 0; index < CCS_QUANTITY; index++)
  2204. {
  2205. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2206. {
  2207. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2208. }
  2209. }
  2210. for (int index = 0; index < GB_QUANTITY; index++)
  2211. {
  2212. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2213. {
  2214. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2215. }
  2216. }
  2217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2218. }
  2219. else
  2220. {
  2221. for (int index = 0; index < AC_QUANTITY; index++)
  2222. {
  2223. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2224. {
  2225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2226. }
  2227. }
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2229. }// END FOR AC ELSE
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2233. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2236. //Power.Active.Export
  2237. //idx_sample=3;
  2238. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2239. {
  2240. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2241. {
  2242. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2243. {
  2244. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2245. }
  2246. }
  2247. for (int index = 0; index < CCS_QUANTITY; index++)
  2248. {
  2249. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2250. {
  2251. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2252. }
  2253. }
  2254. for (int index = 0; index < GB_QUANTITY; index++)
  2255. {
  2256. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2257. {
  2258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2259. }
  2260. }
  2261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2262. }
  2263. else
  2264. {
  2265. for (int index = 0; index < AC_QUANTITY; index++)
  2266. {
  2267. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2268. {
  2269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2270. }
  2271. }
  2272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2273. }// END FOR AC ELSE
  2274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2277. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2280. //Voltage
  2281. //idx_sample=4;
  2282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2283. {
  2284. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2285. {
  2286. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2287. {
  2288. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2289. }
  2290. }
  2291. for (int index = 0; index < CCS_QUANTITY; index++)
  2292. {
  2293. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2294. {
  2295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2296. }
  2297. }
  2298. for (int index = 0; index < GB_QUANTITY; index++)
  2299. {
  2300. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2301. {
  2302. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2303. }
  2304. }
  2305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2306. }
  2307. else
  2308. {
  2309. for (int index = 0; index < AC_QUANTITY; index++)
  2310. {
  2311. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2312. {
  2313. 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
  2314. }
  2315. }
  2316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2317. }// END FOR AC ELSE
  2318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2321. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2322. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2324. //SoC
  2325. //idx_sample=5;
  2326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2327. {
  2328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2329. {
  2330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2331. {
  2332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2333. }
  2334. }
  2335. for (int index = 0; index < CCS_QUANTITY; index++)
  2336. {
  2337. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2338. {
  2339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2340. }
  2341. }
  2342. for (int index = 0; index < GB_QUANTITY; index++)
  2343. {
  2344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2345. {
  2346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2347. }
  2348. }
  2349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2350. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2355. } // END FOR DC CASE
  2356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2357. {
  2358. 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\"}]}]}]"
  2359. ,MESSAGE_TYPE_CALL
  2360. ,guid
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2366. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2409. );
  2410. }
  2411. else
  2412. {
  2413. 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\"}]}]}]"
  2414. ,MESSAGE_TYPE_CALL
  2415. ,guid
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2417. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2418. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2420. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2421. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2427. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2428. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2429. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2446. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2447. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2448. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2449. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2450. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2451. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2452. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2453. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2454. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2455. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2456. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2457. );
  2458. }
  2459. #if 0 // for TempStopTransaction
  2460. //Delete TempStopTransaction
  2461. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  2462. {
  2463. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  2464. }
  2465. #endif
  2466. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2467. if(hashmap_operation(0, guid, tempdata) == 1)
  2468. {
  2469. result = PASS;
  2470. DEBUG_INFO("StopTransaction mapitem pass\n");
  2471. }
  2472. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2473. if(GetTransactionQueueNum() == 1)
  2474. {
  2475. LWS_Send(queuedata);
  2476. }
  2477. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2478. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2479. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2480. {
  2481. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2482. }
  2483. //for test
  2484. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2485. return result;
  2486. }
  2487. int sendMeterValuesRequest(int gun_index)
  2488. {
  2489. mtrace();
  2490. int result = FAIL;
  2491. // char message[1500]={0};
  2492. char guid[37]={0};
  2493. //int idx_sample=0;
  2494. //int length = 0;
  2495. char tempdata[65]={0};
  2496. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2497. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2498. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2499. {
  2500. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2501. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2502. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2503. return result;
  2504. }
  2505. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2506. {
  2507. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2508. }
  2509. memset(queuedata, 0, sizeof(queuedata));
  2510. //set value
  2511. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2512. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2513. random_uuid(guid);
  2514. //UTC Date time
  2515. struct timeval tmnow;
  2516. struct tm *tm;
  2517. char buf[28];//, usec_buf[6];
  2518. gettimeofday(&tmnow, NULL);
  2519. time_t t;
  2520. t = time(NULL);
  2521. /*UTC time and date*/
  2522. tm = gmtime(&t);
  2523. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2525. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2526. //idx_sample=0;
  2527. //********************************(1)Current.Export************************************************/
  2528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2529. {
  2530. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2531. {
  2532. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2533. {
  2534. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2535. }
  2536. }
  2537. for (int index = 0; index < CCS_QUANTITY; index++)
  2538. {
  2539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2540. {
  2541. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2542. }
  2543. }
  2544. for (int index = 0; index < GB_QUANTITY; index++)
  2545. {
  2546. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2547. {
  2548. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2549. }
  2550. }
  2551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2552. }
  2553. else
  2554. {
  2555. for (int index = 0; index < AC_QUANTITY; index++)
  2556. {
  2557. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2558. {
  2559. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2560. }
  2561. }
  2562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2563. }// END FOR AC ELSE
  2564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2567. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2568. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2570. //idx_sample=1;
  2571. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2572. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2573. {
  2574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2577. {
  2578. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2579. }
  2580. }
  2581. for (int index = 0; index < CCS_QUANTITY; index++)
  2582. {
  2583. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2584. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2585. {
  2586. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2587. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2588. }
  2589. }
  2590. for (int index = 0; index < GB_QUANTITY; index++)
  2591. {
  2592. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2593. {
  2594. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2595. }
  2596. }
  2597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2598. }
  2599. else
  2600. {
  2601. for (int index = 0; index < AC_QUANTITY; index++)
  2602. {
  2603. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2604. {
  2605. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2606. }
  2607. }
  2608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2609. }//END FOR AC ELSE
  2610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2613. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2616. //idx_sample=2;
  2617. //********************************(4)Power.Active.Export************************************************/
  2618. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2619. {
  2620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2621. {
  2622. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2623. {
  2624. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2625. }
  2626. }
  2627. for (int index = 0; index < CCS_QUANTITY; index++)
  2628. {
  2629. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2630. {
  2631. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2632. }
  2633. }
  2634. for (int index = 0; index < GB_QUANTITY; index++)
  2635. {
  2636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2637. {
  2638. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2639. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2640. }
  2641. }
  2642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2643. }
  2644. else
  2645. {
  2646. for (int index = 0; index < AC_QUANTITY; index++)
  2647. {
  2648. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2649. {
  2650. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2651. }
  2652. }
  2653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2654. }// END FOR AC ELSE
  2655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2658. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2661. //idx_sample=3;
  2662. //***********************************************(5)VOLTAGE******************************************************/
  2663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2664. {
  2665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2666. {
  2667. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2668. {
  2669. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2670. }
  2671. }
  2672. for (int index = 0; index < CCS_QUANTITY; index++)
  2673. {
  2674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2675. {
  2676. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2677. }
  2678. }
  2679. for (int index = 0; index < GB_QUANTITY; index++)
  2680. {
  2681. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2682. {
  2683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2684. }
  2685. }
  2686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2687. }
  2688. else
  2689. {
  2690. for (int index = 0; index < AC_QUANTITY; index++)
  2691. {
  2692. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2693. {
  2694. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2695. }
  2696. }
  2697. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2698. }//END FOR AC ELSE
  2699. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2700. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2702. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2703. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2705. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2706. {
  2707. //idx_sample=4;
  2708. //sampledValue = NULL;
  2709. //***********************************************(6)SOC******************************************************/
  2710. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2711. {
  2712. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2713. {
  2714. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2715. }
  2716. }
  2717. for (int index = 0; index < CCS_QUANTITY; index++)
  2718. {
  2719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2720. {
  2721. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2722. }
  2723. }
  2724. for (int index = 0; index < GB_QUANTITY; index++)
  2725. {
  2726. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2727. {
  2728. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2729. }
  2730. }
  2731. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2737. }
  2738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2739. {
  2740. 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\"}]}]}]"
  2741. ,MESSAGE_TYPE_CALL
  2742. ,guid
  2743. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2744. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2745. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2781. );
  2782. }
  2783. else
  2784. {
  2785. 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\"}]}]}]"
  2786. ,MESSAGE_TYPE_CALL
  2787. ,guid
  2788. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2789. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2790. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2819. );
  2820. }
  2821. // Put request guid to hash map
  2822. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2823. 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*/)
  2824. {
  2825. result = PASS;
  2826. DEBUG_INFO("MeterValues mapitem pass\n");
  2827. }
  2828. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2829. if(GetTransactionQueueNum() == 1)
  2830. {
  2831. LWS_Send(queuedata);
  2832. }
  2833. #if 0
  2834. // Put request guid to hash map
  2835. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2836. 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*/)
  2837. {
  2838. result = PASS;
  2839. DEBUG_INFO("MeterValues mapitem pass\n");
  2840. }
  2841. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2842. #endif
  2843. return result;
  2844. }
  2845. //==========================================
  2846. // send confirm routine
  2847. //==========================================
  2848. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2849. {
  2850. mtrace();
  2851. int result = FAIL;
  2852. char message[100]={0};
  2853. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2854. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2855. LWS_Send(message);
  2856. result = TRUE;
  2857. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2858. return result;
  2859. }
  2860. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2861. {
  2862. mtrace();
  2863. int result = FAIL;
  2864. char message[100]={0};
  2865. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2866. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2867. LWS_Send(message);
  2868. result = TRUE;
  2869. return result;
  2870. }
  2871. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2872. {
  2873. mtrace();
  2874. int result = FAIL;
  2875. char message[100]={0};
  2876. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2877. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2878. LWS_Send(message);
  2879. result = TRUE;
  2880. return result;
  2881. }
  2882. int sendClearCacheConfirmation(char *uuid,char *payload)
  2883. {
  2884. mtrace();
  2885. int result = FAIL;
  2886. char message[500]={0};
  2887. // int count = 0;
  2888. // int gun_index = 0;
  2889. // char guid[37];
  2890. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2891. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2892. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2893. LWS_Send(message);
  2894. return result;
  2895. }
  2896. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2897. {
  2898. mtrace();
  2899. int result = FAIL;
  2900. char message[500]={0};
  2901. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2902. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2903. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2904. LWS_Send(message);
  2905. return result;
  2906. }
  2907. int sendDataTransferConfirmation(char *uuid,char *payload)
  2908. {
  2909. mtrace();
  2910. char statusStr[20]={0};
  2911. char dataStr[10]={0};
  2912. char sstr[20]={0};
  2913. int c = 0;
  2914. char *loc;
  2915. int result = FAIL;
  2916. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2917. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2918. /**********************status**************************/
  2919. loc = strstr(payload, "status");
  2920. memset(sstr ,0, sizeof(sstr) );
  2921. c = 0;
  2922. while (loc[3+strlen("status")+c] != '\"')
  2923. {
  2924. sstr[c] = loc[3+strlen("status")+c];
  2925. c++;
  2926. }
  2927. sstr[c] = '\0';
  2928. strcpy(statusStr, sstr);
  2929. /**********************data**************************/
  2930. loc = strstr(payload, "data");
  2931. memset(sstr ,0, sizeof(sstr) );
  2932. c = 0;
  2933. while (loc[3+strlen("data")+c] != '\"')
  2934. {
  2935. sstr[c] = loc[3+strlen("data")+c];
  2936. c++;
  2937. }
  2938. sstr[c] = '\0';
  2939. strcpy(dataStr, sstr);
  2940. return result;
  2941. }
  2942. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2943. {
  2944. mtrace();
  2945. int result = FAIL;
  2946. char message[1000]={0};
  2947. double diff_f = 0.0;
  2948. int diff_i = 0;
  2949. int diffSeconds = 0;
  2950. struct tm tp;
  2951. int TimeZero = FALSE;
  2952. int CompositeScheduleIndex = 0;
  2953. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2954. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2955. {
  2956. TimeZero = TRUE;
  2957. }
  2958. else
  2959. {
  2960. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2961. }
  2962. if(TimeZero == FALSE)
  2963. {
  2964. tp.tm_isdst = -1;
  2965. time_t utc = mktime(&tp);
  2966. time_t t = time(NULL);
  2967. diff_f = difftime(t, utc);
  2968. diff_i = (int)diff_f;
  2969. diffSeconds = diff_i % 86400;//86400 seconds/day
  2970. }
  2971. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2972. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2973. #if 0 //remove temporally
  2974. 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}"
  2975. ,MESSAGE_TYPE_CALLRESULT
  2976. ,uuid
  2977. ,payload
  2978. ,connectorIdInt
  2979. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2980. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2981. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2982. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2983. #endif
  2984. if(nPeriod == 0)
  2985. {
  2986. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2987. {
  2988. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2989. ,MESSAGE_TYPE_CALLRESULT
  2990. ,uuid
  2991. ,payload
  2992. ,connectorIdInt);
  2993. }
  2994. else
  2995. {
  2996. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2997. ,MESSAGE_TYPE_CALLRESULT
  2998. ,uuid
  2999. ,payload
  3000. ,connectorIdInt
  3001. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3002. }
  3003. }
  3004. else
  3005. {
  3006. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3007. ,MESSAGE_TYPE_CALLRESULT
  3008. ,uuid
  3009. ,payload
  3010. ,connectorIdInt
  3011. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3012. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3013. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3014. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3015. int len = nPeriod;
  3016. //Last Period StartPriod is less than diffSeconds
  3017. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds) || (diffSeconds == 0))
  3018. {
  3019. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3020. , 0
  3021. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3022. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3023. }
  3024. else
  3025. {
  3026. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3027. {
  3028. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) < diffSeconds) && ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod % 86400) > diffSeconds))//if (idx_sample == 0)
  3029. {
  3030. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3031. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3032. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3033. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3034. }
  3035. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3036. {
  3037. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3038. , ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) - 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*/))
  3039. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3040. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3041. }
  3042. }
  3043. }
  3044. sprintf(message + strlen(message), "]}}]");
  3045. }
  3046. LWS_Send(message);
  3047. result = TRUE;
  3048. return result;
  3049. }
  3050. int sendGetConfigurationConfirmation(char *uuid)
  3051. {
  3052. mtrace();
  3053. int result = FAIL;
  3054. int MaxKeySupported = 0;
  3055. int sentConfigurationNumber= 0;
  3056. int sentunConfigurationNumber= 0;
  3057. char message[4000]={0};
  3058. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3059. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3060. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3061. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3062. ,MESSAGE_TYPE_CALLRESULT
  3063. ,uuid );
  3064. //configuration key
  3065. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3066. {
  3067. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3068. {
  3069. if (sentConfigurationNumber == 0)
  3070. {
  3071. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3072. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3073. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3074. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3075. }
  3076. else
  3077. {
  3078. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3079. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3080. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3081. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3082. }
  3083. sentConfigurationNumber = sentConfigurationNumber + 1;
  3084. }
  3085. }
  3086. sprintf(message + strlen(message), "]");
  3087. if(UnknownKeynum != 0)
  3088. {
  3089. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3090. //unkown key
  3091. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3092. {
  3093. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3094. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3095. if(sentunConfigurationNumber == 0)
  3096. {
  3097. sprintf(message + strlen(message), "\"%s\""
  3098. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3099. }
  3100. else
  3101. {
  3102. sprintf(message + strlen(message), ",\"%s\""
  3103. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3104. }
  3105. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3106. }
  3107. sprintf(message + strlen(message), "]");
  3108. }
  3109. sprintf(message + strlen(message), "}]");
  3110. LWS_Send(message);
  3111. return result;
  3112. }
  3113. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3114. {
  3115. mtrace();
  3116. int result = FAIL;
  3117. char message[400]={0};
  3118. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3119. if(strcmp(payload,"")==0)
  3120. {
  3121. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3122. }
  3123. else
  3124. {
  3125. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3126. }
  3127. LWS_Send(message);
  3128. result = TRUE;
  3129. return result;
  3130. }
  3131. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3132. {
  3133. mtrace();
  3134. int result = FAIL;
  3135. char message[80]={0};
  3136. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3137. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3138. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3139. LWS_Send(message);
  3140. result = TRUE;
  3141. return result;
  3142. }
  3143. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3144. {
  3145. mtrace();
  3146. int result = FAIL;
  3147. char message[80]={0};
  3148. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3149. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3150. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3151. LWS_Send(message);
  3152. result = TRUE;
  3153. return result;
  3154. }
  3155. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3156. {
  3157. mtrace();
  3158. int result = FAIL;
  3159. char message[80]={0};
  3160. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3161. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3162. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3163. LWS_Send(message);
  3164. result = TRUE;
  3165. return result;
  3166. }
  3167. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3168. {
  3169. mtrace();
  3170. int result = FAIL;
  3171. char message[80]={0};
  3172. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3173. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3174. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3175. LWS_Send(message);
  3176. result = TRUE;
  3177. return result;
  3178. }
  3179. int sendResetConfirmation(char *uuid,char *payload)
  3180. {
  3181. mtrace();
  3182. int result = FAIL;
  3183. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3184. char message[80]={0};
  3185. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3186. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3187. LWS_Send(message);
  3188. result = TRUE;
  3189. return result;
  3190. }
  3191. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3192. {
  3193. mtrace();
  3194. int result = FAIL;
  3195. char message[500]={0};
  3196. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3197. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3198. LWS_Send(message);
  3199. result = TRUE;
  3200. return result;
  3201. }
  3202. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3203. {
  3204. mtrace();
  3205. int result = FAIL;
  3206. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3207. char message[80]={0};
  3208. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3209. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3210. LWS_Send(message);
  3211. result = TRUE;
  3212. return result;
  3213. }
  3214. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3215. {
  3216. mtrace();
  3217. int result = FAIL;
  3218. char message[80]={0};
  3219. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3220. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3221. LWS_Send(message);
  3222. result = TRUE;
  3223. return result;
  3224. }
  3225. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3226. {
  3227. mtrace();
  3228. int result = FAIL;
  3229. char message[80]={0};
  3230. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3231. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3232. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3233. LWS_Send(message);
  3234. result = TRUE;
  3235. return result;
  3236. }
  3237. int sendUpdateFirmwareConfirmation(char *uuid)
  3238. {
  3239. mtrace();
  3240. int result = FAIL;
  3241. char message[60]={0};
  3242. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3243. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3244. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3245. LWS_Send(message);
  3246. result = TRUE;
  3247. return result;
  3248. }
  3249. //==========================================
  3250. // send CallError routine
  3251. //==========================================
  3252. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3253. {
  3254. mtrace();
  3255. //int result = FAIL;
  3256. char message[220]={0};
  3257. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3258. #ifdef SystemLogMessage
  3259. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3260. uniqueId, action, errorCode, errorDescription);
  3261. #endif
  3262. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3263. LWS_Send(message);
  3264. //result = TRUE;
  3265. }
  3266. //==========================================
  3267. // Handle server request routine Start
  3268. //==========================================
  3269. #define GUN_NUM 1
  3270. int handleCancelReservationRequest(char *uuid, char *payload)
  3271. {
  3272. mtrace();
  3273. int result = FAIL;
  3274. int gunNO = 0;
  3275. int reservationIdInt =0;
  3276. char comfirmstr[20];
  3277. int c = 0;
  3278. int copyTo = 0;
  3279. char *loc;
  3280. char sstr[100]={0};
  3281. DEBUG_INFO("handle CancelReservationRequest\n");
  3282. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3283. c = 0;
  3284. copyTo = 0;
  3285. loc = strstr(payload, "reservationId");
  3286. memset(sstr ,0, sizeof(sstr) );
  3287. while (loc[strlen("reservationId")+2+c] != '}')
  3288. {
  3289. if(loc[strlen("interval")+2+c] != ' ')
  3290. {
  3291. sstr[copyTo] = loc[strlen("reservationId")+2+c];
  3292. copyTo = copyTo + 1;
  3293. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3294. }
  3295. c++;
  3296. }
  3297. sstr[copyTo] = '\0';
  3298. reservationIdInt = atoi(sstr);
  3299. memset(comfirmstr, 0, sizeof comfirmstr);
  3300. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3301. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3302. //check Transaction active
  3303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3304. {
  3305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3306. {
  3307. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3308. {
  3309. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3310. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3311. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3312. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3313. goto end;
  3314. }
  3315. }
  3316. for (int index = 0; index < CCS_QUANTITY; index++)
  3317. {
  3318. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3319. {
  3320. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3321. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3322. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3323. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3324. goto end;
  3325. }
  3326. }
  3327. for (int index = 0; index < GB_QUANTITY; index++)
  3328. {
  3329. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3330. {
  3331. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3332. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3333. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3334. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3335. goto end;
  3336. }
  3337. }
  3338. }
  3339. else
  3340. {
  3341. for (int index = 0; index < AC_QUANTITY; index++)
  3342. {
  3343. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3344. {
  3345. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3346. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3347. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3348. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3349. goto end;
  3350. }
  3351. }
  3352. }// END FOR AC ELSE
  3353. //The reservationId does NOT match the reservationId
  3354. sendCancelReservationConfirmation(uuid, comfirmstr);
  3355. end:
  3356. // Fill in ocpp packet uuid
  3357. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3358. return result;
  3359. }
  3360. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3361. {
  3362. mtrace();
  3363. int result = FAIL;
  3364. int gunIndex = 0;
  3365. char sstr[90]={0},sstrtemp[50]={ 0 };
  3366. char typeStr[16]={0};
  3367. char comfirmstr[20];
  3368. int specificId = FALSE;
  3369. char *loc;
  3370. //int intervalInt = 0;
  3371. int c = 0;
  3372. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3373. strcpy(sstrtemp, stringtrimspace(payload));
  3374. /*** connectorId ****/
  3375. loc = strstr(sstrtemp, "connectorId");
  3376. memset(sstr ,0, sizeof(sstr) );
  3377. c = 0;
  3378. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') ) // 2: ":
  3379. {
  3380. sstr[c] = loc[strlen("connectorId")+2+c];
  3381. c++;
  3382. }
  3383. sstr[c] = '\0';
  3384. gunIndex = atoi(sstr);
  3385. /***type ****/
  3386. loc = strstr(sstrtemp, "type");
  3387. memset(sstr ,0, sizeof(sstr) );
  3388. c = 0;
  3389. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3390. {
  3391. sstr[c] = loc[3+strlen("type")+c];
  3392. c++;
  3393. }
  3394. sstr[c] = '\0';
  3395. strcpy(typeStr, sstr);
  3396. if(gunIndex != 0)
  3397. {
  3398. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3399. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3400. }
  3401. else
  3402. {
  3403. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3404. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3405. }
  3406. memset(comfirmstr, 0, sizeof comfirmstr);
  3407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3408. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3409. {
  3410. specificId = TRUE;
  3411. }
  3412. if(specificId == FALSE)
  3413. goto end;
  3414. if(gunIndex != 0)
  3415. {
  3416. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3417. }
  3418. else
  3419. {
  3420. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3421. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3422. }
  3423. /*
  3424. enum SYSTEM_STATUS
  3425. {
  3426. SYS_MODE_BOOTING = 0,
  3427. SYS_MODE_IDLE = 1,
  3428. SYS_MODE_AUTHORIZING = 2,
  3429. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3430. SYS_MODE_REASSIGN = 4,
  3431. SYS_MODE_PREPARING = 5,
  3432. SYS_MODE_PREPARE_FOR_EV = 6,
  3433. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3434. SYS_MODE_CHARGING = 8,
  3435. SYS_MODE_TERMINATING = 9,
  3436. SYS_MODE_COMPLETE = 10,
  3437. SYS_MODE_ALARM = 11,
  3438. SYS_MODE_FAULT = 12,
  3439. SYS_MODE_RESERVATION = 13,
  3440. SYS_MODE_BOOKING = 14,
  3441. SYS_MODE_MAINTAIN = 15,
  3442. SYS_MODE_DEBUG = 16,
  3443. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3444. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3445. SYS_MODE_UPDATE = 19
  3446. };
  3447. */
  3448. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3449. {
  3450. //check Transaction active
  3451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3452. {
  3453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3454. {
  3455. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3456. {
  3457. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3458. {
  3459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3460. }
  3461. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3462. {
  3463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3464. }
  3465. else
  3466. {
  3467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3468. }
  3469. goto end;
  3470. }
  3471. }//END FOR CHAdeMO_QUANTITY
  3472. for (int index = 0; index < CCS_QUANTITY; index++)
  3473. {
  3474. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3475. {
  3476. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3477. {
  3478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3479. }
  3480. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3481. {
  3482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3483. }
  3484. else
  3485. {
  3486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3487. }
  3488. goto end;
  3489. }
  3490. }//END FOR CCS_QUANTITY
  3491. for (int index = 0; index < GB_QUANTITY; index++)
  3492. {
  3493. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3494. {
  3495. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3496. {
  3497. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3498. }
  3499. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3500. {
  3501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3502. }
  3503. else
  3504. {
  3505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3506. }
  3507. goto end;
  3508. }
  3509. }// END FOR GB_QUANTITY
  3510. }
  3511. else
  3512. {
  3513. for (int index = 0; index < AC_QUANTITY; index++)
  3514. {
  3515. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3516. {
  3517. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3518. {
  3519. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3520. }
  3521. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3522. {
  3523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3524. }
  3525. else
  3526. {
  3527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3528. }
  3529. goto end;
  3530. }
  3531. }//END FOR AC_QUANTITY
  3532. }// END FOR AC ELSE
  3533. }//END FOR AvailabilityTypeStr[Inoperative]
  3534. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3535. {
  3536. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3537. //check Transaction active
  3538. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3539. {
  3540. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3541. {
  3542. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3543. {
  3544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3545. goto end;
  3546. }
  3547. }//END FOR CHAdeMO_QUANTITY
  3548. for (int index = 0; index < CCS_QUANTITY; index++)
  3549. {
  3550. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3551. {
  3552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3553. goto end;
  3554. }
  3555. }//END FOR CCS_QUANTITY
  3556. for (int index = 0; index < GB_QUANTITY; index++)
  3557. {
  3558. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3559. {
  3560. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3562. goto end;
  3563. }
  3564. }// END FOR GB_QUANTITY
  3565. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3566. }
  3567. else
  3568. {
  3569. for (int index = 0; index < AC_QUANTITY; index++)
  3570. {
  3571. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3572. {
  3573. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3574. goto end;
  3575. }
  3576. }//END FOR CHAdeMO_QUANTITY
  3577. }//END FOR AC ELSE
  3578. }//END FOR AvailabilityTypeStr[Operative]
  3579. end:
  3580. if(gunIndex != 0)
  3581. {
  3582. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3583. }
  3584. else
  3585. {
  3586. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3587. }
  3588. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3589. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3590. return result;
  3591. }
  3592. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3593. {
  3594. mtrace();
  3595. int result = FAIL;
  3596. char sstr[100]={0},sstrtemp[160]={ 0 };
  3597. char keystr[40]={0};
  3598. char valuestr[100]={0};
  3599. char *loc;
  3600. int c = 0;
  3601. char comfirmstr[20]={0};
  3602. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3603. strcpy(sstrtemp, stringtrimspace(payload));
  3604. /***key ****/
  3605. loc = strstr(sstrtemp, "key");
  3606. memset(sstr ,0, sizeof(sstr) );
  3607. c = 0;
  3608. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3609. {
  3610. sstr[c] = loc[3+strlen("key")+c];
  3611. c++;
  3612. }
  3613. sstr[c] = '\0';
  3614. strcpy(keystr, sstr);
  3615. //DEBUG_INFO( "keystr=%s\n",keystr);
  3616. /***value ****/
  3617. loc = strstr(sstrtemp, "value");
  3618. memset(sstr ,0, sizeof(sstr) );
  3619. c = 0;
  3620. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3621. {
  3622. sstr[c] = loc[3+strlen("value")+c];
  3623. c++;
  3624. }
  3625. sstr[c] = '\0';
  3626. strcpy(valuestr, sstr);
  3627. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3628. if((uuid==NULL) || (payload ==NULL) )
  3629. {
  3630. #ifdef Debug
  3631. DEBUG_INFO("payload is null\n");
  3632. #endif
  3633. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3634. }
  3635. else
  3636. {
  3637. int status = setKeyValue(keystr, valuestr);
  3638. switch(status)
  3639. {
  3640. case ConfigurationStatus_Accepted:
  3641. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3642. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3643. StoreConfigurationTable();
  3644. break;
  3645. case ConfigurationStatus_Rejected:
  3646. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3647. break;
  3648. case RebootRequired:
  3649. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3650. StoreConfigurationTable();
  3651. break;
  3652. case NotSupported:
  3653. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3654. break;
  3655. default:
  3656. break;
  3657. }
  3658. }
  3659. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3660. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3661. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3662. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3663. {
  3664. ChageWebSocketPingInterval(atoi(valuestr));
  3665. }
  3666. return result;
  3667. }
  3668. int handleClearCacheRequest(char *uuid, char *payload)
  3669. {
  3670. mtrace();
  3671. int result = FAIL;
  3672. char comfirmstr[20];
  3673. int fd;
  3674. char rmFileCmd[100]={0};
  3675. struct stat stats;
  3676. DEBUG_INFO("handle ClearCacheRequest\n");
  3677. stat("/Storage/OCPP", &stats);
  3678. // Check for directory existence
  3679. if (S_ISDIR(stats.st_mode) == 1)
  3680. {
  3681. //DEBUG_ERROR("\n OCPP directory exist \n");
  3682. }
  3683. else
  3684. {
  3685. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3686. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3687. system(rmFileCmd);
  3688. }
  3689. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3690. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3691. {
  3692. DEBUG_INFO("AuthorizationCache file exist.\n");
  3693. }
  3694. else
  3695. {
  3696. DEBUG_INFO("AuthorizationCache file not exist\n");
  3697. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3698. if(log == NULL)
  3699. {
  3700. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3701. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3702. goto end;
  3703. }
  3704. else
  3705. {
  3706. fclose(log);
  3707. }
  3708. }
  3709. fd = open(AuthorizationCache_JSON,O_RDWR);
  3710. if(fd < 0)
  3711. {
  3712. DEBUG_INFO("open AuthorizationCache file failed\n");
  3713. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3714. }
  3715. else
  3716. {
  3717. DEBUG_INFO("open AuthorizationCache file successful\n");
  3718. //* 清空? 件 */
  3719. ftruncate(fd,0);
  3720. //* ? 新设置? 件? 移??*/
  3721. lseek(fd,0,SEEK_SET);
  3722. close(fd);
  3723. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3724. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3725. }
  3726. end:
  3727. sendClearCacheConfirmation(uuid, comfirmstr);
  3728. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3729. return result;
  3730. }
  3731. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3732. {
  3733. mtrace();
  3734. int result = FAIL;
  3735. int resultRename;
  3736. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3737. char chargingProfilePurposeStr[26]={0};
  3738. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3739. char tempchargingProfilePurposeStr[26]={0};
  3740. char sstr[160]={0},sstrtemp[160]={ 0 };//sstr[200]={ 0 };
  3741. char str[100]={0};
  3742. int c = 0;
  3743. //int i = 0;
  3744. //char * pch;
  3745. char *loc;
  3746. char fname[200]={0};
  3747. char comfirmstr[20]={0};
  3748. char word[1600]={0};
  3749. int clearflag = FALSE;
  3750. int chargingProfileIdIsNULL = FALSE;
  3751. int connectorIsNULL = FALSE;
  3752. int chargingProfilePurposeIsNULL = FALSE;
  3753. int stackLevelIsNULL = FALSE;
  3754. //int GotoEnd = FALSE;
  3755. FILE *fptr1, *fptr2;
  3756. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3757. int n_chargingProfile=0;
  3758. int isEmptyFile = FALSE;
  3759. char sLineWord[1600]={0};
  3760. char chargingProfiles[10][100]={0};
  3761. int ChargeProfileCount = 0;
  3762. char ch;
  3763. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3764. strcpy(sstrtemp, stringtrimspace(payload));
  3765. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3766. //***id ****/
  3767. c = 0;
  3768. loc = strstr(sstrtemp, "id");
  3769. memset(sstr ,0, sizeof(sstr) );
  3770. if(loc == NULL)
  3771. {
  3772. chargingProfileIdIsNULL = TRUE;
  3773. }
  3774. else
  3775. {
  3776. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3777. {
  3778. sstr[c] = loc[strlen("id")+2+c];
  3779. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3780. c++;
  3781. }
  3782. sstr[c] = '\0';
  3783. chargingProfileIdInt = atoi(sstr);
  3784. }
  3785. //***connectorId ****/
  3786. c=0;
  3787. loc = strstr(sstrtemp, "connectorId");
  3788. memset(sstr ,0, sizeof(sstr) );
  3789. if(loc == NULL)
  3790. {
  3791. connectorIsNULL = TRUE;
  3792. }
  3793. else
  3794. {
  3795. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3796. {
  3797. sstr[c] = loc[strlen("connectorId")+2+c];
  3798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3799. c++;
  3800. }
  3801. sstr[c] = '\0';
  3802. connectorIdInt = atoi(sstr);
  3803. }
  3804. //***chargingProfilePurpose ****/
  3805. loc = strstr(sstrtemp, "chargingProfilePurpose");
  3806. memset(sstr ,0, sizeof(sstr) );
  3807. c = 0;
  3808. if(loc == NULL)
  3809. {
  3810. chargingProfilePurposeIsNULL = TRUE;
  3811. }
  3812. else
  3813. {
  3814. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3815. {
  3816. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3817. c++;
  3818. }
  3819. sstr[c] = '\0';
  3820. strcpy(chargingProfilePurposeStr, sstr);
  3821. }
  3822. //***stackLevel ****/
  3823. c=0;
  3824. loc = strstr(sstrtemp, "stackLevel");
  3825. memset(sstr ,0, sizeof(sstr) );
  3826. if(loc == NULL)
  3827. {
  3828. stackLevelIsNULL = TRUE;
  3829. }
  3830. else
  3831. {
  3832. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3833. {
  3834. sstr[c] = loc[strlen("stackLevel")+2+c];
  3835. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3836. c++;
  3837. }
  3838. sstr[c] = '\0';
  3839. stackLevelInt = atoi(sstr);
  3840. }
  3841. if(connectorIsNULL == FALSE)
  3842. {
  3843. switch(connectorIdInt)
  3844. {
  3845. case 0:
  3846. if(chargingProfilePurposeIsNULL == TRUE)
  3847. {
  3848. int l = 0;
  3849. strcpy(fname, ChargePointMaxProfile_JSON);
  3850. if((access(fname,F_OK))!=-1)
  3851. {
  3852. strcpy(chargingProfiles[l], fname);
  3853. l = l + 1;
  3854. }
  3855. strcpy(fname, TxDefaultProfile_0_JSON);
  3856. if((access(fname,F_OK))!=-1)
  3857. {
  3858. strcpy(chargingProfiles[l], fname);
  3859. l = l + 1;
  3860. }
  3861. ChargeProfileCount = l;
  3862. }
  3863. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3864. {
  3865. strcpy(fname, ChargePointMaxProfile_JSON);
  3866. if((access(fname,F_OK))!=-1)
  3867. {
  3868. strcpy(chargingProfiles[0], fname);
  3869. ChargeProfileCount = 1;
  3870. }
  3871. }
  3872. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3873. {
  3874. strcpy(fname, TxDefaultProfile_0_JSON);
  3875. if((access(fname,F_OK))!=-1)
  3876. {
  3877. strcpy(chargingProfiles[0], fname);
  3878. ChargeProfileCount = 1;
  3879. }
  3880. }
  3881. break;
  3882. default:
  3883. if(chargingProfilePurposeIsNULL == TRUE)
  3884. {
  3885. int m = 0;
  3886. memset(fname, 0, sizeof fname);
  3887. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3888. if((access(fname,F_OK))!=-1)
  3889. {
  3890. strcpy(chargingProfiles[m], fname);
  3891. m = m + 1;
  3892. }
  3893. memset(fname, 0, sizeof fname);
  3894. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3895. if((access(fname,F_OK))!=-1)
  3896. {
  3897. strcpy(chargingProfiles[m], fname);
  3898. m = m + 1;
  3899. }
  3900. ChargeProfileCount = m;
  3901. }
  3902. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3903. {
  3904. //strcpy(fname, TxDefaultProfile_1_JSON);
  3905. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3906. if((access(fname,F_OK))!=-1)
  3907. {
  3908. strcpy(chargingProfiles[0], fname);
  3909. ChargeProfileCount = 1;
  3910. }
  3911. }
  3912. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3913. {
  3914. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3915. if((access(fname,F_OK))!=-1)
  3916. {
  3917. strcpy(chargingProfiles[0], fname);
  3918. ChargeProfileCount = 1;
  3919. }
  3920. //strcpy(fname, TxProfile_1_JSON);
  3921. }
  3922. //strcpy(fname, ChargePointMaxProfile_JSON );
  3923. break;
  3924. }
  3925. }
  3926. else // Check all Charging Profiles
  3927. {
  3928. int i = 0;
  3929. char fnametemp[200]={0};
  3930. ChargeProfileCount = 0;
  3931. //Check ChargePointMaxProfile.json exit
  3932. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3933. {
  3934. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3935. i = i + 1;
  3936. }
  3937. //Check TxDefaultProfile_0.json exit
  3938. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3939. {
  3940. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3941. i = i + 1;
  3942. }
  3943. //Check TxDefaultProfile_%d.json
  3944. for(int j=1; j <= gunTotalNumber; j++)
  3945. {
  3946. memset(fnametemp, 0, sizeof fnametemp);
  3947. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3948. if((access(fnametemp,F_OK))!=-1)
  3949. {
  3950. strcpy(chargingProfiles[i], fnametemp);
  3951. i = i + 1;
  3952. }
  3953. }
  3954. //Check TxProfile_%d.json
  3955. for(int j=1; j <= gunTotalNumber; j++)
  3956. {
  3957. memset(fnametemp, 0, sizeof fnametemp);
  3958. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3959. if((access(fnametemp,F_OK))!=-1)
  3960. {
  3961. strcpy(chargingProfiles[i], fnametemp);
  3962. i = i + 1;
  3963. }
  3964. }
  3965. ChargeProfileCount = i;
  3966. }// End connectorIsNULL is TRUE
  3967. if(ChargeProfileCount == 0)
  3968. {
  3969. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3970. goto end;
  3971. }
  3972. #if 0
  3973. fptr1 = fopen(fname, "r");
  3974. if (!fptr1)
  3975. {
  3976. //file not exist
  3977. DEBUG_INFO("Unable to open the input file!!\n");
  3978. fptr1 = fopen(fname, "w+");
  3979. }
  3980. fclose(fptr1);
  3981. #endif
  3982. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3983. {
  3984. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3985. goto end;
  3986. }
  3987. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3988. {
  3989. memset(str, 0, sizeof str);
  3990. // clear temp file
  3991. sprintf(str,"rm -f %s",temp);
  3992. system(str);
  3993. for(int k=0; k < ChargeProfileCount; k++)
  3994. {
  3995. memset(str, 0, sizeof str);
  3996. //clear file in C
  3997. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3998. system(str);
  3999. }
  4000. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4001. goto end;
  4002. }
  4003. else if(connectorIsNULL == TRUE)
  4004. {
  4005. for(int k=0; k < ChargeProfileCount; k++)
  4006. {
  4007. fptr1 = fopen(chargingProfiles[k], "r");
  4008. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  4009. //Check Charging Profile Count
  4010. while(fscanf(fptr1, "%s", word) != EOF)
  4011. {
  4012. //DEBUG_INFO("word=%s\n",word);
  4013. if(strstr(word, "chargingProfileId")!= NULL)
  4014. {
  4015. //DEBUG_INFO("test chargingProfileId \n");
  4016. n_chargingProfile = n_chargingProfile + 1;
  4017. //DEBUG_INFO("chargingProfileId Found\n");
  4018. }
  4019. }
  4020. rewind(fptr1);
  4021. //search Charging Profile Element
  4022. //int i= 0;
  4023. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4024. {
  4025. //------------------------tempconnectorIdInt------------------------//
  4026. loc = strstr(sLineWord, "connectorId");
  4027. c = 0;
  4028. memset(sstr ,0, sizeof(sstr) );
  4029. while (loc[strlen("connectorId")+2+c] != ',')
  4030. {
  4031. sstr[c] = loc[strlen("connectorId")+2+c];
  4032. c++;
  4033. }
  4034. sstr[c] = '\0';
  4035. tempconnectorIdInt = atoi(sstr);
  4036. printf("file's gun number is %d\n", tempconnectorIdInt);
  4037. //--------------------------chargingProfileId--------------------//
  4038. c = 0;
  4039. loc = strstr(sLineWord, "chargingProfileId");
  4040. memset(sstr ,0, sizeof(sstr) );
  4041. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4042. {
  4043. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4044. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4045. c++;
  4046. }
  4047. sstr[c] = '\0';
  4048. tempchargingProfileIdInt = atoi(sstr);
  4049. //stackLevel
  4050. c = 0;
  4051. loc = strstr(sLineWord, "stackLevel");
  4052. memset(sstr ,0, sizeof(sstr) );
  4053. while (loc[strlen("stackLevel")+2+c] != ',')
  4054. {
  4055. sstr[c] = loc[strlen("stackLevel")+2+c];
  4056. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4057. c++;
  4058. }
  4059. sstr[c] = '\0';
  4060. tempstackLevelInt = atoi(sstr);
  4061. c = 0;
  4062. loc = strstr(sLineWord, "chargingProfilePurpose");
  4063. memset(sstr ,0, sizeof(sstr) );
  4064. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4065. {
  4066. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4067. c++;
  4068. }
  4069. sstr[c] = '\0';
  4070. strcpy(tempchargingProfilePurposeStr, sstr);
  4071. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4072. {
  4073. //------- not write to fptr2-------//
  4074. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4075. //clearflag = TRUE;
  4076. }
  4077. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4078. {
  4079. //------- not write to fptr2-------//
  4080. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4081. }
  4082. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4083. {
  4084. //------- not write to fptr2-------//
  4085. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4086. }
  4087. else
  4088. {
  4089. fprintf(fptr2, sLineWord);//writing data into file
  4090. }
  4091. memset(sLineWord, 0, sizeof sLineWord);
  4092. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4093. if(clearflag == TRUE)
  4094. {
  4095. fclose(fptr1);
  4096. fclose(fptr2);
  4097. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4098. system(str);
  4099. // clear temp file
  4100. sprintf(str,"rm -f %s",temp);
  4101. system(str);
  4102. }
  4103. else
  4104. {
  4105. fclose(fptr1);
  4106. fclose(fptr2);
  4107. memset(str, 0, sizeof str);
  4108. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4109. system(str);
  4110. resultRename = rename(temp, chargingProfiles[k]);
  4111. if(resultRename == 0)
  4112. {
  4113. DEBUG_INFO("File ChargingProfile renamed successfully");
  4114. }
  4115. else
  4116. {
  4117. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4118. }
  4119. if(comfirmstr[0]== 0)
  4120. {
  4121. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4122. }
  4123. //Check chargingProfile is empty file
  4124. /*------ Read the file ----------------*/
  4125. fptr1=fopen(chargingProfiles[k],"r");
  4126. ch=fgetc(fptr1);
  4127. rewind(fptr1);
  4128. memset(sLineWord, 0, sizeof sLineWord);
  4129. if(ch!=EOF)
  4130. {
  4131. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4132. {
  4133. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4134. if(sLineWord[0]=='\0')
  4135. {
  4136. isEmptyFile = TRUE;
  4137. break;
  4138. }
  4139. else
  4140. {
  4141. isEmptyFile = FALSE;
  4142. break;
  4143. }
  4144. }
  4145. }
  4146. fclose(fptr1);
  4147. if(isEmptyFile == TRUE)
  4148. {
  4149. memset(str, 0, sizeof str);
  4150. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4151. system(str);
  4152. }
  4153. }
  4154. }// End of while(int k=0; k < ChargePointCount; k++)
  4155. }
  4156. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4157. {
  4158. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4159. for(int k=0; k < ChargeProfileCount; k++)
  4160. {
  4161. fptr1 = fopen(chargingProfiles[k], "r");
  4162. fptr2 = fopen(temp, "w+");
  4163. //Check Charging Profile Count
  4164. while(fscanf(fptr1, "%s", word) != EOF)
  4165. {
  4166. //DEBUG_INFO("word=%s\n",word);
  4167. if(strstr(word, "chargingProfileId")!= NULL)
  4168. {
  4169. //DEBUG_INFO("test chargingProfileId \n");
  4170. n_chargingProfile = n_chargingProfile + 1;
  4171. //DEBUG_INFO("chargingProfileId Found\n");
  4172. }
  4173. }
  4174. rewind(fptr1);
  4175. //search Charging Profile Element
  4176. //int i= 0;
  4177. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4178. {
  4179. //*************************tempconnectorIdInt*********************************/
  4180. loc = strstr(sLineWord, "connectorId");
  4181. c = 0;
  4182. memset(sstr ,0, sizeof(sstr) );
  4183. while (loc[strlen("connectorId")+2+c] != ',')
  4184. {
  4185. sstr[c] = loc[strlen("connectorId")+2+c];
  4186. c++;
  4187. }
  4188. sstr[c] = '\0';
  4189. tempconnectorIdInt = atoi(sstr);
  4190. //chargingProfileId
  4191. c = 0;
  4192. loc = strstr(sLineWord, "chargingProfileId");
  4193. memset(sstr ,0, sizeof(sstr) );
  4194. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4195. {
  4196. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4197. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4198. c++;
  4199. }
  4200. sstr[c] = '\0';
  4201. tempchargingProfileIdInt = atoi(sstr);
  4202. //stackLevel
  4203. c = 0;
  4204. loc = strstr(sLineWord, "stackLevel");
  4205. memset(sstr ,0, sizeof(sstr) );
  4206. while (loc[strlen("stackLevel")+2+c] != ',')
  4207. {
  4208. sstr[c] = loc[strlen("stackLevel")+2+c];
  4209. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4210. c++;
  4211. }
  4212. sstr[c] = '\0';
  4213. tempstackLevelInt = atoi(sstr);
  4214. c = 0;
  4215. loc = strstr(sLineWord, "chargingProfilePurpose");
  4216. memset(sstr ,0, sizeof(sstr) );
  4217. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4218. {
  4219. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4220. c++;
  4221. }
  4222. sstr[c] = '\0';
  4223. strcpy(tempchargingProfilePurposeStr, sstr);
  4224. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4225. {
  4226. //------- not write to fptr2-------//
  4227. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4228. //clearflag = TRUE;
  4229. }
  4230. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4231. {
  4232. //------- not write to fptr2-------//
  4233. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4234. }
  4235. else if(stackLevelIsNULL == TRUE)
  4236. {
  4237. //Clear Whole File
  4238. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4239. clearflag = TRUE;
  4240. break;
  4241. }
  4242. else
  4243. {
  4244. fprintf(fptr2, sLineWord);//writing data into file
  4245. }
  4246. memset(sLineWord, 0, sizeof sLineWord);
  4247. }
  4248. if(clearflag == TRUE)
  4249. {
  4250. fclose(fptr1);
  4251. fclose(fptr2);
  4252. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4253. system(str);
  4254. // clear temp file
  4255. sprintf(str,"rm -f %s",temp);
  4256. system(str);
  4257. }
  4258. else
  4259. {
  4260. fclose(fptr1);
  4261. fclose(fptr2);
  4262. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4263. system(str);
  4264. resultRename = rename(temp, chargingProfiles[k]);
  4265. if(resultRename == 0)
  4266. {
  4267. DEBUG_INFO("File ChargingProfile renamed successfully");
  4268. }
  4269. else
  4270. {
  4271. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4272. }
  4273. if(comfirmstr[0]== 0)
  4274. {
  4275. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4276. }
  4277. //Check chargingProfile is empty file
  4278. /*------ Read the file ----------------*/
  4279. fptr1=fopen(chargingProfiles[k],"r");
  4280. ch=fgetc(fptr1);
  4281. rewind(fptr1);
  4282. memset(sLineWord, 0, sizeof sLineWord);
  4283. if(ch!=EOF)
  4284. {
  4285. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4286. {
  4287. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4288. if(sLineWord[0]=='\0')
  4289. {
  4290. isEmptyFile = TRUE;
  4291. break;
  4292. }
  4293. else
  4294. {
  4295. isEmptyFile = FALSE;
  4296. break;
  4297. }
  4298. }
  4299. }
  4300. fclose(fptr1);
  4301. if(isEmptyFile == TRUE)
  4302. {
  4303. memset(str, 0, sizeof str);
  4304. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4305. system(str);
  4306. }
  4307. /*------- End of reading ---------------*/
  4308. }
  4309. } // while(int k=0; k < ChargeProfileCount; k++)
  4310. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4311. end:
  4312. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4313. return result;
  4314. }
  4315. int handleDataTransferRequest(char *uuid, char *payload)
  4316. {
  4317. mtrace();
  4318. int result = FAIL;
  4319. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4320. char tempvendorId[255]={0};
  4321. char tempmessageId[50]={0};
  4322. char tempdata[50]={0};
  4323. char sstr[160]={0};//sstr[200]={ 0 };
  4324. char message[80]={0};
  4325. int c = 0;
  4326. char *loc;
  4327. DEBUG_INFO("handle DataTransferRequest\n");
  4328. if((uuid != NULL) && (payload != NULL))
  4329. {
  4330. //===============================
  4331. // vendorId
  4332. //===============================
  4333. c = 0;
  4334. loc = strstr(payload, "vendorId");
  4335. while (loc[strlen("vendorId")+3+c] != '\"')
  4336. {
  4337. sstr[c] = loc[strlen("vendorId")+3+c];
  4338. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4339. c++;
  4340. }
  4341. sstr[c] = '\0';
  4342. strcpy(tempvendorId,sstr);
  4343. //===============================
  4344. // messageId
  4345. //===============================
  4346. memset(sstr ,0, sizeof(sstr) );
  4347. c = 0;
  4348. loc = strstr(payload, "messageId");
  4349. while (loc[strlen("messageId")+3+c] != '\"')
  4350. {
  4351. sstr[c] = loc[strlen("messageId")+3+c];
  4352. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4353. c++;
  4354. }
  4355. sstr[c] = '\0';
  4356. strcpy(tempmessageId,sstr);
  4357. //===============================
  4358. // data
  4359. //===============================
  4360. memset(sstr ,0, sizeof(sstr) );
  4361. c = 0;
  4362. loc = strstr(payload, "data");
  4363. printf("loc=%s\n",loc);
  4364. while (loc[strlen("data")+3+c] != '\"')
  4365. {
  4366. sstr[c] = loc[strlen("data")+3+c];
  4367. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4368. c++;
  4369. }
  4370. sstr[c] = '\0';
  4371. strcpy(tempdata,sstr);
  4372. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4373. }
  4374. else
  4375. {
  4376. char guid[37]={0};
  4377. random_uuid(guid);
  4378. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4379. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4380. }
  4381. LWS_Send(message);
  4382. return result;
  4383. }
  4384. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4385. {
  4386. mtrace();
  4387. int result = FAIL;
  4388. int connectorIdInt, durationInt;
  4389. char chargingRateUnitStr[4]={0};
  4390. //int tempconnectorIdInt,
  4391. int tempdurationInt;
  4392. float tempminChargingRateFloat = 0.0;
  4393. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4394. int tempStartPeriodInt=0;
  4395. float tempLimitInt=0.0;//0.1;
  4396. int tempNumberPhasesInt=0;
  4397. char fname[200];
  4398. char comfirmstr[20];
  4399. //float totallimit =0.0;
  4400. float MinChargingRate =0.0;
  4401. //double diff_t;
  4402. //struct tm tp;
  4403. FILE *fptr1;
  4404. int c = 0;
  4405. //int i = 0;
  4406. char * pch;
  4407. char *loc;
  4408. char sstr[200]={ 0 },sstrtemp[50]={ 0 };
  4409. int n_chargingProfile = 0;
  4410. int n_SchedulePeriods = 0;
  4411. char SchedulePeriodList[10][200]={0};
  4412. char sLineWord[1600]={0};
  4413. //int n_periods = 0;
  4414. char word[1000]={0};
  4415. int confirmPeriods = 0;
  4416. struct StructProfile ChargePointMaxProfile;
  4417. struct StructProfile TxDefaultProfile;
  4418. struct StructProfile TxProfile;
  4419. struct StructProfile TxDefaultProfiletemp[2]={0};
  4420. int TxDefaultProfileFileIsNull=FALSE;
  4421. int ChargePointMaxProfileIsNull=FALSE;
  4422. int TxProfileIsNull=FALSE;
  4423. int CompositeSceduleIndex = 0;
  4424. char ChargePointMaxProfileScheduleStr[30]={0};
  4425. char TxDefaultProfileScheduleStr[30]={0};
  4426. char TxProfileScheduleStr[30]={0};
  4427. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4428. strcpy(sstrtemp, stringtrimspace(payload));
  4429. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4430. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4431. memset(&TxProfile,0,sizeof(struct StructProfile));
  4432. c=0;
  4433. loc = strstr(sstrtemp, "connectorId");
  4434. memset(sstr ,0, sizeof(sstr) );
  4435. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4436. {
  4437. sstr[c] = loc[strlen("connectorId")+2+c];
  4438. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4439. c++;
  4440. }
  4441. sstr[c] = '\0';
  4442. connectorIdInt = atoi(sstr);
  4443. c=0;
  4444. loc = strstr(sstrtemp, "duration");
  4445. memset(sstr ,0, sizeof(sstr) );
  4446. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4447. {
  4448. sstr[c] = loc[strlen("duration")+2+c];
  4449. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4450. c++;
  4451. }
  4452. sstr[c] = '\0';
  4453. durationInt = atoi(sstr);
  4454. c = 0;
  4455. loc = strstr(sstrtemp, "chargingRateUnit");
  4456. memset(sstr ,0, sizeof(sstr) );
  4457. if(loc == NULL)
  4458. {
  4459. }
  4460. else
  4461. {
  4462. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4463. {
  4464. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4465. c++;
  4466. }
  4467. sstr[c] = '\0';
  4468. strcpy(chargingRateUnitStr, sstr);
  4469. }
  4470. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4471. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4472. if(connectorIdInt==0) // connectorId is 0
  4473. {
  4474. //******************************ChargePointMaxProfile*****************************************************/
  4475. strcpy(fname, ChargePointMaxProfile_JSON );
  4476. char word[30]={0};
  4477. char sLineWord[1060]={0};
  4478. int n_chargingProfile=0;
  4479. ChargePointMaxProfileIsNull=TRUE;
  4480. if((access(fname,F_OK))!=-1)
  4481. {
  4482. fptr1 = fopen(fname, "r");
  4483. int c;
  4484. c = fgetc(fptr1);
  4485. //DEBUG_INFO("c:%d\n",c);
  4486. rewind(fptr1);
  4487. if(c == EOF)
  4488. {
  4489. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4490. ChargePointMaxProfileIsNull=TRUE;
  4491. fclose(fptr1);
  4492. }
  4493. else
  4494. {
  4495. ChargePointMaxProfileIsNull=FALSE;
  4496. while(fscanf(fptr1, "%s", word) != EOF)
  4497. {
  4498. if(strcmp(word, "chargingProfileId") == 0)
  4499. {
  4500. n_chargingProfile = n_chargingProfile + 1;
  4501. printf("Found\n");
  4502. }
  4503. }
  4504. rewind(fptr1);
  4505. //search Charging Profile Element
  4506. int i= 0;
  4507. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4508. #if 0
  4509. /***********connectorId****************/
  4510. c = 0;
  4511. loc = strstr(sLineWord, "connectorId");
  4512. // printf("loc=%s\n",loc);
  4513. memset(sstr ,0, sizeof(sstr) );
  4514. while (loc[strlen("connectorId")+2+c] != ',')
  4515. {
  4516. sstr[c] = loc[strlen("connectorId")+2+c];
  4517. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4518. c++;
  4519. }
  4520. sstr[c] = '\0';
  4521. tempconnectorIdInt = atoi(sstr);
  4522. #endif
  4523. //***********validFrom**************/
  4524. c = 0;
  4525. loc = strstr(sLineWord, "validFrom");
  4526. //DEBUG_INFO("loc=%s\n",loc);
  4527. memset(sstr ,0, sizeof(sstr) );
  4528. if(loc != NULL)
  4529. {
  4530. while (loc[3+strlen("validFrom")+c] != '\"')
  4531. {
  4532. sstr[c] = loc[3+strlen("validFrom")+c];
  4533. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4534. c++;
  4535. }
  4536. sstr[c] = '\0';
  4537. DEBUG_INFO("validFrom=%s\n",sstr);
  4538. strcpy(tempvalidFromStr,sstr);
  4539. }
  4540. else
  4541. {
  4542. strcpy(tempvalidFromStr,"");
  4543. }
  4544. //**********startSchedule**********/
  4545. c = 0;
  4546. loc = strstr(sLineWord, "startSchedule");
  4547. //DEBUG_INFO("loc=%s\n",loc);
  4548. memset(sstr ,0, sizeof(sstr) );
  4549. if(loc != NULL)
  4550. {
  4551. while (loc[3+strlen("startSchedule")+c] != '\"')
  4552. {
  4553. sstr[c] = loc[3+strlen("startSchedule")+c];
  4554. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4555. c++;
  4556. }
  4557. sstr[c] = '\0';
  4558. strcpy(tempstartScheduleStr, sstr);
  4559. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4560. }
  4561. else
  4562. {
  4563. strcpy(tempstartScheduleStr, "");
  4564. strcpy(ChargePointMaxProfileScheduleStr, "");
  4565. }
  4566. //**********chargingRateUnit**********/
  4567. c = 0;
  4568. loc = strstr(sLineWord, "chargingRateUnit");
  4569. memset(sstr ,0, sizeof(sstr) );
  4570. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4571. {
  4572. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4573. c++;
  4574. }
  4575. sstr[c] = '\0';
  4576. strcpy(tempchargingRateUnitStr, sstr);
  4577. //**********minChargingRate*******/
  4578. c = 0;
  4579. loc = strstr(sLineWord, "minChargingRate");
  4580. //printf("loc=%s\n",loc);
  4581. if(loc != NULL)
  4582. {
  4583. memset(sstr ,0, sizeof(sstr) );
  4584. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4585. {
  4586. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4587. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4588. c++;
  4589. }
  4590. sstr[c] = '\0';
  4591. tempminChargingRateFloat = atof(sstr);
  4592. }
  4593. else
  4594. {
  4595. tempminChargingRateFloat = 0.0;
  4596. }
  4597. //
  4598. #if 0
  4599. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4600. tp.tm_isdst = -1;
  4601. time_t utc = mktime(&tp);
  4602. // current time
  4603. time_t t = time(NULL);
  4604. #endif
  4605. //diff_t = difftime(t, utc);
  4606. //parsing strings to words
  4607. i = 0;
  4608. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4609. loc = loc+3+strlen("chargingSchedulePeriod");
  4610. pch = strtok(loc ,"{");
  4611. while (pch != NULL)
  4612. {
  4613. strcpy(SchedulePeriodList[i], pch);
  4614. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4615. //printf ("%s\n",pch);
  4616. pch = strtok (NULL, "{");
  4617. i = i + 1;
  4618. }
  4619. n_SchedulePeriods = i;
  4620. for(int i=0;i<n_SchedulePeriods;i++)
  4621. {
  4622. //*************startPeriod****************/
  4623. c = 0;
  4624. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4625. memset(sstr ,0, sizeof(sstr) );
  4626. while (loc[strlen("startPeriod")+2+c] != ',')
  4627. {
  4628. sstr[c] = loc[strlen("startPeriod")+2+c];
  4629. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4630. c++;
  4631. }
  4632. sstr[c] = '\0';
  4633. tempStartPeriodInt = atoi(sstr);
  4634. //*************limit****************/
  4635. c = 0;
  4636. loc = strstr(SchedulePeriodList[i], "limit");
  4637. memset(sstr ,0, sizeof(sstr) );
  4638. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  4639. {
  4640. sstr[c] = loc[strlen("limit")+2+c];
  4641. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4642. c++;
  4643. }
  4644. sstr[c] = '\0';
  4645. tempLimitInt = atof(sstr);
  4646. //*************numberPhases****************/
  4647. c = 0;
  4648. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4649. memset(sstr ,0, sizeof(sstr) );
  4650. if(loc != NULL)
  4651. {
  4652. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4653. {
  4654. sstr[c] = loc[strlen("numberPhases")+2+c];
  4655. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4656. c++;
  4657. }
  4658. sstr[c] = '\0';
  4659. tempNumberPhasesInt = atoi(sstr);
  4660. }
  4661. else
  4662. {
  4663. tempNumberPhasesInt = 0;
  4664. }
  4665. ChargePointMaxProfile.Duration = durationInt;
  4666. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4667. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4668. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4669. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4670. }
  4671. if(MinChargingRate < tempminChargingRateFloat)
  4672. MinChargingRate = tempminChargingRateFloat;
  4673. }
  4674. }// End of file ChargingProfile
  4675. } //THE END OF ACCESS ChargePointMaxProfile
  4676. //******************************TxDefaultProfile***********************************************/
  4677. strcpy(fname, TxDefaultProfile_0_JSON);
  4678. memset(word, 0, 30);
  4679. memset(sLineWord, 0, 1060);
  4680. //char word[30]={0};
  4681. //char sLineWord[1060]={0};
  4682. n_chargingProfile=0;
  4683. TxDefaultProfileFileIsNull=TRUE;
  4684. if((access(fname,F_OK))!=-1)
  4685. {
  4686. fptr1 = fopen(fname, "r");
  4687. c = 0;
  4688. c = fgetc(fptr1);
  4689. //DEBUG_INFO("c:%d\n",c);
  4690. rewind(fptr1);
  4691. if(c == EOF)
  4692. {
  4693. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4694. TxDefaultProfileFileIsNull=TRUE;
  4695. fclose(fptr1);
  4696. }
  4697. else
  4698. {
  4699. TxDefaultProfileFileIsNull=FALSE;
  4700. while(fscanf(fptr1, "%s", word) != EOF)
  4701. {
  4702. if(strcmp(word, "chargingProfileId") == 0)
  4703. {
  4704. n_chargingProfile = n_chargingProfile + 1;
  4705. printf("Found\n");
  4706. }
  4707. }
  4708. rewind(fptr1);
  4709. //search Charging Profile Element
  4710. int i= 0;
  4711. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4712. #if 0
  4713. /***********connectorId****************/
  4714. c = 0;
  4715. loc = strstr(sLineWord, "connectorId");
  4716. // printf("loc=%s\n",loc);
  4717. memset(sstr ,0, sizeof(sstr) );
  4718. while (loc[strlen("connectorId")+2+c] != ',')
  4719. {
  4720. sstr[c] = loc[strlen("connectorId")+2+c];
  4721. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4722. c++;
  4723. }
  4724. sstr[c] = '\0';
  4725. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4726. tempconnectorIdInt = atoi(sstr);
  4727. #endif
  4728. //***********validFrom**************/
  4729. c = 0;
  4730. loc = strstr(sLineWord, "validFrom");
  4731. //DEBUG_INFO("loc=%s\n",loc);
  4732. memset(sstr ,0, sizeof(sstr) );
  4733. if(loc != NULL)
  4734. {
  4735. while (loc[3+strlen("validFrom")+c] != '\"')
  4736. {
  4737. sstr[c] = loc[3+strlen("validFrom")+c];
  4738. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4739. c++;
  4740. }
  4741. sstr[c] = '\0';
  4742. DEBUG_INFO("validFrom=%s\n",sstr);
  4743. strcpy(tempvalidFromStr,sstr);
  4744. }
  4745. else
  4746. {
  4747. strcpy(tempvalidFromStr,"");
  4748. }
  4749. //**********startSchedule**********/
  4750. c = 0;
  4751. loc = strstr(sLineWord, "startSchedule");
  4752. //DEBUG_INFO("loc=%s\n",loc);
  4753. memset(sstr ,0, sizeof(sstr) );
  4754. if(loc != NULL)
  4755. {
  4756. while (loc[3+strlen("startSchedule")+c] != '\"')
  4757. {
  4758. sstr[c] = loc[3+strlen("startSchedule")+c];
  4759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4760. c++;
  4761. }
  4762. sstr[c] = '\0';
  4763. strcpy(tempstartScheduleStr, sstr);
  4764. strcpy(TxDefaultProfileScheduleStr, sstr);
  4765. }
  4766. else
  4767. {
  4768. strcpy(tempstartScheduleStr, "");
  4769. strcpy(TxDefaultProfileScheduleStr, "");
  4770. }
  4771. //**********chargingRateUnit**********/
  4772. c = 0;
  4773. loc = strstr(sLineWord, "chargingRateUnit");
  4774. memset(sstr ,0, sizeof(sstr) );
  4775. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4776. {
  4777. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4778. c++;
  4779. }
  4780. sstr[c] = '\0';
  4781. strcpy(tempchargingRateUnitStr, sstr);
  4782. //**********minChargingRate*******/
  4783. c = 0;
  4784. loc = strstr(sLineWord, "minChargingRate");
  4785. //printf("loc=%s\n",loc);
  4786. if(loc != NULL)
  4787. {
  4788. memset(sstr ,0, sizeof(sstr) );
  4789. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4790. {
  4791. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4792. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4793. c++;
  4794. }
  4795. sstr[c] = '\0';
  4796. tempminChargingRateFloat = atof(sstr);
  4797. }
  4798. else
  4799. {
  4800. tempminChargingRateFloat = 0.0;
  4801. }
  4802. #if 0
  4803. //
  4804. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4805. tp.tm_isdst = -1;
  4806. time_t utc = mktime(&tp);
  4807. // current time
  4808. time_t t = time(NULL);
  4809. //diff_t = difftime(t, utc);
  4810. #endif
  4811. //parsing strings to words
  4812. i = 0;
  4813. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4814. loc = loc+3+strlen("chargingSchedulePeriod");
  4815. pch = strtok(loc ,"{");
  4816. while (pch != NULL)
  4817. {
  4818. strcpy(SchedulePeriodList[i], pch);
  4819. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4820. //printf ("%s\n",pch);
  4821. pch = strtok (NULL, "{");
  4822. i = i + 1;
  4823. }
  4824. n_SchedulePeriods = i;
  4825. for(int i=0;i<n_SchedulePeriods;i++)
  4826. {
  4827. //*************startPeriod****************/
  4828. c = 0;
  4829. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4830. memset(sstr ,0, sizeof(sstr) );
  4831. while (loc[strlen("startPeriod")+2+c] != ',')
  4832. {
  4833. sstr[c] = loc[strlen("startPeriod")+2+c];
  4834. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4835. c++;
  4836. }
  4837. sstr[c] = '\0';
  4838. tempStartPeriodInt = atoi(sstr);
  4839. //*************limit****************/
  4840. c = 0;
  4841. loc = strstr(SchedulePeriodList[i], "limit");
  4842. memset(sstr ,0, sizeof(sstr) );
  4843. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  4844. {
  4845. sstr[c] = loc[strlen("limit")+2+c];
  4846. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4847. c++;
  4848. }
  4849. sstr[c] = '\0';
  4850. tempLimitInt = atof(sstr);
  4851. //*************numberPhases****************/
  4852. c = 0;
  4853. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4854. memset(sstr ,0, sizeof(sstr) );
  4855. if(loc != NULL)
  4856. {
  4857. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4858. {
  4859. sstr[c] = loc[strlen("numberPhases")+2+c];
  4860. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4861. c++;
  4862. }
  4863. sstr[c] = '\0';
  4864. tempNumberPhasesInt = atoi(sstr);
  4865. }
  4866. else
  4867. {
  4868. tempNumberPhasesInt = 0;
  4869. }
  4870. TxDefaultProfile.Duration = durationInt;
  4871. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4872. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4873. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4874. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4875. }
  4876. if(MinChargingRate < tempminChargingRateFloat)
  4877. MinChargingRate = tempminChargingRateFloat;
  4878. }
  4879. }
  4880. }// the end of ACCESS TxDefaultProfile
  4881. //--------------------- Composite Schedule-----------------------------//
  4882. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4883. {
  4884. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4885. struct tm tp;
  4886. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4887. tp.tm_isdst = -1;
  4888. time_t utc = mktime(&tp);
  4889. time_t t = time(NULL);
  4890. double diff_f = difftime(t, utc);
  4891. int diff_i; //= (int)diff_f;
  4892. int quotient; //= diff_i / 86400;//86400 seconds/day
  4893. int period = 0;
  4894. if(diff_f >= 0)
  4895. {
  4896. diff_i = (int)diff_f;
  4897. quotient = diff_i / 86400;
  4898. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4899. {
  4900. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4901. {
  4902. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4903. {
  4904. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4905. }
  4906. else
  4907. {
  4908. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4909. }
  4910. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4911. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4912. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4913. period = period + 1;
  4914. }
  4915. }
  4916. }
  4917. confirmPeriods = period;
  4918. }
  4919. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4920. {
  4921. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4922. struct tm tp;
  4923. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4924. tp.tm_isdst = -1;
  4925. time_t utc = mktime(&tp);
  4926. time_t t = time(NULL);
  4927. double diff_f = difftime(t, utc);
  4928. int diff_i; // = (int)diff_f;
  4929. int quotient; // = diff_i / 86400;//86400 seconds/day
  4930. int period = 0;
  4931. if(diff_f >= 0)
  4932. {
  4933. diff_i = (int)diff_f;
  4934. quotient = diff_i / 86400;//86400 seconds/day
  4935. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4936. {
  4937. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4938. {
  4939. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4940. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4941. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4942. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4943. period = period + 1;
  4944. }
  4945. }
  4946. }
  4947. confirmPeriods = period;
  4948. }
  4949. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4950. {
  4951. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4952. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4953. {
  4954. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4955. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4956. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4957. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4958. }
  4959. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4960. }
  4961. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4962. {
  4963. confirmPeriods = 0;
  4964. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4965. //goto end;
  4966. }
  4967. //* Define temporary variables */
  4968. struct tm *gtime;
  4969. time_t now;
  4970. char buf[28];
  4971. /* Read the current system time */
  4972. time(&now);
  4973. /* Convert the system time to GMT (now UTC) */
  4974. gtime = gmtime(&now);
  4975. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4976. // make .conf
  4977. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4978. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4979. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4980. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4981. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4982. }
  4983. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4984. {
  4985. //*****************************ChargePointMaxProfile******************************************/
  4986. strcpy(fname, ChargePointMaxProfile_JSON);
  4987. ChargePointMaxProfileIsNull=TRUE;
  4988. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4989. {
  4990. fptr1 = fopen(fname, "r");
  4991. int c;
  4992. c = fgetc(fptr1);
  4993. //DEBUG_INFO("c:%d\n",c);
  4994. rewind(fptr1);
  4995. if(c == EOF)
  4996. {
  4997. DEBUG_INFO("\n End of file reached.");
  4998. ChargePointMaxProfileIsNull=TRUE;
  4999. fclose(fptr1);
  5000. }
  5001. else
  5002. {
  5003. ChargePointMaxProfileIsNull=FALSE;
  5004. while(fscanf(fptr1, "%s", word) != EOF)
  5005. {
  5006. if(strcmp(word, "chargingProfileId") == 0)
  5007. {
  5008. n_chargingProfile = n_chargingProfile + 1;
  5009. }
  5010. }
  5011. rewind(fptr1);
  5012. //search Charging Profile Element
  5013. int i = 0;
  5014. int j = 0;
  5015. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5016. #if 0
  5017. /***********connectorId****************/
  5018. c = 0;
  5019. loc = strstr(sLineWord, "connectorId");
  5020. memset(sstr ,0, sizeof(sstr) );
  5021. while (loc[strlen("connectorId")+2+c] != ',')
  5022. {
  5023. sstr[c] = loc[strlen("connectorId")+2+c];
  5024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5025. c++;
  5026. }
  5027. sstr[c] = '\0';
  5028. tempconnectorIdInt = atoi(sstr);
  5029. #endif
  5030. //***********validFrom**************/
  5031. c = 0;
  5032. loc = strstr(sLineWord, "validFrom");
  5033. if(loc != NULL)
  5034. {
  5035. memset(sstr ,0, sizeof(sstr) );
  5036. while (loc[3+strlen("validFrom")+c] != '\"')
  5037. {
  5038. sstr[c] = loc[3+strlen("validFrom")+c];
  5039. c++;
  5040. }
  5041. sstr[c] = '\0';
  5042. strcpy(tempvalidFromStr,sstr);
  5043. }
  5044. else
  5045. {
  5046. strcpy(tempvalidFromStr,"");
  5047. }
  5048. //***********validFrom**************/
  5049. c = 0;
  5050. loc = strstr(sLineWord, "duration");
  5051. if(loc != NULL)
  5052. {
  5053. memset(sstr ,0, sizeof(sstr) );
  5054. while (loc[2+strlen("duration")+c] != ',')
  5055. {
  5056. sstr[c] = loc[2+strlen("duration")+c];
  5057. c++;
  5058. }
  5059. sstr[c] = '\0';
  5060. tempdurationInt = atoi(sstr);
  5061. }
  5062. else
  5063. {
  5064. tempdurationInt = 0;
  5065. }
  5066. //**********startSchedule**********/
  5067. c = 0;
  5068. loc = strstr(sLineWord, "startSchedule");
  5069. memset(sstr ,0, sizeof(sstr) );
  5070. if(loc != NULL)
  5071. {
  5072. while (loc[3+strlen("startSchedule")+c] != '\"')
  5073. {
  5074. sstr[c] = loc[3+strlen("startSchedule")+c];
  5075. c++;
  5076. }
  5077. sstr[c] = '\0';
  5078. strcpy(tempstartScheduleStr, sstr);
  5079. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5080. }
  5081. else
  5082. {
  5083. strcpy(tempstartScheduleStr, "");
  5084. strcpy(ChargePointMaxProfileScheduleStr, "");
  5085. }
  5086. //**********chargingRateUnit**********/
  5087. c = 0;
  5088. loc = strstr(sLineWord, "chargingRateUnit");
  5089. memset(sstr ,0, sizeof(sstr) );
  5090. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5091. {
  5092. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5093. c++;
  5094. }
  5095. sstr[c] = '\0';
  5096. strcpy(tempchargingRateUnitStr, sstr);
  5097. //**********minChargingRate*******/
  5098. c = 0;
  5099. loc = strstr(sLineWord, "minChargingRate");
  5100. if(loc != NULL)
  5101. {
  5102. memset(sstr ,0, sizeof(sstr) );
  5103. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5104. {
  5105. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5106. c++;
  5107. }
  5108. sstr[c] = '\0';
  5109. tempminChargingRateFloat = atof(sstr);
  5110. }
  5111. else
  5112. {
  5113. tempminChargingRateFloat = 0.0;
  5114. }
  5115. #if 0
  5116. //
  5117. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5118. tp.tm_isdst = -1;
  5119. time_t utc = mktime(&tp);
  5120. time_t t = time(NULL);
  5121. //diff_t = difftime(t, utc);
  5122. #endif
  5123. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5124. //DEBUG_INFO(" debug 5 -1\n");
  5125. //parsing strings to words
  5126. i = 0;
  5127. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5128. loc = loc+3+strlen("chargingSchedulePeriod");
  5129. pch = strtok(loc ,"{");
  5130. while (pch != NULL)
  5131. {
  5132. strcpy(SchedulePeriodList[i], pch);
  5133. pch = strtok (NULL, "{");
  5134. i = i + 1;
  5135. }
  5136. n_SchedulePeriods = i;
  5137. for(int i=0;i<n_SchedulePeriods;i++)
  5138. {
  5139. //*************startPeriod****************/
  5140. c = 0;
  5141. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5142. memset(sstr ,0, sizeof(sstr) );
  5143. while (loc[strlen("startPeriod")+2+c] != ',')
  5144. {
  5145. sstr[c] = loc[strlen("startPeriod")+2+c];
  5146. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5147. c++;
  5148. }
  5149. sstr[c] = '\0';
  5150. tempStartPeriodInt = atoi(sstr);
  5151. //*************limit****************/
  5152. c = 0;
  5153. loc = strstr(SchedulePeriodList[i], "limit");
  5154. memset(sstr ,0, sizeof(sstr) );
  5155. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5156. {
  5157. sstr[c] = loc[strlen("limit")+2+c];
  5158. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5159. c++;
  5160. }
  5161. sstr[c] = '\0';
  5162. tempLimitInt = atof(sstr);
  5163. //*************numberPhases****************/
  5164. c = 0;
  5165. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5166. memset(sstr ,0, sizeof(sstr) );
  5167. if(loc != NULL)
  5168. {
  5169. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5170. {
  5171. sstr[c] = loc[strlen("numberPhases")+2+c];
  5172. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5173. c++;
  5174. }
  5175. sstr[c] = '\0';
  5176. tempNumberPhasesInt = atoi(sstr);
  5177. }
  5178. else
  5179. {
  5180. tempNumberPhasesInt = 0;
  5181. }
  5182. if(j == 0)
  5183. {
  5184. ChargePointMaxProfile.Duration = tempdurationInt;
  5185. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5186. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5187. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5188. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5189. }
  5190. }
  5191. if(MinChargingRate < tempminChargingRateFloat)
  5192. {
  5193. MinChargingRate = tempminChargingRateFloat;
  5194. }
  5195. if(confirmPeriods < n_SchedulePeriods)
  5196. {
  5197. confirmPeriods = n_SchedulePeriods;
  5198. }
  5199. j = j + 1;
  5200. }
  5201. fclose(fptr1);
  5202. }
  5203. }// the end of access file ChargePointMaxProfile
  5204. //****************************TxDefaultProfile************************************************/
  5205. memset(fname, 0, sizeof fname);
  5206. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5207. TxDefaultProfileFileIsNull=TRUE;
  5208. if((access(fname,F_OK))!=-1)
  5209. {
  5210. fptr1 = fopen(fname, "r");
  5211. c = 0;
  5212. c = fgetc(fptr1);
  5213. //DEBUG_INFO("c:%d\n",c);
  5214. rewind(fptr1);
  5215. if(c == EOF)
  5216. {
  5217. DEBUG_INFO("\n End of file reached.");
  5218. TxDefaultProfileFileIsNull=TRUE;
  5219. fclose(fptr1);
  5220. }
  5221. else
  5222. {
  5223. TxDefaultProfileFileIsNull=FALSE;
  5224. while(fscanf(fptr1, "%s", word) != EOF)
  5225. {
  5226. if(strcmp(word, "chargingProfileId") == 0)
  5227. {
  5228. n_chargingProfile = n_chargingProfile + 1;
  5229. }
  5230. }
  5231. rewind(fptr1);
  5232. //search Charging Profile Element
  5233. int i = 0;
  5234. int j = 0;
  5235. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5236. //DEBUG_INFO(" 1-1\n");
  5237. #if 0
  5238. /***********connectorId****************/
  5239. c = 0;
  5240. loc = strstr(sLineWord, "connectorId");
  5241. memset(sstr ,0, sizeof(sstr) );
  5242. while (loc[strlen("connectorId")+2+c] != ',')
  5243. {
  5244. sstr[c] = loc[strlen("connectorId")+2+c];
  5245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5246. c++;
  5247. }
  5248. sstr[c] = '\0';
  5249. tempconnectorIdInt = atoi(sstr);
  5250. #endif
  5251. //***********validFrom**************/
  5252. c = 0;
  5253. loc = strstr(sLineWord, "validFrom");
  5254. if(loc != NULL)
  5255. {
  5256. memset(sstr ,0, sizeof(sstr) );
  5257. while (loc[3+strlen("validFrom")+c] != '\"')
  5258. {
  5259. sstr[c] = loc[3+strlen("validFrom")+c];
  5260. c++;
  5261. }
  5262. sstr[c] = '\0';
  5263. strcpy(tempvalidFromStr,sstr);
  5264. }
  5265. else
  5266. {
  5267. strcpy(tempvalidFromStr,"");
  5268. }
  5269. //***********validFrom**************/
  5270. c = 0;
  5271. loc = strstr(sLineWord, "duration");
  5272. if(loc != NULL)
  5273. {
  5274. memset(sstr ,0, sizeof(sstr) );
  5275. while (loc[2+strlen("duration")+c] != ',')
  5276. {
  5277. sstr[c] = loc[2+strlen("duration")+c];
  5278. c++;
  5279. }
  5280. sstr[c] = '\0';
  5281. tempdurationInt = atoi(sstr);
  5282. }
  5283. else
  5284. {
  5285. tempdurationInt = 0;
  5286. }
  5287. //**********startSchedule**********/
  5288. c = 0;
  5289. loc = strstr(sLineWord, "startSchedule");
  5290. memset(sstr ,0, sizeof(sstr) );
  5291. if(loc != NULL)
  5292. {
  5293. while (loc[3+strlen("startSchedule")+c] != '\"')
  5294. {
  5295. sstr[c] = loc[3+strlen("startSchedule")+c];
  5296. c++;
  5297. }
  5298. sstr[c] = '\0';
  5299. strcpy(tempstartScheduleStr, sstr);
  5300. strcpy(TxDefaultProfileScheduleStr, sstr);
  5301. }
  5302. else
  5303. {
  5304. strcpy(tempstartScheduleStr, "");
  5305. strcpy(TxDefaultProfileScheduleStr, "");
  5306. }
  5307. //**********chargingRateUnit**********/
  5308. c = 0;
  5309. loc = strstr(sLineWord, "chargingRateUnit");
  5310. memset(sstr ,0, sizeof(sstr) );
  5311. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5312. {
  5313. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5314. c++;
  5315. }
  5316. sstr[c] = '\0';
  5317. strcpy(tempchargingRateUnitStr, sstr);
  5318. //**********minChargingRate*******/
  5319. c = 0;
  5320. loc = strstr(sLineWord, "minChargingRate");
  5321. if(loc != NULL)
  5322. {
  5323. memset(sstr ,0, sizeof(sstr) );
  5324. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5325. {
  5326. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5327. c++;
  5328. }
  5329. sstr[c] = '\0';
  5330. tempminChargingRateFloat = atof(sstr);
  5331. }
  5332. else
  5333. {
  5334. tempminChargingRateFloat = 0.0;
  5335. }
  5336. #if 0
  5337. //
  5338. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5339. tp.tm_isdst = -1;
  5340. time_t utc = mktime(&tp);
  5341. time_t t = time(NULL);
  5342. //diff_t = difftime(t, utc);
  5343. #endif
  5344. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5345. //parsing strings to words
  5346. i = 0;
  5347. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5348. loc = loc+3+strlen("chargingSchedulePeriod");
  5349. pch = strtok(loc ,"{");
  5350. while (pch != NULL)
  5351. {
  5352. strcpy(SchedulePeriodList[i], pch);
  5353. pch = strtok (NULL, "{");
  5354. i = i + 1;
  5355. }
  5356. n_SchedulePeriods = i;
  5357. for(int i=0;i<n_SchedulePeriods;i++)
  5358. {
  5359. //*************startPeriod****************/
  5360. c = 0;
  5361. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5362. memset(sstr ,0, sizeof(sstr) );
  5363. while (loc[strlen("startPeriod")+2+c] != ',')
  5364. {
  5365. sstr[c] = loc[strlen("startPeriod")+2+c];
  5366. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5367. c++;
  5368. }
  5369. sstr[c] = '\0';
  5370. tempStartPeriodInt = atoi(sstr);
  5371. //*************limit****************/
  5372. c = 0;
  5373. loc = strstr(SchedulePeriodList[i], "limit");
  5374. memset(sstr ,0, sizeof(sstr) );
  5375. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5376. {
  5377. sstr[c] = loc[strlen("limit")+2+c];
  5378. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5379. c++;
  5380. }
  5381. sstr[c] = '\0';
  5382. tempLimitInt = atof(sstr);
  5383. //*************numberPhases****************/
  5384. c = 0;
  5385. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5386. memset(sstr ,0, sizeof(sstr) );
  5387. if(loc != NULL)
  5388. {
  5389. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5390. {
  5391. sstr[c] = loc[strlen("numberPhases")+2+c];
  5392. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5393. c++;
  5394. }
  5395. sstr[c] = '\0';
  5396. tempNumberPhasesInt = atoi(sstr);
  5397. }
  5398. else
  5399. {
  5400. tempNumberPhasesInt = 0;
  5401. }
  5402. if(j == 0)
  5403. {
  5404. TxDefaultProfile.Duration = tempdurationInt;
  5405. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5406. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5407. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5408. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5409. }
  5410. else
  5411. {
  5412. //other stack level charging Profile
  5413. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5414. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5415. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5416. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5417. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5418. }
  5419. }
  5420. if(MinChargingRate < tempminChargingRateFloat)
  5421. MinChargingRate = tempminChargingRateFloat;
  5422. if(confirmPeriods < n_SchedulePeriods)
  5423. confirmPeriods = n_SchedulePeriods;
  5424. j = j + 1;
  5425. //DEBUG_INFO(" 1-2\n");
  5426. }
  5427. fclose(fptr1);
  5428. //Stacking Charging Profiles
  5429. for(int l=0; l <(j-1) ;l++)
  5430. {
  5431. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5432. {
  5433. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5434. {
  5435. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5436. {
  5437. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5438. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5439. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5440. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5441. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5442. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5443. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5444. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5445. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5446. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5447. }
  5448. else
  5449. {
  5450. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5451. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5452. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5453. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5454. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5455. }
  5456. }
  5457. }
  5458. }
  5459. //end of Stacking Charging Profiles
  5460. }
  5461. }// the end of ACCESS TxDefaultProfile
  5462. //****************************TxProfile************************************************/
  5463. memset(fname, 0, sizeof fname);
  5464. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5465. TxProfileIsNull=TRUE;
  5466. if((access(fname,F_OK))!=-1)
  5467. {
  5468. fptr1 = fopen(fname, "r");
  5469. c = 0;
  5470. c = fgetc(fptr1);
  5471. //DEBUG_INFO("c:%d\n",c);
  5472. rewind(fptr1);
  5473. if(c == EOF)
  5474. {
  5475. DEBUG_INFO("\n End of file reached.");
  5476. TxProfileIsNull=TRUE;
  5477. fclose(fptr1);
  5478. }
  5479. else
  5480. {
  5481. TxProfileIsNull=FALSE;
  5482. while(fscanf(fptr1, "%s", word) != EOF)
  5483. {
  5484. if(strcmp(word, "chargingProfileId") == 0)
  5485. {
  5486. n_chargingProfile = n_chargingProfile + 1;
  5487. }
  5488. }
  5489. rewind(fptr1);
  5490. //search Charging Profile Element
  5491. int i= 0;
  5492. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5493. #if 0
  5494. /***********connectorId****************/
  5495. c = 0;
  5496. loc = strstr(sLineWord, "connectorId");
  5497. memset(sstr ,0, sizeof(sstr) );
  5498. while (loc[strlen("connectorId")+2+c] != ',')
  5499. {
  5500. sstr[c] = loc[strlen("connectorId")+2+c];
  5501. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5502. c++;
  5503. }
  5504. sstr[c] = '\0';
  5505. tempconnectorIdInt = atoi(sstr);
  5506. #endif
  5507. //***********validFrom**************/
  5508. c = 0;
  5509. loc = strstr(sLineWord, "validFrom");
  5510. if(loc != NULL)
  5511. {
  5512. memset(sstr ,0, sizeof(sstr) );
  5513. while (loc[3+strlen("validFrom")+c] != '\"')
  5514. {
  5515. sstr[c] = loc[3+strlen("validFrom")+c];
  5516. c++;
  5517. }
  5518. sstr[c] = '\0';
  5519. strcpy(tempvalidFromStr,sstr);
  5520. }
  5521. else
  5522. {
  5523. strcpy(tempvalidFromStr,"");
  5524. }
  5525. //**********startSchedule**********/
  5526. c = 0;
  5527. loc = strstr(sLineWord, "startSchedule");
  5528. memset(sstr ,0, sizeof(sstr) );
  5529. if(loc != NULL)
  5530. {
  5531. while (loc[3+strlen("startSchedule")+c] != '\"')
  5532. {
  5533. sstr[c] = loc[3+strlen("startSchedule")+c];
  5534. c++;
  5535. }
  5536. sstr[c] = '\0';
  5537. strcpy(tempstartScheduleStr, sstr);
  5538. strcpy(TxProfileScheduleStr, sstr);
  5539. }
  5540. else
  5541. {
  5542. strcpy(tempstartScheduleStr, "");
  5543. strcpy(TxProfileScheduleStr, "");
  5544. }
  5545. //**********chargingRateUnit**********/
  5546. c = 0;
  5547. loc = strstr(sLineWord, "chargingRateUnit");
  5548. memset(sstr ,0, sizeof(sstr) );
  5549. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5550. {
  5551. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5552. c++;
  5553. }
  5554. sstr[c] = '\0';
  5555. strcpy(tempchargingRateUnitStr, sstr);
  5556. //**********minChargingRate*******/
  5557. c = 0;
  5558. loc = strstr(sLineWord, "minChargingRate");
  5559. if(loc != NULL)
  5560. {
  5561. memset(sstr ,0, sizeof(sstr) );
  5562. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5563. {
  5564. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5565. c++;
  5566. }
  5567. sstr[c] = '\0';
  5568. tempminChargingRateFloat = atof(sstr);
  5569. }
  5570. else
  5571. {
  5572. tempminChargingRateFloat = 0.0;
  5573. }
  5574. #if 0
  5575. //
  5576. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5577. tp.tm_isdst = -1;
  5578. time_t utc = mktime(&tp);
  5579. time_t t = time(NULL);
  5580. //diff_t = difftime(t, utc);
  5581. #endif
  5582. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5583. //parsing strings to words
  5584. i = 0;
  5585. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5586. loc = loc+3+strlen("chargingSchedulePeriod");
  5587. pch = strtok(loc ,"{");
  5588. while (pch != NULL)
  5589. {
  5590. strcpy(SchedulePeriodList[i], pch);
  5591. pch = strtok (NULL, "{");
  5592. i = i + 1;
  5593. }
  5594. n_SchedulePeriods = i;
  5595. for(int i=0;i<n_SchedulePeriods;i++)
  5596. {
  5597. //*************startPeriod****************/
  5598. c = 0;
  5599. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5600. memset(sstr ,0, sizeof(sstr) );
  5601. while (loc[strlen("startPeriod")+2+c] != ',')
  5602. {
  5603. sstr[c] = loc[strlen("startPeriod")+2+c];
  5604. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5605. c++;
  5606. }
  5607. sstr[c] = '\0';
  5608. tempStartPeriodInt = atoi(sstr);
  5609. //*************limit****************/
  5610. c = 0;
  5611. loc = strstr(SchedulePeriodList[i], "limit");
  5612. memset(sstr ,0, sizeof(sstr) );
  5613. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5614. {
  5615. sstr[c] = loc[strlen("limit")+2+c];
  5616. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5617. c++;
  5618. }
  5619. sstr[c] = '\0';
  5620. tempLimitInt = atof(sstr);
  5621. //*************numberPhases****************/
  5622. c = 0;
  5623. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5624. memset(sstr ,0, sizeof(sstr) );
  5625. if(loc != NULL)
  5626. {
  5627. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5628. {
  5629. sstr[c] = loc[strlen("numberPhases")+2+c];
  5630. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5631. c++;
  5632. }
  5633. sstr[c] = '\0';
  5634. tempNumberPhasesInt = atoi(sstr);
  5635. }
  5636. else
  5637. {
  5638. tempNumberPhasesInt = 0;
  5639. }
  5640. TxProfile.Duration = durationInt;
  5641. TxProfile.TotalPeriod = n_SchedulePeriods;
  5642. TxProfile.Period[i].Limit = tempLimitInt;
  5643. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5644. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5645. }
  5646. if(MinChargingRate < tempminChargingRateFloat)
  5647. MinChargingRate = tempminChargingRateFloat;
  5648. if(confirmPeriods < n_SchedulePeriods)
  5649. confirmPeriods = n_SchedulePeriods;
  5650. }
  5651. fclose(fptr1);
  5652. }
  5653. }// the end of ACCESS TxProfile
  5654. //CompositeSchedule
  5655. int period=0;
  5656. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5657. {
  5658. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5659. struct tm tp;
  5660. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5661. tp.tm_isdst = -1;
  5662. time_t utc = mktime(&tp);
  5663. time_t t = time(NULL);
  5664. double diff_f = difftime(t, utc);
  5665. int diff_i; // = (int)diff_f;
  5666. int quotient; // = diff_i / 86400;//86400 seconds/day
  5667. //int remainder = diff_i % 86400;
  5668. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5669. {
  5670. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5671. {
  5672. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5673. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5674. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5675. period = period + 1;
  5676. }
  5677. else
  5678. {
  5679. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5680. {
  5681. }
  5682. else
  5683. {
  5684. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5685. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5686. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5687. period = period + 1;
  5688. }
  5689. }
  5690. }
  5691. if( diff_f >= 0)
  5692. {
  5693. diff_i = (int)diff_f;
  5694. quotient = diff_i / 86400;//86400 seconds/day
  5695. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5696. {
  5697. if(((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)&& ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod %86400) > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5698. {
  5699. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5700. {
  5701. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5702. }
  5703. else
  5704. {
  5705. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5706. }
  5707. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5708. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5709. period = period + 1;
  5710. }
  5711. }
  5712. // Check Last Period
  5713. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5714. {
  5715. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5716. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5717. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5718. period = period + 1;
  5719. }
  5720. } // diff_f >= 0
  5721. }
  5722. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5723. {
  5724. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5725. struct tm tp;
  5726. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5727. tp.tm_isdst = -1;
  5728. time_t utc = mktime(&tp);
  5729. time_t t = time(NULL);
  5730. double diff_f = difftime(t, utc);
  5731. int diff_i;// = (int)diff_f;
  5732. int quotient; // = diff_i / 86400;//86400 seconds/day
  5733. //int remainder = diff_i % 86400;
  5734. if(diff_f >= 0)
  5735. {
  5736. diff_i = (int)diff_f;
  5737. quotient = diff_i / 86400;//86400 seconds/day
  5738. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5739. {
  5740. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5741. {
  5742. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5743. {
  5744. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5745. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5746. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5747. period = period + 1;
  5748. }
  5749. else
  5750. {
  5751. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5752. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5753. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5754. period = period + 1;
  5755. }
  5756. }
  5757. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5758. {
  5759. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5760. {
  5761. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5762. {
  5763. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5764. {
  5765. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5766. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5767. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5768. period = period + 1;
  5769. }
  5770. else
  5771. {
  5772. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5773. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5774. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5775. period = period + 1;
  5776. }
  5777. }
  5778. }
  5779. }
  5780. }
  5781. } // end diff_f >= 0
  5782. }
  5783. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5784. {
  5785. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5786. struct tm tp;
  5787. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5788. tp.tm_isdst = -1;
  5789. time_t utc = mktime(&tp);
  5790. time_t t = time(NULL);
  5791. double diff_f = difftime(t, utc);
  5792. int diff_i; // = (int)diff_f;
  5793. int quotient; // = diff_i / 86400;//86400 seconds/day
  5794. //int remainder = diff_i % 86400;
  5795. if(diff_f >= 0)
  5796. {
  5797. diff_i = (int)diff_f;
  5798. quotient = diff_i / 86400;//86400 seconds/day
  5799. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5800. {
  5801. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5802. {
  5803. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5804. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5805. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5806. period = period + 1;
  5807. }
  5808. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5809. {
  5810. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5811. {
  5812. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5813. {
  5814. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5815. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5816. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5817. period = period + 1;
  5818. }
  5819. }
  5820. }
  5821. }
  5822. } // diff_f >= 0
  5823. }
  5824. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5825. {
  5826. confirmPeriods = 0;
  5827. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5828. //goto end;
  5829. }
  5830. confirmPeriods = period;
  5831. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5832. //---- Define StartSchedule----/
  5833. struct tm *gtime;
  5834. time_t now;
  5835. char buf[28];
  5836. //---Read the current system time---/
  5837. time(&now);
  5838. //---Convert the system time to GMT (now UTC)---/
  5839. gtime = gmtime(&now);
  5840. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5841. // make .conf
  5842. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5843. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5844. //DEBUG_INFO(" debug 11\n");
  5845. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5846. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5847. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5848. }
  5849. else
  5850. {
  5851. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5852. }
  5853. //end:
  5854. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5855. return result;
  5856. }
  5857. int handleGetConfigurationRequest(char *uuid, char *payload)
  5858. {
  5859. mtrace();
  5860. int result = FAIL;
  5861. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5862. //struct json_object *jsonitem;
  5863. int MaxKeySupported = 0;
  5864. int n_keys = 0;
  5865. char requestKey[43][50]={0};
  5866. char search[]="[";
  5867. char sstr[500]={ 0 },sstrtemp[60]={ 0 };
  5868. //int pos;
  5869. int l, c = 0;
  5870. int i = 0;
  5871. char *delim = "\",\"";
  5872. char * pch;
  5873. strcpy(sstrtemp, stringtrimspace(payload));
  5874. char *loc = strstr(sstrtemp, search);
  5875. //********************* Parsing String ***********************************/
  5876. if(loc == NULL) {
  5877. DEBUG_INFO("no key match in Configuration \n");
  5878. }
  5879. else {
  5880. //pos = loc - payload;
  5881. l = strlen(loc)-4;
  5882. while (c < l)
  5883. {
  5884. sstr[c] = loc[c+2];
  5885. c++;
  5886. }
  5887. sstr[c] = '\0';
  5888. //parsing strings to words
  5889. pch = strtok(sstr,delim);
  5890. if(pch == NULL)
  5891. {
  5892. strcpy(requestKey[0], sstr);
  5893. }
  5894. else
  5895. {
  5896. while (pch != NULL)
  5897. {
  5898. strcpy(requestKey[i], pch);
  5899. pch = strtok (NULL, delim);
  5900. i = i + 1;
  5901. }
  5902. n_keys = i;
  5903. }
  5904. }
  5905. UnknownKeynum = 0;
  5906. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5907. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5908. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5909. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5910. if(n_keys != 0)
  5911. {
  5912. for(int i=0;i<n_keys;i++)
  5913. {
  5914. getKeyValue(requestKey[i]);
  5915. //json_object_put(jsonitem);
  5916. }
  5917. }
  5918. else
  5919. {
  5920. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5921. getKeyValue("");
  5922. }
  5923. processUnkownKey();
  5924. sendGetConfigurationConfirmation(uuid);
  5925. return result;
  5926. }
  5927. static char fnamePlusPath[100]={0};
  5928. static char fnamePWithNoPath[60]={0};
  5929. void checkUploadLog(void)
  5930. {
  5931. FILE *fp;
  5932. /* Open the command for reading. */
  5933. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5934. if (fp == NULL) {
  5935. printf("Failed to run command\n" );
  5936. exit(1);
  5937. }
  5938. int ftppathlen = 0;
  5939. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5940. int i = 0;
  5941. /* Read the output a line at a time - output it. */
  5942. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5943. if(i==0)
  5944. {
  5945. ftppathlen = strlen(fnamePlusPath);
  5946. printf("%s\n", fnamePlusPath);
  5947. fnamePlusPath[ftppathlen]='\0';
  5948. break;
  5949. }
  5950. i= i+1;
  5951. }
  5952. /* close */
  5953. pclose(fp);
  5954. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5955. {
  5956. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5957. {
  5958. fnamePlusPath[k]='\0';
  5959. }
  5960. }
  5961. i=1;
  5962. //char fname[60]={0};
  5963. while(i < ftppathlen)
  5964. {
  5965. int len=ftppathlen-i;
  5966. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5967. {
  5968. printf("compare '/' all right\n");
  5969. break;
  5970. }
  5971. i=i+1;
  5972. }
  5973. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5974. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5975. fnamePWithNoPath[i+1] = '\0';
  5976. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5977. {
  5978. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5979. {
  5980. fnamePWithNoPath[j]='\0';
  5981. }
  5982. }
  5983. FILE* fp1 = fopen(fnamePlusPath, "r");
  5984. if (fp1)
  5985. {
  5986. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5987. // file exists
  5988. fclose(fp1);
  5989. }
  5990. else
  5991. {
  5992. // file doesn't exist
  5993. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5994. }
  5995. }
  5996. static char GetDiagnosticspayloadData[300]={0};
  5997. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5998. {
  5999. mtrace();
  6000. int result = FAIL;
  6001. pthread_t t; // pthread 變數
  6002. system("exec /root/logPackTools 'log' 6");
  6003. #if 0
  6004. //char buffer [128];
  6005. time (&rawtime);
  6006. //printf("%ld\n", rawtime);
  6007. timeinfo = localtime (&rawtime);
  6008. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6009. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6010. if((access(fnamePlusPath,F_OK))!=-1)
  6011. {
  6012. DEBUG_INFO("fnamePlusPath exist.\n");
  6013. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6014. }
  6015. else
  6016. {
  6017. DEBUG_INFO("fnamePlusPath not exist!\n");
  6018. }
  6019. #endif
  6020. checkUploadLog();
  6021. memset(GetDiagnosticspayloadData, 0, 300);
  6022. strcpy(GetDiagnosticspayloadData, stringtrimspace(payload));
  6023. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  6024. pthread_create(&t, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6025. return result;
  6026. }
  6027. void* GetDiagnosticsProcess(void* data)
  6028. {
  6029. pthread_detach(pthread_self());
  6030. mtrace();
  6031. int retriesInt=0, retryIntervalInt=0;
  6032. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6033. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6034. 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};
  6035. int port=0;
  6036. char sstr[260]={ 0 };//sstr[200]={ 0 };
  6037. int c = 0;
  6038. char *loc;
  6039. int isSuccess = FALSE;
  6040. char ftpbuf[200]={0};
  6041. //char temp[100]={0};
  6042. char * pch;
  6043. // [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"}]
  6044. char str[300]={ 0 };
  6045. strcpy(str,(const char*)GetDiagnosticspayloadData);
  6046. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6047. DEBUG_INFO("GetDiagnosticsProcess\n");
  6048. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6049. //****************location*******************/
  6050. c = 0;
  6051. memset(sstr ,0, sizeof(sstr) );
  6052. loc = strstr(str, "location");
  6053. while (loc[3+strlen("location")+c] != '\"')
  6054. {
  6055. sstr[c] = loc[3+strlen("location")+c];
  6056. c++;
  6057. }
  6058. sstr[c] = '\0';
  6059. strcpy(locationstr,sstr);
  6060. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6061. if(strcmp(locationstr,"")==0)
  6062. {
  6063. DEBUG_INFO("location is <Empty>!\n");
  6064. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6065. goto end;
  6066. }
  6067. //****************retries*******************/
  6068. c = 0;
  6069. loc = strstr(str, "retries");
  6070. if(loc == NULL)
  6071. {
  6072. retriesIsNULL = TRUE;
  6073. }
  6074. else
  6075. {
  6076. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6077. {
  6078. sstr[c] = loc[strlen("retries")+2+c];
  6079. c++;
  6080. }
  6081. sstr[c] = '\0';
  6082. retriesInt = atoi(sstr);
  6083. }
  6084. if(retriesIsNULL == TRUE)
  6085. {
  6086. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6087. }
  6088. //****************retryInterval*******************/
  6089. c = 0;
  6090. loc = strstr(str, "retryInterval");
  6091. if(loc == NULL)
  6092. {
  6093. retryIntervalIsNULL = TRUE;
  6094. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6095. }
  6096. else
  6097. {
  6098. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6099. {
  6100. sstr[c] = loc[strlen("retryInterval")+2+c];
  6101. c++;
  6102. }
  6103. sstr[c] = '\0';
  6104. retryIntervalInt = atoi(sstr);
  6105. }
  6106. //****************startTime*******************/
  6107. c = 0;
  6108. memset(sstr ,0, sizeof(sstr) );
  6109. loc = strstr(str, "startTime");
  6110. if(loc == NULL)
  6111. {
  6112. startTimeIsNULL = TRUE;
  6113. }
  6114. else
  6115. {
  6116. while (loc[3+strlen("startTime")+c] != '\"')
  6117. {
  6118. sstr[c] = loc[3+strlen("startTime")+c];
  6119. c++;
  6120. }
  6121. sstr[c] = '\0';
  6122. strcpy(startTimestr,sstr);
  6123. }
  6124. //****************stopTime*******************/
  6125. c = 0;
  6126. memset(sstr ,0, sizeof(sstr) );
  6127. loc = strstr(str, "stopTime");
  6128. if(loc == NULL)
  6129. {
  6130. stopTimeIsNULL = TRUE;
  6131. }
  6132. else
  6133. {
  6134. while (loc[3+strlen("stopTime")+c] != '\"')
  6135. {
  6136. sstr[c] = loc[3+strlen("stopTime")+c];
  6137. c++;
  6138. }
  6139. sstr[c] = '\0';
  6140. strcpy(stopTimestr,sstr);
  6141. }
  6142. memset(protocol, 0, sizeof(protocol));
  6143. memset(user, 0, sizeof(user) );
  6144. memset(password, 0, sizeof(password));
  6145. memset(host, 0, sizeof(host));
  6146. memset(path, 0, sizeof(path));
  6147. memset(ftppath, 0, sizeof(ftppath));
  6148. memset(host1, 0, sizeof(host1));
  6149. memset(path1, 0, sizeof(path1));
  6150. /*location: ftp://user:password@host:port/path*/
  6151. #if 0
  6152. time_t rawtime;
  6153. struct tm * timeinfo;
  6154. //char buffer [128];
  6155. time (&rawtime);
  6156. //printf("%ld\n", rawtime);
  6157. timeinfo = localtime (&rawtime);
  6158. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6159. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6160. #endif
  6161. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6162. if((access(fnamePlusPath,F_OK))!=-1)
  6163. {
  6164. DEBUG_INFO("fnamePlusPath exist.\n");
  6165. }
  6166. else
  6167. {
  6168. DEBUG_INFO("fnamePlusPath not exist!\n");
  6169. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6170. goto end;
  6171. }
  6172. pch=strchr(locationstr,'@');
  6173. if(pch==NULL)
  6174. {
  6175. sscanf(locationstr,
  6176. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6177. protocol, host, &port, path);
  6178. strcpy(user,"anonymous");
  6179. strcpy(password,"");
  6180. }
  6181. else
  6182. {
  6183. //DEBUG_INFO("pch=%s\n", pch);
  6184. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6185. protocol, user, password, host, &port, path);
  6186. }
  6187. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6188. {
  6189. DEBUG_INFO("protocol is not ftp/http ! \n");
  6190. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6191. goto end;
  6192. }
  6193. if(strncmp(locationstr,"http", 4) == 0)
  6194. {
  6195. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6196. sprintf(ftppath,"/%s", path);
  6197. do{
  6198. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6199. sleep(retryIntervalInt);
  6200. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6201. if(!isSuccess)
  6202. {
  6203. DEBUG_INFO("Diagnostics fail.\n");
  6204. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6205. }
  6206. else
  6207. {
  6208. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6209. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6210. }
  6211. }
  6212. else
  6213. {
  6214. sscanf(host,"%[^/]%s",host1, path1);
  6215. sprintf(ftppath,"%s", path1);
  6216. int ftppathlen=strlen(ftppath);
  6217. int i=1;
  6218. char filenametemp[50];
  6219. while(i < ftppathlen)
  6220. {
  6221. int len=ftppathlen-i;
  6222. if(ftppath[len]== 47) // '/' ascll code: 47
  6223. {
  6224. DEBUG_INFO("find '/' all right\n");
  6225. break;
  6226. }
  6227. i=i+1;
  6228. }
  6229. memset(filenametemp, 0, sizeof(filenametemp));
  6230. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6231. filenametemp[i+1] = 0;
  6232. memset(ftpbuf, 0, sizeof(ftpbuf));
  6233. if(port == 0)
  6234. port = 21;
  6235. do{
  6236. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6237. sleep(retryIntervalInt);
  6238. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6239. if(!isSuccess)
  6240. {
  6241. DEBUG_INFO("Diagnostics fail.\n");
  6242. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6243. }
  6244. else
  6245. {
  6246. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6247. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6248. }
  6249. }
  6250. end:
  6251. DiagnosticsStatusNotificationStatus = 0; //Idle
  6252. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6253. }
  6254. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6255. {
  6256. mtrace();
  6257. int result = FAIL;
  6258. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6259. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6260. {
  6261. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6262. localversion = -1;
  6263. }
  6264. else
  6265. {
  6266. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6267. OCPP_getListVerion();
  6268. }
  6269. //from db.OCPP_getListVerion
  6270. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6271. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6272. sendGetLocalListVersionConfirmation(uuid,"");
  6273. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6274. return result;
  6275. }
  6276. int handleRemoteStartRequest(char *uuid, char *payload)
  6277. {
  6278. mtrace();
  6279. int result = FAIL;
  6280. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6281. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6282. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6283. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6284. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6285. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6286. int chargingSchedulePeriodCount = 0;
  6287. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6288. int c = 0;
  6289. char *loc;
  6290. char comfirmstr[20]={0};
  6291. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6292. if(server_pending == TRUE)
  6293. {
  6294. return 0;
  6295. }
  6296. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6297. strcpy(sstrtemp, stringtrimspace(payload));
  6298. //**********connectorId****************/
  6299. c = 0;
  6300. memset(sstr ,0, sizeof(sstr) );
  6301. loc = strstr(sstrtemp, "connectorId");
  6302. if(loc == NULL)
  6303. {
  6304. connectorIdIsNULL = TRUE;
  6305. }
  6306. else
  6307. {
  6308. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6309. {
  6310. sstr[c] = loc[strlen("connectorId")+2+c];
  6311. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6312. c++;
  6313. }
  6314. sstr[c] = '\0';
  6315. connectorIdInt = atoi(sstr);
  6316. }
  6317. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6318. {
  6319. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6320. goto end;
  6321. }
  6322. //****************idTag*******************/
  6323. c = 0;
  6324. memset(sstr ,0, sizeof(sstr) );
  6325. loc = strstr(sstrtemp, "idTag");
  6326. while (loc[3+strlen("idTag")+c] != '\"')
  6327. {
  6328. sstr[c] = loc[3+strlen("idTag")+c];
  6329. c++;
  6330. }
  6331. sstr[c] = '\0';
  6332. strcpy(idTagstr,sstr);
  6333. //****************chargingProfile*******************/
  6334. c = 0;
  6335. memset(sstr ,0, sizeof(sstr) );
  6336. loc = strstr(sstrtemp, "chargingProfile");
  6337. if(loc == NULL)
  6338. {
  6339. chargingProfileIsNULL = TRUE;
  6340. }
  6341. else
  6342. {
  6343. //****************chargingProfileId*******************/
  6344. c=0;
  6345. loc = strstr(sstrtemp, "chargingProfileId");
  6346. memset(sstr ,0, sizeof(sstr) );
  6347. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6348. {
  6349. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6350. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6351. c++;
  6352. }
  6353. sstr[c] = '\0';
  6354. chargingProfileIdInt = atoi(sstr);
  6355. //****************transactionId*******************/
  6356. loc = strstr(sstrtemp, "transactionId");
  6357. if(loc == NULL)
  6358. {
  6359. transactionIdIsNULL = TRUE;
  6360. }
  6361. else
  6362. {
  6363. c=0;
  6364. memset(sstr ,0, sizeof(sstr) );
  6365. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6366. {
  6367. sstr[c] = loc[strlen("transactionId")+2+c];
  6368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6369. c++;
  6370. }
  6371. sstr[c] = '\0';
  6372. transactionIdInt = atoi(sstr);
  6373. }
  6374. //****************stackLevel*******************/
  6375. c=0;
  6376. loc = strstr(sstrtemp, "stackLevel");
  6377. memset(sstr ,0, sizeof(sstr) );
  6378. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6379. {
  6380. sstr[c] = loc[strlen("stackLevel")+2+c];
  6381. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6382. c++;
  6383. }
  6384. sstr[c] = '\0';
  6385. stackLevelInt = atoi(sstr);
  6386. //****************chargingProfilePurpose*******************/
  6387. c = 0;
  6388. memset(sstr ,0, sizeof(sstr) );
  6389. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6390. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6391. {
  6392. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6393. c++;
  6394. }
  6395. sstr[c] = '\0';
  6396. strcpy(chargingProfilePurposestr,sstr);
  6397. //****************chargingProfileKind*******************/
  6398. c = 0;
  6399. memset(sstr ,0, sizeof(sstr) );
  6400. loc = strstr(sstrtemp, "chargingProfileKind");
  6401. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6402. {
  6403. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6404. c++;
  6405. }
  6406. sstr[c] = '\0';
  6407. strcpy(chargingProfileKindstr,sstr);
  6408. //****************recurrencyKind*******************/
  6409. loc = strstr(sstrtemp, "recurrencyKind");
  6410. if(loc == NULL)
  6411. {
  6412. recurrencyKindIsNULL = TRUE;
  6413. }
  6414. else
  6415. {
  6416. c = 0;
  6417. memset(sstr ,0, sizeof(sstr) );
  6418. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6419. {
  6420. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6421. c++;
  6422. }
  6423. sstr[c] = '\0';
  6424. strcpy(recurrencyKindstr,sstr);
  6425. }
  6426. //****************validFrom*******************/
  6427. loc = strstr(sstrtemp, "validFrom");
  6428. if(loc == NULL)
  6429. {
  6430. validFromIsNULL = TRUE;
  6431. }
  6432. else
  6433. {
  6434. c = 0;
  6435. memset(sstr ,0, sizeof(sstr) );
  6436. while (loc[3+strlen("validFrom")+c] != '\"')
  6437. {
  6438. sstr[c] = loc[3+strlen("validFrom")+c];
  6439. c++;
  6440. }
  6441. sstr[c] = '\0';
  6442. strcpy(validFromstr,sstr);
  6443. }
  6444. //****************validTo*******************/
  6445. loc = strstr(sstrtemp, "validTo");
  6446. if(loc == NULL)
  6447. {
  6448. validToIsNULL = TRUE;
  6449. }
  6450. else
  6451. {
  6452. c = 0;
  6453. memset(sstr ,0, sizeof(sstr) );
  6454. while (loc[3+strlen("validTo")+c] != '\"')
  6455. {
  6456. sstr[c] = loc[3+strlen("validTo")+c];
  6457. c++;
  6458. }
  6459. sstr[c] = '\0';
  6460. strcpy(validTostr,sstr);
  6461. }
  6462. //****************chargingSchedule*******************/
  6463. loc = strstr(sstrtemp, "chargingSchedule");
  6464. if(loc != NULL)
  6465. {
  6466. //****************duration*******************/
  6467. loc = strstr(sstrtemp, "duration");
  6468. if(loc == NULL)
  6469. {
  6470. durationIsNULL = TRUE;
  6471. }
  6472. else
  6473. {
  6474. c=0;
  6475. memset(sstr ,0, sizeof(sstr) );
  6476. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6477. {
  6478. sstr[c] = loc[strlen("duration")+2+c];
  6479. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6480. c++;
  6481. }
  6482. sstr[c] = '\0';
  6483. durationInt = atoi(sstr);
  6484. }
  6485. //****************startSchedule******************/
  6486. loc = strstr(sstrtemp, "startSchedule");
  6487. if(loc == NULL)
  6488. {
  6489. startScheduleIsNULL = TRUE;
  6490. }
  6491. else
  6492. {
  6493. c = 0;
  6494. memset(sstr ,0, sizeof(sstr) );
  6495. while (loc[3+strlen("startSchedule")+c] != '\"')
  6496. {
  6497. sstr[c] = loc[3+strlen("startSchedule")+c];
  6498. c++;
  6499. }
  6500. sstr[c] = '\0';
  6501. strcpy(startSchedulestr,sstr);
  6502. }
  6503. //****************chargingRateUnit*******************/
  6504. c = 0;
  6505. memset(sstr ,0, sizeof(sstr) );
  6506. loc = strstr(sstrtemp, "chargingRateUnit");
  6507. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6508. {
  6509. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6510. c++;
  6511. }
  6512. sstr[c] = '\0';
  6513. strcpy(chargingRateUnitstr,sstr);
  6514. //****************minChargingRate*******************/
  6515. loc = strstr(sstrtemp, "minChargingRate");
  6516. if(loc == NULL)
  6517. {
  6518. minChargingRateIsNULL = TRUE;
  6519. }
  6520. else
  6521. {
  6522. c=0;
  6523. memset(sstr ,0, sizeof(sstr) );
  6524. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6525. {
  6526. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6527. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6528. c++;
  6529. }
  6530. sstr[c] = '\0';
  6531. minChargingRateflaot = atof(sstr);
  6532. }
  6533. //****************chargingSchedulePeriod count*******************/
  6534. int what_len = strlen("startPeriod");
  6535. char *where = sstrtemp;
  6536. while ((where = strstr(where, "startPeriod"))) {
  6537. where += what_len;
  6538. chargingSchedulePeriodCount++;
  6539. }
  6540. where = sstrtemp;
  6541. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6542. {
  6543. //****************startPeriod*******************/
  6544. c=0;
  6545. loc = strstr(where, "startPeriod");
  6546. memset(sstr ,0, sizeof(sstr) );
  6547. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6548. {
  6549. sstr[c] = loc[strlen("startPeriod")+2+c];
  6550. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6551. c++;
  6552. }
  6553. sstr[c] = '\0';
  6554. startPeriodInt[periodNums] = atoi(sstr);
  6555. //****************limit*******************/
  6556. c=0;
  6557. loc = strstr(where, "limit");
  6558. memset(sstr ,0, sizeof(sstr) );
  6559. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6560. {
  6561. sstr[c] = loc[strlen("limit")+2+c];
  6562. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6563. c++;
  6564. }
  6565. sstr[c] = '\0';
  6566. limitflaot[periodNums] = atof(sstr);
  6567. //****************numberPhases*******************/
  6568. loc = strstr(where, "numberPhases");
  6569. if(loc == NULL)
  6570. {
  6571. numberPhasesIsNULL = TRUE;
  6572. }
  6573. else
  6574. {
  6575. c=0;
  6576. memset(sstr ,0, sizeof(sstr) );
  6577. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6578. {
  6579. sstr[c] = loc[strlen("numberPhases")+2+c];
  6580. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6581. c++;
  6582. }
  6583. sstr[c] = '\0';
  6584. numberPhasesInt[periodNums] = atoi(sstr);
  6585. }
  6586. where = loc;
  6587. }
  6588. }
  6589. }
  6590. /*
  6591. enum _SYSTEM_STATUS
  6592. {
  6593. S_BOOTING = 0,
  6594. S_IDLE, = 1
  6595. S_AUTHORIZING, =2
  6596. S_REASSIGN_CHECK, =3
  6597. S_REASSIGN, =4
  6598. S_PRECHARGE, =5
  6599. S_PREPARING_FOR_EV, =6
  6600. S_PREPARING_FOR_EVSE, =7
  6601. S_CHARGING, =8
  6602. S_TERMINATING, =9
  6603. S_COMPLETE, =10
  6604. S_ALARM, =11
  6605. S_FAULT =12
  6606. }
  6607. */
  6608. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6609. {
  6610. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6611. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6612. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6613. //check Transaction active
  6614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6615. {
  6616. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6617. {
  6618. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6619. {
  6620. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6621. {
  6622. //Reserved
  6623. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6624. }
  6625. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6626. {
  6627. //Reserved
  6628. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6629. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6630. goto end;
  6631. }
  6632. else
  6633. {
  6634. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6635. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6636. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6637. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6638. {
  6639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6640. goto end;
  6641. }
  6642. }//END FOR ELSE
  6643. }
  6644. }// END FOR CHAdeMO_QUANTITY
  6645. for (int index = 0; index < CCS_QUANTITY; index++)
  6646. {
  6647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6648. {
  6649. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6650. {
  6651. //Reserved
  6652. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6653. }
  6654. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6655. {
  6656. //Reserved
  6657. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6658. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6659. goto end;
  6660. }
  6661. else
  6662. {
  6663. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6664. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6665. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6666. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6667. {
  6668. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6669. goto end;
  6670. }
  6671. }// END FOR ELSE
  6672. }
  6673. }// END FOR CCS_QUANTITY
  6674. for (int index = 0; index < GB_QUANTITY; index++)
  6675. {
  6676. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6677. {
  6678. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6679. {
  6680. //Reserved
  6681. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6682. }
  6683. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6684. {
  6685. //Reserved
  6686. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6687. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6688. goto end;
  6689. }
  6690. else
  6691. {
  6692. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6693. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6694. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6695. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6696. {
  6697. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6698. goto end;
  6699. }
  6700. }// END FOR ELSE
  6701. }
  6702. } // END FOR GB_QUANTITY
  6703. }
  6704. else
  6705. {
  6706. for (int index = 0; index < AC_QUANTITY; index++)
  6707. {
  6708. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6709. {
  6710. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6711. {
  6712. //Reserved
  6713. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6714. }
  6715. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6716. {
  6717. //Reserved
  6718. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6719. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6720. goto end;
  6721. }
  6722. else
  6723. {
  6724. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6725. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6726. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6727. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6728. {
  6729. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6730. goto end;
  6731. }
  6732. }//END FOR ELSE
  6733. }
  6734. }// END FOR AC_QUANTITY
  6735. }
  6736. if(chargingProfileIsNULL == FALSE)
  6737. {
  6738. //ChargingProfile
  6739. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6740. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6741. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6742. if(recurrencyKindIsNULL == FALSE) //OPTION
  6743. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6744. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6745. if(transactionIdIsNULL == FALSE) // OPTION
  6746. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6747. if(validFromIsNULL == FALSE) // OPTION
  6748. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6749. if(validToIsNULL == FALSE) //OPTION
  6750. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6751. //ChargingSchedule
  6752. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6753. if(durationIsNULL == FALSE) //OPTION
  6754. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6755. if(minChargingRateIsNULL == FALSE) //OPTION
  6756. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6757. if(startScheduleIsNULL == FALSE) //OPTION
  6758. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6759. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6760. {
  6761. //ChargingSchedulePeriod
  6762. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6763. if(numberPhasesIsNULL == FALSE)
  6764. {
  6765. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6766. }
  6767. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6768. }
  6769. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6770. {
  6771. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6772. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6773. //memset idTag
  6774. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6775. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6776. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6777. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6778. }
  6779. else
  6780. {
  6781. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6782. }
  6783. }
  6784. else
  6785. {
  6786. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6787. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6788. //memset idTag
  6789. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6790. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6791. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6792. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6793. }
  6794. }
  6795. else
  6796. {
  6797. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6798. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6799. }
  6800. end:
  6801. if(connectorIdIsNULL == FALSE)
  6802. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6803. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6804. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6805. //OCPP send RemoteStartConfirmation by first.
  6806. sendRemoteStartConfirmation(uuid, comfirmstr);
  6807. return result;
  6808. }
  6809. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6810. {
  6811. mtrace();
  6812. int result = FAIL;
  6813. int match = FALSE;
  6814. int GunNO = 0;
  6815. int transactionIdInt=0;
  6816. int transactionIdIsNULL= FALSE;
  6817. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  6818. int c = 0;
  6819. char *loc;
  6820. char comfirmstr[20];
  6821. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6822. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6823. if(server_pending == TRUE)
  6824. {
  6825. return 0;
  6826. }
  6827. strcpy(sstrtemp, stringtrimspace(payload));
  6828. c=0;
  6829. loc = strstr(sstrtemp, "transactionId");
  6830. if(loc == NULL)
  6831. {
  6832. transactionIdIsNULL= TRUE;
  6833. }
  6834. else
  6835. {
  6836. memset(sstr ,0, sizeof(sstr) );
  6837. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6838. {
  6839. sstr[c] = loc[strlen("transactionId")+2+c];
  6840. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6841. c++;
  6842. }
  6843. sstr[c] = '\0';
  6844. transactionIdInt = atoi(sstr);
  6845. }
  6846. if(transactionIdIsNULL == FALSE)
  6847. {
  6848. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6849. {
  6850. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6851. {
  6852. //check Transaction active
  6853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6854. {
  6855. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6856. {
  6857. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6858. {
  6859. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6860. {
  6861. match = TRUE;
  6862. GunNO = gun_index;
  6863. }
  6864. }
  6865. }// END FOR CHAdeMO_QUANTITY
  6866. for (int index = 0; index < CCS_QUANTITY; index++)
  6867. {
  6868. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6869. {
  6870. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6871. {
  6872. match = TRUE;
  6873. GunNO = gun_index;
  6874. }
  6875. }
  6876. }// END FOR CCS_QUANTITY
  6877. for (int index = 0; index < GB_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6880. {
  6881. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6882. {
  6883. match = TRUE;
  6884. GunNO = gun_index;
  6885. }
  6886. }
  6887. }// END FOR GB_QUANTITY
  6888. }
  6889. else
  6890. {
  6891. for (int index = 0; index < AC_QUANTITY; index++)
  6892. {
  6893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6894. {
  6895. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6896. {
  6897. match = TRUE;
  6898. GunNO = gun_index;
  6899. }
  6900. }
  6901. }// END FOR CHAdeMO_QUANTITY
  6902. }// END FOR AC ELSE
  6903. }// CHECK IF ResponseTransactionId == transactionIdInt
  6904. }//END FOR
  6905. if( match == TRUE)
  6906. {
  6907. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6908. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6909. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6910. }
  6911. else
  6912. {
  6913. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6914. }
  6915. }
  6916. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6917. return result;
  6918. }
  6919. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6920. {
  6921. mtrace();
  6922. int result = FAIL;
  6923. int connectorIdInt=0, reservationIdInt=0;
  6924. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6925. char comfirmstr[20]={0};
  6926. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  6927. int c = 0;
  6928. char *loc;
  6929. //char *ptr;
  6930. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6931. strcpy(sstrtemp, stringtrimspace(payload));
  6932. //***(1)connectorId ****/
  6933. c=0;
  6934. loc = strstr(sstrtemp, "connectorId");
  6935. memset(sstr ,0, sizeof(sstr) );
  6936. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6937. {
  6938. sstr[c] = loc[strlen("connectorId")+2+c];
  6939. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6940. c++;
  6941. }
  6942. sstr[c] = '\0';
  6943. connectorIdInt = atoi(sstr);
  6944. //***(2)expiryDate ****/
  6945. loc = strstr(sstrtemp, "expiryDate");
  6946. memset(sstr ,0, sizeof(sstr) );
  6947. c = 0;
  6948. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6949. {
  6950. sstr[c] = loc[3+strlen("expiryDate")+c];
  6951. c++;
  6952. }
  6953. sstr[c] = '\0';
  6954. strcpy(expiryDatestr, sstr);
  6955. //***(3)idTag ****/
  6956. loc = strstr(sstrtemp, "idTag");
  6957. memset(sstr ,0, sizeof(sstr) );
  6958. c = 0;
  6959. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6960. {
  6961. sstr[c] = loc[3+strlen("idTag")+c];
  6962. c++;
  6963. }
  6964. sstr[c] = '\0';
  6965. strcpy(idTagstr, sstr);
  6966. //***(4)parentIdTag ****/
  6967. loc = strstr(sstrtemp, "parentIdTag");
  6968. memset(sstr ,0, sizeof(sstr) );
  6969. c = 0;
  6970. if(loc == NULL)
  6971. {
  6972. strcpy(parentIdTagstr, "");
  6973. }
  6974. else
  6975. {
  6976. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6977. {
  6978. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6979. c++;
  6980. }
  6981. sstr[c] = '\0';
  6982. strcpy(parentIdTagstr, sstr);
  6983. }
  6984. //***(5)reservationId ****/
  6985. c=0;
  6986. loc = strstr(sstrtemp, "reservationId");
  6987. memset(sstr ,0, sizeof(sstr) );
  6988. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6989. {
  6990. sstr[c] = loc[strlen("reservationId")+2+c];
  6991. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6992. c++;
  6993. }
  6994. sstr[c] = '\0';
  6995. reservationIdInt = atoi(sstr);
  6996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6997. /*
  6998. enum SYSTEM_STATUS
  6999. {
  7000. SYS_MODE_BOOTING = 0,
  7001. SYS_MODE_IDLE = 1,
  7002. SYS_MODE_AUTHORIZING = 2,
  7003. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7004. SYS_MODE_REASSIGN = 4,
  7005. SYS_MODE_PREPARING = 5,
  7006. SYS_MODE_PREPARE_FOR_EV = 6,
  7007. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7008. SYS_MODE_CHARGING = 8,
  7009. SYS_MODE_TERMINATING = 9,
  7010. SYS_MODE_COMPLETE = 10,
  7011. SYS_MODE_ALARM = 11,
  7012. SYS_MODE_FAULT = 12,
  7013. SYS_MODE_RESERVATION = 13,
  7014. SYS_MODE_BOOKING = 14,
  7015. SYS_MODE_MAINTAIN = 15,
  7016. SYS_MODE_DEBUG = 16,
  7017. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7018. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7019. SYS_MODE_UPDATE = 19
  7020. };
  7021. */
  7022. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7023. {
  7024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7025. goto end;
  7026. }
  7027. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7028. {
  7029. //check Transaction active
  7030. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7031. {
  7032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7033. {
  7034. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7035. {
  7036. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7037. {
  7038. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7039. {
  7040. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7041. {
  7042. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7044. }
  7045. 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'))
  7046. {
  7047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7048. }
  7049. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7050. {
  7051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7052. }
  7053. else
  7054. {
  7055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7056. }
  7057. }
  7058. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7059. {
  7060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7061. }
  7062. }
  7063. else
  7064. {
  7065. //replace reservation
  7066. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7068. }
  7069. }
  7070. } // END FOR CHAdeMO_QUANTITY
  7071. for (int index = 0; index < CCS_QUANTITY; index++)
  7072. {
  7073. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7074. {
  7075. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7076. {
  7077. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7078. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7079. {
  7080. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7081. {
  7082. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7084. }
  7085. 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'))
  7086. {
  7087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7088. }
  7089. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7090. {
  7091. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7092. }
  7093. else
  7094. {
  7095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7096. }
  7097. }
  7098. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  7099. {
  7100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7101. }
  7102. }
  7103. else
  7104. {
  7105. //replace reservation
  7106. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7108. }
  7109. }
  7110. } // END FOR CCS_QUANTITY
  7111. for (int index = 0; index < GB_QUANTITY; index++)
  7112. {
  7113. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7114. {
  7115. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7116. {
  7117. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7118. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7119. {
  7120. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7121. {
  7122. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7124. }
  7125. 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'))
  7126. {
  7127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7128. }
  7129. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7130. {
  7131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7132. }
  7133. else
  7134. {
  7135. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7136. }
  7137. }
  7138. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7139. {
  7140. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7141. }
  7142. }
  7143. else
  7144. {
  7145. //replace reservation
  7146. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7148. }
  7149. }
  7150. }// END FOR GB_QUANTITY
  7151. }
  7152. else
  7153. {
  7154. for (int index = 0; index < AC_QUANTITY; index++)
  7155. {
  7156. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7157. {
  7158. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7159. {
  7160. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7161. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7162. {
  7163. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7164. {
  7165. 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))
  7166. {
  7167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7168. }
  7169. else
  7170. {
  7171. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7172. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7173. }
  7174. }
  7175. 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'))
  7176. {
  7177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7178. }
  7179. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7180. {
  7181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7182. }
  7183. else
  7184. {
  7185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7186. }
  7187. }
  7188. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7189. {
  7190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7191. }
  7192. }
  7193. else
  7194. {
  7195. //replace reservation
  7196. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7198. }
  7199. }
  7200. } // END FOR AC_QUANTITY
  7201. }//END FOR AC ELSE
  7202. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7203. }
  7204. else if(connectorIdInt == 0)
  7205. {
  7206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7207. {
  7208. //check Transaction active
  7209. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7210. {
  7211. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7212. {
  7213. 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'))
  7214. {
  7215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7216. goto end;
  7217. }
  7218. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7219. {
  7220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7221. goto end;
  7222. }
  7223. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7224. {
  7225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7226. goto end;
  7227. }
  7228. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7229. {
  7230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7231. goto end;
  7232. }
  7233. }
  7234. }// END FOR CHAdeMO_QUANTITY
  7235. for (int index = 0; index < CCS_QUANTITY; index++)
  7236. {
  7237. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7238. {
  7239. 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'))
  7240. {
  7241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7242. }
  7243. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7244. {
  7245. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7246. }
  7247. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7248. {
  7249. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7250. }
  7251. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7252. {
  7253. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7254. }
  7255. }
  7256. } // END FOR CCS_QUANTITY
  7257. for (int index = 0; index < GB_QUANTITY; index++)
  7258. {
  7259. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7260. {
  7261. 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'))
  7262. {
  7263. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7264. }
  7265. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7266. {
  7267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7268. }
  7269. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING) ) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7270. {
  7271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7272. }
  7273. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7274. {
  7275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7276. }
  7277. }
  7278. } // END FOR GB_QUANTITY
  7279. }
  7280. else
  7281. {
  7282. for (int index = 0; index < AC_QUANTITY; index++)
  7283. {
  7284. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7285. {
  7286. 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'))
  7287. {
  7288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7289. goto end;
  7290. }
  7291. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7292. {
  7293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7294. goto end;
  7295. }
  7296. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7297. {
  7298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7299. goto end;
  7300. }
  7301. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7302. {
  7303. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7304. goto end;
  7305. }
  7306. }
  7307. }// END FOR AC_QUANTITY
  7308. }
  7309. //The connectorId is 0
  7310. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7311. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7312. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7313. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7314. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7315. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7316. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7317. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7318. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7319. result = TRUE;
  7320. return result;
  7321. }
  7322. else
  7323. {
  7324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7325. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7326. }
  7327. if(strcmp(comfirmstr,"Accepted") == 0)
  7328. {
  7329. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7330. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7331. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7332. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7333. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7334. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7335. result = TRUE;
  7336. return result;
  7337. }
  7338. end:
  7339. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7340. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7341. return result;
  7342. }
  7343. int handleResetRequest(char *uuid, char *payload)
  7344. {
  7345. mtrace();
  7346. int result = FAIL;
  7347. char sstr[10]={0},sstrtemp[30]={ 0 };
  7348. char typestr[10]={0};
  7349. char comfirmstr[20]={0};
  7350. int c = 0;
  7351. char *loc;
  7352. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7353. DEBUG_INFO("handleResetRequest ...\n");
  7354. strcpy(sstrtemp, stringtrimspace(payload));
  7355. loc = strstr(sstrtemp, "type");
  7356. memset(sstr ,0, sizeof(sstr) );
  7357. c = 0;
  7358. while (loc[3+strlen("type")+c] != '\"')
  7359. {
  7360. sstr[c] = loc[3+strlen("type")+c];
  7361. c++;
  7362. }
  7363. sstr[c] = '\0';
  7364. strcpy(typestr,sstr);
  7365. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7366. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7367. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7368. {
  7369. //check Transaction active
  7370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7371. {
  7372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7373. {
  7374. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7375. {
  7376. //0: unplug, 1: Plug-in
  7377. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7378. }
  7379. }
  7380. for (int index = 0; index < CCS_QUANTITY; index++)
  7381. {
  7382. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7383. {
  7384. //0: unplug, 1: Plug-in
  7385. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7386. }
  7387. }
  7388. for (int index = 0; index < GB_QUANTITY; index++)
  7389. {
  7390. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7391. {
  7392. //0: unplug, 1: Plug-in
  7393. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7394. }
  7395. }
  7396. }
  7397. else
  7398. {
  7399. for (int index = 0; index < AC_QUANTITY; index++)
  7400. {
  7401. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7402. {
  7403. //0: unplug, 1: Plug-in
  7404. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7405. }
  7406. }
  7407. }// END FOR AC ELSE
  7408. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7409. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7410. result = TRUE;
  7411. return result;
  7412. }
  7413. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7414. {
  7415. //check Transaction active
  7416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7417. {
  7418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7419. {
  7420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7421. {
  7422. //0: unplug, 1: Plug-in
  7423. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7424. }
  7425. }
  7426. for (int index = 0; index < CCS_QUANTITY; index++)
  7427. {
  7428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7429. {
  7430. //0: unplug, 1: Plug-in
  7431. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7432. }
  7433. }
  7434. for (int index = 0; index < GB_QUANTITY; index++)
  7435. {
  7436. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7437. {
  7438. //0: unplug, 1: Plug-in
  7439. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7440. }
  7441. }
  7442. }
  7443. else
  7444. {
  7445. for (int index = 0; index < AC_QUANTITY; index++)
  7446. {
  7447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7448. {
  7449. //0: unplug, 1: Plug-in
  7450. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7451. }
  7452. }
  7453. }// END FOR AC ELSE
  7454. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7455. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7456. result = TRUE;
  7457. return result;
  7458. }
  7459. else
  7460. {
  7461. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7462. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7463. goto errorend;
  7464. }
  7465. errorend:
  7466. sendResetConfirmation(uuid, comfirmstr);
  7467. return result;
  7468. }
  7469. int handleSendLocalListRequest(char *uuid, char *payload)
  7470. {
  7471. mtrace();
  7472. int result = FAIL;
  7473. int listVersionInt;
  7474. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7475. char listsearch[]="listVersion";
  7476. char updateTypesearch[]="updateType";
  7477. char localAuthorizationListsearch[]="localAuthorizationList";
  7478. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7479. char CardList[500][160]={0};
  7480. char updateTypestr[15]={0};
  7481. char idTagstr[20]={0};
  7482. char parentIdTag[20]={0};
  7483. char expiryDate[30]={0};
  7484. char idTagstatus[16]={0};
  7485. int c = 0;
  7486. int i = 0;
  7487. char *delim1 = "}";
  7488. char * pch;
  7489. char *loc;
  7490. //char *ptr;
  7491. char comfirmstr[20];
  7492. //int n_localAuthorizations = 0;
  7493. int checkState_Faulted = FALSE;
  7494. DEBUG_INFO("handleSendLocalListRequest\n");
  7495. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7496. {
  7497. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7498. goto end;
  7499. }
  7500. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7501. {
  7502. //check Charge Point state
  7503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7504. {
  7505. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7506. {
  7507. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7508. }
  7509. }
  7510. for (int index = 0; index < CCS_QUANTITY; index++)
  7511. {
  7512. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7513. {
  7514. checkState_Faulted = TRUE; //OCPP Status
  7515. }
  7516. }
  7517. for (int index = 0; index < GB_QUANTITY; index++)
  7518. {
  7519. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7520. {
  7521. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7522. }
  7523. }
  7524. }
  7525. else
  7526. {
  7527. //check Charge Point state
  7528. for (int index = 0; index < AC_QUANTITY; index++)
  7529. {
  7530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7531. {
  7532. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7533. }
  7534. }
  7535. }// END FOR AC ELSE
  7536. if(checkState_Faulted == TRUE)
  7537. {
  7538. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7539. goto end;
  7540. }
  7541. strcpy(sstrtemp, stringtrimspace(payload));
  7542. //listVersion
  7543. c = 0;
  7544. loc = strstr(sstrtemp, listsearch);
  7545. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7546. {
  7547. sstr[c] = loc[strlen("listVersion")+2+c];
  7548. c++;
  7549. }
  7550. sstr[c] = '\0';
  7551. listVersionInt = atoi(sstr);
  7552. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7553. //updateType
  7554. loc = strstr(sstrtemp, updateTypesearch);
  7555. c = 0;
  7556. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7557. {
  7558. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7559. c++;
  7560. }
  7561. sstr[c] = '\0';
  7562. strcpy(updateTypestr, sstr);
  7563. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7564. //localAuthorizationList
  7565. memset(sstr ,0, sizeof(sstr) );
  7566. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7567. if(loc != NULL) // localAuthorizationList is not NULL
  7568. {
  7569. //Check UpdateType
  7570. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7571. {
  7572. //Local list full update
  7573. printf("Local list full update.\n");
  7574. OCPP_getListVerion();
  7575. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7576. {
  7577. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7578. goto end;
  7579. }
  7580. OCPP_cleanLocalList();
  7581. }
  7582. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7583. {
  7584. //Local list different update
  7585. printf("Local list different update.\n");
  7586. OCPP_getListVerion();
  7587. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7588. {
  7589. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7590. goto end;
  7591. }
  7592. }
  7593. else
  7594. {
  7595. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7596. goto end;
  7597. }
  7598. c = 0;
  7599. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7600. {
  7601. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7602. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7603. c++;
  7604. }
  7605. sstr[c] = '\0';
  7606. //DEBUG_INFO("sstr=%s\n", sstr);
  7607. //parsing strings to words
  7608. i = 0;
  7609. pch = strtok(sstr,delim1);
  7610. while (pch != NULL)
  7611. {
  7612. strcpy(CardList[i], pch);
  7613. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7614. pch = strtok (NULL, delim1);
  7615. i = i + 1;
  7616. }
  7617. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7618. //local Authorizations List Numbers
  7619. //n_localAuthorizations = i;
  7620. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7621. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7622. c= 0;
  7623. while(c < i) // i is CardList Number
  7624. {
  7625. //Search "IdToken"
  7626. memset(sstr ,0, sizeof(sstr) );
  7627. loc = strstr(CardList[c], "idTag");
  7628. int j = 0;
  7629. while (loc[3+strlen("idTag")+j] != '\"')
  7630. {
  7631. sstr[j] = loc[3+strlen("idTag")+j];
  7632. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7633. j++;
  7634. }
  7635. sstr[j] = '\0';
  7636. strcpy(idTagstr, sstr);
  7637. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7638. //Search "expiryDate"
  7639. memset(sstr ,0, sizeof(sstr) );
  7640. loc = strstr(CardList[c], "expiryDate");
  7641. j = 0;
  7642. if(loc != NULL)
  7643. {
  7644. while (loc[3+strlen("expiryDate")+j] != '\"')
  7645. {
  7646. sstr[j] = loc[3+strlen("expiryDate")+j];
  7647. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7648. j++;
  7649. }
  7650. sstr[j] = '\0';
  7651. strcpy(expiryDate, sstr);
  7652. }
  7653. else
  7654. {
  7655. strcpy(expiryDate, "");
  7656. }
  7657. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7658. //Search "parentIdTag"
  7659. memset(sstr ,0, sizeof(sstr) );
  7660. loc = strstr(CardList[c], "parentIdTag");
  7661. j = 0;
  7662. if(loc != NULL)
  7663. {
  7664. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7665. {
  7666. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7667. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7668. j++;
  7669. }
  7670. sstr[j] = '\0';
  7671. strcpy(parentIdTag, sstr);
  7672. }
  7673. else
  7674. {
  7675. strcpy(parentIdTag, "");
  7676. }
  7677. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7678. //Search "status"
  7679. memset(sstr ,0, sizeof(sstr) );
  7680. loc = strstr(CardList[c], "status");
  7681. j = 0;
  7682. while (loc[3+strlen("status")+j] != '\"')
  7683. {
  7684. sstr[j] = loc[3+strlen("status")+j];
  7685. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7686. j++;
  7687. }
  7688. sstr[j] = '\0';
  7689. strcpy(idTagstatus, sstr);
  7690. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7691. OCPP_getIdTag(idTagstr);
  7692. //OCPP_getIdTag("test"); For Test
  7693. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7694. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7695. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7696. {
  7697. //Local list full update
  7698. DEBUG_INFO("Local list full update.\n");
  7699. // update list
  7700. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7701. //DEBUG_INFO("Local list full update. 1\n");
  7702. //OCPP_get_TableAuthlocalAllData();
  7703. //DEBUG_INFO("Local list full update. 2\n");
  7704. }
  7705. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7706. {
  7707. #if 0
  7708. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7709. {
  7710. //OCPP_deleteIdTag(idTagstr);
  7711. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7712. }
  7713. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7714. {
  7715. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7716. }
  7717. #endif
  7718. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7719. }
  7720. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7721. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7722. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7723. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7724. c++;
  7725. }
  7726. }
  7727. else
  7728. {
  7729. //Check UpdateType
  7730. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7731. {
  7732. //Local list full update
  7733. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7734. OCPP_cleanLocalList();
  7735. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7736. goto end;
  7737. }
  7738. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7739. {
  7740. //Local list different update
  7741. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7742. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7743. goto end;
  7744. }
  7745. }
  7746. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7747. end:
  7748. sendSendLocalListConfirmation(uuid, comfirmstr);
  7749. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7750. return result;
  7751. }
  7752. #define MAX 200
  7753. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7754. {
  7755. mtrace();
  7756. int result = FAIL;
  7757. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7758. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7759. char chargingProfilePurposeStr[30]={0};
  7760. char chargingProfileKindStr[16]={0};
  7761. char recurrencyKindStr[10]={0};
  7762. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7763. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7764. int chargingSchedulePeriodCount = 0;
  7765. //int updateflag = FALSE;
  7766. char comfirmstr[20]={0};
  7767. int meet= FALSE;
  7768. char sstr[10]={0},sstrtemp[1600]={ 0 };
  7769. int c = 0;
  7770. char *loc;
  7771. FILE *fptr1;//, *fptr2;
  7772. //int lno=0;//, linectr = 0;
  7773. //int modifyflag = FALSE;
  7774. char filename[MAX]={0};
  7775. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7776. //int resultRename=0;
  7777. char rmFileCmd[50]={0};
  7778. char tempchargingProfilePurposeStr[30]={0};
  7779. char word[1600]={0};
  7780. int n_chargingProfile = 0;
  7781. //[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}}}]
  7782. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7783. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7784. strcpy(sstrtemp, stringtrimspace(payload));
  7785. //*********************connectorId***************************/
  7786. loc = strstr(sstrtemp, "connectorId");
  7787. c = 0;
  7788. memset(sstr ,0, sizeof(sstr) );
  7789. while (loc[strlen("connectorId")+2+c] != ',')
  7790. {
  7791. sstr[c] = loc[strlen("connectorId")+2+c];
  7792. c++;
  7793. }
  7794. sstr[c] = '\0';
  7795. connectorIdInt = atoi(sstr);
  7796. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7797. {
  7798. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7799. }
  7800. else
  7801. {
  7802. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7803. }
  7804. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7805. //*********************chargingProfileId***************************/
  7806. loc = strstr(sstrtemp, "chargingProfileId");
  7807. c = 0;
  7808. memset(sstr ,0, sizeof(sstr) );
  7809. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7810. {
  7811. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7812. c++;
  7813. }
  7814. sstr[c] = '\0';
  7815. chargingProfileIdInt = atoi(sstr);
  7816. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7817. {
  7818. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7819. }
  7820. else
  7821. {
  7822. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7823. }
  7824. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7825. //*********************transactionId***************************/
  7826. loc = strstr(sstrtemp, "transactionId");
  7827. if(loc != NULL)
  7828. {
  7829. c = 0;
  7830. memset(sstr ,0, sizeof(sstr) );
  7831. while (loc[strlen("transactionId")+2+c] != ',')
  7832. {
  7833. sstr[c] = loc[strlen("transactionId")+2+c];
  7834. c++;
  7835. }
  7836. sstr[c] = '\0';
  7837. transactionIdInt = atoi(sstr);
  7838. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7839. {
  7840. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7841. }
  7842. else
  7843. {
  7844. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7845. }
  7846. }
  7847. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7848. //*********************stackLevel***************************/
  7849. loc = strstr(sstrtemp, "stackLevel");
  7850. c = 0;
  7851. memset(sstr ,0, sizeof(sstr) );
  7852. while (loc[strlen("stackLevel")+2+c] != ',')
  7853. {
  7854. sstr[c] = loc[strlen("stackLevel")+2+c];
  7855. c++;
  7856. }
  7857. sstr[c] = '\0';
  7858. stackLevelInt = atoi(sstr);
  7859. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7860. {
  7861. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7862. }
  7863. else
  7864. {
  7865. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7866. }
  7867. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7868. //*********************chargingProfilePurpose***************************/
  7869. loc = strstr(sstrtemp, "chargingProfilePurpose");
  7870. c = 0;
  7871. memset(sstr ,0, sizeof(sstr) );
  7872. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7873. {
  7874. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7875. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7876. c++;
  7877. }
  7878. sstr[c] = '\0';
  7879. strcpy(chargingProfilePurposeStr,sstr);
  7880. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7881. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7882. {
  7883. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7884. }
  7885. else
  7886. {
  7887. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7888. }
  7889. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7890. //*********************chargingProfileKind***************************/
  7891. loc = strstr(sstrtemp, "chargingProfileKind");
  7892. c = 0;
  7893. memset(sstr ,0, sizeof(sstr) );
  7894. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7895. {
  7896. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7897. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7898. c++;
  7899. }
  7900. sstr[c] = '\0';
  7901. strcpy(chargingProfileKindStr,sstr);
  7902. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7903. {
  7904. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7905. }
  7906. else
  7907. {
  7908. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7909. }
  7910. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7911. //*********************recurrencyKind***************************/
  7912. loc = strstr(sstrtemp, "recurrencyKind");
  7913. if(loc != NULL)
  7914. {
  7915. c = 0;
  7916. memset(sstr ,0, sizeof(sstr) );
  7917. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7918. {
  7919. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7920. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7921. c++;
  7922. }
  7923. sstr[c] = '\0';
  7924. strcpy(recurrencyKindStr,sstr);
  7925. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7926. {
  7927. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7928. }
  7929. else
  7930. {
  7931. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7932. }
  7933. }
  7934. else
  7935. {
  7936. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7937. {
  7938. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7939. }
  7940. else
  7941. {
  7942. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7943. }
  7944. }
  7945. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7946. //*********************validFrom***************************/
  7947. loc = strstr(sstrtemp, "validFrom");
  7948. if(loc != NULL)
  7949. {
  7950. c = 0;
  7951. memset(sstr ,0, sizeof(sstr) );
  7952. while (loc[3+strlen("validFrom")+c] != '\"')
  7953. {
  7954. sstr[c] = loc[3+strlen("validFrom")+c];
  7955. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7956. c++;
  7957. }
  7958. sstr[c] = '\0';
  7959. strcpy(validFromStr,sstr);
  7960. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7961. {
  7962. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7963. }
  7964. else
  7965. {
  7966. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7967. }
  7968. }
  7969. else
  7970. {
  7971. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7972. {
  7973. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7974. }
  7975. else
  7976. {
  7977. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7978. }
  7979. }
  7980. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7981. //*********************validTo***************************/
  7982. loc = strstr(sstrtemp, "validTo");
  7983. if(loc != NULL)
  7984. {
  7985. c = 0;
  7986. memset(sstr ,0, sizeof(sstr) );
  7987. while (loc[3+strlen("validTo")+c] != '\"')
  7988. {
  7989. sstr[c] = loc[3+strlen("validTo")+c];
  7990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7991. c++;
  7992. }
  7993. sstr[c] = '\0';
  7994. strcpy(validToStr,sstr);
  7995. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7996. {
  7997. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7998. }
  7999. else
  8000. {
  8001. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8002. }
  8003. }
  8004. else
  8005. {
  8006. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8007. {
  8008. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8009. }
  8010. else
  8011. {
  8012. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8013. }
  8014. }
  8015. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8016. //*********************duration***************************/
  8017. loc = strstr(sstrtemp, "duration");
  8018. if(loc != NULL)
  8019. {
  8020. c = 0;
  8021. memset(sstr ,0, sizeof(sstr) );
  8022. while (loc[strlen("duration")+2+c] != ',')
  8023. {
  8024. sstr[c] = loc[strlen("duration")+2+c];
  8025. c++;
  8026. }
  8027. sstr[c] = '\0';
  8028. durationInt = atoi(sstr);
  8029. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8030. {
  8031. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8032. }
  8033. else
  8034. {
  8035. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8036. }
  8037. }
  8038. else
  8039. {
  8040. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8041. {
  8042. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8043. }
  8044. else
  8045. {
  8046. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8047. }
  8048. }
  8049. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8050. //*********************startSchedule***************************/
  8051. loc = strstr(sstrtemp, "startSchedule");
  8052. if(loc != NULL)
  8053. {
  8054. c = 0;
  8055. memset(sstr ,0, sizeof(sstr) );
  8056. while (loc[3+strlen("startSchedule")+c] != '\"')
  8057. {
  8058. sstr[c] = loc[3+strlen("startSchedule")+c];
  8059. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8060. c++;
  8061. }
  8062. sstr[c] = '\0';
  8063. strcpy(startScheduleStr,sstr);
  8064. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8065. {
  8066. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8067. }
  8068. else
  8069. {
  8070. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8071. }
  8072. }
  8073. else
  8074. {
  8075. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8076. {
  8077. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8078. }
  8079. else
  8080. {
  8081. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8082. }
  8083. }
  8084. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8085. //*********************chargingRateUnit***************************/
  8086. loc = strstr(sstrtemp, "chargingRateUnit");
  8087. if(loc != NULL)
  8088. {
  8089. c = 0;
  8090. memset(sstr ,0, sizeof(sstr) );
  8091. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8092. {
  8093. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8094. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8095. c++;
  8096. }
  8097. sstr[c] = '\0';
  8098. strcpy(chargingRateUnitStr,sstr);
  8099. #if 0
  8100. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8101. {
  8102. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8103. goto end;
  8104. }
  8105. #endif
  8106. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8107. {
  8108. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8109. }
  8110. else
  8111. {
  8112. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8113. }
  8114. }
  8115. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8116. //****************chargingSchedulePeriod count start*******************/
  8117. int what_len = strlen("startPeriod");
  8118. char tempChargingProfile[1600]={0};
  8119. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8120. char *where = tempChargingProfile;
  8121. if (what_len)
  8122. {
  8123. while ((where = strstr(where, "startPeriod"))) {
  8124. where += what_len;
  8125. chargingSchedulePeriodCount++;
  8126. }
  8127. }
  8128. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8129. {
  8130. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8131. goto end;
  8132. }
  8133. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8134. //where = payload;
  8135. int templength = 0;
  8136. //int searchstart = 0;
  8137. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8138. {
  8139. //****************startPeriod*******************/
  8140. c=0;
  8141. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8142. memset(sstr ,0, sizeof(sstr) );
  8143. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8144. {
  8145. sstr[c] = loc[strlen("startPeriod")+2+c];
  8146. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8147. c++;
  8148. }
  8149. sstr[c] = '\0';
  8150. startPeriodInt[periodNums] = atoi(sstr);
  8151. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8152. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8153. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8154. {
  8155. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8156. }
  8157. else
  8158. {
  8159. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8160. }
  8161. templength = strlen("startPeriod")+2+c;
  8162. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8163. //****************limit*******************/
  8164. c=0;
  8165. loc = strstr(tempChargingProfile + templength, "limit");
  8166. memset(sstr ,0, sizeof(sstr) );
  8167. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8168. {
  8169. sstr[c] = loc[strlen("limit")+2+c];
  8170. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8171. c++;
  8172. }
  8173. sstr[c] = '\0';
  8174. limitflaot[periodNums] = atof(sstr);
  8175. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8176. {
  8177. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8178. }
  8179. else
  8180. {
  8181. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8182. }
  8183. templength = templength + strlen("limit")+2+c;
  8184. //****************numberPhases*******************/
  8185. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8186. if(loc != NULL)
  8187. {
  8188. c=0;
  8189. memset(sstr ,0, sizeof(sstr) );
  8190. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8191. {
  8192. sstr[c] = loc[strlen("numberPhases")+2+c];
  8193. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8194. c++;
  8195. }
  8196. sstr[c] = '\0';
  8197. numberPhasesInt[periodNums] = atoi(sstr);
  8198. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8199. {
  8200. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8201. }
  8202. else
  8203. {
  8204. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8205. }
  8206. templength = templength + strlen("numberPhases")+2+c;
  8207. }
  8208. //where = loc;
  8209. }
  8210. //****************chargingSchedulePeriod count end*******************/
  8211. //*********************minChargingRate***************************/
  8212. loc = strstr(sstrtemp, "minChargingRate");
  8213. if(loc != NULL)
  8214. {
  8215. c = 0;
  8216. memset(sstr ,0, sizeof(sstr) );
  8217. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8218. {
  8219. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8220. c++;
  8221. }
  8222. sstr[c] = '\0';
  8223. minChargingRateFloat = atof(sstr);
  8224. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8225. {
  8226. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8227. }
  8228. else
  8229. {
  8230. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8231. }
  8232. }
  8233. else
  8234. {
  8235. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8236. {
  8237. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8238. }
  8239. else
  8240. {
  8241. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8242. }
  8243. }
  8244. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8245. {
  8246. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8247. if(connectorIdInt != 0)
  8248. {
  8249. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8250. goto end;
  8251. }
  8252. strcpy(filename, ChargePointMaxProfile_JSON );
  8253. fptr1 = fopen(filename, "r");
  8254. if (!fptr1)
  8255. {
  8256. //file not exist
  8257. DEBUG_INFO("Unable to open the input file!!\n");
  8258. fptr1 = fopen(filename, "w+");
  8259. }
  8260. else
  8261. {
  8262. //Check Charging Profile Count
  8263. while(fscanf(fptr1, "%s", word) != EOF)
  8264. {
  8265. //DEBUG_INFO("word=%s\n",word);
  8266. if(strstr(word, "chargingProfileId")!= NULL)
  8267. {
  8268. //DEBUG_INFO("test chargingProfileId \n");
  8269. n_chargingProfile = n_chargingProfile + 1;
  8270. //DEBUG_INFO("chargingProfileId Found\n");
  8271. }
  8272. }
  8273. }
  8274. fclose(fptr1);
  8275. }
  8276. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8277. {
  8278. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8279. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8280. {
  8281. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8282. goto end;
  8283. }
  8284. memset(filename, 0, sizeof filename);
  8285. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8286. fptr1 = fopen(filename, "r");
  8287. if (!fptr1)
  8288. {
  8289. //file not exist
  8290. //DEBUG_INFO("Unable to open the input file!!\n");
  8291. fptr1 = fopen(filename, "w+");
  8292. }
  8293. else
  8294. {
  8295. //Check Charging Profile Count
  8296. while(fscanf(fptr1, "%s", word) != EOF)
  8297. {
  8298. //DEBUG_INFO("word=%s\n",word);
  8299. if(strstr(word, "chargingProfileId")!= NULL)
  8300. {
  8301. //DEBUG_INFO("test chargingProfileId \n");
  8302. n_chargingProfile = n_chargingProfile + 1;
  8303. //DEBUG_INFO("chargingProfileId Found\n");
  8304. }
  8305. }
  8306. }
  8307. fclose(fptr1);
  8308. }
  8309. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8310. {
  8311. //printf("set chargingProfile 1-4\n");
  8312. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8313. //check Transaction active
  8314. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8315. {
  8316. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8317. {
  8318. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8319. {
  8320. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8321. {
  8322. meet = TRUE;
  8323. break;
  8324. }
  8325. }
  8326. }
  8327. }
  8328. for (int index = 0; index < CCS_QUANTITY; index++)
  8329. {
  8330. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8331. {
  8332. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8333. {
  8334. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8335. {
  8336. meet = TRUE;
  8337. break;
  8338. }
  8339. }
  8340. }
  8341. }
  8342. for (int index = 0; index < GB_QUANTITY; index++)
  8343. {
  8344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8345. {
  8346. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8347. {
  8348. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8349. {
  8350. meet = TRUE;
  8351. break;
  8352. }
  8353. }
  8354. }
  8355. }
  8356. for (int index = 0; index < AC_QUANTITY; index++)
  8357. {
  8358. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  8359. {
  8360. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8361. {
  8362. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8363. {
  8364. meet = TRUE;
  8365. break;
  8366. }
  8367. }
  8368. }
  8369. }
  8370. if(meet == FALSE)
  8371. {
  8372. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8373. goto end;
  8374. }
  8375. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8376. {
  8377. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8378. goto end;
  8379. }
  8380. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8381. fptr1 = fopen(filename, "r");
  8382. if (!fptr1)
  8383. {
  8384. //file not exist
  8385. DEBUG_INFO("Unable to open the input file!!\n");
  8386. fptr1 = fopen(filename, "w+");
  8387. }
  8388. else
  8389. {
  8390. //Check Charging Profile Count
  8391. while(fscanf(fptr1, "%s", word) != EOF)
  8392. {
  8393. //DEBUG_INFO("word=%s\n",word);
  8394. if(strstr(word, "chargingProfileId")!= NULL)
  8395. {
  8396. //DEBUG_INFO("test chargingProfileId \n");
  8397. n_chargingProfile = n_chargingProfile + 1;
  8398. //DEBUG_INFO("chargingProfileId Found\n");
  8399. }
  8400. }
  8401. }
  8402. fclose(fptr1);
  8403. }
  8404. // Check ChargeProfileMaxStackLevel
  8405. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8406. {
  8407. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8408. goto end;
  8409. }
  8410. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8411. {
  8412. int i = 0;
  8413. char fnametemp[200]={0};
  8414. n_chargingProfile = 0;
  8415. //Check ChargePointMaxProfile.json exit
  8416. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8417. {
  8418. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8419. //Check Charging Profile Count
  8420. while(fscanf(fptr1, "%s", word) != EOF)
  8421. {
  8422. //DEBUG_INFO("word=%s\n",word);
  8423. if(strstr(word, "chargingProfileId")!= NULL)
  8424. {
  8425. //DEBUG_INFO("test chargingProfileId \n");
  8426. n_chargingProfile = n_chargingProfile + 1;
  8427. i = i + 1;
  8428. //DEBUG_INFO("chargingProfileId Found\n");
  8429. }
  8430. memset(word, 0, sizeof word);
  8431. }
  8432. fclose(fptr1);
  8433. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8434. }
  8435. //Check TxDefaultProfile_0.json exit
  8436. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8437. {
  8438. i = 0;
  8439. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8440. //Check Charging Profile Count
  8441. while(fscanf(fptr1, "%s", word) != EOF)
  8442. {
  8443. //DEBUG_INFO("word=%s\n",word);
  8444. if(strstr(word, "chargingProfileId")!= NULL)
  8445. {
  8446. //DEBUG_INFO("test chargingProfileId \n");
  8447. n_chargingProfile = n_chargingProfile + 1;
  8448. i = i + 1;
  8449. //DEBUG_INFO("chargingProfileId Found\n");
  8450. }
  8451. memset(word, 0, sizeof word);
  8452. }
  8453. fclose(fptr1);
  8454. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8455. }
  8456. //Check TxDefaultProfile_%d.json
  8457. for(int j=1; j <= gunTotalNumber; j++)
  8458. {
  8459. memset(fnametemp, 0, sizeof fnametemp);
  8460. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8461. if((access(fnametemp,F_OK))!=-1)
  8462. {
  8463. i = 0;
  8464. fptr1 = fopen(fnametemp, "r");
  8465. //Check Charging Profile Count
  8466. while(fscanf(fptr1, "%s", word) != EOF)
  8467. {
  8468. //DEBUG_INFO("word=%s\n",word);
  8469. if(strstr(word, "chargingProfileId")!= NULL)
  8470. {
  8471. //DEBUG_INFO("test chargingProfileId \n");
  8472. n_chargingProfile = n_chargingProfile + 1;
  8473. i = i + 1;
  8474. //DEBUG_INFO("chargingProfileId Found\n");
  8475. }
  8476. memset(word, 0, sizeof word);
  8477. }
  8478. fclose(fptr1);
  8479. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8480. }
  8481. }
  8482. //Check TxProfile_%d.json
  8483. for(int j=1; j <= gunTotalNumber; j++)
  8484. {
  8485. memset(fnametemp, 0, sizeof fnametemp);
  8486. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8487. if((access(fnametemp,F_OK))!=-1)
  8488. {
  8489. i = 0;
  8490. fptr1 = fopen(fnametemp, "r");
  8491. //Check Charging Profile Count
  8492. while(fscanf(fptr1, "%s", word) != EOF)
  8493. {
  8494. //DEBUG_INFO("word=%s\n",word);
  8495. if(strstr(word, "chargingProfileId")!= NULL)
  8496. {
  8497. //DEBUG_INFO("test chargingProfileId \n");
  8498. n_chargingProfile = n_chargingProfile + 1;
  8499. i = i + 1;
  8500. //DEBUG_INFO("chargingProfileId Found\n");
  8501. }
  8502. memset(word, 0, sizeof word);
  8503. }
  8504. fclose(fptr1);
  8505. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8506. }
  8507. }
  8508. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8509. {
  8510. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8511. goto end;
  8512. }
  8513. }
  8514. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8515. //**********************************Write to File********************************************************/
  8516. FILE *infile;
  8517. FILE *outfile;
  8518. // open file for writing
  8519. infile = fopen (filename, "r");
  8520. outfile = fopen (tempfile, "w");
  8521. int d =0;
  8522. d = fgetc(infile);
  8523. //DEBUG_INFO("d:%d\n",d);
  8524. rewind(infile);
  8525. //*检测到文件结束标识返回1,否则返回0。*/
  8526. if(d == EOF)
  8527. {
  8528. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8529. fprintf(outfile,"%s\n",payload);
  8530. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8531. fclose(infile);
  8532. fclose(outfile);
  8533. sprintf(rmFileCmd,"rm -f %s",filename);
  8534. system(rmFileCmd);
  8535. rename(tempfile, filename);
  8536. sleep(1);
  8537. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8538. //system(rmFileCmd);
  8539. }
  8540. else
  8541. {
  8542. char buf[1000]={0};
  8543. int ChargingProfileAdded = FALSE;
  8544. while (fgets(buf, sizeof(buf), infile) != NULL)
  8545. {
  8546. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8547. //*************************tempconnectorIdInt*********************************/
  8548. loc = strstr(buf, "connectorId");
  8549. c = 0;
  8550. memset(sstr ,0, sizeof(sstr) );
  8551. while (loc[strlen("connectorId")+2+c] != ',')
  8552. {
  8553. sstr[c] = loc[strlen("connectorId")+2+c];
  8554. c++;
  8555. }
  8556. sstr[c] = '\0';
  8557. tempconnectorIdInt = atoi(sstr);
  8558. //*************************tempchargingProfileIdInt*********************************/
  8559. loc = strstr(buf, "chargingProfileId");
  8560. c = 0;
  8561. memset(sstr ,0, sizeof(sstr) );
  8562. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8563. {
  8564. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8565. c++;
  8566. }
  8567. sstr[c] = '\0';
  8568. tempchargingProfileIdInt = atoi(sstr);
  8569. //*************************tempstackLevelInt*********************************/
  8570. loc = strstr(buf, "stackLevel");
  8571. c = 0;
  8572. memset(sstr ,0, sizeof(sstr) );
  8573. while (loc[strlen("stackLevel")+2+c] != ',')
  8574. {
  8575. sstr[c] = loc[strlen("stackLevel")+2+c];
  8576. c++;
  8577. }
  8578. sstr[c] = '\0';
  8579. tempstackLevelInt = atoi(sstr);
  8580. //*************************tempchargingProfilePurposeStr*********************************/
  8581. loc = strstr(payload, "chargingProfilePurpose");
  8582. c = 0;
  8583. memset(sstr ,0, sizeof(sstr) );
  8584. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8585. {
  8586. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8587. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8588. c++;
  8589. }
  8590. sstr[c] = '\0';
  8591. strcpy(tempchargingProfilePurposeStr,sstr);
  8592. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8593. {
  8594. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8595. {
  8596. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8597. if(ChargingProfileAdded == FALSE)
  8598. {
  8599. fprintf(outfile,"%s\n",payload);
  8600. ChargingProfileAdded = TRUE;
  8601. }
  8602. }
  8603. else
  8604. {
  8605. if(tempstackLevelInt < stackLevelInt)
  8606. {
  8607. if(ChargingProfileAdded == FALSE)
  8608. {
  8609. fprintf(outfile,"%s\n",payload);
  8610. ChargingProfileAdded = TRUE;
  8611. fprintf(outfile,"%s\n",buf);
  8612. }
  8613. else
  8614. {
  8615. fprintf(outfile,"%s\n",buf);
  8616. }
  8617. }
  8618. else
  8619. {
  8620. if(ChargingProfileAdded == FALSE)
  8621. {
  8622. fprintf(outfile,"%s\n",buf);
  8623. fprintf(outfile,"%s\n",payload);
  8624. ChargingProfileAdded = TRUE;
  8625. }
  8626. else
  8627. {
  8628. fprintf(outfile,"%s\n",buf);
  8629. }
  8630. }
  8631. }
  8632. }
  8633. else
  8634. {
  8635. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8636. {
  8637. if(ChargingProfileAdded == FALSE)
  8638. {
  8639. fprintf(outfile,"%s\n",payload);
  8640. ChargingProfileAdded = TRUE;
  8641. fprintf(outfile,"%s\n",buf);
  8642. }
  8643. else
  8644. {
  8645. fprintf(outfile,"%s\n",buf);
  8646. }
  8647. }
  8648. else if(tempstackLevelInt < stackLevelInt)
  8649. {
  8650. if(ChargingProfileAdded == FALSE)
  8651. {
  8652. fprintf(outfile,"%s\n",payload);
  8653. ChargingProfileAdded = TRUE;
  8654. fprintf(outfile,"%s\n",buf);
  8655. }
  8656. else
  8657. {
  8658. fprintf(outfile,"%s\n",buf);
  8659. }
  8660. }
  8661. else
  8662. {
  8663. if(ChargingProfileAdded == FALSE)
  8664. {
  8665. fprintf(outfile,"%s\n",buf);
  8666. fprintf(outfile,"%s\n",payload);
  8667. ChargingProfileAdded = TRUE;
  8668. }
  8669. else
  8670. {
  8671. fprintf(outfile,"%s\n",buf);
  8672. }
  8673. }
  8674. }
  8675. } // end of while loop
  8676. fclose(infile);
  8677. fclose(outfile);
  8678. sprintf(rmFileCmd,"rm -f %s",filename);
  8679. system(rmFileCmd);
  8680. rename(tempfile, filename);
  8681. sleep(1);
  8682. result = TRUE;
  8683. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8684. }
  8685. end:
  8686. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8687. return result;
  8688. return result;
  8689. }
  8690. int handleTriggerMessageRequest(char *uuid, char *payload)
  8691. {
  8692. mtrace();
  8693. int result = FAIL;
  8694. int connectorIdIsNULL = FALSE;
  8695. int connectorIdInt =0;
  8696. char sstr[40]={0},sstrtemp[100]={ 0 };
  8697. char requestedMessagestr[40]={0};
  8698. char comfirmstr[20]={0};
  8699. int c = 0;
  8700. char *loc;
  8701. DEBUG_INFO("handleTriggerMessageRequest\n");
  8702. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8703. strcpy(sstrtemp, stringtrimspace(payload));
  8704. c = 0;
  8705. loc = strstr(sstrtemp, "requestedMessage");
  8706. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8707. {
  8708. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8709. c++;
  8710. }
  8711. sstr[c] = '\0';
  8712. strcpy(requestedMessagestr, sstr);
  8713. c = 0;
  8714. loc = strstr(sstrtemp, "connectorId");
  8715. if(loc == NULL)
  8716. {
  8717. connectorIdIsNULL = TRUE;
  8718. }
  8719. else
  8720. {
  8721. memset(sstr ,0, sizeof(sstr) );
  8722. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8723. {
  8724. sstr[c] = loc[strlen("connectorId")+2+c];
  8725. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8726. c++;
  8727. }
  8728. sstr[c] = '\0';
  8729. connectorIdInt = atoi(sstr);
  8730. }
  8731. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8732. {
  8733. //connectorIdInt = json_object_get_int(connectorId);
  8734. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8735. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8736. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8737. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8738. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8739. }
  8740. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8741. {
  8742. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8743. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8744. return TRUE;
  8745. }
  8746. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8747. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8748. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8749. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8750. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8751. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8752. {
  8753. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8754. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8755. return TRUE;
  8756. }
  8757. else
  8758. {
  8759. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8760. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8761. }
  8762. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8763. {
  8764. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8765. {
  8766. FirmwareStatusNotificationStatus = 3;
  8767. }
  8768. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8769. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8770. }
  8771. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8772. {
  8773. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8774. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8775. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8776. }
  8777. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8778. {
  8779. sendBootNotificationRequest();
  8780. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8781. }
  8782. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8783. {
  8784. sendHeartbeatRequest(connectorIdInt);
  8785. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8786. }
  8787. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8788. {
  8789. if(connectorIdIsNULL == FALSE)
  8790. {
  8791. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8792. {
  8793. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8794. sendMeterValuesRequest(connectorIdInt -1);
  8795. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8796. }
  8797. }
  8798. else
  8799. {
  8800. for(int idx=0;idx< gunTotalNumber;idx++)
  8801. {
  8802. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8803. sendMeterValuesRequest(idx);
  8804. }
  8805. }
  8806. }
  8807. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8808. {
  8809. if(connectorIdIsNULL == FALSE)
  8810. {
  8811. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8812. {
  8813. sendStatusNotificationRequest(connectorIdInt -1);
  8814. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8815. }
  8816. }
  8817. else
  8818. {
  8819. for(int idx=0;idx< gunTotalNumber;idx++)
  8820. sendStatusNotificationRequest(idx);
  8821. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8822. }
  8823. }
  8824. return result;
  8825. }
  8826. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8827. {
  8828. mtrace();
  8829. int result = FAIL;
  8830. char sstr[6]={0},sstrtemp[50]={ 0 };
  8831. int connectorIdInt =0;
  8832. char comfirmstr[20]={0};
  8833. int c = 0;
  8834. char *loc;
  8835. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8836. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8837. strcpy(sstrtemp, stringtrimspace(payload));
  8838. c = 0;
  8839. loc = strstr(sstrtemp, "connectorId");
  8840. memset(sstr ,0, sizeof(sstr) );
  8841. while (loc[strlen("connectorId")+2+c] != '}')
  8842. {
  8843. sstr[c] = loc[strlen("connectorId")+2+c];
  8844. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8845. c++;
  8846. }
  8847. sstr[c] = '\0';
  8848. connectorIdInt = atoi(sstr);
  8849. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8850. if(gunTotalNumber == 0)
  8851. {
  8852. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8853. goto end;
  8854. }
  8855. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8856. {
  8857. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8858. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8859. goto end;
  8860. }
  8861. else
  8862. {
  8863. //check Transaction active
  8864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8865. {
  8866. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8867. {
  8868. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8869. {
  8870. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8871. }
  8872. }
  8873. for (int index = 0; index < CCS_QUANTITY; index++)
  8874. {
  8875. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8876. {
  8877. //stop Transaction
  8878. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8879. }
  8880. }
  8881. for (int index = 0; index < GB_QUANTITY; index++)
  8882. {
  8883. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8884. {
  8885. //stop Transaction
  8886. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8887. }
  8888. }
  8889. }
  8890. else
  8891. {
  8892. for (int index = 0; index < AC_QUANTITY; index++)
  8893. {
  8894. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8895. {
  8896. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8897. }
  8898. }
  8899. }// END FOR AC ELSE
  8900. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8901. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8902. result = TRUE;
  8903. return result;
  8904. }
  8905. end:
  8906. //json_object_put(obj); --- remove temporally
  8907. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8908. return result;
  8909. }
  8910. static char UpdateFirmwarepayloadData[300]={0};
  8911. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8912. {
  8913. mtrace();
  8914. int result = FAIL;
  8915. pthread_t t;
  8916. sendUpdateFirmwareConfirmation(uuid);
  8917. memset(UpdateFirmwarepayloadData, 0, 300);
  8918. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  8919. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  8920. ////pthread_join(t, NULL); //
  8921. //pthread_detach(t);
  8922. //sendUpdateFirmwareConfirmation(uuid);
  8923. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8924. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8925. return result;
  8926. }
  8927. void *UpdateFirmwareProcess(void *data)
  8928. {
  8929. pthread_detach(pthread_self());
  8930. mtrace();
  8931. int retriesInt =0, retryIntervalInt=0;
  8932. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8933. int port=0;
  8934. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8935. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8936. //char comfirmstr[20];
  8937. int isSuccess = 0;
  8938. char ftpbuf[200];
  8939. char temp[100];
  8940. char * pch;
  8941. int retriesISNULL=FALSE;
  8942. int retryInterval=FALSE;
  8943. int c = 0;
  8944. //int i = 0;
  8945. char *loc;
  8946. char sstr[300]={ 0 };
  8947. char str[300]={ 0 };
  8948. //char *str = (char*) data; // ? ?輸入資 ?
  8949. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8950. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8951. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8952. //***************location **************/
  8953. loc = strstr(str, "location");
  8954. memset(sstr ,0, sizeof(sstr) );
  8955. c = 0;
  8956. while (loc[3+strlen("location")+c] != '\"')
  8957. {
  8958. sstr[c] = loc[3+strlen("location")+c];
  8959. c++;
  8960. }
  8961. sstr[c] = '\0';
  8962. strcpy(locationstr, sstr);
  8963. //***************retries**************/
  8964. c = 0;
  8965. loc = strstr(str, "retries");
  8966. if(loc == NULL)
  8967. {
  8968. retriesISNULL=TRUE;
  8969. }
  8970. else
  8971. {
  8972. memset(sstr ,0, sizeof(sstr) );
  8973. while (loc[strlen("retries")+2+c] != ',')
  8974. {
  8975. sstr[c] = loc[strlen("retries")+2+c];
  8976. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8977. c++;
  8978. }
  8979. sstr[c] = '\0';
  8980. }
  8981. if(retriesISNULL == FALSE)
  8982. {
  8983. retriesInt = atoi(sstr);
  8984. }
  8985. //***************retrieveDate **************/
  8986. loc = strstr(str, "retrieveDate");
  8987. memset(sstr ,0, sizeof(sstr) );
  8988. c = 0;
  8989. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8990. {
  8991. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8992. c++;
  8993. }
  8994. sstr[c] = '\0';
  8995. strcpy(retrieveDatestr, sstr);
  8996. //***************retryInterval **************/
  8997. c = 0;
  8998. loc = strstr(str, "retryInterval");
  8999. memset(sstr ,0, sizeof(sstr) );
  9000. if(loc == NULL)
  9001. {
  9002. retryInterval=TRUE;
  9003. }
  9004. else
  9005. {
  9006. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9007. {
  9008. sstr[c] = loc[strlen("retryInterval")+2+c];
  9009. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9010. c++;
  9011. }
  9012. sstr[c] = '\0';
  9013. }
  9014. if(retryInterval==FALSE)
  9015. {
  9016. retryIntervalInt = atoi(sstr);
  9017. }
  9018. memset(ftppath, 0, sizeof(ftppath));
  9019. memset(path, 0, sizeof(path));
  9020. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9021. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9022. if(strncmp(locationstr,"http", 4) == 0)
  9023. {
  9024. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9025. protocol, host, path);
  9026. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9027. // protocol, user, password, host, path);
  9028. sprintf(ftppath,"/%s", path);
  9029. //DEBUG_INFO("protocol =%s\n",protocol);
  9030. //DEBUG_INFO("host =%s\n",host);
  9031. //DEBUG_INFO("path =%s\n",path);
  9032. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9033. int ftppathlen=strlen(ftppath);
  9034. int i=1;
  9035. char filenametemp[50];
  9036. while(i < ftppathlen)
  9037. {
  9038. int len=ftppathlen-i;
  9039. if(ftppath[len]== 47) // '/' ascll code: 47
  9040. {
  9041. DEBUG_INFO("compare '/' all right\n");
  9042. break;
  9043. }
  9044. i=i+1;
  9045. }
  9046. memset(filenametemp, 0, sizeof(filenametemp));
  9047. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9048. filenametemp[i+1] = 0;
  9049. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9050. do{
  9051. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9052. sleep(retryIntervalInt);
  9053. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9054. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9055. if(!isSuccess)
  9056. {
  9057. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9058. }
  9059. else
  9060. {
  9061. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9062. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9063. //isUpdateRequest = TRUE;
  9064. }
  9065. }
  9066. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9067. {
  9068. memset(ftpbuf, 0, sizeof(ftpbuf));
  9069. memset(temp, 0, sizeof(temp));
  9070. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9071. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9072. int ftppathlen=strlen(ftpbuf);
  9073. int i=1;
  9074. char filenametemp[50];
  9075. while(i < ftppathlen)
  9076. {
  9077. int len=ftppathlen-i;
  9078. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9079. {
  9080. DEBUG_INFO(" compare '/' all right\n");
  9081. break;
  9082. }
  9083. i=i+1;
  9084. }
  9085. memset(filenametemp, 0, sizeof(filenametemp));
  9086. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9087. filenametemp[i+1] = 0;
  9088. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9089. pch=strchr(temp,'@');
  9090. if(pch==NULL)
  9091. {
  9092. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9093. protocol, host, &port, path);
  9094. strcpy(user,"anonymous");
  9095. strcpy(password,"");
  9096. }
  9097. else
  9098. {
  9099. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9100. protocol, user, password, host, &port, path);
  9101. }
  9102. sscanf(host,"%[^/]%s",host1, path1);
  9103. sprintf(ftppath,"%s", path1);
  9104. //DEBUG_INFO("protocol =%s\n",protocol);
  9105. //DEBUG_INFO("user =%s\n",user);
  9106. //DEBUG_INFO("password =%s\n",password);
  9107. //DEBUG_INFO("host1 =%s\n",host1);
  9108. //DEBUG_INFO("port =%d\n",port);
  9109. //DEBUG_INFO("path1 =%s\n",path1);
  9110. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9111. //ftpFile(host, user, password, port, ftppath, fname);
  9112. //download firmware pthred
  9113. if(port == 0)
  9114. {
  9115. port = 21;
  9116. }
  9117. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9118. do{
  9119. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9120. sleep(retryIntervalInt);
  9121. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9122. if(!isSuccess)
  9123. {
  9124. //BulldogUtil.sleepMs(interval*1000);
  9125. DEBUG_INFO("Update firmware request and download file fail.\n");
  9126. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9127. }
  9128. else
  9129. {
  9130. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9131. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9132. //isUpdateRequest = TRUE;
  9133. }
  9134. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9135. }
  9136. else
  9137. {
  9138. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9139. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9140. }
  9141. pthread_exit(NULL);
  9142. }
  9143. //==========================================
  9144. // Handle server response routine
  9145. //==========================================
  9146. void handleAuthorizeResponse(char *payload, int gun_index)
  9147. {
  9148. mtrace();
  9149. char expiryDatestr[30]={0};
  9150. char parentIdTagstr[20]={0};
  9151. char statusstr[20]={0};
  9152. char expiryDatestrtemp[30]={0};
  9153. char parentIdTagstrtemp[20]={0};
  9154. char IdTagstrtemp[20]={0};
  9155. char statusstrtemp[20]={0};
  9156. int expiryDateISNULL=FALSE;
  9157. int parentIdTagISNULL=FALSE;
  9158. char sstr[160]={ 0 },sstrtemp[140]={ 0 };
  9159. char* filename = AuthorizationCache_JSON;
  9160. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9161. int c = 0;
  9162. char *loc;
  9163. int resultRename=0;
  9164. int responseIdTagInfoAsZero= 0;
  9165. char rmFileCmd[50]={0};
  9166. char *delim = ":";
  9167. char requestKey[3][50]={0};
  9168. char * pch;
  9169. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9170. //***********expiryDate*************/
  9171. loc = strstr(payload, "expiryDate");
  9172. memset(sstr ,0, sizeof(sstr) );
  9173. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9174. memset(requestKey ,0, sizeof(requestKey) );
  9175. c = 0;
  9176. if(loc == NULL)
  9177. {
  9178. expiryDateISNULL = TRUE;
  9179. }
  9180. else
  9181. {
  9182. strcpy(sstrtemp,loc+strlen("expiryDate")+2);
  9183. //printf("sstrtemp=%s\n",sstrtemp);
  9184. //parsing strings to words: "2020-06-19T09:10:00Z". "parentIdTag":"PTAG" .
  9185. pch = strtok(sstrtemp,",");
  9186. while (pch != NULL)
  9187. {
  9188. strcpy(requestKey[c], pch);
  9189. pch = strtok (NULL, ",");
  9190. c = c + 1;
  9191. }
  9192. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9193. strcpy(expiryDatestr, stringtrim(requestKey[0]));
  9194. }
  9195. //***********parentIdTag*************/
  9196. loc = strstr(payload, "parentIdTag");
  9197. memset(sstr ,0, sizeof(sstr));
  9198. memset(sstrtemp ,0, sizeof(sstrtemp));
  9199. memset(requestKey ,0, sizeof(requestKey));
  9200. c = 0;
  9201. if(loc == NULL)
  9202. {
  9203. parentIdTagISNULL = TRUE;
  9204. }
  9205. else
  9206. {
  9207. strcpy(sstrtemp,loc);
  9208. //printf("sstrtemp=%s\n",sstrtemp);
  9209. //parsing strings to words: parentIdTag". "PTAG"
  9210. pch = strtok(sstrtemp,delim);
  9211. while (pch != NULL)
  9212. {
  9213. strcpy(requestKey[c], pch);
  9214. pch = strtok (NULL, delim);
  9215. c = c + 1;
  9216. }
  9217. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9218. strcpy(parentIdTagstr, stringtrim(requestKey[1]));
  9219. #if 0
  9220. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9221. {
  9222. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9223. c++;
  9224. }
  9225. sstr[c] = '\0';
  9226. strcpy(parentIdTagstr, sstr);
  9227. #endif
  9228. }
  9229. //***********status*************/
  9230. loc = strstr(payload, "status");
  9231. memset(sstr ,0, sizeof(sstr) );
  9232. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9233. memset(requestKey ,0, sizeof(requestKey));
  9234. c = 0;
  9235. if(loc != NULL)
  9236. {
  9237. strcpy(sstrtemp,loc);
  9238. //printf("sstrtemp=%s\n",sstrtemp);
  9239. //parsing strings to words: status":"Accepted"
  9240. pch = strtok(sstrtemp,delim);
  9241. while (pch != NULL)
  9242. {
  9243. strcpy(requestKey[c], pch);
  9244. pch = strtok (NULL, delim);
  9245. c = c + 1;
  9246. }
  9247. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9248. strcpy(statusstr, stringtrim(requestKey[1]));
  9249. }
  9250. #if 0
  9251. while (loc[3+strlen("status")+c] != '\"')
  9252. {
  9253. sstr[c] = loc[3+strlen("status")+c];
  9254. c++;
  9255. }
  9256. sstr[c] = '\0';
  9257. strcpy(statusstr, sstr);
  9258. #endif
  9259. if(expiryDateISNULL == FALSE)
  9260. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9261. if(parentIdTagISNULL == FALSE)
  9262. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9263. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9264. //Update idTag information to authorization cache if supproted
  9265. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9266. {
  9267. if((access(filename,F_OK))!=-1)
  9268. {
  9269. printf("AuthorizationCache exist.\n");
  9270. }
  9271. else
  9272. {
  9273. printf("AuthorizationCache not exist\n");
  9274. FILE *log = fopen(filename, "w+");
  9275. if(log == NULL)
  9276. {
  9277. printf("log is NULL\n");
  9278. goto out;
  9279. }
  9280. else
  9281. {
  9282. fclose(log);
  9283. }
  9284. }
  9285. FILE *infile;
  9286. FILE *outfile;
  9287. // open file for writing
  9288. infile = fopen (filename, "r");
  9289. outfile = fopen (tempfile, "w");
  9290. //*检测到文件结束标识返回1,否则返回0。*/
  9291. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9292. int c;
  9293. c = fgetc(infile);
  9294. //DEBUG_INFO("c:%d\n",c);
  9295. rewind(infile);
  9296. if(c == EOF)
  9297. {
  9298. DEBUG_INFO("Orignal File is NULL\n");
  9299. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9300. {
  9301. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9302. }
  9303. else
  9304. {
  9305. strcpy(expiryDatestrtemp, "");
  9306. }
  9307. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9308. {
  9309. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9310. }
  9311. else
  9312. {
  9313. //write Authorize IdTag
  9314. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9315. }
  9316. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9317. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9318. fclose(infile);
  9319. fclose(outfile);
  9320. sprintf(rmFileCmd,"rm -f %s",filename);
  9321. system(rmFileCmd);
  9322. resultRename = rename(tempfile, filename);
  9323. if(resultRename == 0)
  9324. {
  9325. printf("File renamed successfully");
  9326. }
  9327. else
  9328. {
  9329. printf("Error: unable to rename the file");
  9330. }
  9331. }
  9332. else
  9333. {
  9334. char buf[160]={0};
  9335. while (fgets(buf, sizeof(buf), infile) != NULL)
  9336. {
  9337. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9338. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9339. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9340. memset(statusstr, 0, sizeof(statusstrtemp));
  9341. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9342. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9343. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9344. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9345. //------------------IdTag-----------------------
  9346. loc = strstr(buf, "idTag");
  9347. memset(sstr ,0, sizeof(sstr) );
  9348. c = 0;
  9349. while (loc[3+strlen("idTag")+c] != '\"')
  9350. {
  9351. sstr[c] = loc[3+strlen("idTag")+c];
  9352. c++;
  9353. }
  9354. sstr[c] = '\0';
  9355. strcpy(IdTagstrtemp,sstr);
  9356. //*********************expiryDate***************/
  9357. loc = strstr(buf, "expiryDate");
  9358. memset(sstr ,0, sizeof(sstr) );
  9359. c = 0;
  9360. while (loc[3+strlen("expiryDate")+c] != '\"')
  9361. {
  9362. sstr[c] = loc[3+strlen("expiryDate")+c];
  9363. c++;
  9364. }
  9365. sstr[c] = '\0';
  9366. strcpy(expiryDatestr,sstr);
  9367. //*********************parentIdTag***************/
  9368. loc = strstr(buf, "parentIdTag");
  9369. memset(sstr ,0, sizeof(sstr) );
  9370. c = 0;
  9371. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9372. {
  9373. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9374. c++;
  9375. }
  9376. sstr[c] = '\0';
  9377. strcpy(parentIdTagstr,sstr);
  9378. //*********************status***************/
  9379. loc = strstr(buf, "status");
  9380. memset(sstr ,0, sizeof(sstr) );
  9381. c = 0;
  9382. while (loc[3+strlen("status")+c] != '\"')
  9383. {
  9384. sstr[c] = loc[3+strlen("status")+c];
  9385. c++;
  9386. }
  9387. sstr[c] = '\0';
  9388. strcpy(statusstr,sstr);
  9389. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9390. {
  9391. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9392. responseIdTagInfoAsZero = 1;
  9393. }
  9394. else
  9395. {
  9396. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9397. }
  9398. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9399. {
  9400. //modify item
  9401. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9402. {
  9403. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9404. }
  9405. else
  9406. {
  9407. strcpy(expiryDatestrtemp, "");
  9408. }
  9409. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9410. {
  9411. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9412. }
  9413. else
  9414. {
  9415. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9416. }
  9417. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9418. }
  9419. else
  9420. {
  9421. //wrie original item
  9422. strcpy(expiryDatestrtemp, expiryDatestr);
  9423. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9424. strcpy(statusstrtemp, statusstr);
  9425. }
  9426. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9427. }
  9428. fclose(infile);
  9429. fclose(outfile);
  9430. sprintf(rmFileCmd,"rm -f %s",filename);
  9431. system(rmFileCmd);
  9432. resultRename = rename(tempfile, filename);
  9433. if(resultRename == 0)
  9434. {
  9435. DEBUG_INFO("File renamed successfully");
  9436. }
  9437. else
  9438. {
  9439. DEBUG_INFO("Error: unable to rename the file");
  9440. }
  9441. }
  9442. }
  9443. out:
  9444. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9445. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9446. authorizeRetryTimes = 0;
  9447. }
  9448. char * strtrimc( char * s )
  9449. {
  9450. char * p1 = s;
  9451. char * p2 = s;
  9452. while(*p1 != '\0')
  9453. {
  9454. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9455. {
  9456. if(*p1 != ',')
  9457. {
  9458. p1 ++;
  9459. }
  9460. else
  9461. {
  9462. break;
  9463. }
  9464. }
  9465. if(*p1 != ',')
  9466. {
  9467. * p2 ++ = *p1 ++;
  9468. //printf("p2=%s\n",p2);
  9469. }
  9470. else
  9471. {
  9472. break;
  9473. }
  9474. }
  9475. *p2 = '\0';
  9476. return (s);
  9477. }
  9478. void handleBootNotificationResponse(char *payload, int gun_index)
  9479. {
  9480. mtrace();
  9481. char sstr[140]={ 0 }, sstrtemp[140]={ 0 };//sstr[200]={ 0 };
  9482. char statusStr[12]={0};
  9483. char currentTimeStr[30]={0};
  9484. char *loc;
  9485. int intervalInt = 0;
  9486. int c = 0;
  9487. int copyTo = 0;
  9488. //double diff_t;
  9489. struct tm tp;
  9490. char buf[28]={0};
  9491. char timebuf[50]={0};
  9492. char *delim = ":";
  9493. char requestKey[3][50]={0};
  9494. char * pch;
  9495. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9496. //*** interval ****/
  9497. c = 0;
  9498. copyTo = 0;
  9499. loc = strstr(payload, "interval");
  9500. //printf("loc=%s\n",loc);
  9501. memset(sstr ,0, sizeof(sstr) );
  9502. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9503. {
  9504. if(loc[strlen("interval")+2+c] != ' ')
  9505. {
  9506. sstr[copyTo] = loc[strlen("interval")+2+c];
  9507. copyTo = copyTo + 1;
  9508. }
  9509. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9510. c++;
  9511. }
  9512. sstr[copyTo] = '\0';
  9513. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9514. intervalInt = atoi(sstr);
  9515. //***status ****/
  9516. c = 0;
  9517. copyTo = 0;
  9518. loc = strstr(payload, "status");
  9519. memset(sstr ,0, sizeof(sstr) );
  9520. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9521. if(loc != NULL)
  9522. {
  9523. strcpy(sstrtemp,loc);
  9524. pch = strtok(sstrtemp,delim);
  9525. while (pch != NULL)
  9526. {
  9527. strcpy(requestKey[c], pch);
  9528. pch = strtok (NULL, delim);
  9529. c = c + 1;
  9530. }
  9531. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9532. strcpy(statusStr, stringtrim(requestKey[1]));
  9533. }
  9534. //***currentTime ****/
  9535. c = 0;
  9536. copyTo = 0;
  9537. loc = strstr(payload, "currentTime");
  9538. //printf("loc=%s\n",loc);
  9539. memset(sstr ,0, sizeof(sstr) );
  9540. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9541. memset(requestKey ,0, sizeof(requestKey) );
  9542. if(loc != NULL)
  9543. {
  9544. strcpy(sstrtemp,loc+strlen("currentTime")+2);
  9545. //printf("sstrtemp=%s\n",sstrtemp);
  9546. //parsing strings to words
  9547. pch = strtok(sstrtemp,",");
  9548. while (pch != NULL)
  9549. {
  9550. strcpy(requestKey[c], pch);
  9551. pch = strtok (NULL, ",");
  9552. c = c + 1;
  9553. }
  9554. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9555. strcpy(currentTimeStr, stringtrim(requestKey[0]));
  9556. }
  9557. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9558. HeartBeatWaitTime = BootNotificationInterval;
  9559. clientTime.Heartbeat=time((time_t*)NULL);
  9560. //write back to ShmOCPP16Data->BootNotification
  9561. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9562. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9563. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9564. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9565. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9566. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9567. {
  9568. server_sign = TRUE;
  9569. server_pending =FALSE;
  9570. }
  9571. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9572. {
  9573. server_pending = TRUE;
  9574. }
  9575. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9576. tp.tm_isdst = -1;
  9577. //time_t utc = mktime(&tp);
  9578. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9579. memset(timebuf, 0, sizeof timebuf);
  9580. sprintf(timebuf,"date -s '%s'",buf);
  9581. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9582. system(timebuf);
  9583. //==============================================
  9584. // RTC sync
  9585. //==============================================
  9586. system("/sbin/hwclock -w --systohc");
  9587. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9588. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9589. }
  9590. void handleDataTransferResponse(char *payload, int gun_index)
  9591. {
  9592. char sstr[160]={0};//sstr[200]={ 0 };
  9593. int c = 0;
  9594. char *loc;
  9595. DEBUG_INFO("handleDataTransferResponse ...\n");
  9596. loc = strstr(payload, "status");
  9597. printf("loc=%s\n",loc);
  9598. c = 0;
  9599. while (loc[3+strlen("status")+c] != '\"')
  9600. {
  9601. sstr[c] = loc[3+strlen("status")+c];
  9602. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9603. c++;
  9604. }
  9605. sstr[c] = '\0';
  9606. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9607. }
  9608. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9609. {
  9610. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9611. //struct json_object *obj;
  9612. // obj = json_tokener_parse(payload);
  9613. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9614. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9615. //No fields are defined.
  9616. }
  9617. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9618. {
  9619. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9620. //struct json_object *obj;
  9621. // obj = json_tokener_parse(payload);
  9622. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9623. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9624. //No fields are defined.
  9625. }
  9626. void handleHeartbeatResponse(char *payload, int gun_index)
  9627. {
  9628. mtrace();
  9629. //double diff_t;
  9630. struct tm tp;
  9631. char buf[28]={0};
  9632. char timebuf[50]={0};
  9633. char sstr[30]={ 0 };
  9634. int c = 0;
  9635. char *loc;
  9636. char sstrtemp[140]={ 0 };
  9637. char requestKey[2][50]={0};
  9638. char * pch;
  9639. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9640. c = 0;
  9641. loc = strstr(payload, "currentTime");
  9642. memset(sstr ,0, sizeof(sstr) );
  9643. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9644. memset(requestKey ,0, sizeof(requestKey) );
  9645. if(loc != NULL)
  9646. {
  9647. strcpy(sstrtemp,loc+strlen("currentTime")+2);
  9648. //printf("sstrtemp=%s\n",sstrtemp);
  9649. //parsing strings to words
  9650. pch = strtok(sstrtemp,",");
  9651. while (pch != NULL)
  9652. {
  9653. strcpy(requestKey[c], pch);
  9654. pch = strtok (NULL, ",");
  9655. c = c + 1;
  9656. }
  9657. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9658. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, stringtrim(requestKey[0]));
  9659. }
  9660. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9661. tp.tm_isdst = -1;
  9662. //time_t utc = mktime(&tp);
  9663. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9664. memset(timebuf, 0, sizeof timebuf);
  9665. sprintf(timebuf,"date -s '%s'",buf);
  9666. system(timebuf);
  9667. //==============================================
  9668. // RTC sync
  9669. //==============================================
  9670. system("/sbin/hwclock -w --systohc");
  9671. if(FirstHeartBeat == 0)
  9672. {
  9673. FirstHeartBeat = 1;
  9674. }
  9675. HeartBeatWithNOResponse = 0;
  9676. //===============================================
  9677. //Print Out HeartBeat log
  9678. //===============================================
  9679. {
  9680. double diff_t;
  9681. struct tm tp,tp1;
  9682. // BootNotification Receive Time
  9683. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9684. tp.tm_isdst = -1;
  9685. time_t BootNotificationReceiveTime = mktime(&tp);
  9686. //HeartBeat Receive Time
  9687. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9688. tp1.tm_isdst = -1;
  9689. time_t HeartBeatReceiveTime = mktime(&tp1);
  9690. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9691. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9692. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9693. {
  9694. HeartBeatCountPerHour = (int)diff_t / 3600;
  9695. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9696. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9697. }
  9698. }
  9699. }
  9700. void handleMeterValuesResponse(char *payload, int gun_index)
  9701. {
  9702. mtrace();
  9703. //struct json_object *obj;
  9704. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9705. //No fields are defined.
  9706. }
  9707. void handleStartTransactionResponse(char *payload, int gun_index)
  9708. {
  9709. mtrace();
  9710. char sstr[28]={ 0 },sstrtemp[140]={ 0 };
  9711. int c = 0;
  9712. int copyTo = 0;
  9713. char *loc;
  9714. //int transactionIdInt = 0;
  9715. FILE *outfile;
  9716. char data[100]={0};
  9717. char *delim = ":";
  9718. char requestKey[2][50]={0};
  9719. char * pch;
  9720. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9721. DEBUG_INFO("handleStartTransactionResponse\n");
  9722. //****************expiryDate********************/
  9723. loc = strstr(payload, "expiryDate");
  9724. if(loc == NULL)
  9725. {
  9726. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9727. }
  9728. else
  9729. {
  9730. c = 0;
  9731. memset(sstr ,0, sizeof(sstr) );
  9732. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9733. memset(requestKey ,0, sizeof(requestKey) );
  9734. strcpy(sstrtemp,loc+strlen("expiryDate")+2); // 2: ":
  9735. //printf("sstrtemp=%s\n",sstrtemp);
  9736. //parsing strings to words
  9737. pch = strtok(sstrtemp,",");
  9738. while (pch != NULL)
  9739. {
  9740. strcpy(requestKey[c], pch);
  9741. pch = strtok (NULL, ",");
  9742. c = c + 1;
  9743. }
  9744. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9745. //strcpy(currentTimeStr, strtrimc(requestKey[0]));
  9746. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", stringtrim(requestKey[0]));
  9747. #if 0
  9748. c = 0;
  9749. memset(sstr ,0, sizeof(sstr) );
  9750. while (loc[3+strlen("expiryDate")+c] != '\"')
  9751. {
  9752. sstr[c] = loc[3+strlen("expiryDate")+c];
  9753. c++;
  9754. }
  9755. sstr[c] = '\0';
  9756. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9757. #endif
  9758. }
  9759. //****************parentIdTag********************/
  9760. loc = strstr(payload, "parentIdTag");
  9761. if(loc == NULL)
  9762. {
  9763. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9764. }
  9765. else
  9766. {
  9767. c = 0;
  9768. memset(sstr ,0, sizeof(sstr) );
  9769. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9770. memset(requestKey ,0, sizeof(requestKey) );
  9771. strcpy(sstrtemp,loc);
  9772. //printf("sstrtemp=%s\n",sstrtemp);
  9773. //parsing strings to words
  9774. pch = strtok(sstrtemp,delim);
  9775. while (pch != NULL)
  9776. {
  9777. strcpy(requestKey[c], pch);
  9778. pch = strtok (NULL, delim);
  9779. c = c + 1;
  9780. }
  9781. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9782. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", strtrimc(requestKey[1]));
  9783. #if 0
  9784. c = 0;
  9785. memset(sstr ,0, sizeof(sstr) );
  9786. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9787. {
  9788. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9789. c++;
  9790. }
  9791. sstr[c] = '\0';
  9792. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9793. #endif
  9794. }
  9795. //****************status********************/
  9796. loc = strstr(payload, "status");
  9797. if(loc == NULL)
  9798. {
  9799. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9800. }
  9801. else
  9802. {
  9803. c = 0;
  9804. memset(sstr ,0, sizeof(sstr) );
  9805. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9806. memset(requestKey ,0, sizeof(requestKey) );
  9807. strcpy(sstrtemp,loc);
  9808. //printf("sstrtemp=%s\n",sstrtemp);
  9809. //parsing strings to words
  9810. pch = strtok(sstrtemp,delim);
  9811. while (pch != NULL)
  9812. {
  9813. strcpy(requestKey[c], pch);
  9814. pch = strtok (NULL, delim);
  9815. c = c + 1;
  9816. }
  9817. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9818. //strcpy(statusStr, strtrimc(requestKey[1]));
  9819. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", strtrimc(requestKey[1]));
  9820. #if 0
  9821. c = 0;
  9822. memset(sstr ,0, sizeof(sstr) );
  9823. while (loc[3+strlen("status")+c] != '\"')
  9824. {
  9825. sstr[c] = loc[3+strlen("status")+c];
  9826. c++;
  9827. }
  9828. sstr[c] = '\0';
  9829. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9830. #endif
  9831. }
  9832. //****************transactionId********************/
  9833. c=0;
  9834. copyTo = 0;
  9835. loc = strstr(payload, "transactionId");
  9836. memset(sstr ,0, sizeof(sstr) );
  9837. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9838. {
  9839. if(loc[strlen("transactionId")+2+c] != ' ')
  9840. {
  9841. sstr[copyTo] = loc[strlen("transactionId")+2+c];
  9842. copyTo = copyTo + 1;
  9843. }
  9844. c++;
  9845. }
  9846. sstr[copyTo] = '\0';
  9847. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9848. //transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9849. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9850. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9851. //-----------Start : write to the Queue TransactionId file -----------------//
  9852. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9853. {
  9854. //DEBUG_INFO("QueueTransactionId exist.\n");
  9855. }
  9856. else
  9857. {
  9858. //DEBUG_INFO("QueueTransactionId not exist\n");
  9859. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9860. if(log == NULL)
  9861. {
  9862. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9863. return ;
  9864. }
  9865. else
  9866. {
  9867. fclose(log);
  9868. }
  9869. }
  9870. // open file for writing
  9871. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9872. //DEBUG_INFO("data=%s\n",data);
  9873. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9874. fputs(data, outfile);
  9875. //fputs("\n", outfile);
  9876. fclose (outfile);
  9877. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9878. //TransactionId[gun_index] = transactionIdInt;
  9879. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9880. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9881. #ifdef SystemLogMessage
  9882. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9883. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9884. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9885. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9886. #endif
  9887. }
  9888. void handleStatusNotificationResponse(char *payload, int gun_index)
  9889. {
  9890. mtrace();
  9891. printf("handleStatusNotificationResponse\n");
  9892. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9893. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9894. }
  9895. void handleStopTransactionnResponse(char *payload, int gun_index)
  9896. {
  9897. mtrace();
  9898. char sstr[30]={ 0 },sstrtemp[140]={ 0 };
  9899. int c = 0;
  9900. char *loc;
  9901. char *delim = ":";
  9902. char requestKey[3][50]={0};
  9903. char * pch;
  9904. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9905. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9906. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9907. loc = strstr(payload, "idTagInfo");
  9908. //***********************idTagInfo************************/
  9909. if(loc != NULL)
  9910. {
  9911. //***********************expiryDate************************/
  9912. loc = strstr(payload, "expiryDate");
  9913. if(loc != NULL)
  9914. {
  9915. c = 0;
  9916. memset(sstr ,0, sizeof(sstr) );
  9917. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9918. memset(requestKey ,0, sizeof(requestKey) );
  9919. strcpy(sstrtemp,loc+strlen("expiryDate")+2); // 2: ":
  9920. //printf("sstrtemp=%s\n",sstrtemp);
  9921. //parsing strings to words
  9922. pch = strtok(sstrtemp,",");
  9923. while (pch != NULL)
  9924. {
  9925. strcpy(requestKey[c], pch);
  9926. pch = strtok (NULL, ",");
  9927. c = c + 1;
  9928. }
  9929. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9930. //strcpy(currentTimeStr, strtrimc(requestKey[0]));
  9931. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", stringtrim(requestKey[0]));
  9932. #if 0
  9933. memset(sstr ,0, sizeof(sstr) );
  9934. c = 0;
  9935. while (loc[3+strlen("expiryDate")+c] != '\"')
  9936. {
  9937. sstr[c] = loc[3+strlen("expiryDate")+c];
  9938. c++;
  9939. }
  9940. sstr[c] = '\0';
  9941. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9942. #endif
  9943. }
  9944. //***********************parentIdTag************************/
  9945. loc = strstr(payload, "parentIdTag");
  9946. if(loc != NULL)
  9947. {
  9948. c = 0;
  9949. memset(sstr ,0, sizeof(sstr) );
  9950. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9951. memset(requestKey ,0, sizeof(requestKey) );
  9952. strcpy(sstrtemp,loc);
  9953. //printf("sstrtemp=%s\n",sstrtemp);
  9954. //parsing strings to words
  9955. pch = strtok(sstrtemp,delim);
  9956. while (pch != NULL)
  9957. {
  9958. strcpy(requestKey[c], pch);
  9959. pch = strtok (NULL, delim);
  9960. c = c + 1;
  9961. }
  9962. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9963. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", strtrimc(requestKey[1]));
  9964. #if 0
  9965. memset(sstr ,0, sizeof(sstr) );
  9966. c = 0;
  9967. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9968. {
  9969. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9970. c++;
  9971. }
  9972. sstr[c] = '\0';
  9973. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9974. #endif
  9975. }
  9976. //***********************status************************/
  9977. loc = strstr(payload, "status");
  9978. c = 0;
  9979. memset(sstr ,0, sizeof(sstr) );
  9980. memset(sstrtemp ,0, sizeof(sstrtemp) );
  9981. memset(requestKey ,0, sizeof(requestKey) );
  9982. strcpy(sstrtemp,loc);
  9983. //printf("sstrtemp=%s\n",sstrtemp);
  9984. //parsing strings to words
  9985. pch = strtok(sstrtemp,delim);
  9986. while (pch != NULL)
  9987. {
  9988. strcpy(requestKey[c], pch);
  9989. pch = strtok (NULL, delim);
  9990. c = c + 1;
  9991. }
  9992. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  9993. //strcpy(statusStr, strtrimc(requestKey[1]));
  9994. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", strtrimc(requestKey[1]));
  9995. #if 0
  9996. memset(sstr ,0, sizeof(sstr) );
  9997. c = 0;
  9998. while (loc[3+strlen("status")+c] != '\"')
  9999. {
  10000. sstr[c] = loc[3+strlen("status")+c];
  10001. c++;
  10002. }
  10003. sstr[c] = '\0';
  10004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10005. #endif
  10006. }
  10007. #ifdef SystemLogMessage
  10008. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10009. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10010. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10011. #endif
  10012. }
  10013. //==========================================
  10014. // Handle Error routine
  10015. //==========================================
  10016. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10017. {
  10018. mtrace();
  10019. #ifdef SystemLogMessage
  10020. DEBUG_INFO("errorCode: %s\n", errorCode);
  10021. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10022. DEBUG_INFO("errorDetails: %s\n", payload);
  10023. #endif
  10024. }
  10025. //===============================================
  10026. // Common routine
  10027. //===============================================
  10028. int initialConfigurationTable(void)
  10029. {
  10030. //clock_t start_t, end_t, total_t;
  10031. FILE *fp;
  10032. FILE *outfile;
  10033. char str[200]={0};
  10034. char sstr[100]={0};
  10035. int c = 0;
  10036. char *loc;
  10037. printf("initialConfigurationTable \n");
  10038. //start_t = clock();
  10039. //printf("Starting of the program, start_t = %ld\n", start_t);
  10040. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10041. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10042. {
  10043. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10044. if(outfile == NULL) {
  10045. DEBUG_INFO("Error opening file");
  10046. return FALSE;
  10047. }
  10048. /*Core Profile*/
  10049. //AllowOfflineTxForUnknownId
  10050. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10051. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10055. //AuthorizationCacheEnabled
  10056. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10060. //AuthorizeRemoteTxRequests
  10061. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10065. //BlinkRepeat
  10066. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10070. //ClockAlignedDataInterval
  10071. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10075. //ConnectionTimeOut
  10076. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10080. //GetConfigurationMaxKeys
  10081. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10085. // HeartbeatInterval
  10086. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10090. // LightIntensity
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10095. // LocalAuthorizeOffline
  10096. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10100. // LocalPreAuthorize
  10101. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10105. // MaxEnergyOnInvalidId
  10106. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10109. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10111. // MeterValuesAlignedData
  10112. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10116. // MeterValuesAlignedDataMaxLength
  10117. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10121. // MeterValuesSampledData
  10122. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10126. // MeterValuesSampledDataMaxLength
  10127. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  10131. // MeterValueSampleInterval
  10132. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10136. // MinimumStatusDuration
  10137. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10140. server_cycle_Status = 120; //StatusNotification cycle
  10141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10142. // NumberOfConnectors
  10143. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10145. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10146. {
  10147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10148. }
  10149. else
  10150. {
  10151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10152. }
  10153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10154. // ResetRetries
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10159. // ConnectorPhaseRotation
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10164. // ConnectorPhaseRotationMaxLength
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10169. // StopTransactionOnEVSideDisconnect
  10170. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10174. // StopTransactionOnInvalidId
  10175. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10179. // StopTxnAlignedData
  10180. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10184. // StopTxnAlignedDataMaxLength
  10185. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10189. // StopTxnSampledData
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10194. // StopTxnSampledDataMaxLength
  10195. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10198. {
  10199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10200. }
  10201. else
  10202. {
  10203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10204. }
  10205. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10207. // SupportedFeatureProfiles
  10208. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10212. // SupportedFeatureProfilesMaxLength
  10213. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10217. // TransactionMessageAttempts
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10221. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10223. // TransactionMessageRetryInterval
  10224. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10227. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10229. // UnlockConnectorOnEVSideDisconnect
  10230. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10234. // WebSocketPingInterval
  10235. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10239. //* Local Auth List Management Profile*/
  10240. #if 0
  10241. //For OCTT Test Case
  10242. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10245. #endif
  10246. #if 1
  10247. //LocalAuthListEnabled
  10248. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10252. #endif
  10253. //LocalAuthListMaxLength
  10254. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10258. //SendLocalListMaxLength
  10259. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10263. //ReserveConnectorZeroSupported
  10264. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10268. //* Smart Charging Profile */
  10269. //ChargeProfileMaxStackLevel
  10270. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10274. // ChargingScheduleAllowedChargingRateUnit
  10275. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10279. // ChargingScheduleMaxPeriods
  10280. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10284. // ConnectorSwitch3to1PhaseSupported
  10285. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10289. // MaxChargingProfilesInstalled
  10290. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  10294. fclose(outfile);
  10295. }
  10296. else
  10297. {
  10298. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10299. char keystr[60]={0};
  10300. char readonlystr[10]={0};
  10301. char valuestr[100]={0};
  10302. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10303. if(fp == NULL) {
  10304. DEBUG_INFO("Error opening file");
  10305. return FALSE;
  10306. }
  10307. while( fgets (str, sizeof(str), fp)!=NULL )
  10308. {
  10309. //DEBUG_INFO("Get Configuration \n");
  10310. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10311. //*************************key*********************************/
  10312. loc = strstr(str, "key");
  10313. c = 0;
  10314. memset(sstr ,0, sizeof(sstr) );
  10315. while (loc[strlen("key")+3+c] != '\"')
  10316. {
  10317. sstr[c] = loc[strlen("key")+3+c];
  10318. c++;
  10319. }
  10320. sstr[c] = '\0';
  10321. strcpy(keystr,sstr);
  10322. //*************************readonly*********************************/
  10323. loc = strstr(str, "readonly");
  10324. c = 0;
  10325. memset(sstr ,0, sizeof(sstr) );
  10326. while (loc[strlen("readonly")+2+c] != ',')
  10327. {
  10328. sstr[c] = loc[strlen("readonly")+2+c];
  10329. c++;
  10330. }
  10331. sstr[c] = '\0';
  10332. strcpy(readonlystr,sstr);
  10333. //*************************value*********************************/
  10334. loc = strstr(str, "value");
  10335. c = 0;
  10336. memset(sstr ,0, sizeof(sstr) );
  10337. while (loc[strlen("value")+3+c] != '\"')
  10338. {
  10339. sstr[c] = loc[strlen("value")+3+c];
  10340. c++;
  10341. }
  10342. sstr[c] = '\0';
  10343. strcpy(valuestr,sstr);
  10344. // DEBUG_INFO("keystr=%s\n",keystr);
  10345. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10346. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10347. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10348. {
  10349. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10350. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10352. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10353. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10354. }
  10355. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10356. {
  10357. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10358. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10360. }
  10361. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10362. {
  10363. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10365. }
  10366. if(strcmp(keystr, "BlinkRepeat") == 0)
  10367. {
  10368. //Charger.BlinkRepeat = Integer.parseInt(value);
  10369. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10371. }
  10372. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10373. {
  10374. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10376. }
  10377. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10378. {
  10379. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10381. }
  10382. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10383. {
  10384. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10386. }
  10387. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10388. {
  10389. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10391. HeartBeatWaitTime = atoi(valuestr);
  10392. }
  10393. if(strcmp(keystr, "LightIntensity") == 0)
  10394. {
  10395. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10397. }
  10398. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10399. {
  10400. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10402. }
  10403. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10404. {
  10405. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10407. }
  10408. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10409. {
  10410. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10412. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10413. }
  10414. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10415. {
  10416. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10418. }
  10419. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10420. {
  10421. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10423. }
  10424. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10425. {
  10426. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10428. }
  10429. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10430. {
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10433. }
  10434. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10435. {
  10436. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10438. }
  10439. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10440. {
  10441. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10443. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10444. }
  10445. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10446. {
  10447. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10449. }
  10450. if(strcmp(keystr, "ResetRetries") == 0)
  10451. {
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10454. }
  10455. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10456. {
  10457. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10459. }
  10460. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10461. {
  10462. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10464. }
  10465. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10466. {
  10467. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10469. }
  10470. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10471. {
  10472. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10474. }
  10475. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10476. {
  10477. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10479. }
  10480. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10481. {
  10482. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10484. }
  10485. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10486. {
  10487. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10489. }
  10490. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10491. {
  10492. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10494. }
  10495. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10496. {
  10497. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10499. }
  10500. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10501. {
  10502. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10504. }
  10505. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10506. {
  10507. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10509. TransactionMessageAttemptsValue = atoi(valuestr);
  10510. }
  10511. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10512. {
  10513. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10515. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10516. }
  10517. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10518. {
  10519. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10521. }
  10522. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10523. {
  10524. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10526. }
  10527. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10528. {
  10529. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10531. }
  10532. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10533. {
  10534. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10536. }
  10537. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10538. {
  10539. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10541. }
  10542. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10543. {
  10544. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10546. }
  10547. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10548. {
  10549. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10551. }
  10552. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10553. {
  10554. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10556. }
  10557. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10558. {
  10559. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10561. }
  10562. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10563. {
  10564. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10566. }
  10567. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10568. {
  10569. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10571. }
  10572. }
  10573. fclose(fp);
  10574. }
  10575. //end_t = clock();
  10576. //printf("End of the big loop, end_t = %ld\n", end_t);
  10577. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  10578. //printf("Total time taken by CPU: %f\n", total_t );
  10579. return 0;
  10580. }
  10581. void StoreConfigurationTable(void)
  10582. {
  10583. FILE *outfile;
  10584. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10585. if(outfile == NULL)
  10586. {
  10587. DEBUG_INFO("Error opening file");
  10588. return ;
  10589. }
  10590. /*Core Profile*/
  10591. //AllowOfflineTxForUnknownId
  10592. /*
  10593. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10594. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10597. */
  10598. //DEBUG_INFO("data=%s\n",data);
  10599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10600. //AuthorizationCacheEnabled
  10601. /*
  10602. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10605. */
  10606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10607. //AuthorizeRemoteTxRequests
  10608. /*
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10612. */
  10613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10614. //BlinkRepeat
  10615. /*
  10616. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10619. */
  10620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10621. //ClockAlignedDataInterval
  10622. /*
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10626. */
  10627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10628. //ConnectionTimeOut
  10629. /*
  10630. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10633. */
  10634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10635. //GetConfigurationMaxKeys
  10636. /*
  10637. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10640. */
  10641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10642. // HeartbeatInterval
  10643. /*
  10644. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10647. */
  10648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10649. // LightIntensity
  10650. /*
  10651. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10654. */
  10655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10656. // LocalAuthorizeOffline
  10657. /*
  10658. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10661. */
  10662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10663. // LocalPreAuthorize
  10664. /*
  10665. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10668. */
  10669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10670. // MaxEnergyOnInvalidId
  10671. /*
  10672. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10675. */
  10676. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10678. // MeterValuesAlignedData
  10679. /*
  10680. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10683. */
  10684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10685. // MeterValuesAlignedDataMaxLength
  10686. /*
  10687. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10690. */
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10692. // MeterValuesSampledData
  10693. /*
  10694. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10697. */
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10699. // MeterValuesSampledDataMaxLength
  10700. /*
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10704. */
  10705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10706. // MeterValueSampleInterval
  10707. /*
  10708. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10711. */
  10712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10713. // MinimumStatusDuration
  10714. /*
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10718. */
  10719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10720. // NumberOfConnectors
  10721. /*
  10722. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10725. {
  10726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10727. }
  10728. else
  10729. {
  10730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10731. }
  10732. */
  10733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10734. // ResetRetries
  10735. /*
  10736. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10739. */
  10740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10741. // ConnectorPhaseRotation
  10742. /*
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10746. */
  10747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10748. // ConnectorPhaseRotationMaxLength
  10749. /*
  10750. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10753. */
  10754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10755. // StopTransactionOnEVSideDisconnect
  10756. /*
  10757. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10760. */
  10761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10762. // StopTransactionOnInvalidId
  10763. /*
  10764. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10767. */
  10768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10769. // StopTxnAlignedData
  10770. /*
  10771. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10774. */
  10775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10776. // StopTxnAlignedDataMaxLength
  10777. /*
  10778. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10781. */
  10782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10783. // StopTxnSampledData
  10784. /*
  10785. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10788. */
  10789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10790. // StopTxnSampledDataMaxLength
  10791. /*
  10792. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10795. */
  10796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10797. // SupportedFeatureProfiles
  10798. /*
  10799. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10802. */
  10803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10804. // SupportedFeatureProfilesMaxLength
  10805. /*
  10806. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10809. */
  10810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10811. // TransactionMessageAttempts
  10812. /*
  10813. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10816. */
  10817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10818. // TransactionMessageRetryInterval
  10819. /*
  10820. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10823. */
  10824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10825. // UnlockConnectorOnEVSideDisconnect
  10826. /*
  10827. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10830. */
  10831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10832. // WebSocketPingInterval
  10833. /*
  10834. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10837. */
  10838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10839. //* Local Auth List Management Profile*/
  10840. //LocalAuthListEnabled
  10841. /*
  10842. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10845. */
  10846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10847. //LocalAuthListMaxLength
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10854. //SendLocalListMaxLength
  10855. /*
  10856. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10859. */
  10860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10861. //ReserveConnectorZeroSupported
  10862. /*
  10863. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10866. */
  10867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10868. //* Smart Charging Profile */
  10869. //ChargeProfileMaxStackLevel
  10870. /*
  10871. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10874. */
  10875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10876. // ChargingScheduleAllowedChargingRateUnit
  10877. /*
  10878. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10881. */
  10882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10883. // ChargingScheduleMaxPeriods
  10884. /*
  10885. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10888. */
  10889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10890. // ConnectorSwitch3to1PhaseSupported
  10891. /*
  10892. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10895. */
  10896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10897. // MaxChargingProfilesInstalled
  10898. /*
  10899. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10902. */
  10903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10904. fclose(outfile);
  10905. }
  10906. void getKeyValue(char *keyReq)
  10907. {
  10908. int isEmpty = FALSE;
  10909. int isKnowKey = FALSE;
  10910. //int unKnowIndex = 0;
  10911. DEBUG_INFO("getKeyValue \n");
  10912. DEBUG_INFO("keyReq=%s \n",keyReq);
  10913. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10914. isEmpty = TRUE;
  10915. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10916. {
  10917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10920. {
  10921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10922. }
  10923. else
  10924. {
  10925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10926. }
  10927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10928. isKnowKey = TRUE;
  10929. }
  10930. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10931. {
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10935. {
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10937. }
  10938. else
  10939. {
  10940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10941. }
  10942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10943. isKnowKey = TRUE;
  10944. }
  10945. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10946. {
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10950. {
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10952. }
  10953. else
  10954. {
  10955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10956. }
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10958. isKnowKey = TRUE;
  10959. }
  10960. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10961. {
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10965. {
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10967. }
  10968. else
  10969. {
  10970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10971. }
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10973. isKnowKey = TRUE;
  10974. }
  10975. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10976. {
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10980. {
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10982. }
  10983. else
  10984. {
  10985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10986. }
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10988. isKnowKey = TRUE;
  10989. }
  10990. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10991. {
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10995. {
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10997. }
  10998. else
  10999. {
  11000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11001. }
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11003. isKnowKey = TRUE;
  11004. }
  11005. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11006. {
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11010. {
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11012. }
  11013. else
  11014. {
  11015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11016. }
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11018. isKnowKey = TRUE;
  11019. }
  11020. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11021. {
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11025. {
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11027. }
  11028. else
  11029. {
  11030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11031. }
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11033. isKnowKey = TRUE;
  11034. }
  11035. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11036. {
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11040. {
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11042. }
  11043. else
  11044. {
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11046. }
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11048. isKnowKey = TRUE;
  11049. }
  11050. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11051. {
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11055. {
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11057. }
  11058. else
  11059. {
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11061. }
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11063. isKnowKey = TRUE;
  11064. }
  11065. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11066. {
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11070. {
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11072. }
  11073. else
  11074. {
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11076. }
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11078. isKnowKey = TRUE;
  11079. }
  11080. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11081. {
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11085. {
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11087. }
  11088. else
  11089. {
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11091. }
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11093. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11094. isKnowKey = TRUE;
  11095. }
  11096. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11097. {
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11103. }
  11104. else
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11107. }
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11109. isKnowKey = TRUE;
  11110. }
  11111. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11118. }
  11119. else
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11122. }
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11124. isKnowKey = TRUE;
  11125. }
  11126. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11127. {
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11131. {
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11133. }
  11134. else
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11137. }
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11139. isKnowKey = TRUE;
  11140. }
  11141. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11142. {
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11148. }
  11149. else
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11152. }
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11154. isKnowKey = TRUE;
  11155. }
  11156. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11157. {
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11163. }
  11164. else
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11167. }
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11169. isKnowKey = TRUE;
  11170. }
  11171. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11178. }
  11179. else
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11182. }
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11184. isKnowKey = TRUE;
  11185. }
  11186. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11193. }
  11194. else
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11197. }
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11199. isKnowKey = TRUE;
  11200. }
  11201. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11208. }
  11209. else
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11212. }
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11214. isKnowKey = TRUE;
  11215. }
  11216. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11223. }
  11224. else
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11227. }
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11229. isKnowKey = TRUE;
  11230. }
  11231. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11232. {
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11238. }
  11239. else
  11240. {
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11242. }
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11244. isKnowKey = TRUE;
  11245. }
  11246. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11247. {
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11253. }
  11254. else
  11255. {
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11257. }
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11259. isKnowKey = TRUE;
  11260. }
  11261. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11262. {
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11268. }
  11269. else
  11270. {
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11272. }
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11274. isKnowKey = TRUE;
  11275. }
  11276. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11277. {
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11281. {
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11283. }
  11284. else
  11285. {
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11287. }
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11289. isKnowKey = TRUE;
  11290. }
  11291. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11292. {
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11296. {
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11298. }
  11299. else
  11300. {
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11302. }
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11304. isKnowKey = TRUE;
  11305. }
  11306. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11307. {
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11311. {
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11313. }
  11314. else
  11315. {
  11316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11317. }
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11319. isKnowKey = TRUE;
  11320. }
  11321. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11322. {
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11326. {
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11328. }
  11329. else
  11330. {
  11331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11332. }
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11334. isKnowKey = TRUE;
  11335. }
  11336. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11337. {
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11341. {
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11343. }
  11344. else
  11345. {
  11346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11347. }
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11349. isKnowKey = TRUE;
  11350. }
  11351. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11352. {
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11356. {
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11358. }
  11359. else
  11360. {
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11362. }
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11364. isKnowKey = TRUE;
  11365. }
  11366. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11367. {
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11371. {
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11373. }
  11374. else
  11375. {
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11377. }
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11379. isKnowKey = TRUE;
  11380. }
  11381. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11382. {
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11386. {
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11388. }
  11389. else
  11390. {
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11392. }
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11394. isKnowKey = TRUE;
  11395. }
  11396. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11401. {
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11403. }
  11404. else
  11405. {
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11407. }
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11409. isKnowKey = TRUE;
  11410. }
  11411. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11416. {
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11418. }
  11419. else
  11420. {
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11422. }
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11424. isKnowKey = TRUE;
  11425. }
  11426. #if 0
  11427. //For OCTT Test Case
  11428. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11429. {
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11432. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11433. {
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11435. }
  11436. else
  11437. {
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11439. }
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11441. isKnowKey = TRUE;
  11442. }
  11443. #endif
  11444. #if 1
  11445. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11446. {
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11449. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11450. {
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11452. }
  11453. else
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11456. }
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11458. isKnowKey = TRUE;
  11459. }
  11460. #endif
  11461. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11465. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11468. }
  11469. else
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11472. }
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11474. isKnowKey = TRUE;
  11475. }
  11476. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11480. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11483. }
  11484. else
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11487. }
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11489. isKnowKey = TRUE;
  11490. }
  11491. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11495. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11498. }
  11499. else
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11502. }
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11504. isKnowKey = TRUE;
  11505. }
  11506. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11510. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11513. }
  11514. else
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11517. }
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11519. isKnowKey = TRUE;
  11520. }
  11521. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11525. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11528. }
  11529. else
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11532. }
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11534. isKnowKey = TRUE;
  11535. }
  11536. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11540. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11543. }
  11544. else
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11547. }
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11549. isKnowKey = TRUE;
  11550. }
  11551. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11555. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11556. {
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11558. }
  11559. else
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11562. }
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11564. isKnowKey = TRUE;
  11565. }
  11566. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11570. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11571. {
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11573. }
  11574. else
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11577. }
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11579. isKnowKey = TRUE;
  11580. }
  11581. //=========================================================
  11582. if(!isEmpty && !isKnowKey)
  11583. {
  11584. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11585. strcpy(unknownkey[UnknownKeynum], keyReq);
  11586. UnknownKeynum = UnknownKeynum + 1;
  11587. }
  11588. }
  11589. void processUnkownKey(void)
  11590. {
  11591. DEBUG_INFO("processUnkownKey\n");
  11592. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11593. for(int index=0; index < UnknownKeynum; index++)
  11594. {
  11595. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11596. {
  11597. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11598. }
  11599. }
  11600. }
  11601. int setKeyValue(char *key, char *value)
  11602. {
  11603. int isSuccess = NotSupported;
  11604. int check_ascii=0;
  11605. char str[10]={0};
  11606. #ifdef Debug
  11607. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11608. #endif
  11609. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11610. {
  11611. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11612. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11613. {
  11614. strcpy(str, (const char*)value);
  11615. for(int i = 0; str[i]; i++){
  11616. str[i] = tolower(str[i]);
  11617. }
  11618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11619. isSuccess = ConfigurationStatus_Accepted;
  11620. }
  11621. else
  11622. {
  11623. isSuccess = ConfigurationStatus_Rejected;
  11624. }
  11625. }
  11626. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11627. {
  11628. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11630. {
  11631. strcpy(str, (const char*)value);
  11632. for(int i = 0; str[i]; i++){
  11633. str[i] = tolower(str[i]);
  11634. }
  11635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11636. isSuccess = ConfigurationStatus_Accepted;
  11637. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11638. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11639. }
  11640. else
  11641. {
  11642. isSuccess = ConfigurationStatus_Rejected;
  11643. }
  11644. }
  11645. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11646. {
  11647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11648. {
  11649. strcpy(str, (const char*)value);
  11650. for(int i = 0; str[i]; i++)
  11651. {
  11652. str[i] = tolower(str[i]);
  11653. }
  11654. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11656. isSuccess = ConfigurationStatus_Accepted;
  11657. }
  11658. else
  11659. {
  11660. isSuccess = ConfigurationStatus_Rejected;
  11661. }
  11662. }
  11663. if(strcmp(key, "BlinkRepeat") == 0)
  11664. {
  11665. //Charger.BlinkRepeat = Integer.parseInt(value);
  11666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11667. {
  11668. check_ascii = value[0];
  11669. if( (check_ascii < 48) || (check_ascii > 57) )
  11670. {
  11671. isSuccess = ConfigurationStatus_Rejected;
  11672. }
  11673. else
  11674. {
  11675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11676. isSuccess = ConfigurationStatus_Accepted;
  11677. }
  11678. }
  11679. else
  11680. {
  11681. isSuccess = ConfigurationStatus_Rejected;
  11682. }
  11683. }
  11684. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11685. {
  11686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11687. {
  11688. check_ascii = value[0];
  11689. if( (check_ascii < 48) || (check_ascii > 57) )
  11690. {
  11691. isSuccess = ConfigurationStatus_Rejected;
  11692. }
  11693. else
  11694. {
  11695. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11697. isSuccess = ConfigurationStatus_Accepted;
  11698. }
  11699. }
  11700. else
  11701. {
  11702. isSuccess = ConfigurationStatus_Rejected;
  11703. }
  11704. }
  11705. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11706. {
  11707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11708. {
  11709. check_ascii = value[0];
  11710. if( (check_ascii < 48) || (check_ascii > 57) )
  11711. {
  11712. isSuccess = ConfigurationStatus_Rejected;
  11713. }
  11714. else
  11715. {
  11716. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11718. isSuccess = ConfigurationStatus_Accepted;
  11719. }
  11720. }
  11721. else
  11722. {
  11723. isSuccess = ConfigurationStatus_Rejected;
  11724. }
  11725. }
  11726. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11727. {
  11728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11729. {
  11730. check_ascii = value[0];
  11731. if( (check_ascii < 48) || (check_ascii > 57) )
  11732. {
  11733. isSuccess = ConfigurationStatus_Rejected;
  11734. }
  11735. else
  11736. {
  11737. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11739. isSuccess = ConfigurationStatus_Accepted;
  11740. }
  11741. }
  11742. else
  11743. {
  11744. isSuccess = ConfigurationStatus_Rejected;
  11745. }
  11746. }
  11747. if(strcmp(key, "HeartbeatInterval") == 0)
  11748. {
  11749. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11750. {
  11751. check_ascii = value[0];
  11752. if( (check_ascii < 48) || (check_ascii > 57) )
  11753. {
  11754. isSuccess = ConfigurationStatus_Rejected;
  11755. }
  11756. else
  11757. {
  11758. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11760. HeartBeatWaitTime = atoi(value);
  11761. isSuccess = ConfigurationStatus_Accepted;
  11762. }
  11763. }
  11764. else
  11765. {
  11766. isSuccess = ConfigurationStatus_Rejected;
  11767. }
  11768. }
  11769. if(strcmp(key, "LightIntensity") == 0)
  11770. {
  11771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11772. {
  11773. check_ascii = value[0];
  11774. if( (check_ascii < 48) || (check_ascii > 57) )
  11775. {
  11776. isSuccess = ConfigurationStatus_Rejected;
  11777. }
  11778. else
  11779. {
  11780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11781. isSuccess = ConfigurationStatus_Accepted;
  11782. }
  11783. }
  11784. else
  11785. {
  11786. isSuccess = ConfigurationStatus_Rejected;
  11787. }
  11788. }
  11789. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11790. {
  11791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11792. {
  11793. strcpy(str, (const char*)value);
  11794. for(int i = 0; str[i]; i++)
  11795. {
  11796. str[i] = tolower(str[i]);
  11797. }
  11798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11799. isSuccess = ConfigurationStatus_Accepted;
  11800. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11801. }
  11802. else
  11803. {
  11804. isSuccess = ConfigurationStatus_Rejected;
  11805. }
  11806. }
  11807. if(strcmp(key, "LocalPreAuthorize") == 0)
  11808. {
  11809. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11810. {
  11811. strcpy(str, (const char*)value);
  11812. for(int i = 0; str[i]; i++)
  11813. {
  11814. str[i] = tolower(str[i]);
  11815. }
  11816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11817. isSuccess = ConfigurationStatus_Accepted;
  11818. }
  11819. else
  11820. {
  11821. isSuccess = ConfigurationStatus_Rejected;
  11822. }
  11823. }
  11824. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11825. {
  11826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11827. {
  11828. check_ascii = value[0];
  11829. if( (check_ascii < 48) || (check_ascii > 57) )
  11830. {
  11831. isSuccess = ConfigurationStatus_Rejected;
  11832. }
  11833. else
  11834. {
  11835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11836. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11837. isSuccess = ConfigurationStatus_Accepted;
  11838. }
  11839. }
  11840. else
  11841. {
  11842. isSuccess = ConfigurationStatus_Rejected;
  11843. }
  11844. }
  11845. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11846. {
  11847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11848. {
  11849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11850. isSuccess = ConfigurationStatus_Accepted;
  11851. }
  11852. else
  11853. {
  11854. isSuccess = ConfigurationStatus_Rejected;
  11855. }
  11856. }
  11857. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11858. {
  11859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11860. {
  11861. check_ascii = value[0];
  11862. if( (check_ascii < 48) || (check_ascii > 57) )
  11863. {
  11864. isSuccess = ConfigurationStatus_Rejected;
  11865. }
  11866. else
  11867. {
  11868. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11870. isSuccess = ConfigurationStatus_Accepted;
  11871. }
  11872. }
  11873. else
  11874. {
  11875. isSuccess = ConfigurationStatus_Rejected;
  11876. }
  11877. }
  11878. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11879. {
  11880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11881. {
  11882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11883. isSuccess = ConfigurationStatus_Accepted;
  11884. }
  11885. else
  11886. {
  11887. isSuccess = ConfigurationStatus_Rejected;
  11888. }
  11889. }
  11890. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11891. {
  11892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11893. {
  11894. check_ascii = value[0];
  11895. if( (check_ascii < 48) || (check_ascii > 57) )
  11896. {
  11897. isSuccess = ConfigurationStatus_Rejected;
  11898. }
  11899. else
  11900. {
  11901. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11903. isSuccess = ConfigurationStatus_Accepted;
  11904. }
  11905. }
  11906. else
  11907. {
  11908. isSuccess = ConfigurationStatus_Rejected;
  11909. }
  11910. }
  11911. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11912. {
  11913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11914. {
  11915. check_ascii = value[0];
  11916. if( (check_ascii < 48) || (check_ascii > 57) )
  11917. {
  11918. isSuccess = ConfigurationStatus_Rejected;
  11919. }
  11920. else
  11921. {
  11922. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11924. isSuccess = ConfigurationStatus_Accepted;
  11925. }
  11926. }
  11927. else
  11928. {
  11929. isSuccess = ConfigurationStatus_Rejected;
  11930. }
  11931. }
  11932. if(strcmp(key, "MinimumStatusDuration") == 0)
  11933. {
  11934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11935. {
  11936. check_ascii = value[0];
  11937. if( (check_ascii < 48) || (check_ascii > 57) )
  11938. {
  11939. isSuccess = ConfigurationStatus_Rejected;
  11940. }
  11941. else
  11942. {
  11943. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11944. {
  11945. isSuccess = ConfigurationStatus_Rejected;
  11946. }
  11947. else
  11948. {
  11949. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11951. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11952. isSuccess = ConfigurationStatus_Accepted;
  11953. }
  11954. }
  11955. }
  11956. else
  11957. {
  11958. isSuccess = ConfigurationStatus_Rejected;
  11959. }
  11960. }
  11961. if(strcmp(key, "NumberOfConnectors") == 0)
  11962. {
  11963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11964. {
  11965. check_ascii = value[0];
  11966. if( (check_ascii < 48) || (check_ascii > 57) )
  11967. {
  11968. isSuccess = ConfigurationStatus_Rejected;
  11969. }
  11970. else
  11971. {
  11972. //Charger.ResetRetries = Integer.parseInt(value);
  11973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11974. isSuccess = ConfigurationStatus_Accepted;
  11975. }
  11976. }
  11977. else
  11978. {
  11979. isSuccess = ConfigurationStatus_Rejected;
  11980. }
  11981. }
  11982. if(strcmp(key, "ResetRetries") == 0)
  11983. {
  11984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11985. {
  11986. check_ascii = value[0];
  11987. if( (check_ascii < 48) || (check_ascii > 57) )
  11988. {
  11989. isSuccess = ConfigurationStatus_Rejected;
  11990. }
  11991. else
  11992. {
  11993. //Charger.ResetRetries = Integer.parseInt(value);
  11994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11995. isSuccess = ConfigurationStatus_Accepted;
  11996. }
  11997. }
  11998. else
  11999. {
  12000. isSuccess = ConfigurationStatus_Rejected;
  12001. }
  12002. }
  12003. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12004. {
  12005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12006. {
  12007. strcpy(str, (const char*)value);
  12008. for(int i = 0; str[i]; i++)
  12009. {
  12010. str[i] = tolower(str[i]);
  12011. }
  12012. if(strcmp(str, "notapplicable")== 0)
  12013. {
  12014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12015. isSuccess = ConfigurationStatus_Accepted;
  12016. }
  12017. else if(strcmp(str, "unknown")== 0)
  12018. {
  12019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12020. isSuccess = ConfigurationStatus_Accepted;
  12021. }
  12022. else if(strcmp(str, "rst")== 0)
  12023. {
  12024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12025. isSuccess = ConfigurationStatus_Accepted;
  12026. }
  12027. else if(strcmp(str, "rts")== 0)
  12028. {
  12029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12030. isSuccess = ConfigurationStatus_Accepted;
  12031. }
  12032. else if(strcmp(str, "srt")== 0)
  12033. {
  12034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12035. isSuccess = ConfigurationStatus_Accepted;
  12036. }
  12037. else if(strcmp(str, "str")== 0)
  12038. {
  12039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12040. isSuccess = ConfigurationStatus_Accepted;
  12041. }
  12042. else if(strcmp(str, "trs")== 0)
  12043. {
  12044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12045. isSuccess = ConfigurationStatus_Accepted;
  12046. }
  12047. else if(strcmp(str, "tsr")== 0)
  12048. {
  12049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12050. isSuccess = ConfigurationStatus_Accepted;
  12051. }
  12052. else
  12053. {
  12054. isSuccess = ConfigurationStatus_Rejected;
  12055. }
  12056. }
  12057. else
  12058. {
  12059. isSuccess = ConfigurationStatus_Rejected;
  12060. }
  12061. }
  12062. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12063. {
  12064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12065. {
  12066. check_ascii = value[0];
  12067. if( (check_ascii < 48) || (check_ascii > 57) )
  12068. {
  12069. isSuccess = ConfigurationStatus_Rejected;
  12070. }
  12071. else
  12072. {
  12073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12074. isSuccess = ConfigurationStatus_Accepted;
  12075. }
  12076. }
  12077. else
  12078. {
  12079. isSuccess = ConfigurationStatus_Rejected;
  12080. }
  12081. }
  12082. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12083. {
  12084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12085. {
  12086. strcpy(str, (const char*)value);
  12087. for(int i = 0; str[i]; i++)
  12088. {
  12089. str[i] = tolower(str[i]);
  12090. }
  12091. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12093. isSuccess = ConfigurationStatus_Accepted;
  12094. }
  12095. else
  12096. {
  12097. isSuccess = ConfigurationStatus_Rejected;
  12098. }
  12099. }
  12100. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12101. {
  12102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12103. {
  12104. strcpy(str, (const char*)value);
  12105. for(int i = 0; str[i]; i++)
  12106. {
  12107. str[i] = tolower(str[i]);
  12108. }
  12109. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12111. isSuccess = ConfigurationStatus_Accepted;
  12112. }
  12113. else
  12114. {
  12115. isSuccess = ConfigurationStatus_Rejected;
  12116. }
  12117. }
  12118. if(strcmp(key, "StopTxnAlignedData") == 0)
  12119. {
  12120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12121. {
  12122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12123. isSuccess = ConfigurationStatus_Accepted;
  12124. }
  12125. else
  12126. {
  12127. isSuccess = ConfigurationStatus_Rejected;
  12128. }
  12129. }
  12130. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12131. {
  12132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12133. {
  12134. check_ascii = value[0];
  12135. if( (check_ascii < 48) || (check_ascii > 57) )
  12136. {
  12137. isSuccess = ConfigurationStatus_Rejected;
  12138. }
  12139. else
  12140. {
  12141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12142. isSuccess = ConfigurationStatus_Accepted;
  12143. }
  12144. }
  12145. else
  12146. {
  12147. isSuccess = ConfigurationStatus_Rejected;
  12148. }
  12149. }
  12150. if(strcmp(key, "StopTxnSampledData") == 0)
  12151. {
  12152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12153. {
  12154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12155. isSuccess = ConfigurationStatus_Accepted;
  12156. }
  12157. else
  12158. {
  12159. isSuccess = ConfigurationStatus_Rejected;
  12160. }
  12161. }
  12162. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12163. {
  12164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12165. {
  12166. check_ascii = value[0];
  12167. if( (check_ascii < 48) || (check_ascii > 57) )
  12168. {
  12169. isSuccess = ConfigurationStatus_Rejected;
  12170. }
  12171. else
  12172. {
  12173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12174. isSuccess = ConfigurationStatus_Accepted;
  12175. }
  12176. }
  12177. else
  12178. {
  12179. isSuccess = ConfigurationStatus_Rejected;
  12180. }
  12181. }
  12182. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12183. {
  12184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12185. {
  12186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12187. isSuccess = ConfigurationStatus_Accepted;
  12188. }
  12189. else
  12190. {
  12191. isSuccess = ConfigurationStatus_Rejected;
  12192. }
  12193. }
  12194. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12195. {
  12196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12197. {
  12198. check_ascii = value[0];
  12199. if( (check_ascii < 48) || (check_ascii > 57) )
  12200. {
  12201. isSuccess = ConfigurationStatus_Rejected;
  12202. }
  12203. else
  12204. {
  12205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12206. isSuccess = ConfigurationStatus_Accepted;
  12207. }
  12208. }
  12209. else
  12210. {
  12211. isSuccess = ConfigurationStatus_Rejected;
  12212. }
  12213. }
  12214. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12215. {
  12216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12217. {
  12218. check_ascii = value[0];
  12219. if( (check_ascii < 48) || (check_ascii > 57) )
  12220. {
  12221. isSuccess = ConfigurationStatus_Rejected;
  12222. }
  12223. else
  12224. {
  12225. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12227. TransactionMessageAttemptsValue = atoi(value);
  12228. isSuccess = ConfigurationStatus_Accepted;
  12229. }
  12230. }
  12231. else
  12232. {
  12233. isSuccess = ConfigurationStatus_Rejected;
  12234. }
  12235. }
  12236. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12237. {
  12238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12239. {
  12240. check_ascii = value[0];
  12241. if( (check_ascii < 48) || (check_ascii > 57) )
  12242. {
  12243. isSuccess = ConfigurationStatus_Rejected;
  12244. }
  12245. else
  12246. {
  12247. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12249. TransactionMessageRetryIntervalValue = atoi(value);
  12250. isSuccess = ConfigurationStatus_Accepted;
  12251. }
  12252. }
  12253. else
  12254. {
  12255. isSuccess = ConfigurationStatus_Rejected;
  12256. }
  12257. }
  12258. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12259. {
  12260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12261. {
  12262. strcpy(str, (const char*)value);
  12263. for(int i = 0; str[i]; i++)
  12264. {
  12265. str[i] = tolower(str[i]);
  12266. }
  12267. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12269. isSuccess = ConfigurationStatus_Accepted;
  12270. }
  12271. else
  12272. {
  12273. isSuccess = ConfigurationStatus_Rejected;
  12274. }
  12275. }
  12276. if(strcmp(key, "WebSocketPingInterval") == 0)
  12277. {
  12278. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12279. {
  12280. check_ascii = value[0];
  12281. if( (check_ascii < 48) || (check_ascii > 57) )
  12282. {
  12283. isSuccess = ConfigurationStatus_Rejected;
  12284. }
  12285. else
  12286. {
  12287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12288. isSuccess = ConfigurationStatus_Accepted;
  12289. }
  12290. }
  12291. else
  12292. {
  12293. isSuccess = ConfigurationStatus_Rejected;
  12294. }
  12295. }
  12296. #if 0
  12297. //For OCPP Test Case
  12298. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12299. {
  12300. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12301. {
  12302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12303. isSuccess = ConfigurationStatus_Accepted;
  12304. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12305. }
  12306. else
  12307. {
  12308. isSuccess = ConfigurationStatus_Rejected;
  12309. }
  12310. }
  12311. #endif
  12312. #if 1
  12313. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12314. {
  12315. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12316. {
  12317. strcpy(str, (const char*)value);
  12318. for(int i = 0; str[i]; i++)
  12319. {
  12320. str[i] = tolower(str[i]);
  12321. }
  12322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12323. isSuccess = ConfigurationStatus_Accepted;
  12324. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12325. }
  12326. else
  12327. {
  12328. isSuccess = ConfigurationStatus_Rejected;
  12329. }
  12330. }
  12331. #endif
  12332. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12333. {
  12334. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12335. {
  12336. check_ascii = value[0];
  12337. if( (check_ascii < 48) || (check_ascii > 57) )
  12338. {
  12339. isSuccess = ConfigurationStatus_Rejected;
  12340. }
  12341. else
  12342. {
  12343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12344. isSuccess = ConfigurationStatus_Accepted;
  12345. }
  12346. }
  12347. else
  12348. {
  12349. isSuccess = ConfigurationStatus_Rejected;
  12350. }
  12351. }
  12352. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12353. {
  12354. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12355. {
  12356. check_ascii = value[0];
  12357. if( (check_ascii < 48) || (check_ascii > 57) )
  12358. {
  12359. isSuccess = ConfigurationStatus_Rejected;
  12360. }
  12361. else
  12362. {
  12363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12364. isSuccess = ConfigurationStatus_Accepted;
  12365. }
  12366. }
  12367. else
  12368. {
  12369. isSuccess = ConfigurationStatus_Rejected;
  12370. }
  12371. }
  12372. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12373. {
  12374. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12375. {
  12376. strcpy(str, (const char*)value);
  12377. for(int i = 0; str[i]; i++)
  12378. {
  12379. str[i] = tolower(str[i]);
  12380. }
  12381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12382. isSuccess = ConfigurationStatus_Accepted;
  12383. }
  12384. else
  12385. {
  12386. isSuccess = ConfigurationStatus_Rejected;
  12387. }
  12388. }
  12389. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12390. {
  12391. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12392. {
  12393. check_ascii = value[0];
  12394. if( (check_ascii < 48) || (check_ascii > 57) )
  12395. {
  12396. isSuccess = ConfigurationStatus_Rejected;
  12397. }
  12398. else
  12399. {
  12400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12401. isSuccess = ConfigurationStatus_Accepted;
  12402. }
  12403. }
  12404. else
  12405. {
  12406. isSuccess = ConfigurationStatus_Rejected;
  12407. }
  12408. }
  12409. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12410. {
  12411. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12412. {
  12413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12414. isSuccess = ConfigurationStatus_Accepted;
  12415. }
  12416. else
  12417. {
  12418. isSuccess = ConfigurationStatus_Rejected;
  12419. }
  12420. }
  12421. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12422. {
  12423. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12424. {
  12425. check_ascii = value[0];
  12426. if( (check_ascii < 48) || (check_ascii > 57) )
  12427. {
  12428. isSuccess = ConfigurationStatus_Rejected;
  12429. }
  12430. else
  12431. {
  12432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12433. isSuccess = ConfigurationStatus_Accepted;
  12434. }
  12435. }
  12436. else
  12437. {
  12438. isSuccess = ConfigurationStatus_Rejected;
  12439. }
  12440. }
  12441. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12442. {
  12443. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12444. {
  12445. strcpy(str, (const char*)value);
  12446. for(int i = 0; str[i]; i++)
  12447. {
  12448. str[i] = tolower(str[i]);
  12449. }
  12450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12451. isSuccess = ConfigurationStatus_Accepted;
  12452. }
  12453. else
  12454. {
  12455. isSuccess = ConfigurationStatus_Rejected;
  12456. }
  12457. }
  12458. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12459. {
  12460. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12461. {
  12462. check_ascii = value[0];
  12463. if( (check_ascii < 48) || (check_ascii > 57) )
  12464. {
  12465. isSuccess = ConfigurationStatus_Rejected;
  12466. }
  12467. else
  12468. {
  12469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12470. isSuccess = ConfigurationStatus_Accepted;
  12471. }
  12472. }
  12473. else
  12474. {
  12475. isSuccess = ConfigurationStatus_Rejected;
  12476. }
  12477. }
  12478. return isSuccess;
  12479. }
  12480. int updateSetting(char *key, char *value)
  12481. {
  12482. mtrace();
  12483. int isSuccess = FALSE;
  12484. char string[1000]={0}, buffer[1000]={0};
  12485. char strtemp[50]={0};
  12486. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12487. int pos, c = 0;
  12488. char *loc;
  12489. int pos1=0;
  12490. FILE *f = fopen("/var/www/settings1", "r");
  12491. if(f == NULL)
  12492. {
  12493. #ifdef Debug
  12494. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12495. #endif
  12496. return isSuccess;
  12497. }
  12498. fseek(f, 0, SEEK_END);
  12499. long fsize = ftell(f);
  12500. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12501. fread(string, 1, fsize, f);
  12502. fclose(f);
  12503. string[fsize] = 0;
  12504. loc = strstr(string, key);
  12505. if(loc != NULL)
  12506. {
  12507. DEBUG_INFO("key exist!\n");
  12508. pos = loc - string-1;
  12509. f = fopen("/var/www/settings1", "w");
  12510. strncpy(buffer, string, pos);
  12511. fprintf(f, "%s", buffer);
  12512. memset(sstr ,0, sizeof(sstr) );
  12513. c = 0;
  12514. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12515. {
  12516. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12517. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12518. c++;
  12519. }
  12520. sstr[c] = '\0';
  12521. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12522. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12523. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12524. memset(buffer ,0, sizeof(buffer) );
  12525. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12526. //printf("buffer=%s",buffer);
  12527. fprintf(f, "%s", buffer);
  12528. fclose(f);
  12529. }
  12530. else
  12531. {
  12532. printf("key not exist!\n");
  12533. f = fopen("/var/www/settings1", "w+");
  12534. fputs(string, f);
  12535. fseek(f, -1, SEEK_CUR);
  12536. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12537. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12538. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12539. fclose(f);
  12540. }
  12541. isSuccess = TRUE;
  12542. return isSuccess;
  12543. }
  12544. int TransactionMessageAttemptsGet(void)
  12545. {
  12546. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12547. }
  12548. int FirstHeartBeatResponse(void)
  12549. {
  12550. return FirstHeartBeat;
  12551. }
  12552. int TransactionMessageRetryIntervalGet(void)
  12553. {
  12554. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12555. }
  12556. #define SA struct sockaddr
  12557. #define MAXBUF 1024
  12558. //static int m_socket_data;
  12559. //static int sockfd;
  12560. int ReadHttpStatus(int sock){
  12561. //char c;
  12562. char buff[1024]="",*ptr=buff+1;
  12563. int bytes_received, status;
  12564. DEBUG_INFO("Begin Response ..\n");
  12565. while((bytes_received = recv(sock, ptr, 1, 0))){
  12566. if(bytes_received==-1){
  12567. perror("ReadHttpStatus");
  12568. exit(1);
  12569. }
  12570. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12571. ptr++;
  12572. }
  12573. *ptr=0;
  12574. ptr=buff+1;
  12575. sscanf(ptr,"%*s %d ", &status);
  12576. DEBUG_INFO("%s\n",ptr);
  12577. DEBUG_INFO("status=%d\n",status);
  12578. DEBUG_INFO("End Response ..\n");
  12579. return (bytes_received>0)?status:0;
  12580. }
  12581. //the only filed that it parsed is 'Content-Length'
  12582. int ParseHeader(int sock){
  12583. //char c;
  12584. char buff[1024]="",*ptr=buff+4;
  12585. int bytes_received;
  12586. DEBUG_INFO("Begin HEADER ..\n");
  12587. while((bytes_received = recv(sock, ptr, 1, 0))){
  12588. if(bytes_received==-1){
  12589. perror("Parse Header");
  12590. exit(1);
  12591. }
  12592. if(
  12593. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12594. (ptr[-1]=='\r') && (*ptr=='\n' )
  12595. ) break;
  12596. ptr++;
  12597. }
  12598. *ptr=0;
  12599. ptr=buff+4;
  12600. //printf("%s",ptr);
  12601. if(bytes_received){
  12602. ptr=strstr(ptr,"Content-Length:");
  12603. if(ptr){
  12604. sscanf(ptr,"%*s %d",&bytes_received);
  12605. }else
  12606. bytes_received=-1; //unknown size
  12607. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12608. }
  12609. DEBUG_INFO("End HEADER ..\n");
  12610. return bytes_received ;
  12611. }
  12612. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12613. {
  12614. char rmFileCmd[100]={0};
  12615. char FilePath[100]={0};
  12616. char ftpbuf[200];
  12617. int systemresult;
  12618. //DEBUG_INFO("filename=%s\n",filename);
  12619. //DEBUG_INFO("url=%s\n",url);
  12620. sprintf(FilePath,"/mnt/%s",filename);
  12621. if((access(FilePath,F_OK))!=-1)
  12622. {
  12623. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12624. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12625. system(rmFileCmd);
  12626. }
  12627. memset(ftpbuf, 0, sizeof(ftpbuf));
  12628. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12629. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12630. systemresult = system(ftpbuf);
  12631. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12632. if(systemresult != 0)
  12633. {
  12634. DEBUG_INFO("http DownLoad error!\n");
  12635. return FALSE;
  12636. }
  12637. return TRUE;
  12638. }
  12639. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12640. {
  12641. char rmFileCmd[100]={0};
  12642. char FilePath[100]={0};
  12643. char ftpbuf[200];
  12644. int systemresult;
  12645. //char temp[100];
  12646. #if 0
  12647. struct hostent* server;
  12648. char *IPbuffer;
  12649. server = gethostbyname(location);
  12650. // To convert an Internet network
  12651. // address into ASCII string
  12652. IPbuffer = inet_ntoa(*((struct in_addr*)
  12653. server->h_addr_list[0]));
  12654. #endif
  12655. sprintf(FilePath,"/mnt/%s",filename);
  12656. if((access(FilePath,F_OK))!=-1)
  12657. {
  12658. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12659. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12660. system(rmFileCmd);
  12661. }
  12662. memset(ftpbuf, 0, sizeof(ftpbuf));
  12663. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12664. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12665. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12666. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12667. systemresult = system(ftpbuf);
  12668. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12669. if(systemresult != 0)
  12670. {
  12671. printf("wget error!\n");
  12672. return FALSE;
  12673. }
  12674. return TRUE;
  12675. }
  12676. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12677. {
  12678. char rmFileCmd[100]={0};
  12679. char FilePath[100]={0};
  12680. char ftpbuf[200];
  12681. char filenametemp[60]={0};
  12682. int systemresult;
  12683. //DEBUG_INFO("filename=%s\n",filename);
  12684. //DEBUG_INFO("url=%s\n",url);
  12685. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12686. if((access(FilePath,F_OK))!=-1)
  12687. {
  12688. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12689. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12690. system(rmFileCmd);
  12691. }
  12692. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12693. if(fp == NULL)
  12694. {
  12695. DEBUG_INFO("log is NULL\n");
  12696. return FALSE;
  12697. }
  12698. else
  12699. {
  12700. fprintf(fp, "%s\n", url);
  12701. sscanf(filename, "%*2[.]%s", filenametemp);
  12702. fprintf(fp, "%s\n", filenametemp);
  12703. fclose(fp);
  12704. }
  12705. memset(ftpbuf, 0, sizeof(ftpbuf));
  12706. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12707. systemresult = system(ftpbuf);
  12708. DEBUG_INFO("systemresult=%d\n",systemresult);
  12709. if(systemresult != 0)
  12710. {
  12711. DEBUG_INFO("http upload error!\n");
  12712. return FALSE;
  12713. }
  12714. return TRUE;
  12715. }
  12716. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12717. {
  12718. struct hostent* server;
  12719. char *IPbuffer;
  12720. char ftpbuf[200];
  12721. int systemresult;
  12722. // To retrieve host information
  12723. server = gethostbyname(location);
  12724. // To convert an Internet network
  12725. // address into ASCII string
  12726. IPbuffer = inet_ntoa(*((struct in_addr*)
  12727. server->h_addr_list[0]));
  12728. memset(ftpbuf, 0, sizeof(ftpbuf));
  12729. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12730. /* format : ftpput -u username -p passwd IP target source*/
  12731. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12732. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12733. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12734. systemresult = system(ftpbuf);
  12735. DEBUG_INFO("systemresult=%d\n",systemresult);
  12736. if(systemresult != 0)
  12737. {
  12738. DEBUG_INFO("ftpput error!\n");
  12739. return FALSE;
  12740. }
  12741. return TRUE;
  12742. }
  12743. int SettingChargingRecord(int target, int transactionId)
  12744. {
  12745. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12746. {
  12747. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12748. {
  12749. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12750. {
  12751. addBuff(target, transactionId, 0);
  12752. return TRUE;
  12753. }
  12754. }
  12755. for (int index = 0; index < CCS_QUANTITY; index++)
  12756. {
  12757. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12758. {
  12759. addBuff(target, transactionId, 0);
  12760. return TRUE;
  12761. }
  12762. }
  12763. for (int index = 0; index < GB_QUANTITY; index++)
  12764. {
  12765. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12766. {
  12767. addBuff(target, transactionId, 0);
  12768. return TRUE;
  12769. }
  12770. }
  12771. }
  12772. else
  12773. {
  12774. for (int index = 0; index < AC_QUANTITY; index++)
  12775. {
  12776. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12777. {
  12778. addBuff(target, transactionId, 0);
  12779. return TRUE;
  12780. }
  12781. }
  12782. }
  12783. return FALSE;
  12784. }
  12785. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12786. {
  12787. int isSuccess = FALSE;
  12788. //char *query = NULL;
  12789. sqlite3_stmt *stmt;
  12790. int rc; // return code
  12791. char str[20];
  12792. sprintf(str,"%d",user_id);
  12793. 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 */
  12794. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12795. rc = sqlite3_step(stmt); /* 3 */
  12796. if (rc != SQLITE_DONE) {
  12797. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12798. goto out;
  12799. }
  12800. sqlite3_finalize(stmt);
  12801. // free(query);
  12802. out:
  12803. //----------------------
  12804. // close SQLite database
  12805. //----------------------
  12806. sqlite3_close(db);
  12807. printf("database closed.\n");
  12808. return isSuccess;
  12809. }
  12810. /**
  12811. * Place the contents of the specified file into a memory buffer
  12812. *
  12813. * @param[in] filename The path and name of the file to read
  12814. * @param[out] filebuffer A pointer to the contents in memory
  12815. * @return status 0 success, 1 on failure
  12816. */
  12817. int get_file_contents(const char* filename, char** outbuffer) {
  12818. FILE* file = NULL;
  12819. long filesize;
  12820. const int blocksize = 1;
  12821. size_t readsize;
  12822. char* filebuffer;
  12823. // Open the file
  12824. file = fopen(filename, "r");
  12825. if (NULL == file)
  12826. {
  12827. printf("'%s' not opened\n", filename);
  12828. exit(EXIT_FAILURE);
  12829. }
  12830. // Determine the file size
  12831. fseek(file, 0, SEEK_END);
  12832. filesize = ftell(file);
  12833. rewind (file);
  12834. // Allocate memory for the file contents
  12835. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12836. *outbuffer = filebuffer;
  12837. if (filebuffer == NULL)
  12838. {
  12839. fputs ("malloc out-of-memory", stderr);
  12840. exit(EXIT_FAILURE);
  12841. }
  12842. // Read in the file
  12843. readsize = fread(filebuffer, blocksize, filesize, file);
  12844. if (readsize != filesize)
  12845. {
  12846. fputs ("didn't read file completely",stderr);
  12847. exit(EXIT_FAILURE);
  12848. }
  12849. // Clean exit
  12850. fclose(file);
  12851. return EXIT_SUCCESS;
  12852. }
  12853. static int selectSqlCount = 0;
  12854. static int callback(void *data, int argc, char **argv, char **azColName){
  12855. int i;
  12856. //printf("%s: ", (const char*)data);
  12857. selectSqlCount = argc;
  12858. for(i = 0; i<argc; i++){
  12859. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12860. }
  12861. //printf("\n");
  12862. return 0;
  12863. }
  12864. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12865. //int i;
  12866. //printf("%s:\n", (const char*)data);
  12867. localversion = argv[5] ? atoi(argv[5]) : 0;
  12868. //printf("localversion=%d\n", localversion);
  12869. return 0;
  12870. }
  12871. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12872. //int i;
  12873. //printf("%s:\n", (const char*)data);
  12874. //idTag
  12875. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12876. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12877. //parentIdTag
  12878. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12879. //expir_date
  12880. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12881. //status
  12882. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12883. //version
  12884. idTagQuery.listVersionInt = atoi(argv[5]);
  12885. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12886. return 0;
  12887. }
  12888. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12889. #if 0
  12890. int i;
  12891. //printf("%s:\n", (const char*)data);
  12892. for(i=0; i<argc; i++){
  12893. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12894. }
  12895. //printf("");
  12896. #endif
  12897. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12898. // printf("localversion=%d\n", localversion);
  12899. return 0;
  12900. }
  12901. /** sqlite3_exec的回调。
  12902. *
  12903. * 向控制台打印查询的结果。
  12904. *
  12905. * @param in data 传递给回调函数的数据。
  12906. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12907. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12908. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12909. * @return 状态码。
  12910. */
  12911. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12912. {
  12913. for (int i = 0; i < n_columns; i++)
  12914. {
  12915. DEBUG_INFO("%s/t", col_values[i]);
  12916. }
  12917. DEBUG_INFO("/n");
  12918. return 0;
  12919. }
  12920. void OCPP_getListVerion()
  12921. {
  12922. int rc = 0;
  12923. // const char* data = "Callback function called";
  12924. char sql[100];
  12925. char zErrMsg[100];
  12926. memset(sql, 0, 100);
  12927. memset(zErrMsg, 0, 100);
  12928. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12929. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12930. /* Execute SQL statement */
  12931. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12932. DEBUG_INFO("rc=%d\n",rc);
  12933. if( rc != SQLITE_OK ){
  12934. DEBUG_INFO("SQL error: %s", zErrMsg);
  12935. //sqlite3_free(zErrMsg);
  12936. }
  12937. }
  12938. void OCPP_getIdTag(char idTag[])
  12939. {
  12940. int rc = 0;
  12941. // const char* data = "Callback function called";
  12942. char sql[100];
  12943. char zErrMsg[100];
  12944. memset(sql, 0, 100);
  12945. memset(zErrMsg, 0, 100);
  12946. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12947. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12948. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12949. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12950. /* Execute SQL statement */
  12951. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12952. if( rc != SQLITE_OK ){
  12953. DEBUG_INFO("SQL error: %s", zErrMsg);
  12954. //sqlite3_free(zErrMsg);
  12955. }
  12956. //return ver;
  12957. }
  12958. void OCPP_get_TableAuthlocalAllData(void)
  12959. {
  12960. int rc = 0;
  12961. // const char* data = "Callback function called";
  12962. char sql[100];
  12963. char zErrMsg[100];
  12964. memset(sql, 0, 100);
  12965. memset(zErrMsg, 0, 100);
  12966. sprintf(sql,"select * from ocpp_auth_local ");
  12967. /* Execute SQL statement */
  12968. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12969. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12970. if( rc != SQLITE_OK ){
  12971. DEBUG_INFO("SQL error: %s", zErrMsg);
  12972. //sqlite3_free(zErrMsg);
  12973. }
  12974. //return ver;
  12975. }
  12976. int OCPP_cleanLocalList()
  12977. {
  12978. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12979. char *errMsg = 0;
  12980. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12981. if (SQLITE_OK != rc)
  12982. {
  12983. DEBUG_INFO("%s\n",errMsg);
  12984. return FALSE;
  12985. }
  12986. else
  12987. {
  12988. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12989. }
  12990. return TRUE;
  12991. }
  12992. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12993. {
  12994. int isSuccess = FALSE;
  12995. int ret = 0;
  12996. //const char* data = "Callback function called";
  12997. char sql[300];
  12998. char zErrMsg[200];
  12999. memset(sql, 0, 300);
  13000. memset(zErrMsg, 0, 200);
  13001. 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);
  13002. //* Execute SQL statement */
  13003. //zErrMsg = 0;
  13004. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13005. if( ret != SQLITE_OK ){
  13006. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13007. // free(zErrMsg);
  13008. // free(sql);
  13009. return isSuccess;
  13010. }
  13011. memset(sql, 0, 300);
  13012. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13013. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13014. if( ret != SQLITE_OK ){
  13015. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13016. // free(zErrMsg);
  13017. // free(sql);
  13018. return isSuccess;
  13019. }
  13020. // DEBUG_INFO("successfully Insert records created\n");
  13021. isSuccess = TRUE;
  13022. return isSuccess;
  13023. }
  13024. void OCPP_deleteIdTag(char idTag[])
  13025. {
  13026. //int ver = 0;
  13027. //int isSuccess = FALSE;
  13028. int rc = 0;
  13029. char sql[100];
  13030. char zErrMsg[100];
  13031. memset(sql, 0, 100);
  13032. memset(zErrMsg, 0, 100);
  13033. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13034. //* Execute SQL statement */
  13035. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13036. if( rc != SQLITE_OK ){
  13037. DEBUG_INFO("SQL error: %s", zErrMsg);
  13038. //sqlite3_free(zErrMsg);
  13039. }
  13040. }
  13041. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13042. {
  13043. int isSuccess = FALSE;
  13044. int ret = 0;
  13045. const char* data = "Callback function called";
  13046. char sql[200];
  13047. char zErrMsg[100];
  13048. memset(sql, 0, 200);
  13049. memset(zErrMsg, 0, 100);
  13050. //* selectFromTable */
  13051. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  13052. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13053. //* Execute SQL statement */
  13054. selectSqlCount = 0;
  13055. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13056. if( ret != SQLITE_OK ){
  13057. printf("Error SQL: %s\n", zErrMsg);
  13058. }
  13059. printf("successfully select operation done\n");
  13060. memset(sql, 0, 200);
  13061. memset(zErrMsg, 0, 100);
  13062. if(selectSqlCount == 0)
  13063. {
  13064. //Insert
  13065. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  13066. 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);
  13067. DEBUG_INFO("sql:%s\n", sql);
  13068. //* Execute SQL statement */
  13069. //zErrMsg = 0;
  13070. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  13071. if( ret != SQLITE_OK ){
  13072. printf("SQL error: %s\n", zErrMsg);
  13073. return isSuccess;
  13074. }
  13075. DEBUG_INFO("successfully Insert records created\n");
  13076. isSuccess = TRUE;
  13077. }
  13078. else
  13079. {
  13080. //Update
  13081. //* Create merged SQL statement */
  13082. 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);
  13083. /* Execute SQL statement */
  13084. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13085. if( ret != SQLITE_OK ){
  13086. printf("SQL error: %s\n", zErrMsg);
  13087. //sqlite3_free(zErrMsg);
  13088. //sqlite3_free(sql);
  13089. return isSuccess;
  13090. }
  13091. DEBUG_INFO("Successfully operation done \n");
  13092. isSuccess = TRUE;
  13093. }
  13094. return isSuccess;
  13095. }
  13096. int GetOcppServerURL()
  13097. {
  13098. int result = FALSE;
  13099. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  13100. memset(OcppHost, 0, sizeof(OcppHost));
  13101. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  13102. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13103. {
  13104. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  13105. #if 1
  13106. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13107. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13108. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13109. #endif
  13110. #if 0
  13111. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13112. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  13113. OcppProtocol, OcppHost, OcppTempPath);
  13114. OcppPort = 443;
  13115. #endif
  13116. result = TRUE;
  13117. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13118. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13119. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13120. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13121. goto End;
  13122. }
  13123. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13124. {
  13125. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  13126. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13127. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13128. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13129. result = TRUE;
  13130. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13131. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13132. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13133. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13134. goto End;
  13135. }
  13136. else
  13137. {
  13138. strcpy(OcppHost,"");
  13139. }
  13140. End:
  13141. return result;
  13142. }
  13143. int GetOcppPath()
  13144. {
  13145. int result = FALSE;
  13146. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13147. {
  13148. if(OcppTempPath == NULL)
  13149. {
  13150. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13151. }
  13152. else
  13153. {
  13154. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13155. }
  13156. result = TRUE;
  13157. goto End;
  13158. }
  13159. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13160. {
  13161. if(OcppTempPath == NULL)
  13162. {
  13163. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13164. }
  13165. else
  13166. {
  13167. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13168. }
  13169. result = TRUE;
  13170. goto End;
  13171. }
  13172. else
  13173. {
  13174. strcpy(OcppPath,"");
  13175. }
  13176. End:
  13177. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  13178. return result;
  13179. }
  13180. int GetOcppPort()
  13181. {
  13182. return OcppPort;
  13183. }
  13184. int GetOcppConnStatus(void)
  13185. {
  13186. return ShmOCPP16Data->OcppConnStatus;
  13187. }
  13188. void SetOcppConnStatus(uint8_t status)
  13189. {
  13190. ShmOCPP16Data->OcppConnStatus = status;
  13191. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13192. if(status == FALSE)
  13193. {
  13194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13195. {
  13196. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  13197. }
  13198. else
  13199. {
  13200. SystemInitial = AC_QUANTITY;
  13201. }
  13202. }
  13203. }
  13204. int GetHeartBeatWithNOResponse(void)
  13205. {
  13206. return HeartBeatWithNOResponse;
  13207. }
  13208. void SetHeartBeatWithNOResponse(void)
  13209. {
  13210. HeartBeatWithNOResponse = 0;
  13211. }
  13212. void splitstring(char *src,const char *separator,char **dest,int *num) {
  13213. /*
  13214. src 源字串的首地址(buf的地址)
  13215. separator 指定的分割字元
  13216. dest 接收子字串的陣列
  13217. num 分割後子字串的個數
  13218. */
  13219. char *pNext;
  13220. int count = 0;
  13221. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  13222. return;
  13223. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  13224. return;
  13225. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  13226. while(pNext != NULL) {
  13227. *dest++ = pNext;
  13228. ++count;
  13229. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  13230. }
  13231. *num = count;
  13232. }
  13233. int GetTransactionId(int gunindex, unsigned char idTag[])
  13234. {
  13235. char ch;
  13236. FILE *fptr1;
  13237. int temptransactionId;
  13238. char str[100]={0};
  13239. temptransactionId = 0;
  13240. /*------ Read the file ----------------*/
  13241. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13242. if (!fptr1)
  13243. {
  13244. printf(" File not found or unable to open the input file!!\n");
  13245. return temptransactionId;
  13246. }
  13247. ch=fgetc(fptr1);
  13248. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13249. rewind(fptr1);
  13250. if(ch!=EOF)
  13251. {
  13252. // printf("%c",ch);
  13253. while (fgets(str, 100, fptr1) != NULL)
  13254. {
  13255. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13256. if(str[0]=='\0')
  13257. {
  13258. break;
  13259. }
  13260. char *revbuf[8] = {0}; //存放分割後的子字串
  13261. int num = 0;//分割後子字串的個數
  13262. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13263. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13264. {
  13265. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13266. {
  13267. temptransactionId = atoi(revbuf[2]);
  13268. break;
  13269. }
  13270. }
  13271. }
  13272. }
  13273. fclose(fptr1);
  13274. /*------- End of reading ---------------*/
  13275. return temptransactionId;
  13276. }
  13277. void SetTransactionIdZero(int transactionId)
  13278. {
  13279. //TransactionId[gunindex] = 0;
  13280. char ch;
  13281. FILE *fptr1, *fptr2;
  13282. int temptransactionId = 0;
  13283. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13284. printf("\n Delete a specific line from a file :\n");
  13285. printf("-----------------------------------------\n");
  13286. //scanf("%s",fname);
  13287. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13288. if (!fptr1)
  13289. {
  13290. printf(" File not found or unable to open the input file!!\n");
  13291. return ;
  13292. }
  13293. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13294. if (!fptr2)
  13295. {
  13296. printf("Unable to open a temporary file to write!!\n");
  13297. fclose(fptr1);
  13298. return ;
  13299. }
  13300. ch=fgetc(fptr1);
  13301. //printf(" Now the content of the file %s is : \n",fname);
  13302. rewind(fptr1);
  13303. if(ch!=EOF)
  13304. {
  13305. // copy all contents to the temporary file except the specific line
  13306. while (fgets(str, 100, fptr1) != NULL)
  13307. {
  13308. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13309. if(str[0]=='\0')
  13310. {
  13311. break;
  13312. }
  13313. char *revbuf[8] = {0}; //存放分割後的子字串
  13314. int num = 0;//分割後子字串的個數
  13315. strcpy(strtemp, str);
  13316. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13317. if(revbuf[2][0] != '\0')
  13318. {
  13319. temptransactionId = atoi(revbuf[2]);
  13320. if(transactionId != temptransactionId)
  13321. {
  13322. fprintf(fptr2, "%s", strtemp);
  13323. }
  13324. }
  13325. }
  13326. }
  13327. fclose(fptr1);
  13328. fclose(fptr2);
  13329. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13330. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13331. printf("\n Delete a specific line from a file End\n");
  13332. printf("-----------------------------------------\n");
  13333. /*------ Read the file ----------------*/
  13334. }
  13335. int InternetDisconnect(void)
  13336. {
  13337. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13338. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13339. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13340. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13341. }
  13342. void GetChargingProfileRequest(int gunindex)
  13343. {
  13344. mtrace();
  13345. //int connectorIdInt, durationInt;
  13346. //char chargingRateUnitStr[4]={0};
  13347. int tempdurationInt = 0;
  13348. int tempchargingProfileId = 0;
  13349. int tempstackLevel = 0;
  13350. int temptransactionId = 0;
  13351. float tempminChargingRateFloat = 0.0;
  13352. char tempchargingProfilePurposeStr[24]={0};
  13353. char tempchargingProfileKindStr[12]={0};
  13354. char temprecurrencyKindStr[8]={0};
  13355. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13356. char tempvalidToStr[28]={0};
  13357. int tempStartPeriodInt = 0;
  13358. float tempLimitInt = 0.0;//0.1;
  13359. int tempNumberPhasesInt=0;
  13360. char fname[200];
  13361. //char comfirmstr[20];
  13362. float MinChargingRate =0.0;
  13363. double diff_t;
  13364. struct tm tp;
  13365. FILE *fptr1;//, *fptr2;
  13366. int c = 0;
  13367. char * pch;
  13368. char *loc;
  13369. char sstr[200]={ 0 };
  13370. int n_chargingProfile = 0;
  13371. int n_SchedulePeriods = 0;
  13372. char SchedulePeriodList[10][200]={0};
  13373. char sLineWord[1600]={0};
  13374. char word[1000]={0};
  13375. int confirmPeriods = 0;
  13376. struct StructProfile ChargePointMaxProfile;
  13377. struct StructProfile TxDefaultProfile;
  13378. struct StructProfile TxProfile;
  13379. struct StructProfile TxDefaultProfiletemp[2]={0};
  13380. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13381. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13382. struct StructChargingProfile TxProfile_TEMP={0};
  13383. int TxDefaultProfileFileIsNull=FALSE;
  13384. int ChargePointMaxProfileIsNull=FALSE;
  13385. int TxProfileIsNull=FALSE;
  13386. // int CompositeSceduleIndex = 0;
  13387. char ChargePointMaxProfileScheduleStr[30]={0};
  13388. char TxDefaultProfileScheduleStr[30]={0};
  13389. char TxProfileScheduleStr[30]={0};
  13390. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13391. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13392. memset(&TxProfile,0,sizeof(struct StructProfile));
  13393. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13394. DEBUG_INFO("GetChargingProfileRequest\n");
  13395. //*****************************ChargePointMaxProfile******************************************/
  13396. strcpy(fname, ChargePointMaxProfile_JSON);
  13397. ChargePointMaxProfileIsNull=TRUE;
  13398. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13399. {
  13400. fptr1 = fopen(fname, "r");
  13401. int c;
  13402. c = fgetc(fptr1);
  13403. //DEBUG_INFO("c:%d\n",c);
  13404. rewind(fptr1);
  13405. if(c == EOF)
  13406. {
  13407. DEBUG_INFO("\n End of file reached.");
  13408. ChargePointMaxProfileIsNull=TRUE;
  13409. fclose(fptr1);
  13410. }
  13411. else
  13412. {
  13413. ChargePointMaxProfileIsNull=FALSE;
  13414. while(fscanf(fptr1, "%s", word) != EOF)
  13415. {
  13416. if(strcmp(word, "chargingProfileId") == 0)
  13417. {
  13418. n_chargingProfile = n_chargingProfile + 1;
  13419. }
  13420. }
  13421. rewind(fptr1);
  13422. //search Charging Profile Element
  13423. int i = 0;
  13424. int j = 0;
  13425. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13426. //***********chargingProfileId**************/
  13427. c = 0;
  13428. loc = strstr(sLineWord, "chargingProfileId");
  13429. //DEBUG_INFO("loc=%s\n",loc);
  13430. memset(sstr ,0, sizeof(sstr) );
  13431. if(loc != NULL)
  13432. {
  13433. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13434. {
  13435. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13436. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13437. c++;
  13438. }
  13439. sstr[c] = '\0';
  13440. tempchargingProfileId = atoi(sstr);
  13441. }
  13442. else
  13443. {
  13444. tempchargingProfileId = 0;
  13445. }
  13446. //***********stackLevel**************/
  13447. c = 0;
  13448. loc = strstr(sLineWord, "stackLevel");
  13449. //DEBUG_INFO("loc=%s\n",loc);
  13450. memset(sstr ,0, sizeof(sstr) );
  13451. if(loc != NULL)
  13452. {
  13453. while (loc[2+strlen("stackLevel")+c] != '\"')
  13454. {
  13455. sstr[c] = loc[2+strlen("stackLevel")+c];
  13456. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13457. c++;
  13458. }
  13459. sstr[c] = '\0';
  13460. tempstackLevel = atoi(sstr);
  13461. }
  13462. else
  13463. {
  13464. tempstackLevel = 0;
  13465. }
  13466. //***********chargingProfilePurpose **************/
  13467. c = 0;
  13468. loc = strstr(sLineWord, "chargingProfilePurpose");
  13469. //DEBUG_INFO("loc=%s\n",loc);
  13470. memset(sstr ,0, sizeof(sstr) );
  13471. if(loc != NULL)
  13472. {
  13473. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13474. {
  13475. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13476. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13477. c++;
  13478. }
  13479. sstr[c] = '\0';
  13480. strcpy(tempchargingProfilePurposeStr,sstr);
  13481. }
  13482. else
  13483. {
  13484. strcpy(tempchargingProfilePurposeStr,"");
  13485. }
  13486. //***********chargingProfileKind **************/
  13487. c = 0;
  13488. loc = strstr(sLineWord, "chargingProfileKind");
  13489. //DEBUG_INFO("loc=%s\n",loc);
  13490. memset(sstr ,0, sizeof(sstr) );
  13491. if(loc != NULL)
  13492. {
  13493. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13494. {
  13495. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13496. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13497. c++;
  13498. }
  13499. sstr[c] = '\0';
  13500. strcpy(tempchargingProfileKindStr,sstr);
  13501. }
  13502. else
  13503. {
  13504. strcpy(tempchargingProfileKindStr,"");
  13505. }
  13506. //***********recurrencyKind **************/
  13507. c = 0;
  13508. loc = strstr(sLineWord, "recurrencyKind");
  13509. //DEBUG_INFO("loc=%s\n",loc);
  13510. memset(sstr ,0, sizeof(sstr) );
  13511. if(loc != NULL)
  13512. {
  13513. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13514. {
  13515. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13516. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13517. c++;
  13518. }
  13519. sstr[c] = '\0';
  13520. strcpy(temprecurrencyKindStr,sstr);
  13521. }
  13522. else
  13523. {
  13524. strcpy(temprecurrencyKindStr,"");
  13525. }
  13526. //***********validFrom**************/
  13527. c = 0;
  13528. loc = strstr(sLineWord, "validFrom");
  13529. //DEBUG_INFO("loc=%s\n",loc);
  13530. memset(sstr ,0, sizeof(sstr) );
  13531. if(loc != NULL)
  13532. {
  13533. while (loc[3+strlen("validFrom")+c] != '\"')
  13534. {
  13535. sstr[c] = loc[3+strlen("validFrom")+c];
  13536. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13537. c++;
  13538. }
  13539. sstr[c] = '\0';
  13540. strcpy(tempvalidFromStr,sstr);
  13541. }
  13542. else
  13543. {
  13544. strcpy(tempvalidFromStr,"");
  13545. }
  13546. //***********validTo **************/
  13547. c = 0;
  13548. loc = strstr(sLineWord, "validTo");
  13549. //DEBUG_INFO("loc=%s\n",loc);
  13550. memset(sstr ,0, sizeof(sstr) );
  13551. if(loc != NULL)
  13552. {
  13553. while (loc[3+strlen("validTo")+c] != '\"')
  13554. {
  13555. sstr[c] = loc[3+strlen("validTo")+c];
  13556. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13557. c++;
  13558. }
  13559. sstr[c] = '\0';
  13560. strcpy(tempvalidToStr,sstr);
  13561. }
  13562. else
  13563. {
  13564. strcpy(tempvalidToStr,"");
  13565. }
  13566. //***********validFrom**************/
  13567. c = 0;
  13568. loc = strstr(sLineWord, "validFrom");
  13569. if(loc != NULL)
  13570. {
  13571. memset(sstr ,0, sizeof(sstr) );
  13572. while (loc[3+strlen("validFrom")+c] != '\"')
  13573. {
  13574. sstr[c] = loc[3+strlen("validFrom")+c];
  13575. c++;
  13576. }
  13577. sstr[c] = '\0';
  13578. strcpy(tempvalidFromStr,sstr);
  13579. }
  13580. else
  13581. {
  13582. strcpy(tempvalidFromStr,"");
  13583. }
  13584. //***********validTo **************/
  13585. c = 0;
  13586. loc = strstr(sLineWord, "validTo");
  13587. if(loc != NULL)
  13588. {
  13589. memset(sstr ,0, sizeof(sstr) );
  13590. while (loc[3+strlen("validTo")+c] != '\"')
  13591. {
  13592. sstr[c] = loc[3+strlen("validTo")+c];
  13593. c++;
  13594. }
  13595. sstr[c] = '\0';
  13596. strcpy(tempvalidToStr,sstr);
  13597. }
  13598. else
  13599. {
  13600. strcpy(tempvalidToStr,"");
  13601. }
  13602. //***********duration**************/
  13603. c = 0;
  13604. loc = strstr(sLineWord, "duration");
  13605. if(loc != NULL)
  13606. {
  13607. memset(sstr ,0, sizeof(sstr) );
  13608. while (loc[2+strlen("duration")+c] != ',')
  13609. {
  13610. sstr[c] = loc[2+strlen("duration")+c];
  13611. c++;
  13612. }
  13613. sstr[c] = '\0';
  13614. tempdurationInt = atoi(sstr);
  13615. }
  13616. else
  13617. {
  13618. tempdurationInt = 0;
  13619. }
  13620. //**********startSchedule**********/
  13621. c = 0;
  13622. loc = strstr(sLineWord, "startSchedule");
  13623. if(loc != NULL)
  13624. {
  13625. memset(sstr ,0, sizeof(sstr) );
  13626. while (loc[3+strlen("startSchedule")+c] != '\"')
  13627. {
  13628. sstr[c] = loc[3+strlen("startSchedule")+c];
  13629. c++;
  13630. }
  13631. sstr[c] = '\0';
  13632. strcpy(tempstartScheduleStr, sstr);
  13633. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13634. }
  13635. else
  13636. {
  13637. strcpy(tempstartScheduleStr, "");
  13638. strcpy(ChargePointMaxProfileScheduleStr, "");
  13639. }
  13640. //**********chargingRateUnit**********/
  13641. c = 0;
  13642. loc = strstr(sLineWord, "chargingRateUnit");
  13643. memset(sstr ,0, sizeof(sstr) );
  13644. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13645. {
  13646. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13647. c++;
  13648. }
  13649. sstr[c] = '\0';
  13650. strcpy(tempchargingRateUnitStr, sstr);
  13651. //**********minChargingRate*******/
  13652. c = 0;
  13653. loc = strstr(sLineWord, "minChargingRate");
  13654. if(loc != NULL)
  13655. {
  13656. memset(sstr ,0, sizeof(sstr) );
  13657. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13658. {
  13659. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13660. c++;
  13661. }
  13662. sstr[c] = '\0';
  13663. tempminChargingRateFloat = atof(sstr);
  13664. }
  13665. else
  13666. {
  13667. tempminChargingRateFloat = 0.0;
  13668. }
  13669. //
  13670. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13671. tp.tm_isdst = -1;
  13672. time_t utc = mktime(&tp);
  13673. time_t t = time(NULL);
  13674. diff_t = difftime(t, utc);
  13675. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13676. //parsing strings to words
  13677. i = 0;
  13678. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13679. loc = loc+3+strlen("chargingSchedulePeriod");
  13680. pch = strtok(loc ,"{");
  13681. while (pch != NULL)
  13682. {
  13683. strcpy(SchedulePeriodList[i], pch);
  13684. pch = strtok (NULL, "{");
  13685. i = i + 1;
  13686. }
  13687. n_SchedulePeriods = i;
  13688. for(int i=0;i<n_SchedulePeriods;i++)
  13689. {
  13690. //*************startPeriod****************/
  13691. c = 0;
  13692. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13693. memset(sstr ,0, sizeof(sstr) );
  13694. while (loc[strlen("startPeriod")+2+c] != ',')
  13695. {
  13696. sstr[c] = loc[strlen("startPeriod")+2+c];
  13697. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13698. c++;
  13699. }
  13700. sstr[c] = '\0';
  13701. tempStartPeriodInt = atoi(sstr);
  13702. //*************limit****************/
  13703. c = 0;
  13704. loc = strstr(SchedulePeriodList[i], "limit");
  13705. memset(sstr ,0, sizeof(sstr) );
  13706. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  13707. {
  13708. sstr[c] = loc[strlen("limit")+2+c];
  13709. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13710. c++;
  13711. }
  13712. sstr[c] = '\0';
  13713. tempLimitInt = atof(sstr);
  13714. //*************numberPhases****************/
  13715. c = 0;
  13716. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13717. memset(sstr ,0, sizeof(sstr) );
  13718. if(loc != NULL)
  13719. {
  13720. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  13721. {
  13722. sstr[c] = loc[strlen("numberPhases")+2+c];
  13723. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13724. c++;
  13725. }
  13726. sstr[c] = '\0';
  13727. tempNumberPhasesInt = atoi(sstr);
  13728. }
  13729. else
  13730. {
  13731. tempNumberPhasesInt = 0;
  13732. }
  13733. if(j == 0)
  13734. {
  13735. ChargePointMaxProfile.Duration = tempdurationInt;
  13736. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13737. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13738. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13739. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13740. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13741. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13742. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13743. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13744. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13745. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13746. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13747. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13748. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13749. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13750. }
  13751. }
  13752. if(MinChargingRate < tempminChargingRateFloat)
  13753. {
  13754. MinChargingRate = tempminChargingRateFloat;
  13755. }
  13756. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13757. if(confirmPeriods < n_SchedulePeriods)
  13758. {
  13759. confirmPeriods = n_SchedulePeriods;
  13760. }
  13761. j = j + 1;
  13762. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13763. fclose(fptr1);
  13764. }// end else
  13765. }// the end of access file ChargePointMaxProfile
  13766. //****************************TxDefaultProfile************************************************/
  13767. memset(fname, 0, sizeof fname);
  13768. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13769. TxDefaultProfileFileIsNull=TRUE;
  13770. if((access(fname,F_OK))!=-1)
  13771. {
  13772. fptr1 = fopen(fname, "r");
  13773. c = 0;
  13774. c = fgetc(fptr1);
  13775. //DEBUG_INFO("c:%d\n",c);
  13776. rewind(fptr1);
  13777. if(c == EOF)
  13778. {
  13779. DEBUG_INFO("\n End of file reached.");
  13780. TxDefaultProfileFileIsNull=TRUE;
  13781. fclose(fptr1);
  13782. }
  13783. else
  13784. {
  13785. TxDefaultProfileFileIsNull=FALSE;
  13786. while(fscanf(fptr1, "%s", word) != EOF)
  13787. {
  13788. if(strcmp(word, "chargingProfileId") == 0)
  13789. {
  13790. n_chargingProfile = n_chargingProfile + 1;
  13791. }
  13792. }
  13793. rewind(fptr1);
  13794. //search Charging Profile Element
  13795. int i = 0;
  13796. int j = 0;
  13797. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13798. {
  13799. #if 0
  13800. //***********connectorId****************/
  13801. c = 0;
  13802. loc = strstr(sLineWord, "connectorId");
  13803. memset(sstr ,0, sizeof(sstr) );
  13804. while (loc[strlen("connectorId")+2+c] != ',')
  13805. {
  13806. sstr[c] = loc[strlen("connectorId")+2+c];
  13807. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13808. c++;
  13809. }
  13810. sstr[c] = '\0';
  13811. tempconnectorIdInt = atoi(sstr);
  13812. #endif
  13813. //***********chargingProfileId**************/
  13814. c = 0;
  13815. loc = strstr(sLineWord, "chargingProfileId");
  13816. //DEBUG_INFO("loc=%s\n",loc);
  13817. memset(sstr ,0, sizeof(sstr) );
  13818. if(loc != NULL)
  13819. {
  13820. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13821. {
  13822. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13823. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13824. c++;
  13825. }
  13826. sstr[c] = '\0';
  13827. tempchargingProfileId = atoi(sstr);
  13828. }
  13829. else
  13830. {
  13831. tempchargingProfileId = 0;
  13832. }
  13833. //***********stackLevel**************/
  13834. c = 0;
  13835. loc = strstr(sLineWord, "stackLevel");
  13836. //DEBUG_INFO("loc=%s\n",loc);
  13837. memset(sstr ,0, sizeof(sstr) );
  13838. if(loc != NULL)
  13839. {
  13840. while (loc[2+strlen("stackLevel")+c] != '\"')
  13841. {
  13842. sstr[c] = loc[2+strlen("stackLevel")+c];
  13843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13844. c++;
  13845. }
  13846. sstr[c] = '\0';
  13847. tempstackLevel = atoi(sstr);
  13848. }
  13849. else
  13850. {
  13851. tempstackLevel = 0;
  13852. }
  13853. //***********chargingProfilePurpose **************/
  13854. c = 0;
  13855. loc = strstr(sLineWord, "chargingProfilePurpose");
  13856. //DEBUG_INFO("loc=%s\n",loc);
  13857. memset(sstr ,0, sizeof(sstr) );
  13858. if(loc != NULL)
  13859. {
  13860. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13861. {
  13862. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13863. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13864. c++;
  13865. }
  13866. sstr[c] = '\0';
  13867. strcpy(tempchargingProfilePurposeStr,sstr);
  13868. }
  13869. else
  13870. {
  13871. strcpy(tempchargingProfilePurposeStr,"");
  13872. }
  13873. //***********chargingProfileKind **************/
  13874. c = 0;
  13875. loc = strstr(sLineWord, "chargingProfileKind");
  13876. //DEBUG_INFO("loc=%s\n",loc);
  13877. memset(sstr ,0, sizeof(sstr) );
  13878. if(loc != NULL)
  13879. {
  13880. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13881. {
  13882. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13883. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13884. c++;
  13885. }
  13886. sstr[c] = '\0';
  13887. strcpy(tempchargingProfileKindStr,sstr);
  13888. }
  13889. else
  13890. {
  13891. strcpy(tempchargingProfileKindStr,"");
  13892. }
  13893. //***********recurrencyKind **************/
  13894. c = 0;
  13895. loc = strstr(sLineWord, "recurrencyKind");
  13896. //DEBUG_INFO("loc=%s\n",loc);
  13897. memset(sstr ,0, sizeof(sstr) );
  13898. if(loc != NULL)
  13899. {
  13900. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13901. {
  13902. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13903. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13904. c++;
  13905. }
  13906. sstr[c] = '\0';
  13907. strcpy(temprecurrencyKindStr,sstr);
  13908. }
  13909. else
  13910. {
  13911. strcpy(temprecurrencyKindStr,"");
  13912. }
  13913. //***********validFrom**************/
  13914. c = 0;
  13915. loc = strstr(sLineWord, "validFrom");
  13916. if(loc != NULL)
  13917. {
  13918. memset(sstr ,0, sizeof(sstr) );
  13919. while (loc[3+strlen("validFrom")+c] != '\"')
  13920. {
  13921. sstr[c] = loc[3+strlen("validFrom")+c];
  13922. c++;
  13923. }
  13924. sstr[c] = '\0';
  13925. strcpy(tempvalidFromStr,sstr);
  13926. }
  13927. else
  13928. {
  13929. strcpy(tempvalidFromStr,"");
  13930. }
  13931. //***********validTo **************/
  13932. c = 0;
  13933. loc = strstr(sLineWord, "validTo");
  13934. if(loc != NULL)
  13935. {
  13936. memset(sstr ,0, sizeof(sstr) );
  13937. while (loc[3+strlen("validTo")+c] != '\"')
  13938. {
  13939. sstr[c] = loc[3+strlen("validTo")+c];
  13940. c++;
  13941. }
  13942. sstr[c] = '\0';
  13943. strcpy(tempvalidToStr,sstr);
  13944. }
  13945. else
  13946. {
  13947. strcpy(tempvalidToStr,"");
  13948. }
  13949. //***********duration**************/
  13950. c = 0;
  13951. loc = strstr(sLineWord, "duration");
  13952. if(loc != NULL)
  13953. {
  13954. memset(sstr ,0, sizeof(sstr) );
  13955. while (loc[2+strlen("duration")+c] != ',')
  13956. {
  13957. sstr[c] = loc[2+strlen("duration")+c];
  13958. c++;
  13959. }
  13960. sstr[c] = '\0';
  13961. tempdurationInt = atoi(sstr);
  13962. }
  13963. else
  13964. {
  13965. tempdurationInt = 0;
  13966. }
  13967. //**********startSchedule**********/
  13968. c = 0;
  13969. loc = strstr(sLineWord, "startSchedule");
  13970. if(loc != NULL)
  13971. {
  13972. memset(sstr ,0, sizeof(sstr) );
  13973. while (loc[3+strlen("startSchedule")+c] != '\"')
  13974. {
  13975. sstr[c] = loc[3+strlen("startSchedule")+c];
  13976. c++;
  13977. }
  13978. sstr[c] = '\0';
  13979. strcpy(tempstartScheduleStr, sstr);
  13980. strcpy(TxDefaultProfileScheduleStr, sstr);
  13981. }
  13982. else
  13983. {
  13984. strcpy(tempstartScheduleStr, "");
  13985. strcpy(TxDefaultProfileScheduleStr, "");
  13986. }
  13987. //**********chargingRateUnit**********/
  13988. c = 0;
  13989. loc = strstr(sLineWord, "chargingRateUnit");
  13990. memset(sstr ,0, sizeof(sstr) );
  13991. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13992. {
  13993. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13994. c++;
  13995. }
  13996. sstr[c] = '\0';
  13997. strcpy(tempchargingRateUnitStr, sstr);
  13998. //**********minChargingRate*******/
  13999. c = 0;
  14000. loc = strstr(sLineWord, "minChargingRate");
  14001. if(loc != NULL)
  14002. {
  14003. memset(sstr ,0, sizeof(sstr) );
  14004. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14005. {
  14006. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14007. c++;
  14008. }
  14009. sstr[c] = '\0';
  14010. tempminChargingRateFloat = atof(sstr);
  14011. }
  14012. else
  14013. {
  14014. tempminChargingRateFloat = 0.0;
  14015. }
  14016. //
  14017. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14018. tp.tm_isdst = -1;
  14019. time_t utc = mktime(&tp);
  14020. time_t t = time(NULL);
  14021. diff_t = difftime(t, utc);
  14022. printf("diff between startScheduleStr and now =%f\n",diff_t);
  14023. //parsing strings to words
  14024. i = 0;
  14025. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14026. loc = loc+3+strlen("chargingSchedulePeriod");
  14027. pch = strtok(loc ,"{");
  14028. while (pch != NULL)
  14029. {
  14030. strcpy(SchedulePeriodList[i], pch);
  14031. pch = strtok (NULL, "{");
  14032. i = i + 1;
  14033. }
  14034. n_SchedulePeriods = i;
  14035. for(int i=0;i<n_SchedulePeriods;i++)
  14036. {
  14037. //*************startPeriod****************/
  14038. c = 0;
  14039. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14040. memset(sstr ,0, sizeof(sstr) );
  14041. while (loc[strlen("startPeriod")+2+c] != ',')
  14042. {
  14043. sstr[c] = loc[strlen("startPeriod")+2+c];
  14044. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14045. c++;
  14046. }
  14047. sstr[c] = '\0';
  14048. tempStartPeriodInt = atoi(sstr);
  14049. //*************limit****************/
  14050. c = 0;
  14051. loc = strstr(SchedulePeriodList[i], "limit");
  14052. memset(sstr ,0, sizeof(sstr) );
  14053. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14054. {
  14055. sstr[c] = loc[strlen("limit")+2+c];
  14056. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14057. c++;
  14058. }
  14059. sstr[c] = '\0';
  14060. tempLimitInt = atof(sstr);
  14061. //*************numberPhases****************/
  14062. c = 0;
  14063. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14064. memset(sstr ,0, sizeof(sstr) );
  14065. if(loc != NULL)
  14066. {
  14067. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14068. {
  14069. sstr[c] = loc[strlen("numberPhases")+2+c];
  14070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14071. c++;
  14072. }
  14073. sstr[c] = '\0';
  14074. tempNumberPhasesInt = atoi(sstr);
  14075. }
  14076. else
  14077. {
  14078. tempNumberPhasesInt = 0;
  14079. }
  14080. if(j == 0)
  14081. {
  14082. TxDefaultProfile.Duration = tempdurationInt;
  14083. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  14084. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  14085. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14086. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14087. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14088. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  14089. TxDefaultProfile_TEMP.TransactionId = 0;
  14090. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14091. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14092. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14093. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14094. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14095. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14096. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14097. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14098. }
  14099. else
  14100. {
  14101. //other stack level charging Profile
  14102. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  14103. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  14104. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  14105. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  14106. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  14107. }
  14108. }
  14109. if(MinChargingRate < tempminChargingRateFloat)
  14110. {
  14111. MinChargingRate = tempminChargingRateFloat;
  14112. }
  14113. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14114. if(confirmPeriods < n_SchedulePeriods)
  14115. confirmPeriods = n_SchedulePeriods;
  14116. j = j + 1;
  14117. }
  14118. fclose(fptr1);
  14119. //Stacking Charging Profiles
  14120. for(int l=0; l <(j-1) ;l++)
  14121. {
  14122. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  14123. {
  14124. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  14125. {
  14126. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  14127. {
  14128. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  14129. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  14130. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  14131. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14132. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14133. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14134. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14135. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14136. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14137. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14138. }
  14139. else
  14140. {
  14141. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14142. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14143. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14144. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14145. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14146. }
  14147. }
  14148. }
  14149. }//end of Stacking Charging Profiles
  14150. }// end else
  14151. }// the end of ACCESS TxDefaultProfile
  14152. //****************************TxProfile************************************************/
  14153. memset(fname, 0, sizeof fname);
  14154. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  14155. TxProfileIsNull=TRUE;
  14156. if((access(fname,F_OK))!=-1)
  14157. {
  14158. fptr1 = fopen(fname, "r");
  14159. c = 0;
  14160. c = fgetc(fptr1);
  14161. //DEBUG_INFO("c:%d\n",c);
  14162. rewind(fptr1);
  14163. if(c == EOF)
  14164. {
  14165. DEBUG_INFO("\n End of file reached.");
  14166. TxProfileIsNull=TRUE;
  14167. fclose(fptr1);
  14168. }
  14169. else
  14170. {
  14171. TxProfileIsNull=FALSE;
  14172. while(fscanf(fptr1, "%s", word) != EOF)
  14173. {
  14174. if(strcmp(word, "chargingProfileId") == 0)
  14175. {
  14176. n_chargingProfile = n_chargingProfile + 1;
  14177. }
  14178. }
  14179. rewind(fptr1);
  14180. //search Charging Profile Element
  14181. int i= 0;
  14182. int j= 0;
  14183. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14184. #if 0
  14185. /***********connectorId****************/
  14186. c = 0;
  14187. loc = strstr(sLineWord, "connectorId");
  14188. memset(sstr ,0, sizeof(sstr) );
  14189. while (loc[strlen("connectorId")+2+c] != ',')
  14190. {
  14191. sstr[c] = loc[strlen("connectorId")+2+c];
  14192. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14193. c++;
  14194. }
  14195. sstr[c] = '\0';
  14196. tempconnectorIdInt = atoi(sstr);
  14197. #endif
  14198. //***********chargingProfileId**************/
  14199. c = 0;
  14200. loc = strstr(sLineWord, "chargingProfileId");
  14201. memset(sstr ,0, sizeof(sstr) );
  14202. if(loc != NULL)
  14203. {
  14204. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14205. {
  14206. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14207. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14208. c++;
  14209. }
  14210. sstr[c] = '\0';
  14211. tempchargingProfileId = atoi(sstr);
  14212. }
  14213. else
  14214. {
  14215. tempchargingProfileId = 0;
  14216. }
  14217. //***********transactionId **************/
  14218. c = 0;
  14219. loc = strstr(sLineWord, "transactionId");
  14220. //DEBUG_INFO("loc=%s\n",loc);
  14221. memset(sstr ,0, sizeof(sstr) );
  14222. if(loc != NULL)
  14223. {
  14224. while (loc[2+strlen("transactionId")+c] != '\"')
  14225. {
  14226. sstr[c] = loc[2+strlen("transactionId")+c];
  14227. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14228. c++;
  14229. }
  14230. sstr[c] = '\0';
  14231. temptransactionId = atoi(sstr);
  14232. }
  14233. else
  14234. {
  14235. temptransactionId = 0;
  14236. }
  14237. //***********stackLevel**************/
  14238. c = 0;
  14239. loc = strstr(sLineWord, "stackLevel");
  14240. //DEBUG_INFO("loc=%s\n",loc);
  14241. memset(sstr ,0, sizeof(sstr) );
  14242. if(loc != NULL)
  14243. {
  14244. while (loc[2+strlen("stackLevel")+c] != '\"')
  14245. {
  14246. sstr[c] = loc[2+strlen("stackLevel")+c];
  14247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14248. c++;
  14249. }
  14250. sstr[c] = '\0';
  14251. tempstackLevel = atoi(sstr);
  14252. }
  14253. else
  14254. {
  14255. tempstackLevel = 0;
  14256. }
  14257. //***********chargingProfilePurpose **************/
  14258. c = 0;
  14259. loc = strstr(sLineWord, "chargingProfilePurpose");
  14260. //DEBUG_INFO("loc=%s\n",loc);
  14261. memset(sstr ,0, sizeof(sstr) );
  14262. if(loc != NULL)
  14263. {
  14264. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14265. {
  14266. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14267. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14268. c++;
  14269. }
  14270. sstr[c] = '\0';
  14271. strcpy(tempchargingProfilePurposeStr,sstr);
  14272. }
  14273. else
  14274. {
  14275. strcpy(tempchargingProfilePurposeStr,"");
  14276. }
  14277. //***********chargingProfileKind **************/
  14278. c = 0;
  14279. loc = strstr(sLineWord, "chargingProfileKind");
  14280. //DEBUG_INFO("loc=%s\n",loc);
  14281. memset(sstr ,0, sizeof(sstr) );
  14282. if(loc != NULL)
  14283. {
  14284. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14285. {
  14286. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14287. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14288. c++;
  14289. }
  14290. sstr[c] = '\0';
  14291. strcpy(tempchargingProfileKindStr,sstr);
  14292. }
  14293. else
  14294. {
  14295. strcpy(tempchargingProfileKindStr,"");
  14296. }
  14297. //***********recurrencyKind **************/
  14298. c = 0;
  14299. loc = strstr(sLineWord, "recurrencyKind");
  14300. //DEBUG_INFO("loc=%s\n",loc);
  14301. memset(sstr ,0, sizeof(sstr) );
  14302. if(loc != NULL)
  14303. {
  14304. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14305. {
  14306. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14307. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14308. c++;
  14309. }
  14310. sstr[c] = '\0';
  14311. strcpy(temprecurrencyKindStr,sstr);
  14312. }
  14313. else
  14314. {
  14315. strcpy(temprecurrencyKindStr,"");
  14316. }
  14317. //***********validFrom**************/
  14318. c = 0;
  14319. loc = strstr(sLineWord, "validFrom");
  14320. if(loc != NULL)
  14321. {
  14322. memset(sstr ,0, sizeof(sstr) );
  14323. while (loc[3+strlen("validFrom")+c] != '\"')
  14324. {
  14325. sstr[c] = loc[3+strlen("validFrom")+c];
  14326. c++;
  14327. }
  14328. sstr[c] = '\0';
  14329. strcpy(tempvalidFromStr,sstr);
  14330. }
  14331. else
  14332. {
  14333. strcpy(tempvalidFromStr,"");
  14334. }
  14335. //***********validTo**************/
  14336. c = 0;
  14337. loc = strstr(sLineWord, "validTo");
  14338. if(loc != NULL)
  14339. {
  14340. memset(sstr ,0, sizeof(sstr) );
  14341. while (loc[3+strlen("validTo")+c] != '\"')
  14342. {
  14343. sstr[c] = loc[3+strlen("validTo")+c];
  14344. c++;
  14345. }
  14346. sstr[c] = '\0';
  14347. strcpy(tempvalidToStr,sstr);
  14348. }
  14349. else
  14350. {
  14351. strcpy(tempvalidToStr,"");
  14352. }
  14353. //***********duration**************/
  14354. c = 0;
  14355. loc = strstr(sLineWord, "duration");
  14356. //DEBUG_INFO("loc=%s\n",loc);
  14357. memset(sstr ,0, sizeof(sstr) );
  14358. if(loc != NULL)
  14359. {
  14360. while (loc[2+strlen("duration")+c] != '\"')
  14361. {
  14362. sstr[c] = loc[2+strlen("duration")+c];
  14363. c++;
  14364. }
  14365. sstr[c] = '\0';
  14366. tempdurationInt = atoi(sstr);
  14367. }
  14368. else
  14369. {
  14370. tempdurationInt = 0;
  14371. }
  14372. //**********startSchedule**********/
  14373. c = 0;
  14374. loc = strstr(sLineWord, "startSchedule");
  14375. if(loc != NULL)
  14376. {
  14377. memset(sstr ,0, sizeof(sstr) );
  14378. while (loc[3+strlen("startSchedule")+c] != '\"')
  14379. {
  14380. sstr[c] = loc[3+strlen("startSchedule")+c];
  14381. c++;
  14382. }
  14383. sstr[c] = '\0';
  14384. strcpy(tempstartScheduleStr, sstr);
  14385. strcpy(TxProfileScheduleStr, sstr);
  14386. }
  14387. else
  14388. {
  14389. strcpy(tempstartScheduleStr, "");
  14390. strcpy(TxProfileScheduleStr, "");
  14391. }
  14392. //**********chargingRateUnit**********/
  14393. c = 0;
  14394. loc = strstr(sLineWord, "chargingRateUnit");
  14395. memset(sstr ,0, sizeof(sstr) );
  14396. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14397. {
  14398. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14399. c++;
  14400. }
  14401. sstr[c] = '\0';
  14402. strcpy(tempchargingRateUnitStr, sstr);
  14403. //**********minChargingRate*******/
  14404. c = 0;
  14405. loc = strstr(sLineWord, "minChargingRate");
  14406. if(loc != NULL)
  14407. {
  14408. memset(sstr ,0, sizeof(sstr) );
  14409. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14410. {
  14411. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14412. c++;
  14413. }
  14414. sstr[c] = '\0';
  14415. tempminChargingRateFloat = atof(sstr);
  14416. }
  14417. else
  14418. {
  14419. tempminChargingRateFloat = 0.0;
  14420. }
  14421. //
  14422. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14423. tp.tm_isdst = -1;
  14424. time_t utc = mktime(&tp);
  14425. time_t t = time(NULL);
  14426. diff_t = difftime(t, utc);
  14427. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14428. //parsing strings to words
  14429. i = 0;
  14430. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14431. loc = loc+3+strlen("chargingSchedulePeriod");
  14432. pch = strtok(loc ,"{");
  14433. while (pch != NULL)
  14434. {
  14435. strcpy(SchedulePeriodList[i], pch);
  14436. pch = strtok (NULL, "{");
  14437. i = i + 1;
  14438. }
  14439. n_SchedulePeriods = i;
  14440. for(int i=0;i<n_SchedulePeriods;i++)
  14441. {
  14442. //*************startPeriod****************/
  14443. c = 0;
  14444. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14445. memset(sstr ,0, sizeof(sstr) );
  14446. while (loc[strlen("startPeriod")+2+c] != ',')
  14447. {
  14448. sstr[c] = loc[strlen("startPeriod")+2+c];
  14449. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14450. c++;
  14451. }
  14452. sstr[c] = '\0';
  14453. tempStartPeriodInt = atoi(sstr);
  14454. //*************limit****************/
  14455. c = 0;
  14456. loc = strstr(SchedulePeriodList[i], "limit");
  14457. memset(sstr ,0, sizeof(sstr) );
  14458. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14459. {
  14460. sstr[c] = loc[strlen("limit")+2+c];
  14461. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14462. c++;
  14463. }
  14464. sstr[c] = '\0';
  14465. tempLimitInt = atof(sstr);
  14466. //*************numberPhases****************/
  14467. c = 0;
  14468. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14469. memset(sstr ,0, sizeof(sstr) );
  14470. if(loc != NULL)
  14471. {
  14472. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14473. {
  14474. sstr[c] = loc[strlen("numberPhases")+2+c];
  14475. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14476. c++;
  14477. }
  14478. sstr[c] = '\0';
  14479. tempNumberPhasesInt = atoi(sstr);
  14480. }
  14481. else
  14482. {
  14483. tempNumberPhasesInt = 0;
  14484. }
  14485. //TxProfile.Duration = durationInt;
  14486. TxProfile.TotalPeriod = n_SchedulePeriods;
  14487. TxProfile.Period[i].Limit = tempLimitInt;
  14488. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14489. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14490. }
  14491. if(MinChargingRate < tempminChargingRateFloat)
  14492. {
  14493. MinChargingRate = tempminChargingRateFloat;
  14494. }
  14495. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14496. if(confirmPeriods < n_SchedulePeriods)
  14497. confirmPeriods = n_SchedulePeriods;
  14498. if(j == 0)
  14499. {
  14500. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14501. TxProfile_TEMP.StackLevel = tempstackLevel;
  14502. TxProfile_TEMP.TransactionId = 0;
  14503. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14504. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14505. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14506. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14507. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14508. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14509. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14510. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14511. }
  14512. }
  14513. fclose(fptr1);
  14514. }
  14515. }// the end of ACCESS TxProfile
  14516. //-----------------------------------------------CompositeSchedule--------------------------//
  14517. int period=0;
  14518. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14519. {
  14520. //TxProfile
  14521. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14522. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14523. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14524. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14525. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14526. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14527. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14528. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14529. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14530. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14531. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14532. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14533. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14534. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14535. {
  14536. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14537. {
  14538. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14539. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14540. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14541. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14542. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14543. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14544. period = period + 1;
  14545. }
  14546. else
  14547. {
  14548. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14549. {
  14550. }
  14551. else
  14552. {
  14553. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14554. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14555. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14556. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14557. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14558. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14559. period = period + 1;
  14560. }
  14561. }
  14562. }
  14563. struct tm tp;
  14564. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14565. tp.tm_isdst = -1;
  14566. time_t utc = mktime(&tp);
  14567. time_t t = time(NULL);
  14568. double diff_f = difftime(t, utc);
  14569. int diff_i;// = (int)diff_f;
  14570. int quotient; // = diff_i / 86400;//86400 seconds/day
  14571. if(diff_f >= 0)
  14572. {
  14573. diff_i = (int)diff_f;
  14574. quotient = diff_i / 86400;//86400 seconds/day
  14575. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14576. {
  14577. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14578. {
  14579. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14580. {
  14581. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14582. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14583. }
  14584. else
  14585. {
  14586. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14587. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14588. }
  14589. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14590. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14591. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14592. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14593. period = period + 1;
  14594. }
  14595. }
  14596. }// end of if(diff_f >= 0)
  14597. }
  14598. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14599. {
  14600. //TxDefaultProfile
  14601. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14602. struct tm tp;
  14603. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14604. tp.tm_isdst = -1;
  14605. time_t utc = mktime(&tp);
  14606. time_t t = time(NULL);
  14607. double diff_f = difftime(t, utc);
  14608. int diff_i;// = (int)diff_f;
  14609. int quotient; // = diff_i / 86400;//86400 seconds/day
  14610. int remainder;
  14611. //---- Define StartSchedule----/
  14612. struct tm *gtime;
  14613. time_t now;
  14614. char buf[28];
  14615. //---Read the current system time---/
  14616. time(&now);
  14617. //---Convert the system time to GMT (now UTC)---/
  14618. gtime = gmtime(&now);
  14619. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14620. if(diff_f >= 0)
  14621. {
  14622. diff_i = (int)diff_f;
  14623. quotient = diff_i / 86400;//86400 seconds/day
  14624. remainder = diff_i % 86400;
  14625. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14626. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14627. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14628. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14629. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14630. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14631. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14632. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14633. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14634. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14635. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14636. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14637. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14638. {
  14639. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14640. {
  14641. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14642. {
  14643. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14644. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14645. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14646. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14647. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14648. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14649. period = period + 1;
  14650. }
  14651. else
  14652. {
  14653. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14654. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14655. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14656. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14657. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14658. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14659. period = period + 1;
  14660. }
  14661. }
  14662. }
  14663. } // end of diff_f >= 0
  14664. }
  14665. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14666. {
  14667. //TxDefaultProfile
  14668. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14669. struct tm tp;
  14670. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14671. tp.tm_isdst = -1;
  14672. time_t utc = mktime(&tp);
  14673. time_t t = time(NULL);
  14674. double diff_f = difftime(t, utc);
  14675. int diff_i;// = (int)diff_f;
  14676. int quotient; // = diff_i / 86400;//86400 seconds/day
  14677. int remainder;
  14678. //---- Define StartSchedule----/
  14679. struct tm *gtime;
  14680. time_t now;
  14681. char buf[28];
  14682. //---Read the current system time---/
  14683. time(&now);
  14684. //---Convert the system time to GMT (now UTC)---/
  14685. gtime = gmtime(&now);
  14686. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14687. if(diff_f >= 0)
  14688. {
  14689. diff_i = (int)diff_f;
  14690. quotient = diff_i / 86400;//86400 seconds/day
  14691. remainder = diff_i % 86400;
  14692. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14693. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14694. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14695. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14696. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14697. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14698. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14699. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14700. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14701. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14702. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14703. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14704. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14705. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14706. {
  14707. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14708. {
  14709. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14710. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14711. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14712. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14713. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14714. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14715. period = period + 1;
  14716. }
  14717. }
  14718. } //end of diff_f >= 0
  14719. }
  14720. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14721. {
  14722. //ChargePointMaxProfile
  14723. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14724. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14725. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14726. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14727. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14728. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14729. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14730. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14731. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14732. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14733. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14734. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14735. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14736. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14737. {
  14738. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14739. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14740. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14741. period = period + 1;
  14742. }
  14743. }
  14744. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14745. {
  14746. //TxProfile Daily
  14747. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14748. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14749. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14750. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14751. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14752. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14753. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14754. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14755. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14756. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14757. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14758. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14759. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14760. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14761. {
  14762. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14763. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14764. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14765. }
  14766. }
  14767. confirmPeriods = period;
  14768. if(confirmPeriods != 0)
  14769. {
  14770. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14771. 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,"
  14772. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14773. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14774. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14775. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14776. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14777. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14778. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14779. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14780. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14781. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14782. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14783. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14784. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14785. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14786. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14787. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14788. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14789. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14790. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14791. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14792. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14793. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14794. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14795. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14796. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14797. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14798. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14799. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14800. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14801. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14802. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14803. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14804. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14805. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14806. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14807. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14808. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14809. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14810. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14811. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14812. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14813. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14814. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14815. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14816. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14817. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14818. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14819. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14820. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14821. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14822. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14823. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14824. }
  14825. }
  14826. void storeTempStopTransaction(int gun_index)
  14827. {
  14828. //int result = FAIL;
  14829. //char message[1500]={0};
  14830. char guid[37]={0};
  14831. //char tempdata[65]={0};
  14832. //int idx_sample=0;
  14833. DEBUG_ERROR("sendStopTransactionRequest \n");
  14834. memset(queuedata, 0, sizeof(queuedata));
  14835. //ENERGY_ACTIVE_IMPORT_REGISTER
  14836. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14837. {
  14838. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14839. {
  14840. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  14841. {
  14842. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  14843. }
  14844. }// END OF CHAdeMO_QUANTITY
  14845. for (int index = 0; index < CCS_QUANTITY; index++)
  14846. {
  14847. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  14848. {
  14849. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  14850. }
  14851. }// END OF CCS_QUANTITY
  14852. for (int index = 0; index < GB_QUANTITY; index++)
  14853. {
  14854. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  14855. {
  14856. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  14857. }
  14858. }// END OF GB_QUANTITY
  14859. }
  14860. else
  14861. {
  14862. for (int index = 0; index < AC_QUANTITY; index++)
  14863. {
  14864. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  14865. {
  14866. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  14867. }
  14868. }// END OF AC_QUANTITY
  14869. }//END OF ELSE
  14870. //Stop Transaction Time
  14871. struct timeval tmnow;
  14872. struct tm *tm;
  14873. char buf[28];//, usec_buf[6];
  14874. gettimeofday(&tmnow, NULL);
  14875. time_t t;
  14876. t = time(NULL);
  14877. /*UTC time and date*/
  14878. tm = gmtime(&t);
  14879. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14881. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14882. random_uuid(guid);
  14883. /***********************************transactionData******************************************************/
  14884. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  14885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14886. //=================================
  14887. // Transaction_Begin
  14888. //=================================
  14889. // Energy.Active.Export.Interval
  14890. //idx_sample=0;
  14891. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  14892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14894. 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*/]);
  14895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14896. {
  14897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14898. }
  14899. else
  14900. {
  14901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14902. }
  14903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14905. //=================================
  14906. // Transaction_End
  14907. //=================================
  14908. //Current.Export
  14909. //idx_sample=1;
  14910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14911. {
  14912. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14913. {
  14914. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  14915. {
  14916. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14917. }
  14918. }
  14919. for (int index = 0; index < CCS_QUANTITY; index++)
  14920. {
  14921. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  14922. {
  14923. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14924. }
  14925. }
  14926. for (int index = 0; index < GB_QUANTITY; index++)
  14927. {
  14928. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  14929. {
  14930. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14931. }
  14932. }
  14933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14934. }
  14935. else
  14936. {
  14937. for (int index = 0; index < AC_QUANTITY; index++)
  14938. {
  14939. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  14940. {
  14941. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14942. }
  14943. }
  14944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14945. }// END FOR AC ELSE
  14946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  14949. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14952. //Energy.Active.Export.Interval
  14953. //idx_sample=2;
  14954. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14955. {
  14956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14957. {
  14958. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  14959. {
  14960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14961. }
  14962. }
  14963. for (int index = 0; index < CCS_QUANTITY; index++)
  14964. {
  14965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  14966. {
  14967. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14968. }
  14969. }
  14970. for (int index = 0; index < GB_QUANTITY; index++)
  14971. {
  14972. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  14973. {
  14974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14975. }
  14976. }
  14977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14978. }
  14979. else
  14980. {
  14981. for (int index = 0; index < AC_QUANTITY; index++)
  14982. {
  14983. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  14984. {
  14985. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14986. }
  14987. }
  14988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14989. }// END FOR AC ELSE
  14990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  14993. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14996. //Power.Active.Export
  14997. //idx_sample=3;
  14998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14999. {
  15000. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15001. {
  15002. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  15003. {
  15004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15005. }
  15006. }
  15007. for (int index = 0; index < CCS_QUANTITY; index++)
  15008. {
  15009. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  15010. {
  15011. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15012. }
  15013. }
  15014. for (int index = 0; index < GB_QUANTITY; index++)
  15015. {
  15016. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  15017. {
  15018. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15019. }
  15020. }
  15021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15022. }
  15023. else
  15024. {
  15025. for (int index = 0; index < AC_QUANTITY; index++)
  15026. {
  15027. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  15028. {
  15029. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15030. }
  15031. }
  15032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15033. }// END FOR AC ELSE
  15034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  15037. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15040. //Voltage
  15041. //idx_sample=4;
  15042. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15043. {
  15044. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15045. {
  15046. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  15047. {
  15048. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15049. }
  15050. }
  15051. for (int index = 0; index < CCS_QUANTITY; index++)
  15052. {
  15053. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  15054. {
  15055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15056. }
  15057. }
  15058. for (int index = 0; index < GB_QUANTITY; index++)
  15059. {
  15060. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  15061. {
  15062. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15063. }
  15064. }
  15065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15066. }
  15067. else
  15068. {
  15069. for (int index = 0; index < AC_QUANTITY; index++)
  15070. {
  15071. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  15072. {
  15073. 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
  15074. }
  15075. }
  15076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15077. }// END FOR AC ELSE
  15078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15081. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15084. //SoC
  15085. //idx_sample=5;
  15086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15087. {
  15088. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15089. {
  15090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  15091. {
  15092. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15093. }
  15094. }
  15095. for (int index = 0; index < CCS_QUANTITY; index++)
  15096. {
  15097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  15098. {
  15099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15100. }
  15101. }
  15102. for (int index = 0; index < GB_QUANTITY; index++)
  15103. {
  15104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  15105. {
  15106. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15107. }
  15108. }
  15109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  15114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15115. } // END FOR DC CASE
  15116. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15117. {
  15118. 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\"}]}]}]"
  15119. ,MESSAGE_TYPE_CALL
  15120. ,guid
  15121. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15122. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15123. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15124. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15125. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  15126. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15127. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15128. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15129. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15130. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15131. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15132. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15133. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15134. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15135. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15136. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15137. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15138. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15139. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15140. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15141. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15142. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15143. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15144. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15145. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15146. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15147. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15148. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15149. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15150. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15151. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15152. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15153. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15154. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15155. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15156. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15157. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15158. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15159. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15160. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15161. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15162. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  15163. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  15164. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  15165. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  15166. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  15167. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  15168. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  15169. );
  15170. }
  15171. else
  15172. {
  15173. 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\"}]}]}]"
  15174. ,MESSAGE_TYPE_CALL
  15175. ,guid
  15176. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15177. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15178. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15179. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15180. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  15181. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15182. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15183. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15184. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15185. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15186. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15187. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15188. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15189. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15190. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15191. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15192. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15193. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15194. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15195. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15196. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15197. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15198. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15199. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15200. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15201. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15202. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15203. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15204. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15205. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15206. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15207. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15208. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15209. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15210. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15211. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15212. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15213. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15214. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15215. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15216. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15217. );
  15218. }
  15219. // Check File "TempStopTransaction" Exist
  15220. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  15221. {
  15222. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15223. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  15224. }
  15225. else
  15226. {
  15227. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15228. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  15229. if(log == NULL)
  15230. {
  15231. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15232. return ;
  15233. }
  15234. else
  15235. {
  15236. fclose(log);
  15237. }
  15238. }
  15239. //Add TempStopTransaction | Update TempStopTransaction
  15240. // open file for writing
  15241. FILE *outfile;
  15242. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  15243. DEBUG_INFO("data=%s\n",queuedata);
  15244. fputs(queuedata, outfile);
  15245. fputs("\n", outfile);
  15246. fclose (outfile);
  15247. #if 0
  15248. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15249. if(hashmap_operation(0, guid, tempdata) == 1)
  15250. {
  15251. result = PASS;
  15252. DEBUG_INFO("StopTransaction mapitem pass\n");
  15253. }
  15254. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  15255. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  15256. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  15257. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  15258. {
  15259. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  15260. }
  15261. #endif
  15262. }
  15263. void checkTempStopTransaction(int gun_index)
  15264. {
  15265. FILE *fptr1;
  15266. char ch;
  15267. char str[100]={0};
  15268. char guid[37]={0};
  15269. char tempdata[65]={0};
  15270. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15271. if (!fptr1)
  15272. {
  15273. printf(" File not found or unable to open the input file!!\n");
  15274. return ;
  15275. }
  15276. ch=fgetc(fptr1);
  15277. //printf(" Now the content of the file %s is : \n",fname);
  15278. rewind(fptr1);
  15279. if(ch!=EOF)
  15280. {
  15281. // copy all contents to the temporary file except the specific line
  15282. while (fgets(str, 1200, fptr1) != NULL)
  15283. {
  15284. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15285. if(str[0]=='\0')
  15286. {
  15287. break;
  15288. }
  15289. random_uuid(guid);
  15290. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15291. if(hashmap_operation(0, guid, tempdata) == 1)
  15292. {
  15293. DEBUG_INFO("StopTransaction mapitem pass\n");
  15294. }
  15295. queue_operation(4, guid, str );//addq(guid, queuedata); ---> remove temporally
  15296. if(GetTransactionQueueNum() == 1)
  15297. {
  15298. LWS_Send(str);
  15299. }
  15300. }
  15301. }
  15302. fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15303. fclose(fptr1);
  15304. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  15305. }
  15306. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15307. {
  15308. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15309. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15310. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15311. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15312. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15313. }
  15314. int GetWebSocketPingInterval(void)
  15315. {
  15316. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15317. }
  15318. int GetServerSign(void)
  15319. {
  15320. return server_sign;
  15321. }
  15322. void SetServerSign(int value)
  15323. {
  15324. server_sign = value;
  15325. }
  15326. int GetBootNotificationInterval(void)
  15327. {
  15328. return BootNotificationInterval;
  15329. }
  15330. int GetInternetConn(void)
  15331. {
  15332. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15333. }
  15334. void InitialSystemValue(void)
  15335. {
  15336. server_cycle_Status = 120;
  15337. gunTotalNumber=0;
  15338. localversion=0;
  15339. BootNotificationInterval = 0;
  15340. authorizeRetryTimes = 0;
  15341. GunStatusInterval = 10;
  15342. TransactionMessageAttemptsValue = 0;
  15343. TransactionMessageRetryIntervalValue = 0;
  15344. HeartBeatWithNOResponse = 0;
  15345. HeartBeatCountPerHour = 0;
  15346. HeartBeatWaitTime = 10;
  15347. FirstHeartBeat = 0;
  15348. FirmwareStatusNotificationStatus = 3; // Idle
  15349. DiagnosticsStatusNotificationStatus = 0; // Idle
  15350. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  15351. memset(statusModeChage, 0, sizeof(statusModeChage));
  15352. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  15353. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  15354. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  15355. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  15356. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  15357. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  15358. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  15359. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  15360. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  15361. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15362. {
  15363. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  15364. //DEBUG_INFO("DC ...\n");
  15365. }
  15366. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15367. {
  15368. SystemInitial = AC_QUANTITY;
  15369. //DEBUG_INFO("AC ...\n");
  15370. }
  15371. //Status / ConnectorPlugIn Setting
  15372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15373. {
  15374. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15375. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15376. }
  15377. for (int index = 0; index < CCS_QUANTITY; index++)
  15378. {
  15379. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15380. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15381. }
  15382. for (int index = 0; index < GB_QUANTITY; index++)
  15383. {
  15384. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15385. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15386. }
  15387. for (int index = 0; index < AC_QUANTITY; index++)
  15388. {
  15389. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15390. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15391. }
  15392. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15393. {
  15394. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15395. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15396. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15397. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15398. }
  15399. // Charger PRE_SYS_MODE
  15400. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  15401. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15402. clientTime.Heartbeat=time((time_t*)NULL);
  15403. }
  15404. void LWS_Send(char * str)
  15405. {
  15406. //=====================================================
  15407. // Check InternetConn 0: disconnected, 1: connected
  15408. //====================================================
  15409. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  15410. {
  15411. DEBUG_INFO("\n offline now !!!\n");
  15412. return;
  15413. }
  15414. pthread_mutex_lock(&lock);
  15415. memset(SendBuffer,0,SendBufLen);
  15416. sprintf((char *)SendBuffer, "%s", str);
  15417. pthread_mutex_unlock(&lock);
  15418. lws_callback_on_writable(wsi_client);
  15419. lws_service(context, 10000);//timeout_ms
  15420. }