MessageHandler.c 521 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "SystemLogMessage.h"
  24. #include "define.h"
  25. #include "ShareMemory.h"
  26. #include "SystemLogMessage.h"
  27. //#include "config.h"
  28. #include <sys/socket.h>
  29. #include <netinet/in.h>
  30. #include <stdlib.h>
  31. /*for sendfile()*/
  32. #include <sys/sendfile.h>
  33. /*for O_RDONLY*/
  34. #include <fcntl.h>
  35. #include "sqlite3.h"
  36. #include <arpa/inet.h>
  37. //#define _GNU_SOURCE
  38. #include <time.h>
  39. #include "MessageHandler.h"
  40. #include <assert.h>
  41. #include <pthread.h>
  42. #include <mcheck.h>
  43. #define PASS 1
  44. #define FAIL -1
  45. #define FALSE 0
  46. #define TRUE 1 // Option 1
  47. //ChargePointMaxProfile
  48. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  49. //TxDefaultProfile
  50. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  51. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  52. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  53. //TxProfile
  54. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  55. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  56. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  57. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  58. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  59. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  60. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  61. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  62. struct StatusCodeData *ShmStatusCodeData;
  63. struct PsuData *ShmPsuData ;
  64. struct OCPP16Data *ShmOCPP16Data;
  65. // define Macro
  66. #define SystemLogMessage
  67. // OCPP Message Type
  68. #define MESSAGE_TYPE_CALL 2
  69. #define MESSAGE_TYPE_CALLRESULT 3
  70. #define MESSAGE_TYPE_CALLERROR 4
  71. //
  72. #define server_cycle_Status 120
  73. #define MACROSTR(k) #k
  74. //ConfigurationMaxKeys
  75. #define GetConfigurationMaxKeysNUM 43
  76. //char guid[37];
  77. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  78. char queuedata[2600]={0};
  79. //===============================
  80. // Configuration: unknownkey
  81. //===============================
  82. static char unknownkey[10][20]={0};
  83. static int UnknownKeynum = 0;
  84. //===============================
  85. // Gun Total Numbers
  86. //===============================
  87. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  88. static int gunTotalNumber=0;
  89. //===============================
  90. // Local List Version
  91. //===============================
  92. static int localversion=0;
  93. static char idTagAuthorization[32]={0};
  94. //===============================
  95. // OCPP Path
  96. //===============================
  97. extern char OcppPath[160];
  98. extern char OcppProtocol[10];
  99. extern char OcppHost[50];
  100. extern char OcppTempPath[50];
  101. int OcppPort=0;
  102. //===============================
  103. // OCPP sign variable
  104. //===============================
  105. int server_sign = FALSE;
  106. int server_pending = FALSE;
  107. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  108. int BootNotificationInterval = 0;
  109. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  110. //===============================
  111. // OCPP auth variable
  112. //===============================
  113. int authenrequest = FALSE;
  114. int authorizeRetryTimes = 0; //number of Retry times
  115. //===============================
  116. // OCPP StartTransaction transactionId variables
  117. //===============================
  118. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  119. //===============================
  120. // OCPP other variables
  121. //===============================
  122. int isUpdateRequest = FALSE;
  123. static int HeartBeatWaitTime = 10;
  124. static int FirstHeartBeat = 0;
  125. static int FirmwareStatusNotificationStatus = 3; // Idle
  126. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  127. static char CurrentChargingProfileScheduleStr[30]={0};
  128. //========================================
  129. // OCPP status/previous related variables
  130. //========================================
  131. static int GunStatusInterval = 10;
  132. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  133. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  134. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  135. static int GbPreviousSystemStatus[GB_QUANTITY];
  136. static int AcPreviousSystemStatus[AC_QUANTITY];
  137. int TransactionMessageAttemptsValue = 0;
  138. int TransactionMessageRetryIntervalValue = 0;
  139. static struct OCPPAuthLocalElemet
  140. {
  141. int listVersionInt;
  142. char idTagstr[20];
  143. char parentIdTag[20];
  144. char expiryDate[30];
  145. char idTagstatus[16];
  146. }idTagQuery;
  147. //=============================================
  148. // OCPP HeartBeat Response Not Receive Counts
  149. //============================================
  150. static int HeartBeatWithNOResponse = 0;
  151. static int HeartBeatCount = 0;
  152. extern struct lws *wsi_client;
  153. extern struct lws_context *context;
  154. #if 0
  155. extern unsigned char *SendBuffer;
  156. #endif
  157. extern unsigned char SendBuffer[4096];
  158. extern int SendBufLen;
  159. //extern map_t hashMap;
  160. //extern data_struct_t* mapItem; --- remove for temporally
  161. //extern data_struct_t mapItem[0];
  162. extern char *random_uuid( char buf[37] );
  163. extern void split(char **arr, char *str, const char *del);
  164. extern pthread_mutex_t mutex1;
  165. extern struct Charger_Info Charger;
  166. extern sqlite3 *db;
  167. int TransactionMessageAttemptsGet(void);
  168. int TransactionMessageRetryIntervalGet(void);
  169. int GetOcppConnStatus(void);
  170. void SetOcppConnStatus(uint8_t status);
  171. int updateSetting(char *key, char *value);
  172. int setKeyValue(char *key, char *value);
  173. void OCPP_get_TableAuthlocalAllData(void);
  174. void processUnkownKey(void);
  175. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  176. struct StructOCPPMeterValue
  177. {
  178. unsigned char TimeStamp[28];
  179. struct StructSampledValue SampledValue[10];
  180. };
  181. struct ClientTime
  182. {
  183. unsigned int Heartbeat;
  184. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  185. unsigned int StartTransaction;
  186. unsigned int StopTransaction;
  187. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  188. }clientTime;
  189. typedef union
  190. {
  191. //Operations Initiated by Central System
  192. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  193. struct
  194. {
  195. //CsMsgValue[0]
  196. unsigned char StatusNotificationReq :1; //bit 0,
  197. unsigned char StatusNotificationConf :1; //bit 0,
  198. unsigned char :6; //bit 2~7
  199. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  200. }CpinitiateMsg;
  201. CpinitiateMsg cpinitateMsg;
  202. //==========================================
  203. // Init all Enumeration & Mapping String
  204. //==========================================
  205. /*ChargePointErrorCode*/
  206. typedef enum {
  207. ConnectorLockFailure,
  208. EVCommunicationError,
  209. GroundFailure,
  210. HighTemperature,
  211. InternalError,
  212. LocalListConflict,
  213. NoError,
  214. OtherError,
  215. OverCurrentFailure,
  216. OverVoltage,
  217. PowerMeterFailure,
  218. PowerSwitchFailure,
  219. ReaderFailure,
  220. ResetFailure,
  221. UnderVoltage,
  222. WeakSignal
  223. } ChargePointErrorCode;
  224. #if 0
  225. static char *ChargePointErrorCodeStr[] = {
  226. MACROSTR(ConnectorLockFailure),
  227. MACROSTR(EVCommunicationError),
  228. MACROSTR(GroundFailure),
  229. MACROSTR(HighTemperature),
  230. MACROSTR(InternalError),
  231. MACROSTR(LocalListConflict),
  232. MACROSTR(NoError),
  233. MACROSTR(OtherError),
  234. MACROSTR(OverCurrentFailure),
  235. MACROSTR(OverVoltage),
  236. MACROSTR(PowerMeterFailure),
  237. MACROSTR(PowerSwitchFailure),
  238. MACROSTR(ReaderFailure),
  239. MACROSTR(ResetFailure),
  240. MACROSTR(UnderVoltage),
  241. MACROSTR(WeakSignal)
  242. };
  243. #endif
  244. /*ChargePointStatus*/
  245. typedef enum {
  246. Available =0,
  247. Preparing,
  248. Charging,
  249. SuspendedEVSE,
  250. SuspendedEV,
  251. Finishing,
  252. Reserved,
  253. Unavailable,
  254. Faulted
  255. } ChargePointStatus;
  256. static char * ChargePointStatusStr[] = {
  257. MACROSTR(Available),
  258. MACROSTR(Preparing),
  259. MACROSTR(Charging),
  260. MACROSTR(SuspendedEVSE),
  261. MACROSTR(SuspendedEV),
  262. MACROSTR(Finishing),
  263. MACROSTR(Reserved),
  264. MACROSTR(Unavailable),
  265. MACROSTR(Faulted)
  266. };
  267. /*AvailabilityType*/
  268. typedef enum {
  269. RegistrationStatus_Accepted,
  270. RegistrationStatus_Pending,
  271. RegistrationStatus_Rejected
  272. } RegistrationStatus;
  273. static char *RegistrationStatusStr[] = {
  274. MACROSTR(Accepted),
  275. MACROSTR(Pending),
  276. MACROSTR(Rejected)
  277. };
  278. /*AvailabilityType*/
  279. typedef enum {
  280. Inoperative,
  281. Operative
  282. } AvailabilityType;
  283. static char *AvailabilityTypeStr[] = {
  284. MACROSTR(Inoperative),
  285. MACROSTR(Operative)
  286. };
  287. /*AvailabilityStatus*/
  288. typedef enum {
  289. Accepted,
  290. Rejected,
  291. Scheduled
  292. } AvailabilityStatus;
  293. static char *AvailabilityStatusStr[] = {
  294. MACROSTR(Accepted),
  295. MACROSTR(Rejected),
  296. MACROSTR(Scheduled)
  297. };
  298. /*ConfigurationStatus*/
  299. typedef enum {
  300. ConfigurationStatus_Accepted,
  301. ConfigurationStatus_Rejected,
  302. RebootRequired,
  303. NotSupported
  304. } ConfigurationStatus;
  305. static char *ConfigurationStatusStr[] = {
  306. MACROSTR(Accepted),
  307. MACROSTR(Rejected),
  308. MACROSTR(RebootRequired),
  309. MACROSTR(NotSupported)
  310. };
  311. /*ClearCacheStatus*/
  312. typedef enum {
  313. ClearCacheStatus_Accepted,
  314. ClearCacheStatus_Rejected
  315. } ClearCacheStatus;
  316. static char *ClearCacheStatusStr[] = {
  317. MACROSTR(Accepted),
  318. MACROSTR(Rejected)
  319. };
  320. /*ChargingProfilePurposeType*/
  321. typedef enum {
  322. ChargePointMaxProfile,
  323. TxDefaultProfile,
  324. TxProfile
  325. } ChargingProfilePurposeType;
  326. static char *ChargingProfilePurposeTypeStr[] = {
  327. MACROSTR(ChargePointMaxProfile),
  328. MACROSTR(TxDefaultProfile),
  329. MACROSTR(TxProfile)
  330. };
  331. /*ChargingProfileStatus*/
  332. typedef enum {
  333. ChargingProfileStatus_Accepted,
  334. ChargingProfileStatus_Rejected,
  335. ChargingProfileStatus_NotSupported
  336. } ChargingProfileStatus;
  337. static char *ChargingProfileStatusStr[] = {
  338. MACROSTR(Accepted),
  339. MACROSTR(Rejected),
  340. MACROSTR(NotSupported)
  341. };
  342. /*ClearChargingProfileStatus*/
  343. typedef enum {
  344. ClearChargingProfileStatus_Accepted,
  345. ClearChargingProfileStatus_Unknown
  346. } ClearChargingProfileStatus;
  347. static char *ClearChargingProfileStatusStr[] = {
  348. MACROSTR(Accepted),
  349. MACROSTR(Unknown)
  350. };
  351. /*GetCompositeScheduleStatus*/
  352. typedef enum {
  353. GetCompositeScheduleStatus_Accepted,
  354. GetCompositeScheduleStatus_Rejected
  355. } GetCompositeScheduleStatus;
  356. static char *GetCompositeScheduleStatusStr[] = {
  357. MACROSTR(Accepted),
  358. MACROSTR(Rejected)
  359. };
  360. /*ChargingRateUnitType*/
  361. typedef enum {
  362. ChargingRateUnitType_W,
  363. ChargingRateUnitType_A
  364. } ChargingRateUnitType;
  365. /*AuthorizationStatus*/
  366. typedef enum {
  367. AuthorizationStatus_Accepted ,
  368. AuthorizationStatus_Blocked ,
  369. AuthorizationStatus_Expired ,
  370. AuthorizationStatus_Invalid ,
  371. AuthorizationStatus_ConcurrentTx
  372. } AuthorizationStatus;
  373. /*UpdateType*/
  374. typedef enum {
  375. Differential ,
  376. Full
  377. } UpdateType;
  378. static char *UpdateTypeStr[] = {
  379. MACROSTR(Differential),
  380. MACROSTR(Full)
  381. };
  382. /*UpdateStatus*/
  383. typedef enum {
  384. UpdateStatus_Accepted ,
  385. UpdateStatus_Failed ,
  386. UpdateStatus_NotSupported ,
  387. UpdateStatus_VersionMismatch
  388. } UpdateStatus;
  389. static char *UpdateStatusStr[] = {
  390. MACROSTR(Accepted),
  391. MACROSTR(Failed),
  392. MACROSTR(NotSupported),
  393. MACROSTR(VersionMismatch)
  394. };
  395. /*RemoteStartStopStatus*/
  396. typedef enum {
  397. RemoteStartStopStatus_Accepted,
  398. RemoteStartStopStatus_Rejected
  399. } RemoteStartStopStatus;
  400. static char *RemoteStartStopStatusStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Rejected)
  403. };
  404. /*ReservationStatus*/
  405. typedef enum {
  406. ReservationStatus_Accepted,
  407. ReservationStatus_Faulted,
  408. ReservationStatus_Occupied,
  409. ReservationStatus_Rejected,
  410. ReservationStatus_Unavailable
  411. } ReservationStatus;
  412. static char *ReservationStatusStr[] = {
  413. MACROSTR(Accepted),
  414. MACROSTR(Faulted),
  415. MACROSTR(Occupied),
  416. MACROSTR(Rejected),
  417. MACROSTR(Unavailable)
  418. };
  419. /*ResetType*/
  420. typedef enum {
  421. Hard,
  422. Soft
  423. } ResetType;
  424. static char *ResetTypeStr[] = {
  425. MACROSTR(Hard),
  426. MACROSTR(Soft)
  427. };
  428. /*ResetStatus*/
  429. typedef enum {
  430. ResetStatus_Accepted,
  431. ResetStatus_Rejected
  432. } ResetStatus;
  433. static char *ResetStatusStr[] = {
  434. MACROSTR(Accepted),
  435. MACROSTR(Rejected)
  436. };
  437. /*DiagnosticsStatus*/
  438. typedef enum {
  439. DiagnosticsStatus_Idle,
  440. DiagnosticsStatus_Uploaded,
  441. DiagnosticsStatus_UploadFailed,
  442. DiagnosticsStatus_Uploading
  443. } DiagnosticsStatus;
  444. static char * DiagnosticsStatusStr[] = {
  445. MACROSTR(Idle),
  446. MACROSTR(Uploaded),
  447. MACROSTR(UploadFailed),
  448. MACROSTR(Uploading)
  449. };
  450. /*FirmwareStatus*/
  451. typedef enum {
  452. FirmwareStatus_Downloaded,
  453. FirmwareStatus_DownloadFailed,
  454. FirmwareStatus_Downloading,
  455. FirmwareStatus_Idle,
  456. FirmwareStatus_InstallationFailed,
  457. FirmwareStatus_Installing,
  458. FirmwareStatus_Installed
  459. } FirmwareStatus;
  460. static char * FirmwareStatusStr[] = {
  461. MACROSTR(Downloaded),
  462. MACROSTR(DownloadFailed),
  463. MACROSTR(Downloading),
  464. MACROSTR(Idle),
  465. MACROSTR(InstallationFailed),
  466. MACROSTR(Installing),
  467. MACROSTR(Installed)
  468. };
  469. /*MessageTrigger*/
  470. typedef enum {
  471. BootNotification,
  472. DiagnosticsStatusNotification,
  473. FirmwareStatusNotification,
  474. Heartbeat,
  475. MeterValues,
  476. StatusNotification
  477. } MessageTrigger;
  478. static char * MessageTriggerStr[] = {
  479. MACROSTR(BootNotification),
  480. MACROSTR(DiagnosticsStatusNotification),
  481. MACROSTR(FirmwareStatusNotification),
  482. MACROSTR(Heartbeat),
  483. MACROSTR(MeterValues),
  484. MACROSTR(StatusNotification)
  485. };
  486. /*TriggerMessageStatus*/
  487. typedef enum {
  488. TriggerMessageStatus_Accepted ,
  489. TriggerMessageStatus_Rejected ,
  490. TriggerMessageStatus_NotImplemented
  491. } TriggerMessageStatus;
  492. static char * TriggerMessageStatusStr[] = {
  493. MACROSTR(Accepted),
  494. MACROSTR(Rejected),
  495. MACROSTR(NotImplemented)
  496. };
  497. /*UnlockStatus*/
  498. typedef enum {
  499. Unlocked,
  500. UnlockFailed,
  501. UnlockStatus_NotSupported
  502. } UnlockStatus;
  503. static char * UnlockStatusStr[] = {
  504. MACROSTR(Unlocked),
  505. MACROSTR(UnlockFailed),
  506. MACROSTR(NotSupported)
  507. };
  508. /*StopTransactionReason*/
  509. typedef enum {
  510. EmergencyStop,
  511. EVDisconnected,
  512. HardReset,
  513. Local,
  514. Other,
  515. PowerLoss,
  516. Reboot,
  517. Remote,
  518. SoftReset,
  519. UnlockCommand,
  520. DeAuthorized
  521. } StopTransactionReason;
  522. static char * StopTransactionReasonStr[] = {
  523. MACROSTR(EmergencyStop),
  524. MACROSTR(EVDisconnected),
  525. MACROSTR(HardReset),
  526. MACROSTR(Local),
  527. MACROSTR(Other),
  528. MACROSTR(PowerLoss),
  529. MACROSTR(Reboot),
  530. MACROSTR(Remote),
  531. MACROSTR(SoftReset),
  532. MACROSTR(UnlockCommand),
  533. MACROSTR(DeAuthorized)
  534. };
  535. /*CancelReservationStatus*/
  536. typedef enum {
  537. CancelReservationStatus_Accepted,
  538. CancelReservationStatus_Rejected
  539. } CancelReservationStatus;
  540. static char * CancelReservationStatusStr[] = {
  541. MACROSTR(Accepted),
  542. MACROSTR(Rejected)
  543. };
  544. /*ReadingContext*/
  545. typedef enum {
  546. ReadingContext_Interruption_Begin,
  547. ReadingContext_Interruption_End,
  548. ReadingContext_Other,
  549. ReadingContext_Sample_Clock,
  550. ReadingContext_Sample_Periodic ,
  551. ReadingContext_Transaction_Begin ,
  552. ReadingContext_Transaction_End,
  553. ReadingContext_Trigger
  554. } ReadingContext;
  555. static char * ReadingContextStr[] = {
  556. MACROSTR(Interruption.Begin),
  557. MACROSTR(Interruption.End),
  558. MACROSTR(Other),
  559. MACROSTR(Sample.Clock),
  560. MACROSTR(Sample.Periodic),
  561. MACROSTR(Transaction.Begin),
  562. MACROSTR(Transaction.End),
  563. MACROSTR(Trigger)
  564. };
  565. /*ValueFormat*/
  566. typedef enum {
  567. Raw,
  568. SignedData
  569. } ValueFormat;
  570. static char * ValueFormatStr[] = {
  571. MACROSTR(Raw),
  572. MACROSTR(SignedData)
  573. };
  574. /*Measurand*/
  575. typedef enum {
  576. Current_Export ,
  577. Current_Import,
  578. Current_Offered,
  579. Energy_Active_Export_Register,
  580. Energy_Active_Import_Register,
  581. Energy_Reactive_Export_Register,
  582. Energy_Reactive_Import_Register,
  583. Energy_Active_Export_Interval,
  584. Energy_Active_Import_Interval,
  585. Energy_Reactive_Export_Interval,
  586. Energy_Reactive_Import_Interval,
  587. Frequency,
  588. Power_Active_Export ,
  589. Power_Active_Import,
  590. Power_Factor,
  591. Power_Offered,
  592. Power_Reactive_Export,
  593. Power_Reactive_Import,
  594. RPM,
  595. SoC,
  596. Temperature ,
  597. Voltage
  598. } Measurand;
  599. static char * MeasurandStr[] = {
  600. MACROSTR(Current.Export),
  601. MACROSTR(Current.Import),
  602. MACROSTR(Current.Offered),
  603. MACROSTR(Energy.Active.Export.Register),
  604. MACROSTR(Energy.Active.Import.Register),
  605. MACROSTR(Energy.Reactive.Export.Register),
  606. MACROSTR(Energy.Reactive.Import.Register),
  607. MACROSTR(Energy.Active.Export.Interval),
  608. MACROSTR(Energy.Active.Import.Interval),
  609. MACROSTR(Energy.Reactive.Export.Interval),
  610. MACROSTR(Energy.Reactive.Import.Interval),
  611. MACROSTR(Frequency),
  612. MACROSTR(Power.Active.Export),
  613. MACROSTR(Power.Active.Import),
  614. MACROSTR(Power.Factor),
  615. MACROSTR(Power.Offered),
  616. MACROSTR(Power.Reactive.ExportMACROSTR),
  617. MACROSTR(Power.Reactive.Import),
  618. MACROSTR(RPM),
  619. MACROSTR(SoC),
  620. MACROSTR(Temperature),
  621. MACROSTR(Voltage)
  622. };
  623. /*Location*/
  624. typedef enum {
  625. Location_Body,
  626. Location_Cable,
  627. Location_EV,
  628. Location_Inlet ,
  629. Location_Outlet
  630. } Location;
  631. static char * LocationStr[] = {
  632. MACROSTR(Body),
  633. MACROSTR(Cable),
  634. MACROSTR(EV),
  635. MACROSTR(Inlet),
  636. MACROSTR(Outlet)
  637. };
  638. /*Phase*/
  639. typedef enum {
  640. L1,
  641. L2,
  642. L3,
  643. N,
  644. L1_N,
  645. L2_N,
  646. L3_N,
  647. L1_L2,
  648. L2_L3,
  649. L3_L1
  650. } Phase;
  651. static char * PhaseStr[] = {
  652. MACROSTR(L1),
  653. MACROSTR(L2),
  654. MACROSTR(L3),
  655. MACROSTR(N),
  656. MACROSTR(L1-N),
  657. MACROSTR(L2-N),
  658. MACROSTR(L3-N),
  659. MACROSTR(L1-L2),
  660. MACROSTR(L2-L3),
  661. MACROSTR(L3-L1)
  662. };
  663. /*UnitOfMeasure*/
  664. typedef enum {
  665. UnitOfMeasure_Wh,
  666. UnitOfMeasure_kWh ,
  667. UnitOfMeasure_varh ,
  668. UnitOfMeasure_kvarh ,
  669. UnitOfMeasure_W ,
  670. UnitOfMeasure_kW ,
  671. UnitOfMeasure_VA ,
  672. UnitOfMeasure_kVA ,
  673. UnitOfMeasure_var ,
  674. UnitOfMeasure_kvar ,
  675. UnitOfMeasure_A ,
  676. UnitOfMeasure_V ,
  677. UnitOfMeasure_Celsius ,
  678. UnitOfMeasure_Fahrenheit ,
  679. UnitOfMeasure_K ,
  680. UnitOfMeasure_Percent
  681. } UnitOfMeasure;
  682. static char * UnitOfMeasureStr[] = {
  683. MACROSTR(Wh),
  684. MACROSTR(kWh),
  685. MACROSTR(varh),
  686. MACROSTR(kvarh),
  687. MACROSTR(W),
  688. MACROSTR(kW),
  689. MACROSTR(VA),
  690. MACROSTR(kVA),
  691. MACROSTR(var),
  692. MACROSTR(kvar),
  693. MACROSTR(A),
  694. MACROSTR(V),
  695. MACROSTR(Celsius),
  696. MACROSTR(Fahrenheit),
  697. MACROSTR(K),
  698. MACROSTR(Percent)
  699. };
  700. #if 0
  701. /*Configuration enum*/
  702. enum CoreProfile {
  703. AllowOfflineTxForUnknownId=0,
  704. AuthorizationCacheEnabled,
  705. AuthorizeRemoteTxRequests,
  706. BlinkRepeat,
  707. ClockAlignedDataInterval,
  708. ConnectionTimeOut,
  709. GetConfigurationMaxKeys,
  710. HeartbeatInterval,
  711. LightIntensity,
  712. LocalAuthorizeOffline,
  713. LocalPreAuthorize,
  714. MaxEnergyOnInvalidId,
  715. MeterValuesAlignedData,
  716. MeterValuesAlignedDataMaxLength,
  717. MeterValuesSampledData,
  718. MeterValuesSampledDataMaxLength,
  719. MeterValueSampleInterval,
  720. MinimumStatusDuration,
  721. NumberOfConnectors,
  722. ResetRetries,
  723. ConnectorPhaseRotation,
  724. ConnectorPhaseRotationMaxLength,
  725. StopTransactionOnEVSideDisconnect,
  726. StopTransactionOnInvalidId,
  727. StopTxnAlignedData,
  728. StopTxnAlignedDataMaxLength,
  729. StopTxnSampledData,
  730. StopTxnSampledDataMaxLength,
  731. SupportedFeatureProfiles,
  732. SupportedFeatureProfilesMaxLength,
  733. TransactionMessageAttempts,
  734. TransactionMessageRetryInterval,
  735. UnlockConnectorOnEVSideDisconnect,
  736. WebSocketPingInterval,
  737. _CoreProfile_CNT
  738. };
  739. #endif
  740. enum LocalAuthListManagementProfile{
  741. LocalAuthListEnabled=0,
  742. LocalAuthListMaxLength,
  743. SendLocalListMaxLength,
  744. _LocalAuthListManagementProfile_CNT
  745. };
  746. enum ReservationProfile{
  747. ReserveConnectorZeroSupported
  748. };
  749. enum SmartChargingProfile{
  750. ChargeProfileMaxStackLevel,
  751. ChargingScheduleAllowedChargingRateUnit,
  752. ChargingScheduleMaxPeriods,
  753. ConnectorSwitch3to1PhaseSupported,
  754. MaxChargingProfilesInstalled
  755. };
  756. enum ChargerSystemStatus{
  757. ChargerSystemStatus_Booting,
  758. ChargerSystemStatus_Idle,
  759. ChargerSystemStatus_Authorizing,
  760. ChargerSystemStatus_Preparing,
  761. ChargerSystemStatus_Charging,
  762. ChargerSystemStatus_Terminating,
  763. ChargerSystemStatus_Alarm,
  764. ChargerSystemStatus_Fault
  765. };
  766. enum GetConfigurationKey {
  767. GetConfiguration_AllowOfflineTxForUnknownId=0,
  768. GetConfiguration_AuthorizationCacheEnabled,
  769. GetConfiguration_AuthorizeRemoteTxRequests,
  770. GetConfiguration_BlinkRepeat,
  771. GetConfiguration_ClockAlignedDataInterval,
  772. GetConfiguration_ConnectionTimeOut,
  773. GetConfiguration_GetConfigurationMaxKeys,
  774. GetConfiguration_HeartbeatInterval,
  775. GetConfiguration_LightIntensity,
  776. GetConfiguration_LocalAuthorizeOffline,
  777. GetConfiguration_LocalPreAuthorize,
  778. GetConfiguration_MaxEnergyOnInvalidId,
  779. GetConfiguration_MeterValuesAlignedData,
  780. GetConfiguration_MeterValuesAlignedDataMaxLength,
  781. GetConfiguration_MeterValuesSampledData,
  782. GetConfiguration_MeterValuesSampledDataMaxLength,
  783. GetConfiguration_MeterValueSampleInterval,
  784. GetConfiguration_MinimumStatusDuration,
  785. GetConfiguration_NumberOfConnectors,
  786. GetConfiguration_ResetRetries,
  787. GetConfiguration_ConnectorPhaseRotation,
  788. GetConfiguration_ConnectorPhaseRotationMaxLength,
  789. GetConfiguration_StopTransactionOnEVSideDisconnect,
  790. GetConfiguration_StopTransactionOnInvalidId,
  791. GetConfiguration_StopTxnAlignedData,
  792. GetConfiguration_StopTxnAlignedDataMaxLength,
  793. GetConfiguration_StopTxnSampledData,
  794. GetConfiguration_StopTxnSampledDataMaxLength,
  795. GetConfiguration_SupportedFeatureProfiles,
  796. GetConfiguration_SupportedFeatureProfilesMaxLength,
  797. GetConfiguration_TransactionMessageAttempts,
  798. GetConfiguration_TransactionMessageRetryInterval,
  799. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  800. GetConfiguration_WebSocketPingInterval,
  801. GetConfiguration_LocalAuthListEnabled,
  802. GetConfiguration_LocalAuthListMaxLength,
  803. GetConfiguration_SendLocalListMaxLength,
  804. GetConfiguration_ReserveConnectorZeroSupported,
  805. GetConfiguration_ChargeProfileMaxStackLevel,
  806. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  807. GetConfiguration_ChargingScheduleMaxPeriods,
  808. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  809. GetConfiguration_MaxChargingProfilesInstalled,
  810. };
  811. //GetConfiguration Array
  812. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  813. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  814. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  815. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  816. //==========================================
  817. // Init all share memory
  818. //==========================================
  819. int InitShareMemory()
  820. {
  821. int result = PASS;
  822. int MeterSMId;
  823. //printf("1\n");
  824. //creat ShmSysConfigAndInfo
  825. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  826. {
  827. #ifdef SystemLogMessage
  828. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  829. #endif
  830. result = FAIL;
  831. }
  832. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  833. {
  834. #ifdef SystemLogMessage
  835. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  836. #endif
  837. result = FAIL;
  838. }
  839. else
  840. {}
  841. //printf("2\n");
  842. //creat ShmStatusCodeData
  843. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  844. {
  845. #ifdef SystemLogMessage
  846. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  847. #endif
  848. result = FAIL;
  849. }
  850. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else
  858. {}
  859. //printf("3\n");
  860. //creat ShmPsuData
  861. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  862. {
  863. #ifdef SystemLogMessage
  864. DEBUG_ERROR("shmget ShmPsuData NG\n");
  865. #endif
  866. result = FAIL;
  867. }
  868. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmat ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else
  876. {}
  877. //creat ShmOCPP16Data
  878. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  879. {
  880. #ifdef SystemLogMessage
  881. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  882. #endif
  883. result = FAIL;
  884. }
  885. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else
  893. {}
  894. /****************************** For Initial Settings************************************************/
  895. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  896. //memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  897. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  898. {
  899. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  900. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  901. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  902. }
  903. // Charger PRE_SYS_MODE
  904. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  905. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  906. clientTime.Heartbeat=time((time_t*)NULL);
  907. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  908. {
  909. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  910. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  911. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  912. }
  913. //HeartBeatWaitTime = 10;
  914. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  915. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  916. // allocate Configuration memory address
  917. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  918. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  919. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  920. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  922. {
  923. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  924. DEBUG_INFO("DC ...\n");
  925. }
  926. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  927. {
  928. SystemInitial = AC_QUANTITY;
  929. DEBUG_INFO("AC ...\n");
  930. }
  931. //Status Setting
  932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  933. {
  934. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  935. }
  936. for (int index = 0; index < CCS_QUANTITY; index++)
  937. {
  938. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  939. }
  940. for (int index = 0; index < GB_QUANTITY; index++)
  941. {
  942. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  943. }
  944. for (int index = 0; index < AC_QUANTITY; index++)
  945. {
  946. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  947. }
  948. //memset(unknownkey, 0, 10);
  949. return result;
  950. }
  951. int ProcessShareMemory()
  952. {
  953. if(InitShareMemory() == FAIL)
  954. {
  955. #ifdef SystemLogMessage
  956. DEBUG_ERROR("InitShareMemory NG\n");
  957. #endif
  958. if(ShmStatusCodeData!=NULL)
  959. {
  960. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  961. }
  962. sleep(5);
  963. return FAIL;
  964. }
  965. return PASS;
  966. }
  967. //---------------------------------------------
  968. // new:
  969. // enum SYSTEM_STATUS
  970. // {
  971. // SYS_MODE_BOOTING = 0,
  972. // SYS_MODE_IDLE = 1,
  973. // SYS_MODE_AUTHORIZING = 2,
  974. // SYS_MODE_PREPARING = 3,
  975. // SYS_MODE_CHARGING = 4,
  976. // SYS_MODE_TERMINATING = 5,
  977. // SYS_MODE_ALARM = 6,
  978. // SYS_MODE_FAULT = 7,
  979. // SYS_MODE_RESERVATION = 8,
  980. // SYS_MODE_BOOKING = 9,
  981. // SYS_MODE_MAINTAIN = 10,
  982. // SYS_MODE_DEBUG = 11,
  983. // SYS_MODE_REASSIGN_CHECK = 12,
  984. // SYS_MODE_REASSIGN = 13,
  985. // SYS_MODE_PRECHARGE = 14,
  986. // SYS_MODE_PREPARING_EV = 15,
  987. // SYS_MODE_PREPARING_EVSE = 16,
  988. // SYS_MODE_COMPLETE = 17
  989. // };
  990. //
  991. // old:
  992. // enum _SYSTEM_STATUS
  993. // {
  994. // S_BOOTING = 0,
  995. // S_IDLE, =1
  996. // S_AUTHORIZING, =2
  997. // S_REASSIGN_CHECK, =3
  998. // S_REASSIGN, =4
  999. // S_PRECHARGE, =5
  1000. // S_PREPARING_FOR_EV, =6
  1001. // S_PREPARING_FOR_EVSE, =7
  1002. // S_CHARGING, =8
  1003. // S_TERMINATING, =9
  1004. // S_COMPLETE, =10
  1005. // S_ALARM, =11
  1006. // S_FAULT =12
  1007. // };
  1008. //
  1009. //-----------------------------------------
  1010. void CheckSystemValue(void)
  1011. {
  1012. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1013. int IdleModeCnt = 0;
  1014. char filenmae[100]={0};
  1015. char str[100]={0};
  1016. //===============================
  1017. // send Heartbeat
  1018. //===============================
  1019. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1020. {
  1021. //parameter for test
  1022. sendHeartbeatRequest(0);
  1023. //==============================================
  1024. // Reset Waiting Time
  1025. //==============================================
  1026. clientTime.Heartbeat=time((time_t*)NULL);
  1027. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1028. }
  1029. //==============================================
  1030. // Update firmware request
  1031. //==============================================
  1032. if(isUpdateRequest == TRUE )
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1037. {
  1038. //check SystemStatus
  1039. /*************************DC*******************************/
  1040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1041. {
  1042. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1043. {
  1044. IdleModeCnt = IdleModeCnt + 1;
  1045. }
  1046. }
  1047. for (int index = 0; index < CCS_QUANTITY; index++)
  1048. {
  1049. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1050. {
  1051. IdleModeCnt = IdleModeCnt + 1;
  1052. }
  1053. }
  1054. for (int index = 0; index < GB_QUANTITY; index++)
  1055. {
  1056. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1057. {
  1058. IdleModeCnt = IdleModeCnt + 1;
  1059. }
  1060. }
  1061. }
  1062. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1063. {
  1064. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1065. isUpdateRequest = FALSE;
  1066. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1067. }
  1068. }
  1069. else
  1070. {
  1071. /*************************AC*******************************/
  1072. for (int index = 0; index < AC_QUANTITY; index++)
  1073. {
  1074. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1075. {
  1076. IdleModeCnt = IdleModeCnt + 1;
  1077. }
  1078. }
  1079. if(IdleModeCnt == AC_QUANTITY)
  1080. {
  1081. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1082. isUpdateRequest = FALSE;
  1083. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1084. }
  1085. }
  1086. }
  1087. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1088. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1089. {
  1090. //===============================
  1091. // CSU Trigger Reset Conf
  1092. //===============================
  1093. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1094. {
  1095. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1096. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1097. {
  1098. server_sign = FALSE;
  1099. }
  1100. }
  1101. //===============================
  1102. // CSU Trigger Authorize Request
  1103. //===============================
  1104. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1105. {
  1106. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1107. {
  1108. sendAuthorizeRequest(0);
  1109. authorizeRetryTimes = authorizeRetryTimes + 1;
  1110. // authenrequest = TRUE
  1111. if(authorizeRetryTimes < 3)
  1112. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1113. }
  1114. }
  1115. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1116. {
  1117. authorizeRetryTimes = 0;
  1118. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1119. server_sign = FALSE;
  1120. }
  1121. //===============================
  1122. // CSU Trigger Smart Charging Profilw
  1123. //===============================
  1124. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1125. {
  1126. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1127. GetChargingProfileRequest(gun_index);
  1128. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1129. }
  1130. //==============================================
  1131. // Charger start transaction
  1132. //==============================================
  1133. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1134. {
  1135. sendStartTransactionRequest(gun_index);
  1136. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1137. clientTime.StartTransaction = time((time_t*)NULL);
  1138. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1139. }
  1140. //==============================================
  1141. // Charger stop transaction
  1142. //==============================================
  1143. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1144. {
  1145. sendStopTransactionRequest(gun_index);
  1146. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1147. clientTime.StopTransaction = time((time_t*)NULL);
  1148. }
  1149. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1150. //==============================================
  1151. // Charger status report
  1152. //==============================================
  1153. /* Check Mode Change */
  1154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1155. {
  1156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1157. {
  1158. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1159. {
  1160. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1161. {
  1162. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1163. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1164. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1165. statusModeChage[gun_index] = TRUE;
  1166. }
  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]/*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. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1178. statusModeChage[gun_index] = TRUE;
  1179. }
  1180. }
  1181. }
  1182. for (int index = 0; index < GB_QUANTITY; index++)
  1183. {
  1184. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1185. {
  1186. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1187. {
  1188. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1189. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1190. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1191. statusModeChage[gun_index] = TRUE;
  1192. }
  1193. }
  1194. }
  1195. }
  1196. else //AC
  1197. {
  1198. for (int index = 0; index < AC_QUANTITY; index++)
  1199. {
  1200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1201. {
  1202. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1203. {
  1204. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1205. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1206. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1207. statusModeChage[gun_index] = TRUE;
  1208. }
  1209. }
  1210. }// END OF FOR
  1211. }// END OF ELSE
  1212. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1213. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1214. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1215. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1216. {
  1217. if(SystemInitial != 0)
  1218. SystemInitial = SystemInitial -1;
  1219. //GunStatusInterval= GunStatusInterval* gun_index;
  1220. sendStatusNotificationRequest(gun_index);
  1221. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1222. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1223. statusModeChage[gun_index] = FALSE;
  1224. //sleep(30); // sleep for 30 seconds
  1225. }
  1226. //==============================================
  1227. // Meter report
  1228. //==============================================
  1229. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1230. {
  1231. //check Transaction active
  1232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1233. {
  1234. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1235. {
  1236. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1237. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1238. {
  1239. meterValueSend[gun_index] =1;
  1240. }
  1241. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1242. {
  1243. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1244. if((access(filenmae,F_OK))!=-1)
  1245. {
  1246. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1247. sprintf(str,"rm -f %s",filenmae);
  1248. system(str);
  1249. }
  1250. }
  1251. }// End for CHAdeMO
  1252. for (int index = 0; index < CCS_QUANTITY; index++)
  1253. {
  1254. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1255. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1256. {
  1257. meterValueSend[gun_index] =1;
  1258. }
  1259. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[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 CCS
  1270. for (int index = 0; index < GB_QUANTITY; index++)
  1271. {
  1272. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1273. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1274. {
  1275. meterValueSend[gun_index] =1;
  1276. }
  1277. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[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 GB
  1288. }
  1289. else
  1290. {
  1291. for (int index = 0; index < AC_QUANTITY; index++)
  1292. {
  1293. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1294. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1295. {
  1296. meterValueSend[gun_index] =1;
  1297. }
  1298. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1299. {
  1300. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1301. if((access(filenmae,F_OK))!=-1)
  1302. {
  1303. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1304. sprintf(str,"rm -f %s",filenmae);
  1305. system(str);
  1306. }
  1307. }
  1308. }//End for AC
  1309. }//END OF ELSE
  1310. // sleep(1);
  1311. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1312. if(meterValueSend[gun_index] == 1)
  1313. sendMeterValuesRequest(gun_index);
  1314. }
  1315. //==============================================
  1316. // Check Connector reserved
  1317. //==============================================
  1318. //===============================
  1319. // Check if Reserve is expired
  1320. //===============================
  1321. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1322. {
  1323. double diff_t;
  1324. struct tm tp;
  1325. // current time
  1326. time_t t = time(NULL);
  1327. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1328. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1329. tp.tm_isdst = -1;
  1330. time_t utc = mktime(&tp);
  1331. diff_t = difftime(utc, t);
  1332. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1333. if(diff_t <= 0)
  1334. {
  1335. DEBUG_INFO("reserve expired !!! \n");
  1336. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1337. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1338. }
  1339. #if 0
  1340. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1341. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1342. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1343. {
  1344. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1345. }
  1346. else
  1347. {
  1348. //check Transaction active
  1349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1350. {
  1351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1352. {
  1353. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1354. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1355. {
  1356. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1357. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1358. {
  1359. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1360. }
  1361. }
  1362. }
  1363. for (int index = 0; index < CCS_QUANTITY; index++)
  1364. {
  1365. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1366. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1367. {
  1368. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1369. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1370. {
  1371. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1372. }
  1373. }
  1374. }
  1375. for (int index = 0; index < GB_QUANTITY; index++)
  1376. {
  1377. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1378. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1379. {
  1380. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1381. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1382. {
  1383. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1384. }
  1385. }
  1386. }
  1387. }
  1388. else //AC
  1389. {
  1390. for (int index = 0; index < AC_QUANTITY; index++)
  1391. {
  1392. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1393. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1394. {
  1395. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1396. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1397. {
  1398. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1399. }
  1400. }
  1401. }
  1402. }// END OF ELSE
  1403. }// END OF check Transaction active
  1404. #endif
  1405. }//END OF Check if Reserve is expired
  1406. //==========================================
  1407. // csu trigger FirmwareStatusNotificationReq
  1408. //==========================================
  1409. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1410. {
  1411. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1412. }
  1413. //==========================================
  1414. // csu trigger CancelReservationConf
  1415. //==========================================
  1416. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1417. {
  1418. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1419. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1420. }
  1421. //==========================================
  1422. // csu trigger ChangeAvailabilityConf
  1423. //==========================================
  1424. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1425. {
  1426. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1427. }
  1428. //==========================================
  1429. // csu trigger UnlockConnectorConf
  1430. //==========================================
  1431. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1432. {
  1433. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1434. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1435. }
  1436. //==========================================
  1437. // csu trigger ReserveNowConf
  1438. //==========================================
  1439. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1440. {
  1441. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1442. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1443. }
  1444. //==========================================
  1445. // csu trigger DataTransferReq
  1446. //==========================================
  1447. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1448. {
  1449. sendDataTransferRequest(gun_index);
  1450. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1451. }
  1452. }
  1453. }
  1454. //==========================================
  1455. // send request routine
  1456. //==========================================
  1457. int sendAuthorizeRequest(int gun_index)
  1458. {
  1459. mtrace();
  1460. int result = FAIL;
  1461. char message[100]={0};
  1462. char guid[37];
  1463. char tempdata[65]={0};
  1464. DEBUG_INFO("sendAuthorizeRequest \n");
  1465. //Local Authorize
  1466. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1467. {
  1468. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1469. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1470. {
  1471. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1472. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1473. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1474. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1475. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1476. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1477. authorizeRetryTimes = 0;
  1478. return result;
  1479. }
  1480. else
  1481. {
  1482. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1483. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1484. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1485. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1486. result = PASS;
  1487. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1488. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1489. authorizeRetryTimes = 0;
  1490. return result;
  1491. }
  1492. }
  1493. //initailize struct Authorize
  1494. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1495. //get data from shared memory
  1496. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1497. random_uuid(guid);
  1498. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1499. LWS_Send(message);
  1500. sprintf(tempdata, "Authorize,%d", gun_index);
  1501. if(hashmap_operation(0, guid, tempdata) == 1)
  1502. {
  1503. result = PASS;
  1504. DEBUG_ERROR("Authorize mapItem pass\n");
  1505. }
  1506. //#ifdef SystemLogMessage
  1507. //DEBUG_INFO(">>>>>Authorize request\n");
  1508. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1509. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1510. //#endif
  1511. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1512. return result;
  1513. }
  1514. int sendBootNotificationRequest(void)
  1515. {
  1516. mtrace();
  1517. int result = FAIL;
  1518. char message[500]={0}, payload[700]={0};
  1519. char guid[37]={0};
  1520. char tempdata[65]={0};
  1521. int IsGunCharging = FALSE;
  1522. //check Transaction active
  1523. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1524. {
  1525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1526. {
  1527. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1528. {
  1529. IsGunCharging = TRUE;
  1530. }
  1531. }
  1532. for (int index = 0; index < CCS_QUANTITY; index++)
  1533. {
  1534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1535. {
  1536. IsGunCharging = TRUE;
  1537. }
  1538. }
  1539. for (int index = 0; index < GB_QUANTITY; index++)
  1540. {
  1541. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1542. {
  1543. IsGunCharging = TRUE;
  1544. }
  1545. }
  1546. }
  1547. else
  1548. {
  1549. for (int index = 0; index < AC_QUANTITY; index++)
  1550. {
  1551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1552. {
  1553. IsGunCharging = TRUE;
  1554. }
  1555. }
  1556. }
  1557. if(IsGunCharging == TRUE)
  1558. {
  1559. server_sign = TRUE;
  1560. return result;
  1561. }
  1562. // Fill BootNotification fields
  1563. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1564. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1565. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1566. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1567. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1568. ShmOCPP16Data->ChargeBoxId
  1569. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1570. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1571. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1572. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1573. ,ShmOCPP16Data->BootNotification.CpIccid
  1574. ,ShmOCPP16Data->BootNotification.CpImsi
  1575. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1576. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1577. random_uuid(guid);
  1578. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1579. LWS_Send(message);
  1580. sprintf(tempdata, "BootNotification,0");
  1581. 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*/)
  1582. {
  1583. result = PASS;
  1584. }
  1585. memset(queuedata, 0, sizeof(queuedata));
  1586. strcpy(queuedata,message);
  1587. HeartBeatCount = 0;
  1588. //#ifdef SystemLogMessage
  1589. //DEBUG_INFO(">>>>>BootNotification request\n");
  1590. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1591. //#endif
  1592. return result;
  1593. }
  1594. int sendDataTransferRequest(int gun_index)
  1595. {
  1596. mtrace();
  1597. char message[1000]={0};
  1598. char guid[37]={0};
  1599. char tempdata[65]={0};
  1600. int result = FAIL;
  1601. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1602. random_uuid(guid);
  1603. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1604. MESSAGE_TYPE_CALL,
  1605. guid,
  1606. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1607. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1608. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1609. LWS_Send(message);
  1610. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1611. 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*/)
  1612. {
  1613. result = PASS;
  1614. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1615. }
  1616. //#ifdef SystemLogMessage
  1617. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1618. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1619. //#endif
  1620. return result;
  1621. }
  1622. int sendDiagnosticsStatusNotificationRequest(char *status)
  1623. {
  1624. mtrace();
  1625. int result = FAIL;
  1626. char message[110]={0};
  1627. char guid[37]={0};
  1628. char tempdata[65]={0};
  1629. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1630. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1631. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1632. random_uuid(guid);
  1633. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1634. LWS_Send(message);
  1635. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1636. if(hashmap_operation(0, guid, tempdata) == 1)
  1637. {
  1638. result = PASS;
  1639. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1640. }
  1641. //#ifdef SystemLogMessage
  1642. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1643. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1644. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1645. //#endif
  1646. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1647. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1648. //record status
  1649. if(strcmp(status,"Idle")==0)
  1650. {
  1651. DiagnosticsStatusNotificationStatus = 0;
  1652. }
  1653. else if(strcmp(status,"Uploaded")==0)
  1654. {
  1655. DiagnosticsStatusNotificationStatus = 1;
  1656. }
  1657. else if(strcmp(status,"UploadFailed")==0)
  1658. {
  1659. DiagnosticsStatusNotificationStatus = 2;
  1660. }
  1661. else if(strcmp(status,"Uploading")==0)
  1662. {
  1663. DiagnosticsStatusNotificationStatus = 3;
  1664. }
  1665. return result;
  1666. }
  1667. int sendFirmwareStatusNotificationRequest(char *status)
  1668. {
  1669. mtrace();
  1670. int result = FAIL;
  1671. char message[110]={0};
  1672. char guid[37]={0};
  1673. char tempdata[65]={0};
  1674. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1675. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1676. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1677. random_uuid(guid);
  1678. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1679. LWS_Send(message);
  1680. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1681. 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*/)
  1682. {
  1683. result = PASS;
  1684. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1685. }
  1686. //#ifdef SystemLogMessage
  1687. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1688. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1689. //#endif
  1690. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1691. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1692. //record status
  1693. if(strcmp(status,"Downloaded")==0)
  1694. {
  1695. FirmwareStatusNotificationStatus = 0;
  1696. }
  1697. else if(strcmp(status,"DownloadFailed")==0)
  1698. {
  1699. FirmwareStatusNotificationStatus = 1;
  1700. }
  1701. else if(strcmp(status,"Downloading")==0)
  1702. {
  1703. FirmwareStatusNotificationStatus = 2;
  1704. }
  1705. else if(strcmp(status,"Idle")==0)
  1706. {
  1707. FirmwareStatusNotificationStatus = 3;
  1708. }
  1709. else if(strcmp(status,"InstallationFailed")==0)
  1710. {
  1711. FirmwareStatusNotificationStatus = 4;
  1712. }
  1713. else if(strcmp(status,"Installing")==0)
  1714. {
  1715. FirmwareStatusNotificationStatus = 5;
  1716. }
  1717. else if(strcmp(status,"Installed")==0)
  1718. {
  1719. FirmwareStatusNotificationStatus = 6;
  1720. }
  1721. return result;
  1722. }
  1723. int sendHeartbeatRequest(int gun_index)
  1724. {
  1725. mtrace();
  1726. int result = FAIL;
  1727. char message[80]={0};
  1728. char guid[37]={0};
  1729. char tempdata[65]={0};
  1730. random_uuid(guid);
  1731. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1732. , MESSAGE_TYPE_CALL
  1733. , guid );
  1734. LWS_Send(message);
  1735. sprintf(tempdata, "Heartbeat,%d", 0);
  1736. 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*/)
  1737. {
  1738. result = PASS;
  1739. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1740. }
  1741. return result;
  1742. }
  1743. int sendStartTransactionRequest(int gun_index)
  1744. {
  1745. mtrace();
  1746. int result = FAIL;
  1747. char message[250]={0};
  1748. char guid[37]={0};
  1749. struct timeval tmnow;
  1750. struct tm *tm;
  1751. char buf[28];//, usec_buf[6];
  1752. char tempdata[65]={0};
  1753. DEBUG_INFO("sendStartTransactionRequest...");
  1754. gettimeofday(&tmnow, NULL);
  1755. time_t t;
  1756. t = time(NULL);
  1757. /*UTC time and date*/
  1758. tm = gmtime(&t);
  1759. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1760. #if 0 // remove temporally
  1761. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1762. strcat(buf,".");
  1763. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1764. strcat(buf,usec_buf);
  1765. #endif
  1766. //printf("Start Charging Time :%s",buf);
  1767. // set value
  1768. //if(ShmOCPP16Data->OcppConnStatus == 1 )
  1769. //{
  1770. //memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1771. //}
  1772. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1773. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1774. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1776. {
  1777. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1778. {
  1779. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1780. {
  1781. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1782. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1783. }
  1784. }
  1785. for (int index = 0; index < CCS_QUANTITY; index++)
  1786. {
  1787. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1788. {
  1789. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1790. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1791. }
  1792. }
  1793. for (int index = 0; index < GB_QUANTITY; index++)
  1794. {
  1795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1796. {
  1797. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1798. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1799. }
  1800. }
  1801. }
  1802. else
  1803. {
  1804. for (int index = 0; index < AC_QUANTITY; index++)
  1805. {
  1806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1807. {
  1808. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1809. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1810. }
  1811. }
  1812. }//END OF ELSE
  1813. random_uuid(guid);
  1814. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1815. , MESSAGE_TYPE_CALL
  1816. , guid
  1817. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1818. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1819. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1820. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1821. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1822. LWS_Send(message);
  1823. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1824. 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*/)
  1825. {
  1826. result = PASS;
  1827. }
  1828. strcpy(queuedata, message);
  1829. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1830. //#ifdef SystemLogMessage
  1831. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1832. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1833. //#endif
  1834. return result;
  1835. }
  1836. int sendStatusNotificationRequest(int gun_index)
  1837. {
  1838. mtrace();
  1839. int result = FAIL;
  1840. char message[600]={0};
  1841. char guid[37];
  1842. int currentStatus = 0;
  1843. struct timeval tmnow;
  1844. struct tm *tm;
  1845. char buf[28];//, usec_buf[6];
  1846. char tempdata[65]={0};
  1847. gettimeofday(&tmnow, NULL);
  1848. time_t t;
  1849. t = time(NULL);
  1850. /*UTC time and date*/
  1851. tm = gmtime(&t);
  1852. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1853. #if 0 // remove temporally
  1854. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1855. strcat(buf,".");
  1856. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1857. strcat(buf,usec_buf);
  1858. #endif
  1859. printf("%s",buf);
  1860. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1861. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1862. // it's option
  1863. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1864. /*
  1865. enum _SYSTEM_STATUS
  1866. {
  1867. S_BOOTING = 0,
  1868. S_IDLE, = 1
  1869. S_AUTHORIZING, =2
  1870. S_REASSIGN_CHECK, =3
  1871. S_REASSIGN, =4
  1872. S_PRECHARGE, =5
  1873. S_PREPARING_FOR_EV, =6
  1874. S_PREPARING_FOR_EVSE, =7
  1875. S_CHARGING, =8
  1876. S_TERMINATING, =9
  1877. S_COMPLETE, =10
  1878. S_ALARM, =11
  1879. S_FAULT =12
  1880. }
  1881. */
  1882. //check Transaction active
  1883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1884. {
  1885. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1886. {
  1887. //printf("gun_index=%d\n",gun_index);
  1888. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1889. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1890. {
  1891. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1892. currentStatus = 0; //OCPP Status
  1893. }
  1894. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1895. {
  1896. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1897. currentStatus = 1; //OCPP Status
  1898. }
  1899. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1900. {
  1901. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1902. currentStatus = 2; //OCPP Status
  1903. }
  1904. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1905. {
  1906. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1907. currentStatus = 5; //OCPP Status
  1908. }
  1909. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1910. {
  1911. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1912. currentStatus = 4; //OCPP Status
  1913. }
  1914. 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) )) //S_TERMINATING ---> Unavailable
  1915. {
  1916. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1917. currentStatus = 7; //OCPP Status: Unavailable
  1918. }
  1919. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1920. {
  1921. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1922. currentStatus = 8; //OCPP Status: Faulted
  1923. }
  1924. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1925. {
  1926. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1927. currentStatus = 6; //OCPP Status: Reserved
  1928. }
  1929. }//end of for CHAdeMO_QUANTITY
  1930. for (int index = 0; index < CCS_QUANTITY; index++)
  1931. {
  1932. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1933. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1934. {
  1935. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1936. currentStatus = 0; //OCPP Status
  1937. }
  1938. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1939. {
  1940. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1941. currentStatus = 1; //OCPP Status
  1942. }
  1943. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1944. {
  1945. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1946. currentStatus = 2; //OCPP Status
  1947. }
  1948. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1949. {
  1950. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1951. currentStatus = 5; //OCPP Status
  1952. }
  1953. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1954. {
  1955. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1956. currentStatus = 4; //OCPP Status
  1957. }
  1958. 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) )) //S_TERMINATING ---> Unavailable
  1959. {
  1960. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1961. currentStatus = 7; //OCPP Status
  1962. }
  1963. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1964. {
  1965. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1966. currentStatus = 8; //OCPP Status
  1967. }
  1968. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1969. {
  1970. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1971. currentStatus = 6; //OCPP Status
  1972. }
  1973. }
  1974. for (int index = 0; index < GB_QUANTITY; index++)
  1975. {
  1976. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1977. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1978. {
  1979. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1980. currentStatus = 0; //OCPP Status
  1981. }
  1982. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1983. {
  1984. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1985. currentStatus = 1; //OCPP Status
  1986. }
  1987. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1988. {
  1989. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1990. currentStatus = 2; //OCPP Status
  1991. }
  1992. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1993. {
  1994. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1995. currentStatus = 5; //OCPP Status
  1996. }
  1997. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1998. {
  1999. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2000. currentStatus = 4; //OCPP Status
  2001. }
  2002. 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))) //S_TERMINATING ---> Unavailable
  2003. {
  2004. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2005. currentStatus = 7; //OCPP Status: Unavailable
  2006. }
  2007. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2008. {
  2009. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2010. currentStatus = 8; //OCPP Status: Faulted
  2011. }
  2012. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2013. {
  2014. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2015. currentStatus = 6; //OCPP Status: Faulted
  2016. }
  2017. }
  2018. }
  2019. else
  2020. {
  2021. for (int index = 0; index < AC_QUANTITY; index++)
  2022. {
  2023. //printf("gun_index=%d\n",gun_index);
  2024. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2025. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2026. {
  2027. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2028. currentStatus = 0; //OCPP Status
  2029. }
  2030. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2031. {
  2032. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2033. currentStatus = 1; //OCPP Status
  2034. }
  2035. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2036. {
  2037. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2038. currentStatus = 2; //OCPP Status
  2039. }
  2040. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2041. {
  2042. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2043. currentStatus = 5; //OCPP Status
  2044. }
  2045. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2046. {
  2047. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2048. currentStatus = 4; //OCPP Status
  2049. }
  2050. 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) )) //S_TERMINATING ---> Unavailable
  2051. {
  2052. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2053. currentStatus = 7; //OCPP Status: Unavailable
  2054. }
  2055. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2056. {
  2057. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2058. currentStatus = 8; //OCPP Status: Faulted
  2059. }
  2060. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2061. {
  2062. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2063. currentStatus = 6; //OCPP Status: Reserved
  2064. }
  2065. }//end of for AC_QUANTITY
  2066. }//END OF ELSE
  2067. //it's option
  2068. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2069. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2070. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2071. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2072. random_uuid(guid);
  2073. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2074. , MESSAGE_TYPE_CALL
  2075. , guid
  2076. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2077. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2078. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2079. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2080. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2081. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2082. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2083. LWS_Send(message);
  2084. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2085. 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*/)
  2086. {
  2087. //DEBUG_ERROR("statusNotification mapitem pass");
  2088. result = PASS;
  2089. }
  2090. //#ifdef SystemLogMessage
  2091. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2092. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2093. //#endif
  2094. return result;
  2095. }
  2096. int sendStopTransactionRequest(int gun_index)
  2097. {
  2098. mtrace();
  2099. int result = FAIL;
  2100. //char message[1500]={0};
  2101. char guid[37]={0};
  2102. char tempdata[65]={0};
  2103. //int idx_sample=0;
  2104. DEBUG_ERROR("sendStopTransactionRequest \n");
  2105. memset(queuedata, 0, sizeof(queuedata));
  2106. //ENERGY_ACTIVE_IMPORT_REGISTER
  2107. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2108. {
  2109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2110. {
  2111. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2112. {
  2113. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2114. //Check Status
  2115. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2116. {
  2117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2118. }
  2119. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2120. }
  2121. }// END OF CHAdeMO_QUANTITY
  2122. for (int index = 0; index < CCS_QUANTITY; index++)
  2123. {
  2124. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2125. {
  2126. //for test
  2127. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2128. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2129. //Check Status
  2130. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2131. {
  2132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2133. }
  2134. else
  2135. {
  2136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2137. }
  2138. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2139. }
  2140. }// END OF CCS_QUANTITY
  2141. for (int index = 0; index < GB_QUANTITY; index++)
  2142. {
  2143. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2144. {
  2145. // for test
  2146. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2147. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2148. //Check Status
  2149. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2150. {
  2151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2152. }
  2153. else
  2154. {
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2156. }
  2157. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2158. }
  2159. }// END OF GB_QUANTITY
  2160. }
  2161. else
  2162. {
  2163. for (int index = 0; index < AC_QUANTITY; index++)
  2164. {
  2165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2166. {
  2167. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2168. //Check Status
  2169. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2170. {
  2171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2172. }
  2173. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2174. }
  2175. }// END OF AC_QUANTITY
  2176. }//END OF ELSE
  2177. //Stop Transaction Time
  2178. struct timeval tmnow;
  2179. struct tm *tm;
  2180. char buf[28];//, usec_buf[6];
  2181. gettimeofday(&tmnow, NULL);
  2182. time_t t;
  2183. t = time(NULL);
  2184. /*UTC time and date*/
  2185. tm = gmtime(&t);
  2186. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2187. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2189. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2190. random_uuid(guid);
  2191. /***********************************transactionData******************************************************/
  2192. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2193. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2194. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2196. //=================================
  2197. // Transaction_Begin
  2198. //=================================
  2199. // Energy.Active.Export.Interval
  2200. //idx_sample=0;
  2201. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2204. 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*/]);
  2205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2206. {
  2207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2208. }
  2209. else
  2210. {
  2211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2212. }
  2213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2215. //=================================
  2216. // Transaction_End
  2217. //=================================
  2218. //Current.Export
  2219. //idx_sample=1;
  2220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2221. {
  2222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2223. {
  2224. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2225. {
  2226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2227. }
  2228. }
  2229. for (int index = 0; index < CCS_QUANTITY; index++)
  2230. {
  2231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2232. {
  2233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2234. }
  2235. }
  2236. for (int index = 0; index < GB_QUANTITY; index++)
  2237. {
  2238. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2239. {
  2240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2241. }
  2242. }
  2243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2244. }
  2245. else
  2246. {
  2247. for (int index = 0; index < AC_QUANTITY; index++)
  2248. {
  2249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2250. {
  2251. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2252. }
  2253. }
  2254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2255. }// END FOR AC ELSE
  2256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2259. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2262. //Energy.Active.Export.Interval
  2263. //idx_sample=2;
  2264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2265. {
  2266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2267. {
  2268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2269. {
  2270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2271. }
  2272. }
  2273. for (int index = 0; index < CCS_QUANTITY; index++)
  2274. {
  2275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2276. {
  2277. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2278. }
  2279. }
  2280. for (int index = 0; index < GB_QUANTITY; index++)
  2281. {
  2282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2283. {
  2284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2285. }
  2286. }
  2287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2288. }
  2289. else
  2290. {
  2291. for (int index = 0; index < AC_QUANTITY; index++)
  2292. {
  2293. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2294. {
  2295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2296. }
  2297. }
  2298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2299. }// END FOR AC ELSE
  2300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2303. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2306. //Power.Active.Export
  2307. //idx_sample=3;
  2308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2309. {
  2310. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2311. {
  2312. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2313. {
  2314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2315. }
  2316. }
  2317. for (int index = 0; index < CCS_QUANTITY; index++)
  2318. {
  2319. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2320. {
  2321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2322. }
  2323. }
  2324. for (int index = 0; index < GB_QUANTITY; index++)
  2325. {
  2326. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2327. {
  2328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2329. }
  2330. }
  2331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2332. }
  2333. else
  2334. {
  2335. for (int index = 0; index < AC_QUANTITY; index++)
  2336. {
  2337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2338. {
  2339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2340. }
  2341. }
  2342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2343. }// END FOR AC ELSE
  2344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2347. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2350. //Voltage
  2351. //idx_sample=4;
  2352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2353. {
  2354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2355. {
  2356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2357. {
  2358. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2359. }
  2360. }
  2361. for (int index = 0; index < CCS_QUANTITY; index++)
  2362. {
  2363. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2364. {
  2365. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2366. }
  2367. }
  2368. for (int index = 0; index < GB_QUANTITY; index++)
  2369. {
  2370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2371. {
  2372. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2373. }
  2374. }
  2375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2376. }
  2377. else
  2378. {
  2379. for (int index = 0; index < AC_QUANTITY; index++)
  2380. {
  2381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2382. {
  2383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2384. }
  2385. }
  2386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2387. }// END FOR AC ELSE
  2388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2391. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2394. //SoC
  2395. //idx_sample=5;
  2396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2397. {
  2398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2399. {
  2400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2401. {
  2402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2403. }
  2404. }
  2405. for (int index = 0; index < CCS_QUANTITY; index++)
  2406. {
  2407. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2408. {
  2409. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2410. }
  2411. }
  2412. for (int index = 0; index < GB_QUANTITY; index++)
  2413. {
  2414. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2415. {
  2416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2417. }
  2418. }
  2419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2425. } // END FOR DC CASE
  2426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2427. {
  2428. 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\" } ] } ] } ]"
  2429. ,MESSAGE_TYPE_CALL
  2430. ,guid
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2436. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2446. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2447. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2448. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2449. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2450. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2451. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2452. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2453. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2454. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2455. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2456. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2457. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2458. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2459. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2460. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2461. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2462. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2463. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2464. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2465. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2466. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2467. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2468. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2469. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2470. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2471. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2472. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2473. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2474. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2475. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2476. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2477. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2478. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2479. );
  2480. }
  2481. else
  2482. {
  2483. 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\" } ] } ] } ]"
  2484. ,MESSAGE_TYPE_CALL
  2485. ,guid
  2486. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2487. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2488. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2489. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2490. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2491. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2492. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2493. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2494. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2495. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2496. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2497. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2498. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2499. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2500. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2501. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2502. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2503. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2504. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2505. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2506. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2507. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2508. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2509. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2510. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2511. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2512. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2513. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2514. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2515. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2516. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2517. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2518. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2519. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2520. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2521. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2522. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2523. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2524. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2525. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2526. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2527. );
  2528. }
  2529. LWS_Send(queuedata);
  2530. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2531. if(hashmap_operation(0, guid, tempdata) == 1)
  2532. {
  2533. result = PASS;
  2534. DEBUG_INFO("StopTransaction mapitem pass\n");
  2535. }
  2536. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2537. //for test
  2538. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2539. return result;
  2540. }
  2541. int sendMeterValuesRequest(int gun_index)
  2542. {
  2543. mtrace();
  2544. int result = FAIL;
  2545. // char message[1500]={0};
  2546. char guid[37]={0};
  2547. //int idx_sample=0;
  2548. //int length = 0;
  2549. char tempdata[65]={0};
  2550. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2551. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2552. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2553. {
  2554. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2555. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2556. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2557. return result;
  2558. }
  2559. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2560. {
  2561. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2562. }
  2563. memset(queuedata, 0, sizeof(queuedata));
  2564. //set value
  2565. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2566. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2567. random_uuid(guid);
  2568. //UTC Date time
  2569. struct timeval tmnow;
  2570. struct tm *tm;
  2571. char buf[28];//, usec_buf[6];
  2572. gettimeofday(&tmnow, NULL);
  2573. time_t t;
  2574. t = time(NULL);
  2575. /*UTC time and date*/
  2576. tm = gmtime(&t);
  2577. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2579. //idx_sample=0;
  2580. //********************************(1)Current.Export************************************************/
  2581. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2582. {
  2583. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2584. {
  2585. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2586. {
  2587. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2588. }
  2589. }
  2590. for (int index = 0; index < CCS_QUANTITY; index++)
  2591. {
  2592. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2593. {
  2594. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2595. }
  2596. }
  2597. for (int index = 0; index < GB_QUANTITY; index++)
  2598. {
  2599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2600. {
  2601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2602. }
  2603. }
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2605. }
  2606. else
  2607. {
  2608. for (int index = 0; index < AC_QUANTITY; index++)
  2609. {
  2610. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2611. {
  2612. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2613. }
  2614. }
  2615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2616. }// END FOR AC ELSE
  2617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2619. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2620. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2623. //idx_sample=1;
  2624. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2626. {
  2627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2628. {
  2629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2630. {
  2631. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2632. }
  2633. }
  2634. for (int index = 0; index < CCS_QUANTITY; index++)
  2635. {
  2636. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2637. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2638. {
  2639. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2640. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2641. }
  2642. }
  2643. for (int index = 0; index < GB_QUANTITY; index++)
  2644. {
  2645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2646. {
  2647. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2648. }
  2649. }
  2650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2651. }
  2652. else
  2653. {
  2654. for (int index = 0; index < AC_QUANTITY; index++)
  2655. {
  2656. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2657. {
  2658. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2659. }
  2660. }
  2661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2662. }//END FOR AC ELSE
  2663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2666. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2668. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2669. //idx_sample=2;
  2670. //********************************(4)Power.Active.Export************************************************/
  2671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2672. {
  2673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2676. {
  2677. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2678. }
  2679. }
  2680. for (int index = 0; index < CCS_QUANTITY; index++)
  2681. {
  2682. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2683. {
  2684. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2685. }
  2686. }
  2687. for (int index = 0; index < GB_QUANTITY; index++)
  2688. {
  2689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2690. {
  2691. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2692. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2693. }
  2694. }
  2695. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2696. }
  2697. else
  2698. {
  2699. for (int index = 0; index < AC_QUANTITY; index++)
  2700. {
  2701. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2702. {
  2703. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2704. }
  2705. }
  2706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2707. }// END FOR AC ELSE
  2708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2711. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2712. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2714. //idx_sample=3;
  2715. //***********************************************(5)VOLTAGE******************************************************/
  2716. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2717. {
  2718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2719. {
  2720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2721. {
  2722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2723. }
  2724. }
  2725. for (int index = 0; index < CCS_QUANTITY; index++)
  2726. {
  2727. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2728. {
  2729. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2730. }
  2731. }
  2732. for (int index = 0; index < GB_QUANTITY; index++)
  2733. {
  2734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2735. {
  2736. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2737. }
  2738. }
  2739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2740. }
  2741. else
  2742. {
  2743. for (int index = 0; index < AC_QUANTITY; index++)
  2744. {
  2745. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2746. {
  2747. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2748. }
  2749. }
  2750. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2751. }//END FOR AC ELSE
  2752. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2753. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2755. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2759. {
  2760. //idx_sample=4;
  2761. //sampledValue = NULL;
  2762. //***********************************************(6)SOC******************************************************/
  2763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2764. {
  2765. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2766. {
  2767. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2768. }
  2769. }
  2770. for (int index = 0; index < CCS_QUANTITY; index++)
  2771. {
  2772. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2773. {
  2774. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2775. }
  2776. }
  2777. for (int index = 0; index < GB_QUANTITY; index++)
  2778. {
  2779. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2780. {
  2781. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2782. }
  2783. }
  2784. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2785. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2786. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2787. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2788. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2789. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2790. }
  2791. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2792. {
  2793. 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\"}]}]}]"
  2794. ,MESSAGE_TYPE_CALL
  2795. ,guid
  2796. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2797. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2798. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2834. );
  2835. }
  2836. else
  2837. {
  2838. 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\"}]}]}]"
  2839. ,MESSAGE_TYPE_CALL
  2840. ,guid
  2841. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2842. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2843. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2844. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2845. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2846. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2847. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2848. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2849. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2850. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2851. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2852. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2853. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2854. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2855. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2856. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2857. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2858. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2859. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2860. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2861. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2862. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2863. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2864. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2865. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2866. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2867. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2868. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2869. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2870. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2871. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2872. );
  2873. }
  2874. LWS_Send(queuedata);
  2875. // Put request guid to hash map
  2876. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2877. 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*/)
  2878. {
  2879. result = PASS;
  2880. DEBUG_INFO("MeterValues mapitem pass\n");
  2881. }
  2882. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2883. return result;
  2884. }
  2885. //==========================================
  2886. // send confirm routine
  2887. //==========================================
  2888. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2889. {
  2890. mtrace();
  2891. int result = FAIL;
  2892. char message[100]={0};
  2893. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2894. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2895. LWS_Send(message);
  2896. result = TRUE;
  2897. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2898. return result;
  2899. }
  2900. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2901. {
  2902. mtrace();
  2903. int result = FAIL;
  2904. char message[100]={0};
  2905. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2906. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2907. LWS_Send(message);
  2908. result = TRUE;
  2909. return result;
  2910. }
  2911. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2912. {
  2913. mtrace();
  2914. int result = FAIL;
  2915. char message[100]={0};
  2916. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2917. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2918. LWS_Send(message);
  2919. result = TRUE;
  2920. return result;
  2921. }
  2922. int sendClearCacheConfirmation(char *uuid,char *payload)
  2923. {
  2924. mtrace();
  2925. int result = FAIL;
  2926. char message[500]={0};
  2927. // int count = 0;
  2928. // int gun_index = 0;
  2929. // char guid[37];
  2930. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2931. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2932. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2933. LWS_Send(message);
  2934. return result;
  2935. }
  2936. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2937. {
  2938. mtrace();
  2939. int result = FAIL;
  2940. char message[500]={0};
  2941. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2942. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2943. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2944. LWS_Send(message);
  2945. return result;
  2946. }
  2947. int sendDataTransferConfirmation(char *uuid,char *payload)
  2948. {
  2949. mtrace();
  2950. char statusStr[20]={0};
  2951. char dataStr[10]={0};
  2952. char sstr[20]={0};
  2953. int c = 0;
  2954. char *loc;
  2955. int result = FAIL;
  2956. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2957. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2958. /**********************status**************************/
  2959. loc = strstr(payload, "status");
  2960. memset(sstr ,0, sizeof(sstr) );
  2961. c = 0;
  2962. while (loc[3+strlen("status")+c] != '\"')
  2963. {
  2964. sstr[c] = loc[3+strlen("status")+c];
  2965. c++;
  2966. }
  2967. sstr[c] = '\0';
  2968. strcpy(statusStr, sstr);
  2969. /**********************data**************************/
  2970. loc = strstr(payload, "data");
  2971. memset(sstr ,0, sizeof(sstr) );
  2972. c = 0;
  2973. while (loc[3+strlen("data")+c] != '\"')
  2974. {
  2975. sstr[c] = loc[3+strlen("data")+c];
  2976. c++;
  2977. }
  2978. sstr[c] = '\0';
  2979. strcpy(dataStr, sstr);
  2980. return result;
  2981. }
  2982. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2983. {
  2984. mtrace();
  2985. int result = FAIL;
  2986. char message[1000]={0};
  2987. double diff_f = 0.0;
  2988. int diff_i = 0;
  2989. int diffSeconds = 0;
  2990. struct tm tp;
  2991. int TimeZero = FALSE;
  2992. int CompositeScheduleIndex = 0;
  2993. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2994. #if 0
  2995. if(connectorIdInt > 0)
  2996. {
  2997. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2998. {
  2999. TimeZero = TRUE;
  3000. }
  3001. else
  3002. {
  3003. strptime((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  3004. }
  3005. }
  3006. else
  3007. {
  3008. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  3009. {
  3010. TimeZero = TRUE;
  3011. }
  3012. else
  3013. {
  3014. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  3015. }
  3016. }
  3017. DEBUG_INFO("ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule=%s\n",ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule);
  3018. #endif
  3019. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  3020. {
  3021. TimeZero = TRUE;
  3022. }
  3023. else
  3024. {
  3025. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3026. }
  3027. if(TimeZero == FALSE)
  3028. {
  3029. tp.tm_isdst = -1;
  3030. time_t utc = mktime(&tp);
  3031. time_t t = time(NULL);
  3032. diff_f = difftime(t, utc);
  3033. diff_i = (int)diff_f;
  3034. diffSeconds = diff_i % 86400;//86400 seconds/day
  3035. }
  3036. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3037. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3038. #if 0 //remove temporally
  3039. 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}"
  3040. ,MESSAGE_TYPE_CALLRESULT
  3041. ,uuid
  3042. ,payload
  3043. ,connectorIdInt
  3044. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3045. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3046. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3047. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3048. #endif
  3049. if(nPeriod == 0)
  3050. {
  3051. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3052. ,MESSAGE_TYPE_CALLRESULT
  3053. ,uuid
  3054. ,payload
  3055. ,connectorIdInt
  3056. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3057. }
  3058. else
  3059. {
  3060. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3061. ,MESSAGE_TYPE_CALLRESULT
  3062. ,uuid
  3063. ,payload
  3064. ,connectorIdInt
  3065. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3066. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3067. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3068. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3069. int len = nPeriod;
  3070. //Last Period StartPriod is less than diffSeconds
  3071. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  3072. {
  3073. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3074. , 0
  3075. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3076. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3077. }
  3078. else
  3079. {
  3080. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3081. {
  3082. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  3083. {
  3084. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3085. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3086. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3087. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3088. }
  3089. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3090. {
  3091. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3092. , (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  3093. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3094. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3095. }
  3096. }
  3097. }
  3098. sprintf(message + strlen(message), "]}}]");
  3099. }
  3100. LWS_Send(message);
  3101. result = TRUE;
  3102. return result;
  3103. }
  3104. int sendGetConfigurationConfirmation(char *uuid)
  3105. {
  3106. mtrace();
  3107. int result = FAIL;
  3108. int MaxKeySupported = 0;
  3109. int sentConfigurationNumber= 0;
  3110. int sentunConfigurationNumber= 0;
  3111. char message[4000]={0};
  3112. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3113. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3114. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3115. ,MESSAGE_TYPE_CALLRESULT
  3116. ,uuid );
  3117. //configuration key
  3118. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3119. {
  3120. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3121. {
  3122. if (sentConfigurationNumber == 0)
  3123. {
  3124. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3125. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3126. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3127. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3128. }
  3129. else
  3130. {
  3131. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3132. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3133. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3134. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3135. }
  3136. sentConfigurationNumber = sentConfigurationNumber + 1;
  3137. }
  3138. }
  3139. sprintf(message + strlen(message), "]");
  3140. if(UnknownKeynum != 0)
  3141. {
  3142. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3143. //unkown key
  3144. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3145. {
  3146. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3147. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3148. if(sentunConfigurationNumber == 0)
  3149. {
  3150. sprintf(message + strlen(message), "\"%s\""
  3151. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3152. }
  3153. else
  3154. {
  3155. sprintf(message + strlen(message), ",\"%s\""
  3156. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3157. }
  3158. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3159. }
  3160. sprintf(message + strlen(message), "]");
  3161. }
  3162. sprintf(message + strlen(message), "} ]");
  3163. LWS_Send(message);
  3164. #if 0
  3165. printf("error 1-0\n");
  3166. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3167. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3168. #endif
  3169. return result;
  3170. }
  3171. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3172. {
  3173. mtrace();
  3174. int result = FAIL;
  3175. char message[400]={0};
  3176. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3177. if(strcmp(payload,"")==0)
  3178. {
  3179. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3180. }
  3181. else
  3182. {
  3183. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3184. }
  3185. LWS_Send(message);
  3186. result = TRUE;
  3187. return result;
  3188. }
  3189. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3190. {
  3191. mtrace();
  3192. int result = FAIL;
  3193. char message[80]={0};
  3194. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3195. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3196. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3197. LWS_Send(message);
  3198. result = TRUE;
  3199. return result;
  3200. }
  3201. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3202. {
  3203. mtrace();
  3204. int result = FAIL;
  3205. char message[80]={0};
  3206. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3207. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3208. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3209. LWS_Send(message);
  3210. result = TRUE;
  3211. return result;
  3212. }
  3213. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3214. {
  3215. mtrace();
  3216. int result = FAIL;
  3217. char message[80]={0};
  3218. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3219. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\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 sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3226. {
  3227. mtrace();
  3228. int result = FAIL;
  3229. char message[80]={0};
  3230. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3231. DEBUG_ERROR("sendReserveNowTransactionConfirmation\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 sendResetConfirmation(char *uuid,char *payload)
  3238. {
  3239. mtrace();
  3240. int result = FAIL;
  3241. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3242. char message[80]={0};
  3243. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3244. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3245. LWS_Send(message);
  3246. result = TRUE;
  3247. return result;
  3248. }
  3249. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3250. {
  3251. mtrace();
  3252. int result = FAIL;
  3253. char message[500]={0};
  3254. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3255. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3256. LWS_Send(message);
  3257. result = TRUE;
  3258. return result;
  3259. }
  3260. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3261. {
  3262. mtrace();
  3263. int result = FAIL;
  3264. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3265. char message[80]={0};
  3266. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3267. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3268. LWS_Send(message);
  3269. result = TRUE;
  3270. return result;
  3271. }
  3272. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3273. {
  3274. mtrace();
  3275. int result = FAIL;
  3276. char message[80]={0};
  3277. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3278. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3279. LWS_Send(message);
  3280. result = TRUE;
  3281. return result;
  3282. }
  3283. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3284. {
  3285. mtrace();
  3286. int result = FAIL;
  3287. char message[80]={0};
  3288. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3289. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3290. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3291. LWS_Send(message);
  3292. result = TRUE;
  3293. return result;
  3294. }
  3295. int sendUpdateFirmwareConfirmation(char *uuid)
  3296. {
  3297. mtrace();
  3298. int result = FAIL;
  3299. char message[60]={0};
  3300. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3301. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3302. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3303. LWS_Send(message);
  3304. result = TRUE;
  3305. return result;
  3306. }
  3307. //==========================================
  3308. // send CallError routine
  3309. //==========================================
  3310. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3311. {
  3312. mtrace();
  3313. //int result = FAIL;
  3314. char message[220]={0};
  3315. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3316. #ifdef SystemLogMessage
  3317. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3318. uniqueId, action, errorCode, errorDescription);
  3319. #endif
  3320. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3321. LWS_Send(message);
  3322. //result = TRUE;
  3323. }
  3324. //==========================================
  3325. // Handle server request routine Start
  3326. //==========================================
  3327. #define GUN_NUM 1
  3328. int handleCancelReservationRequest(char *uuid, char *payload)
  3329. {
  3330. mtrace();
  3331. int result = FAIL;
  3332. int gunNO = 0;
  3333. int reservationIdInt =0;
  3334. char comfirmstr[20];
  3335. int c = 0;
  3336. char *loc;
  3337. char sstr[100]={0};
  3338. DEBUG_INFO("handle CancelReservationRequest\n");
  3339. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3340. c = 0;
  3341. loc = strstr(payload, "reservationId");
  3342. memset(sstr ,0, sizeof(sstr) );
  3343. while (loc[strlen("reservationId")+2+c] != '}')
  3344. {
  3345. sstr[c] = loc[strlen("reservationId")+2+c];
  3346. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3347. c++;
  3348. }
  3349. sstr[c] = '\0';
  3350. reservationIdInt = atoi(sstr);
  3351. memset(comfirmstr, 0, sizeof comfirmstr);
  3352. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3353. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3354. //check Transaction active
  3355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3356. {
  3357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3358. {
  3359. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3360. {
  3361. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3362. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3363. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3364. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3365. goto end;
  3366. }
  3367. }
  3368. for (int index = 0; index < CCS_QUANTITY; index++)
  3369. {
  3370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3371. {
  3372. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3373. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3374. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3375. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3376. goto end;
  3377. }
  3378. }
  3379. for (int index = 0; index < GB_QUANTITY; index++)
  3380. {
  3381. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3382. {
  3383. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3384. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3385. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3386. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3387. goto end;
  3388. }
  3389. }
  3390. }
  3391. else
  3392. {
  3393. for (int index = 0; index < AC_QUANTITY; index++)
  3394. {
  3395. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3396. {
  3397. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3398. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3399. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3400. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3401. goto end;
  3402. }
  3403. }
  3404. }// END FOR AC ELSE
  3405. //The reservationId does NOT match the reservationId
  3406. sendCancelReservationConfirmation(uuid, comfirmstr);
  3407. end:
  3408. // Fill in ocpp packet uuid
  3409. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3410. return result;
  3411. }
  3412. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3413. {
  3414. mtrace();
  3415. int result = FAIL;
  3416. int gunIndex = 0;
  3417. char sstr[90]={0};
  3418. char typeStr[16]={0};
  3419. char comfirmstr[20];
  3420. int specificId = FALSE;
  3421. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3422. char *loc;
  3423. //int intervalInt = 0;
  3424. int c = 0;
  3425. /*** connectorId ****/
  3426. c = 0;
  3427. loc = strstr(payload, "connectorId");
  3428. memset(sstr ,0, sizeof(sstr) );
  3429. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3430. {
  3431. sstr[c] = loc[strlen("connectorId")+2+c];
  3432. c++;
  3433. }
  3434. sstr[c] = '\0';
  3435. gunIndex = atoi(sstr);
  3436. /***type ****/
  3437. loc = strstr(payload, "type");
  3438. memset(sstr ,0, sizeof(sstr) );
  3439. c = 0;
  3440. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3441. {
  3442. sstr[c] = loc[3+strlen("type")+c];
  3443. c++;
  3444. }
  3445. sstr[c] = '\0';
  3446. strcpy(typeStr, sstr);
  3447. if(gunIndex != 0)
  3448. {
  3449. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3450. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3451. }
  3452. else
  3453. {
  3454. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3455. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3456. }
  3457. memset(comfirmstr, 0, sizeof comfirmstr);
  3458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3459. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3460. {
  3461. specificId = TRUE;
  3462. }
  3463. if(specificId == FALSE)
  3464. goto end;
  3465. if(gunIndex != 0)
  3466. {
  3467. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3468. }
  3469. else
  3470. {
  3471. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3472. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3473. }
  3474. /*
  3475. enum _SYSTEM_STATUS
  3476. {
  3477. S_BOOTING = 0,
  3478. S_IDLE, = 1
  3479. S_AUTHORIZING, =2
  3480. S_REASSIGN_CHECK, =3
  3481. S_REASSIGN, =4
  3482. S_PRECHARGE, =5
  3483. S_PREPARING_FOR_EV, =6
  3484. S_PREPARING_FOR_EVSE, =7
  3485. S_CHARGING, =8
  3486. S_TERMINATING, =9
  3487. S_COMPLETE, =10
  3488. S_ALARM, =11
  3489. S_FAULT =12
  3490. }
  3491. */
  3492. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3493. {
  3494. //check Transaction active
  3495. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3496. {
  3497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3498. {
  3499. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3500. {
  3501. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3502. {
  3503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3504. }
  3505. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3506. {
  3507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3508. }
  3509. else
  3510. {
  3511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3512. }
  3513. goto end;
  3514. }
  3515. }//END FOR CHAdeMO_QUANTITY
  3516. for (int index = 0; index < CCS_QUANTITY; index++)
  3517. {
  3518. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3519. {
  3520. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3521. {
  3522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3523. }
  3524. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3525. {
  3526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3527. }
  3528. else
  3529. {
  3530. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3531. }
  3532. goto end;
  3533. }
  3534. }//END FOR CCS_QUANTITY
  3535. for (int index = 0; index < GB_QUANTITY; index++)
  3536. {
  3537. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3538. {
  3539. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3540. {
  3541. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3542. }
  3543. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3544. {
  3545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3546. }
  3547. else
  3548. {
  3549. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3550. }
  3551. goto end;
  3552. }
  3553. }// END FOR GB_QUANTITY
  3554. }
  3555. else
  3556. {
  3557. for (int index = 0; index < AC_QUANTITY; index++)
  3558. {
  3559. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3560. {
  3561. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3562. {
  3563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3564. }
  3565. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3566. {
  3567. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3568. }
  3569. else
  3570. {
  3571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3572. }
  3573. goto end;
  3574. }
  3575. }//END FOR AC_QUANTITY
  3576. }// END FOR AC ELSE
  3577. }//END FOR AvailabilityTypeStr[Inoperative]
  3578. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3579. {
  3580. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3581. //check Transaction active
  3582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3583. {
  3584. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3585. {
  3586. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3587. {
  3588. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3589. goto end;
  3590. }
  3591. }//END FOR CHAdeMO_QUANTITY
  3592. for (int index = 0; index < CCS_QUANTITY; index++)
  3593. {
  3594. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3595. {
  3596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3597. goto end;
  3598. }
  3599. }//END FOR CCS_QUANTITY
  3600. for (int index = 0; index < GB_QUANTITY; index++)
  3601. {
  3602. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3603. {
  3604. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3606. goto end;
  3607. }
  3608. }// END FOR GB_QUANTITY
  3609. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3610. }
  3611. else
  3612. {
  3613. for (int index = 0; index < AC_QUANTITY; index++)
  3614. {
  3615. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3616. {
  3617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3618. goto end;
  3619. }
  3620. }//END FOR CHAdeMO_QUANTITY
  3621. }//END FOR AC ELSE
  3622. }//END FOR AvailabilityTypeStr[Operative]
  3623. end:
  3624. if(gunIndex != 0)
  3625. {
  3626. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3627. }
  3628. else
  3629. {
  3630. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3631. }
  3632. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3633. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3634. return result;
  3635. }
  3636. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3637. {
  3638. mtrace();
  3639. int result = FAIL;
  3640. char sstr[100]={0};
  3641. char keystr[40]={0};
  3642. char valuestr[16]={0};
  3643. char *loc;
  3644. int c = 0;
  3645. char comfirmstr[20];
  3646. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3647. /***key ****/
  3648. loc = strstr(payload, "key");
  3649. memset(sstr ,0, sizeof(sstr) );
  3650. c = 0;
  3651. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3652. {
  3653. sstr[c] = loc[3+strlen("key")+c];
  3654. c++;
  3655. }
  3656. sstr[c] = '\0';
  3657. strcpy(keystr, sstr);
  3658. /***value ****/
  3659. loc = strstr(payload, "value");
  3660. memset(sstr ,0, sizeof(sstr) );
  3661. c = 0;
  3662. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3663. {
  3664. sstr[c] = loc[3+strlen("value")+c];
  3665. c++;
  3666. }
  3667. sstr[c] = '\0';
  3668. strcpy(valuestr, sstr);
  3669. if((uuid==NULL) || (payload ==NULL) )
  3670. {
  3671. #ifdef Debug
  3672. DEBUG_INFO("payload is null\n");
  3673. #endif
  3674. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3675. }
  3676. else
  3677. {
  3678. int status = setKeyValue(keystr, valuestr);
  3679. switch(status)
  3680. {
  3681. case ConfigurationStatus_Accepted:
  3682. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3683. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3684. break;
  3685. case ConfigurationStatus_Rejected:
  3686. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3687. break;
  3688. case RebootRequired:
  3689. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3690. break;
  3691. case NotSupported:
  3692. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3693. break;
  3694. default:
  3695. break;
  3696. }
  3697. }
  3698. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3699. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3700. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3701. return result;
  3702. }
  3703. int handleClearCacheRequest(char *uuid, char *payload)
  3704. {
  3705. mtrace();
  3706. int result = FAIL;
  3707. char comfirmstr[20];
  3708. int fd;
  3709. char rmFileCmd[100]={0};
  3710. struct stat stats;
  3711. DEBUG_ERROR("handle ClearCacheRequest\n");
  3712. stat("../Storage/OCPP", &stats);
  3713. // Check for directory existence
  3714. if (S_ISDIR(stats.st_mode) == 1)
  3715. {
  3716. //DEBUG_ERROR("\n OCPP directory exist \n");
  3717. }
  3718. else
  3719. {
  3720. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3721. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3722. system(rmFileCmd);
  3723. }
  3724. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3725. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3726. {
  3727. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3728. }
  3729. else
  3730. {
  3731. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3732. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3733. if(log == NULL)
  3734. {
  3735. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3736. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3737. goto end;
  3738. }
  3739. else
  3740. {
  3741. fclose(log);
  3742. }
  3743. }
  3744. fd = open(AuthorizationCache_JSON,O_RDWR);
  3745. if(fd < 0)
  3746. {
  3747. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3748. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3749. }
  3750. else
  3751. {
  3752. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3753. //* 清空? 件 */
  3754. ftruncate(fd,0);
  3755. //* ? 新设置? 件? 移??*/
  3756. lseek(fd,0,SEEK_SET);
  3757. close(fd);
  3758. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3759. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3760. }
  3761. end:
  3762. sendClearCacheConfirmation(uuid, comfirmstr);
  3763. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3764. return result;
  3765. }
  3766. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3767. {
  3768. mtrace();
  3769. int result = FAIL;
  3770. int resultRename;
  3771. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3772. char chargingProfilePurposeStr[26]={0};
  3773. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3774. char tempchargingProfilePurposeStr[26]={0};
  3775. char sstr[160]={0};//sstr[200]={ 0 };
  3776. char str[100]={0};
  3777. int c = 0;
  3778. //int i = 0;
  3779. //char * pch;
  3780. char *loc;
  3781. char fname[200];
  3782. char comfirmstr[20]={0};
  3783. char word[1000]={0};
  3784. int clearflag = FALSE;
  3785. int chargingProfileIdIsNULL = FALSE;
  3786. int connectorIsNULL = FALSE;
  3787. int chargingProfilePurposeIsNULL = FALSE;
  3788. int stackLevelIsNULL = FALSE;
  3789. FILE *fptr1, *fptr2;
  3790. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3791. int n_chargingProfile=0;
  3792. char sLineWord[1060]={0};
  3793. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3794. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3795. //***id ****/
  3796. c = 0;
  3797. loc = strstr(payload, "id");
  3798. memset(sstr ,0, sizeof(sstr) );
  3799. if(loc == NULL)
  3800. {
  3801. chargingProfileIdIsNULL = TRUE;
  3802. }
  3803. else
  3804. {
  3805. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3806. {
  3807. sstr[c] = loc[strlen("id")+2+c];
  3808. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3809. c++;
  3810. }
  3811. sstr[c] = '\0';
  3812. chargingProfileIdInt = atoi(sstr);
  3813. }
  3814. //***connectorId ****/
  3815. c=0;
  3816. loc = strstr(payload, "connectorId");
  3817. memset(sstr ,0, sizeof(sstr) );
  3818. if(loc == NULL)
  3819. {
  3820. connectorIsNULL = TRUE;
  3821. }
  3822. else
  3823. {
  3824. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3825. {
  3826. sstr[c] = loc[strlen("connectorId")+2+c];
  3827. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3828. c++;
  3829. }
  3830. sstr[c] = '\0';
  3831. connectorIdInt = atoi(sstr);
  3832. }
  3833. //***chargingProfilePurpose ****/
  3834. loc = strstr(payload, "chargingProfilePurpose");
  3835. memset(sstr ,0, sizeof(sstr) );
  3836. c = 0;
  3837. if(loc == NULL)
  3838. {
  3839. chargingProfilePurposeIsNULL = TRUE;
  3840. }
  3841. else
  3842. {
  3843. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3844. {
  3845. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3846. c++;
  3847. }
  3848. sstr[c] = '\0';
  3849. strcpy(chargingProfilePurposeStr, sstr);
  3850. }
  3851. //***stackLevel ****/
  3852. c=0;
  3853. loc = strstr(payload, "stackLevel");
  3854. memset(sstr ,0, sizeof(sstr) );
  3855. if(loc == NULL)
  3856. {
  3857. stackLevelIsNULL = TRUE;
  3858. }
  3859. else
  3860. {
  3861. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3862. {
  3863. sstr[c] = loc[strlen("stackLevel")+2+c];
  3864. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3865. c++;
  3866. }
  3867. sstr[c] = '\0';
  3868. stackLevelInt = atoi(sstr);
  3869. }
  3870. if(connectorIsNULL == FALSE)
  3871. {
  3872. switch(connectorIdInt)
  3873. {
  3874. case 0:
  3875. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3876. {
  3877. strcpy(fname, ChargePointMaxProfile_JSON);
  3878. }
  3879. // else
  3880. // {
  3881. // strcpy(fname, TxDefaultProfile_0_JSON);
  3882. // }
  3883. break;
  3884. case 1:
  3885. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3886. {
  3887. strcpy(fname, TxDefaultProfile_1_JSON);
  3888. }
  3889. // else
  3890. // {
  3891. // strcpy(fname, TxProfile_1_JSON);
  3892. // }
  3893. break;
  3894. case 2:
  3895. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3896. {
  3897. strcpy(fname, TxDefaultProfile_2_JSON);
  3898. }
  3899. // else
  3900. // {
  3901. // strcpy(fname, TxProfile_2_JSON);
  3902. // }
  3903. break;
  3904. default:
  3905. strcpy(fname, ChargePointMaxProfile_JSON );
  3906. break;
  3907. }
  3908. }
  3909. else
  3910. {
  3911. strcpy(fname, ChargePointMaxProfile_JSON );
  3912. }
  3913. fptr1 = fopen(fname, "r");
  3914. if (!fptr1)
  3915. {
  3916. //file not exist
  3917. DEBUG_ERROR("Unable to open the input file!!\n");
  3918. fptr1 = fopen(fname, "w+");
  3919. }
  3920. fclose(fptr1);
  3921. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3922. {
  3923. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3924. goto end;
  3925. }
  3926. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3927. {
  3928. //clear the whole contents of a file in C
  3929. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3930. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3931. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3932. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3933. fclose(fopen(TxProfile_1_JSON, "w"));
  3934. fclose(fopen(TxProfile_2_JSON, "w"));
  3935. #if 0
  3936. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3937. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3938. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3939. #endif
  3940. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3941. }
  3942. else
  3943. {
  3944. fptr1 = fopen(fname, "r");
  3945. fptr2 = fopen(temp, "w+");
  3946. while(fscanf(fptr1, "%s", word) != EOF)
  3947. {
  3948. //DEBUG_INFO("word=%s\n",word);
  3949. if(strcmp(word, "chargingProfileId") == 0)
  3950. {
  3951. n_chargingProfile = n_chargingProfile + 1;
  3952. DEBUG_INFO("chargingProfileId Found\n");
  3953. }
  3954. }
  3955. rewind(fptr1);
  3956. //search Charging Profile Element
  3957. //int i= 0;
  3958. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3959. {
  3960. //*************************tempconnectorIdInt*********************************/
  3961. loc = strstr(sLineWord, "connectorId");
  3962. c = 0;
  3963. memset(sstr ,0, sizeof(sstr) );
  3964. while (loc[strlen("connectorId")+2+c] != ',')
  3965. {
  3966. sstr[c] = loc[strlen("connectorId")+2+c];
  3967. c++;
  3968. }
  3969. sstr[c] = '\0';
  3970. tempconnectorIdInt = atoi(sstr);
  3971. //chargingProfileId
  3972. c = 0;
  3973. loc = strstr(sLineWord, "chargingProfileId");
  3974. memset(sstr ,0, sizeof(sstr) );
  3975. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3976. {
  3977. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3979. c++;
  3980. }
  3981. sstr[c] = '\0';
  3982. tempchargingProfileIdInt = atoi(sstr);
  3983. //stackLevel
  3984. c = 0;
  3985. loc = strstr(sLineWord, "stackLevel");
  3986. memset(sstr ,0, sizeof(sstr) );
  3987. while (loc[strlen("stackLevel")+2+c] != ',')
  3988. {
  3989. sstr[c] = loc[strlen("stackLevel")+2+c];
  3990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3991. c++;
  3992. }
  3993. sstr[c] = '\0';
  3994. tempstackLevelInt = atoi(sstr);
  3995. c = 0;
  3996. loc = strstr(sLineWord, "chargingProfilePurpose");
  3997. memset(sstr ,0, sizeof(sstr) );
  3998. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3999. {
  4000. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4001. c++;
  4002. }
  4003. sstr[c] = '\0';
  4004. strcpy(tempchargingProfilePurposeStr, sstr);
  4005. if(chargingProfileIdIsNULL == FALSE)
  4006. {
  4007. if(tempchargingProfileIdInt == chargingProfileIdInt)
  4008. {
  4009. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  4010. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4011. clearflag = TRUE;
  4012. continue;
  4013. }
  4014. else
  4015. {
  4016. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  4017. //json_object_array_add(newHeatMap, jsonitem);
  4018. fprintf(fptr2, sLineWord);//writing data into file
  4019. }
  4020. }
  4021. else
  4022. {
  4023. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  4024. {
  4025. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  4026. {
  4027. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4028. clearflag = TRUE;
  4029. continue;
  4030. }
  4031. }
  4032. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4033. {
  4034. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  4035. {
  4036. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  4037. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  4038. {
  4039. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4040. clearflag = TRUE;
  4041. continue;
  4042. }
  4043. }
  4044. }
  4045. else
  4046. {
  4047. //json_object_array_add(newHeatMap, jsonitem);
  4048. fprintf(fptr2, sLineWord);//writing data into file
  4049. }
  4050. }
  4051. memset(sLineWord, 0, sizeof sLineWord);
  4052. }
  4053. if(clearflag == FALSE)
  4054. {
  4055. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4056. goto end;
  4057. }
  4058. fclose(fptr1);
  4059. fclose(fptr2);
  4060. sprintf(str,"rm -f %s",fname);
  4061. system(str);
  4062. resultRename = rename(temp, fname);
  4063. if(resultRename == 0)
  4064. {
  4065. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4066. }
  4067. else
  4068. {
  4069. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4070. }
  4071. }
  4072. end:
  4073. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4074. return result;
  4075. }
  4076. int handleDataTransferRequest(char *uuid, char *payload)
  4077. {
  4078. mtrace();
  4079. int result = FAIL;
  4080. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4081. char tempvendorId[255]={0};
  4082. char tempmessageId[50]={0};
  4083. char tempdata[50]={0};
  4084. char sstr[160]={0};//sstr[200]={ 0 };
  4085. char message[80]={0};
  4086. int c = 0;
  4087. char *loc;
  4088. DEBUG_INFO("handle DataTransferRequest\n");
  4089. if((uuid != NULL) && (payload != NULL))
  4090. {
  4091. //===============================
  4092. // vendorId
  4093. //===============================
  4094. c = 0;
  4095. loc = strstr(payload, "vendorId");
  4096. while (loc[strlen("vendorId")+3+c] != '\"')
  4097. {
  4098. sstr[c] = loc[strlen("vendorId")+3+c];
  4099. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4100. c++;
  4101. }
  4102. sstr[c] = '\0';
  4103. strcpy(tempvendorId,sstr);
  4104. //===============================
  4105. // messageId
  4106. //===============================
  4107. memset(sstr ,0, sizeof(sstr) );
  4108. c = 0;
  4109. loc = strstr(payload, "messageId");
  4110. while (loc[strlen("messageId")+3+c] != '\"')
  4111. {
  4112. sstr[c] = loc[strlen("messageId")+3+c];
  4113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4114. c++;
  4115. }
  4116. sstr[c] = '\0';
  4117. strcpy(tempmessageId,sstr);
  4118. //===============================
  4119. // data
  4120. //===============================
  4121. memset(sstr ,0, sizeof(sstr) );
  4122. c = 0;
  4123. loc = strstr(payload, "data");
  4124. printf("loc=%s\n",loc);
  4125. while (loc[strlen("data")+3+c] != '\"')
  4126. {
  4127. sstr[c] = loc[strlen("data")+3+c];
  4128. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4129. c++;
  4130. }
  4131. sstr[c] = '\0';
  4132. strcpy(tempdata,sstr);
  4133. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4134. }
  4135. else
  4136. {
  4137. char guid[37]={0};
  4138. random_uuid(guid);
  4139. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4140. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4141. }
  4142. LWS_Send(message);
  4143. return result;
  4144. }
  4145. #if 0
  4146. long long diff_tm(struct tm *a, struct tm *b) {
  4147. return a->tm_sec - b->tm_sec
  4148. + 60LL * (a->tm_min - b->tm_min)
  4149. + 3600LL * (a->tm_hour - b->tm_hour)
  4150. + 86400LL * (a->tm_yday - b->tm_yday)
  4151. + (a->tm_year - 70) * 31536000LL
  4152. - (a->tm_year - 69) / 4 * 86400LL
  4153. + (a->tm_year - 1) / 100 * 86400LL
  4154. - (a->tm_year + 299) / 400 * 86400LL
  4155. - (b->tm_year - 70) * 31536000LL
  4156. + (b->tm_year - 69) / 4 * 86400LL
  4157. - (b->tm_year - 1) / 100 * 86400LL
  4158. + (b->tm_year + 299) /400 * 86400LL;
  4159. }
  4160. #endif
  4161. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4162. {
  4163. mtrace();
  4164. int result = FAIL;
  4165. int connectorIdInt, durationInt;
  4166. char chargingRateUnitStr[4]={0};
  4167. //int tempconnectorIdInt,
  4168. int tempdurationInt;
  4169. float tempminChargingRateFloat = 0.0;
  4170. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4171. int tempStartPeriodInt=0;
  4172. float tempLimitInt=0.0;//0.1;
  4173. int tempNumberPhasesInt=0;
  4174. char fname[200];
  4175. char comfirmstr[20];
  4176. //float totallimit =0.0;
  4177. float MinChargingRate =0.0;
  4178. //double diff_t;
  4179. //struct tm tp;
  4180. FILE *fptr1;
  4181. int c = 0;
  4182. //int i = 0;
  4183. char * pch;
  4184. char *loc;
  4185. char sstr[200]={ 0 };
  4186. int n_chargingProfile = 0;
  4187. int n_SchedulePeriods = 0;
  4188. char SchedulePeriodList[10][200]={0};
  4189. char sLineWord[800]={0};
  4190. //int n_periods = 0;
  4191. char word[1000]={0};
  4192. int confirmPeriods = 0;
  4193. struct StructProfile ChargePointMaxProfile;
  4194. struct StructProfile TxDefaultProfile;
  4195. struct StructProfile TxProfile;
  4196. struct StructProfile TxDefaultProfiletemp[2]={0};
  4197. int TxDefaultProfileFileIsNull=FALSE;
  4198. int ChargePointMaxProfileIsNull=FALSE;
  4199. int TxProfileIsNull=FALSE;
  4200. int CompositeSceduleIndex = 0;
  4201. char ChargePointMaxProfileScheduleStr[30]={0};
  4202. char TxDefaultProfileScheduleStr[30]={0};
  4203. char TxProfileScheduleStr[30]={0};
  4204. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4205. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4206. memset(&TxProfile,0,sizeof(struct StructProfile));
  4207. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4208. c=0;
  4209. loc = strstr(payload, "connectorId");
  4210. memset(sstr ,0, sizeof(sstr) );
  4211. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4212. {
  4213. sstr[c] = loc[strlen("connectorId")+2+c];
  4214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4215. c++;
  4216. }
  4217. sstr[c] = '\0';
  4218. connectorIdInt = atoi(sstr);
  4219. c=0;
  4220. loc = strstr(payload, "duration");
  4221. memset(sstr ,0, sizeof(sstr) );
  4222. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4223. {
  4224. sstr[c] = loc[strlen("duration")+2+c];
  4225. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4226. c++;
  4227. }
  4228. sstr[c] = '\0';
  4229. durationInt = atoi(sstr);
  4230. c = 0;
  4231. loc = strstr(payload, "chargingRateUnit");
  4232. memset(sstr ,0, sizeof(sstr) );
  4233. if(loc == NULL)
  4234. {
  4235. }
  4236. else
  4237. {
  4238. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4239. {
  4240. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4241. c++;
  4242. }
  4243. sstr[c] = '\0';
  4244. strcpy(chargingRateUnitStr, sstr);
  4245. }
  4246. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4247. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4248. if(connectorIdInt==0) // connectorId is 0
  4249. {
  4250. //******************************ChargePointMaxProfile*****************************************************/
  4251. strcpy(fname, ChargePointMaxProfile_JSON );
  4252. char word[30]={0};
  4253. char sLineWord[1060]={0};
  4254. int n_chargingProfile=0;
  4255. ChargePointMaxProfileIsNull=TRUE;
  4256. if((access(fname,F_OK))!=-1)
  4257. {
  4258. fptr1 = fopen(fname, "r");
  4259. int c;
  4260. c = fgetc(fptr1);
  4261. //DEBUG_INFO("c:%d\n",c);
  4262. rewind(fptr1);
  4263. if(c == EOF)
  4264. {
  4265. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4266. ChargePointMaxProfileIsNull=TRUE;
  4267. fclose(fptr1);
  4268. }
  4269. else
  4270. {
  4271. ChargePointMaxProfileIsNull=FALSE;
  4272. while(fscanf(fptr1, "%s", word) != EOF)
  4273. {
  4274. if(strcmp(word, "chargingProfileId") == 0)
  4275. {
  4276. n_chargingProfile = n_chargingProfile + 1;
  4277. printf("Found\n");
  4278. }
  4279. }
  4280. rewind(fptr1);
  4281. //search Charging Profile Element
  4282. int i= 0;
  4283. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4284. #if 0
  4285. /***********connectorId****************/
  4286. c = 0;
  4287. loc = strstr(sLineWord, "connectorId");
  4288. // printf("loc=%s\n",loc);
  4289. memset(sstr ,0, sizeof(sstr) );
  4290. while (loc[strlen("connectorId")+2+c] != ',')
  4291. {
  4292. sstr[c] = loc[strlen("connectorId")+2+c];
  4293. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4294. c++;
  4295. }
  4296. sstr[c] = '\0';
  4297. tempconnectorIdInt = atoi(sstr);
  4298. #endif
  4299. //***********validFrom**************/
  4300. c = 0;
  4301. loc = strstr(sLineWord, "validFrom");
  4302. //DEBUG_INFO("loc=%s\n",loc);
  4303. memset(sstr ,0, sizeof(sstr) );
  4304. if(loc != NULL)
  4305. {
  4306. while (loc[3+strlen("validFrom")+c] != '\"')
  4307. {
  4308. sstr[c] = loc[3+strlen("validFrom")+c];
  4309. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4310. c++;
  4311. }
  4312. sstr[c] = '\0';
  4313. DEBUG_INFO("validFrom=%s\n",sstr);
  4314. strcpy(tempvalidFromStr,sstr);
  4315. }
  4316. else
  4317. {
  4318. strcpy(tempvalidFromStr,"");
  4319. }
  4320. //**********startSchedule**********/
  4321. c = 0;
  4322. loc = strstr(sLineWord, "startSchedule");
  4323. //DEBUG_INFO("loc=%s\n",loc);
  4324. memset(sstr ,0, sizeof(sstr) );
  4325. while (loc[3+strlen("startSchedule")+c] != '\"')
  4326. {
  4327. sstr[c] = loc[3+strlen("startSchedule")+c];
  4328. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4329. c++;
  4330. }
  4331. sstr[c] = '\0';
  4332. strcpy(tempstartScheduleStr, sstr);
  4333. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4334. //**********chargingRateUnit**********/
  4335. c = 0;
  4336. loc = strstr(sLineWord, "chargingRateUnit");
  4337. memset(sstr ,0, sizeof(sstr) );
  4338. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4339. {
  4340. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4341. c++;
  4342. }
  4343. sstr[c] = '\0';
  4344. strcpy(tempchargingRateUnitStr, sstr);
  4345. //**********minChargingRate*******/
  4346. c = 0;
  4347. loc = strstr(sLineWord, "minChargingRate");
  4348. //printf("loc=%s\n",loc);
  4349. if(loc != NULL)
  4350. {
  4351. memset(sstr ,0, sizeof(sstr) );
  4352. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4353. {
  4354. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4356. c++;
  4357. }
  4358. sstr[c] = '\0';
  4359. tempminChargingRateFloat = atof(sstr);
  4360. }
  4361. else
  4362. {
  4363. tempminChargingRateFloat = 0.0;
  4364. }
  4365. //
  4366. #if 0
  4367. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4368. tp.tm_isdst = -1;
  4369. time_t utc = mktime(&tp);
  4370. // current time
  4371. time_t t = time(NULL);
  4372. #endif
  4373. //diff_t = difftime(t, utc);
  4374. //parsing strings to words
  4375. i = 0;
  4376. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4377. loc = loc+3+strlen("chargingSchedulePeriod");
  4378. pch = strtok(loc ,"{");
  4379. while (pch != NULL)
  4380. {
  4381. strcpy(SchedulePeriodList[i], pch);
  4382. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4383. //printf ("%s\n",pch);
  4384. pch = strtok (NULL, "{");
  4385. i = i + 1;
  4386. }
  4387. n_SchedulePeriods = i;
  4388. for(int i=0;i<n_SchedulePeriods;i++)
  4389. {
  4390. //*************startPeriod****************/
  4391. c = 0;
  4392. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4393. memset(sstr ,0, sizeof(sstr) );
  4394. while (loc[strlen("startPeriod")+2+c] != ',')
  4395. {
  4396. sstr[c] = loc[strlen("startPeriod")+2+c];
  4397. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4398. c++;
  4399. }
  4400. sstr[c] = '\0';
  4401. tempStartPeriodInt = atoi(sstr);
  4402. //*************limit****************/
  4403. c = 0;
  4404. loc = strstr(SchedulePeriodList[i], "limit");
  4405. memset(sstr ,0, sizeof(sstr) );
  4406. while (loc[strlen("limit")+2+c] != ',')
  4407. {
  4408. sstr[c] = loc[strlen("limit")+2+c];
  4409. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4410. c++;
  4411. }
  4412. sstr[c] = '\0';
  4413. tempLimitInt = atof(sstr);
  4414. //*************numberPhases****************/
  4415. c = 0;
  4416. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4417. memset(sstr ,0, sizeof(sstr) );
  4418. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4419. {
  4420. sstr[c] = loc[strlen("numberPhases")+2+c];
  4421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4422. c++;
  4423. }
  4424. sstr[c] = '\0';
  4425. tempNumberPhasesInt = atoi(sstr);
  4426. ChargePointMaxProfile.Duration = durationInt;
  4427. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4428. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4429. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4430. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4431. }
  4432. if(MinChargingRate < tempminChargingRateFloat)
  4433. MinChargingRate = tempminChargingRateFloat;
  4434. }
  4435. }// End of file ChargingProfile
  4436. } //THE END OF ACCESS ChargePointMaxProfile
  4437. //******************************TxDefaultProfile***********************************************/
  4438. strcpy(fname, TxDefaultProfile_0_JSON);
  4439. memset(word, 0, 30);
  4440. memset(sLineWord, 0, 1060);
  4441. //char word[30]={0};
  4442. //char sLineWord[1060]={0};
  4443. n_chargingProfile=0;
  4444. TxDefaultProfileFileIsNull=TRUE;
  4445. if((access(fname,F_OK))!=-1)
  4446. {
  4447. fptr1 = fopen(fname, "r");
  4448. c = 0;
  4449. c = fgetc(fptr1);
  4450. //DEBUG_INFO("c:%d\n",c);
  4451. rewind(fptr1);
  4452. if(c == EOF)
  4453. {
  4454. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4455. TxDefaultProfileFileIsNull=TRUE;
  4456. fclose(fptr1);
  4457. }
  4458. else
  4459. {
  4460. TxDefaultProfileFileIsNull=FALSE;
  4461. while(fscanf(fptr1, "%s", word) != EOF)
  4462. {
  4463. if(strcmp(word, "chargingProfileId") == 0)
  4464. {
  4465. n_chargingProfile = n_chargingProfile + 1;
  4466. printf("Found\n");
  4467. }
  4468. }
  4469. rewind(fptr1);
  4470. //search Charging Profile Element
  4471. int i= 0;
  4472. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4473. #if 0
  4474. /***********connectorId****************/
  4475. c = 0;
  4476. loc = strstr(sLineWord, "connectorId");
  4477. // printf("loc=%s\n",loc);
  4478. memset(sstr ,0, sizeof(sstr) );
  4479. while (loc[strlen("connectorId")+2+c] != ',')
  4480. {
  4481. sstr[c] = loc[strlen("connectorId")+2+c];
  4482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4483. c++;
  4484. }
  4485. sstr[c] = '\0';
  4486. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4487. tempconnectorIdInt = atoi(sstr);
  4488. #endif
  4489. //***********validFrom**************/
  4490. c = 0;
  4491. loc = strstr(sLineWord, "validFrom");
  4492. //DEBUG_INFO("loc=%s\n",loc);
  4493. memset(sstr ,0, sizeof(sstr) );
  4494. if(loc != NULL)
  4495. {
  4496. while (loc[3+strlen("validFrom")+c] != '\"')
  4497. {
  4498. sstr[c] = loc[3+strlen("validFrom")+c];
  4499. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4500. c++;
  4501. }
  4502. sstr[c] = '\0';
  4503. DEBUG_INFO("validFrom=%s\n",sstr);
  4504. strcpy(tempvalidFromStr,sstr);
  4505. }
  4506. else
  4507. {
  4508. strcpy(tempvalidFromStr,"");
  4509. }
  4510. //**********startSchedule**********/
  4511. c = 0;
  4512. loc = strstr(sLineWord, "startSchedule");
  4513. //DEBUG_INFO("loc=%s\n",loc);
  4514. memset(sstr ,0, sizeof(sstr) );
  4515. while (loc[3+strlen("startSchedule")+c] != '\"')
  4516. {
  4517. sstr[c] = loc[3+strlen("startSchedule")+c];
  4518. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4519. c++;
  4520. }
  4521. sstr[c] = '\0';
  4522. strcpy(tempstartScheduleStr, sstr);
  4523. strcpy(TxDefaultProfileScheduleStr, sstr);
  4524. DEBUG_INFO(" debug 3-1\n");
  4525. //**********chargingRateUnit**********/
  4526. c = 0;
  4527. loc = strstr(sLineWord, "chargingRateUnit");
  4528. memset(sstr ,0, sizeof(sstr) );
  4529. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4530. {
  4531. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4532. c++;
  4533. }
  4534. sstr[c] = '\0';
  4535. strcpy(tempchargingRateUnitStr, sstr);
  4536. //**********minChargingRate*******/
  4537. c = 0;
  4538. loc = strstr(sLineWord, "minChargingRate");
  4539. //printf("loc=%s\n",loc);
  4540. if(loc != NULL)
  4541. {
  4542. memset(sstr ,0, sizeof(sstr) );
  4543. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4544. {
  4545. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4546. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4547. c++;
  4548. }
  4549. sstr[c] = '\0';
  4550. tempminChargingRateFloat = atof(sstr);
  4551. }
  4552. else
  4553. {
  4554. tempminChargingRateFloat = 0.0;
  4555. }
  4556. #if 0
  4557. //
  4558. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4559. tp.tm_isdst = -1;
  4560. time_t utc = mktime(&tp);
  4561. // current time
  4562. time_t t = time(NULL);
  4563. //diff_t = difftime(t, utc);
  4564. #endif
  4565. //parsing strings to words
  4566. i = 0;
  4567. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4568. loc = loc+3+strlen("chargingSchedulePeriod");
  4569. pch = strtok(loc ,"{");
  4570. while (pch != NULL)
  4571. {
  4572. strcpy(SchedulePeriodList[i], pch);
  4573. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4574. //printf ("%s\n",pch);
  4575. pch = strtok (NULL, "{");
  4576. i = i + 1;
  4577. }
  4578. n_SchedulePeriods = i;
  4579. for(int i=0;i<n_SchedulePeriods;i++)
  4580. {
  4581. //*************startPeriod****************/
  4582. c = 0;
  4583. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4584. memset(sstr ,0, sizeof(sstr) );
  4585. while (loc[strlen("startPeriod")+2+c] != ',')
  4586. {
  4587. sstr[c] = loc[strlen("startPeriod")+2+c];
  4588. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4589. c++;
  4590. }
  4591. sstr[c] = '\0';
  4592. tempStartPeriodInt = atoi(sstr);
  4593. //*************limit****************/
  4594. c = 0;
  4595. loc = strstr(SchedulePeriodList[i], "limit");
  4596. memset(sstr ,0, sizeof(sstr) );
  4597. while (loc[strlen("limit")+2+c] != ',')
  4598. {
  4599. sstr[c] = loc[strlen("limit")+2+c];
  4600. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4601. c++;
  4602. }
  4603. sstr[c] = '\0';
  4604. tempLimitInt = atof(sstr);
  4605. //*************numberPhases****************/
  4606. c = 0;
  4607. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4608. memset(sstr ,0, sizeof(sstr) );
  4609. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4610. {
  4611. sstr[c] = loc[strlen("numberPhases")+2+c];
  4612. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4613. c++;
  4614. }
  4615. sstr[c] = '\0';
  4616. tempNumberPhasesInt = atoi(sstr);
  4617. TxDefaultProfile.Duration = durationInt;
  4618. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4619. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4620. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4621. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4622. }
  4623. if(MinChargingRate < tempminChargingRateFloat)
  4624. MinChargingRate = tempminChargingRateFloat;
  4625. }
  4626. }
  4627. }// the end of ACCESS TxDefaultProfile
  4628. // Composite Schedule
  4629. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4630. {
  4631. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4632. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4633. {
  4634. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4635. {
  4636. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4637. }
  4638. else
  4639. {
  4640. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4641. }
  4642. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4643. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4644. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4645. }
  4646. }
  4647. //* Define temporary variables */
  4648. struct tm *gtime;
  4649. time_t now;
  4650. char buf[28];
  4651. /* Read the current system time */
  4652. time(&now);
  4653. /* Convert the system time to GMT (now UTC) */
  4654. gtime = gmtime(&now);
  4655. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4656. // make .conf
  4657. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4658. //MaxChargingProfilesInstalled is 10
  4659. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4660. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4661. //nPeriod = 1;
  4662. if(chargingRateUnitStr[0] != 0)
  4663. {
  4664. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4665. }
  4666. else
  4667. {
  4668. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4669. }
  4670. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4671. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4672. confirmPeriods = 1;
  4673. }
  4674. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4675. {
  4676. //*****************************ChargePointMaxProfile******************************************/
  4677. strcpy(fname, ChargePointMaxProfile_JSON);
  4678. ChargePointMaxProfileIsNull=TRUE;
  4679. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4680. {
  4681. fptr1 = fopen(fname, "r");
  4682. int c;
  4683. c = fgetc(fptr1);
  4684. //DEBUG_INFO("c:%d\n",c);
  4685. rewind(fptr1);
  4686. if(c == EOF)
  4687. {
  4688. DEBUG_INFO("\n End of file reached.");
  4689. ChargePointMaxProfileIsNull=TRUE;
  4690. fclose(fptr1);
  4691. }
  4692. else
  4693. {
  4694. ChargePointMaxProfileIsNull=FALSE;
  4695. while(fscanf(fptr1, "%s", word) != EOF)
  4696. {
  4697. if(strcmp(word, "chargingProfileId") == 0)
  4698. {
  4699. n_chargingProfile = n_chargingProfile + 1;
  4700. }
  4701. }
  4702. rewind(fptr1);
  4703. //search Charging Profile Element
  4704. int i = 0;
  4705. int j = 0;
  4706. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4707. #if 0
  4708. /***********connectorId****************/
  4709. c = 0;
  4710. loc = strstr(sLineWord, "connectorId");
  4711. memset(sstr ,0, sizeof(sstr) );
  4712. while (loc[strlen("connectorId")+2+c] != ',')
  4713. {
  4714. sstr[c] = loc[strlen("connectorId")+2+c];
  4715. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4716. c++;
  4717. }
  4718. sstr[c] = '\0';
  4719. tempconnectorIdInt = atoi(sstr);
  4720. #endif
  4721. //***********validFrom**************/
  4722. c = 0;
  4723. loc = strstr(sLineWord, "validFrom");
  4724. if(loc != NULL)
  4725. {
  4726. memset(sstr ,0, sizeof(sstr) );
  4727. while (loc[3+strlen("validFrom")+c] != '\"')
  4728. {
  4729. sstr[c] = loc[3+strlen("validFrom")+c];
  4730. c++;
  4731. }
  4732. sstr[c] = '\0';
  4733. strcpy(tempvalidFromStr,sstr);
  4734. }
  4735. else
  4736. {
  4737. strcpy(tempvalidFromStr,"");
  4738. }
  4739. //***********validFrom**************/
  4740. c = 0;
  4741. loc = strstr(sLineWord, "duration");
  4742. if(loc != NULL)
  4743. {
  4744. memset(sstr ,0, sizeof(sstr) );
  4745. while (loc[2+strlen("duration")+c] != ',')
  4746. {
  4747. sstr[c] = loc[2+strlen("duration")+c];
  4748. c++;
  4749. }
  4750. sstr[c] = '\0';
  4751. tempdurationInt = atoi(sstr);
  4752. }
  4753. else
  4754. {
  4755. tempdurationInt = 0;
  4756. }
  4757. //**********startSchedule**********/
  4758. c = 0;
  4759. loc = strstr(sLineWord, "startSchedule");
  4760. memset(sstr ,0, sizeof(sstr) );
  4761. while (loc[3+strlen("startSchedule")+c] != '\"')
  4762. {
  4763. sstr[c] = loc[3+strlen("startSchedule")+c];
  4764. c++;
  4765. }
  4766. sstr[c] = '\0';
  4767. strcpy(tempstartScheduleStr, sstr);
  4768. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4769. //**********chargingRateUnit**********/
  4770. c = 0;
  4771. loc = strstr(sLineWord, "chargingRateUnit");
  4772. memset(sstr ,0, sizeof(sstr) );
  4773. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4774. {
  4775. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4776. c++;
  4777. }
  4778. sstr[c] = '\0';
  4779. strcpy(tempchargingRateUnitStr, sstr);
  4780. //**********minChargingRate*******/
  4781. c = 0;
  4782. loc = strstr(sLineWord, "minChargingRate");
  4783. if(loc != NULL)
  4784. {
  4785. memset(sstr ,0, sizeof(sstr) );
  4786. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4787. {
  4788. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4789. c++;
  4790. }
  4791. sstr[c] = '\0';
  4792. tempminChargingRateFloat = atof(sstr);
  4793. }
  4794. else
  4795. {
  4796. tempminChargingRateFloat = 0.0;
  4797. }
  4798. #if 0
  4799. //
  4800. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4801. tp.tm_isdst = -1;
  4802. time_t utc = mktime(&tp);
  4803. time_t t = time(NULL);
  4804. //diff_t = difftime(t, utc);
  4805. #endif
  4806. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4807. //DEBUG_INFO(" debug 5 -1\n");
  4808. //parsing strings to words
  4809. i = 0;
  4810. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4811. loc = loc+3+strlen("chargingSchedulePeriod");
  4812. pch = strtok(loc ,"{");
  4813. while (pch != NULL)
  4814. {
  4815. strcpy(SchedulePeriodList[i], pch);
  4816. pch = strtok (NULL, "{");
  4817. i = i + 1;
  4818. }
  4819. n_SchedulePeriods = i;
  4820. for(int i=0;i<n_SchedulePeriods;i++)
  4821. {
  4822. //*************startPeriod****************/
  4823. c = 0;
  4824. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4825. memset(sstr ,0, sizeof(sstr) );
  4826. while (loc[strlen("startPeriod")+2+c] != ',')
  4827. {
  4828. sstr[c] = loc[strlen("startPeriod")+2+c];
  4829. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4830. c++;
  4831. }
  4832. sstr[c] = '\0';
  4833. tempStartPeriodInt = atoi(sstr);
  4834. //*************limit****************/
  4835. c = 0;
  4836. loc = strstr(SchedulePeriodList[i], "limit");
  4837. memset(sstr ,0, sizeof(sstr) );
  4838. while (loc[strlen("limit")+2+c] != ',')
  4839. {
  4840. sstr[c] = loc[strlen("limit")+2+c];
  4841. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4842. c++;
  4843. }
  4844. sstr[c] = '\0';
  4845. tempLimitInt = atof(sstr);
  4846. //*************numberPhases****************/
  4847. c = 0;
  4848. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4849. memset(sstr ,0, sizeof(sstr) );
  4850. while (loc[strlen("numberPhases")+2+c] != '}')
  4851. {
  4852. sstr[c] = loc[strlen("numberPhases")+2+c];
  4853. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4854. c++;
  4855. }
  4856. sstr[c] = '\0';
  4857. tempNumberPhasesInt = atoi(sstr);
  4858. if(j == 0)
  4859. {
  4860. ChargePointMaxProfile.Duration = tempdurationInt;
  4861. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4862. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4863. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4864. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4865. }
  4866. }
  4867. if(MinChargingRate < tempminChargingRateFloat)
  4868. {
  4869. MinChargingRate = tempminChargingRateFloat;
  4870. }
  4871. if(confirmPeriods < n_SchedulePeriods)
  4872. {
  4873. confirmPeriods = n_SchedulePeriods;
  4874. }
  4875. j = j + 1;
  4876. }
  4877. fclose(fptr1);
  4878. }
  4879. }// the end of access file ChargePointMaxProfile
  4880. //****************************TxDefaultProfile************************************************/
  4881. switch(connectorIdInt)
  4882. {
  4883. case 0:
  4884. break;
  4885. case 1:
  4886. strcpy(fname, TxDefaultProfile_1_JSON );
  4887. break;
  4888. case 2:
  4889. strcpy(fname, TxDefaultProfile_2_JSON );
  4890. break;
  4891. default:
  4892. strcpy(fname, TxDefaultProfile_1_JSON );
  4893. break;
  4894. }
  4895. TxDefaultProfileFileIsNull=TRUE;
  4896. if((access(fname,F_OK))!=-1)
  4897. {
  4898. fptr1 = fopen(fname, "r");
  4899. c = 0;
  4900. c = fgetc(fptr1);
  4901. //DEBUG_INFO("c:%d\n",c);
  4902. rewind(fptr1);
  4903. if(c == EOF)
  4904. {
  4905. DEBUG_INFO("\n End of file reached.");
  4906. TxDefaultProfileFileIsNull=TRUE;
  4907. fclose(fptr1);
  4908. }
  4909. else
  4910. {
  4911. TxDefaultProfileFileIsNull=FALSE;
  4912. while(fscanf(fptr1, "%s", word) != EOF)
  4913. {
  4914. if(strcmp(word, "chargingProfileId") == 0)
  4915. {
  4916. n_chargingProfile = n_chargingProfile + 1;
  4917. }
  4918. }
  4919. rewind(fptr1);
  4920. //search Charging Profile Element
  4921. int i = 0;
  4922. int j = 0;
  4923. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4924. //DEBUG_INFO(" 1-1\n");
  4925. #if 0
  4926. /***********connectorId****************/
  4927. c = 0;
  4928. loc = strstr(sLineWord, "connectorId");
  4929. memset(sstr ,0, sizeof(sstr) );
  4930. while (loc[strlen("connectorId")+2+c] != ',')
  4931. {
  4932. sstr[c] = loc[strlen("connectorId")+2+c];
  4933. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4934. c++;
  4935. }
  4936. sstr[c] = '\0';
  4937. tempconnectorIdInt = atoi(sstr);
  4938. #endif
  4939. //***********validFrom**************/
  4940. c = 0;
  4941. loc = strstr(sLineWord, "validFrom");
  4942. if(loc != NULL)
  4943. {
  4944. memset(sstr ,0, sizeof(sstr) );
  4945. while (loc[3+strlen("validFrom")+c] != '\"')
  4946. {
  4947. sstr[c] = loc[3+strlen("validFrom")+c];
  4948. c++;
  4949. }
  4950. sstr[c] = '\0';
  4951. strcpy(tempvalidFromStr,sstr);
  4952. }
  4953. else
  4954. {
  4955. strcpy(tempvalidFromStr,"");
  4956. }
  4957. //***********validFrom**************/
  4958. c = 0;
  4959. loc = strstr(sLineWord, "duration");
  4960. if(loc != NULL)
  4961. {
  4962. memset(sstr ,0, sizeof(sstr) );
  4963. while (loc[2+strlen("duration")+c] != ',')
  4964. {
  4965. sstr[c] = loc[2+strlen("duration")+c];
  4966. c++;
  4967. }
  4968. sstr[c] = '\0';
  4969. tempdurationInt = atoi(sstr);
  4970. }
  4971. else
  4972. {
  4973. tempdurationInt = 0;
  4974. }
  4975. //**********startSchedule**********/
  4976. c = 0;
  4977. loc = strstr(sLineWord, "startSchedule");
  4978. memset(sstr ,0, sizeof(sstr) );
  4979. while (loc[3+strlen("startSchedule")+c] != '\"')
  4980. {
  4981. sstr[c] = loc[3+strlen("startSchedule")+c];
  4982. c++;
  4983. }
  4984. sstr[c] = '\0';
  4985. strcpy(tempstartScheduleStr, sstr);
  4986. strcpy(TxDefaultProfileScheduleStr, sstr);
  4987. //**********chargingRateUnit**********/
  4988. c = 0;
  4989. loc = strstr(sLineWord, "chargingRateUnit");
  4990. memset(sstr ,0, sizeof(sstr) );
  4991. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4992. {
  4993. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4994. c++;
  4995. }
  4996. sstr[c] = '\0';
  4997. strcpy(tempchargingRateUnitStr, sstr);
  4998. //**********minChargingRate*******/
  4999. c = 0;
  5000. loc = strstr(sLineWord, "minChargingRate");
  5001. if(loc != NULL)
  5002. {
  5003. memset(sstr ,0, sizeof(sstr) );
  5004. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5005. {
  5006. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5007. c++;
  5008. }
  5009. sstr[c] = '\0';
  5010. tempminChargingRateFloat = atof(sstr);
  5011. }
  5012. else
  5013. {
  5014. tempminChargingRateFloat = 0.0;
  5015. }
  5016. #if 0
  5017. //
  5018. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5019. tp.tm_isdst = -1;
  5020. time_t utc = mktime(&tp);
  5021. time_t t = time(NULL);
  5022. //diff_t = difftime(t, utc);
  5023. #endif
  5024. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5025. //parsing strings to words
  5026. i = 0;
  5027. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5028. loc = loc+3+strlen("chargingSchedulePeriod");
  5029. pch = strtok(loc ,"{");
  5030. while (pch != NULL)
  5031. {
  5032. strcpy(SchedulePeriodList[i], pch);
  5033. pch = strtok (NULL, "{");
  5034. i = i + 1;
  5035. }
  5036. n_SchedulePeriods = i;
  5037. for(int i=0;i<n_SchedulePeriods;i++)
  5038. {
  5039. //*************startPeriod****************/
  5040. c = 0;
  5041. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5042. memset(sstr ,0, sizeof(sstr) );
  5043. while (loc[strlen("startPeriod")+2+c] != ',')
  5044. {
  5045. sstr[c] = loc[strlen("startPeriod")+2+c];
  5046. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5047. c++;
  5048. }
  5049. sstr[c] = '\0';
  5050. tempStartPeriodInt = atoi(sstr);
  5051. //*************limit****************/
  5052. c = 0;
  5053. loc = strstr(SchedulePeriodList[i], "limit");
  5054. memset(sstr ,0, sizeof(sstr) );
  5055. while (loc[strlen("limit")+2+c] != ',')
  5056. {
  5057. sstr[c] = loc[strlen("limit")+2+c];
  5058. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5059. c++;
  5060. }
  5061. sstr[c] = '\0';
  5062. tempLimitInt = atof(sstr);
  5063. //*************numberPhases****************/
  5064. c = 0;
  5065. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5066. memset(sstr ,0, sizeof(sstr) );
  5067. while (loc[strlen("numberPhases")+2+c] != '}')
  5068. {
  5069. sstr[c] = loc[strlen("numberPhases")+2+c];
  5070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5071. c++;
  5072. }
  5073. sstr[c] = '\0';
  5074. tempNumberPhasesInt = atoi(sstr);
  5075. if(j == 0)
  5076. {
  5077. TxDefaultProfile.Duration = tempdurationInt;
  5078. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5079. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5080. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5081. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5082. }
  5083. else
  5084. {
  5085. //other stack level charging Profile
  5086. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5087. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5088. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5089. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5090. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5091. }
  5092. }
  5093. if(MinChargingRate < tempminChargingRateFloat)
  5094. MinChargingRate = tempminChargingRateFloat;
  5095. if(confirmPeriods < n_SchedulePeriods)
  5096. confirmPeriods = n_SchedulePeriods;
  5097. j = j + 1;
  5098. //DEBUG_INFO(" 1-2\n");
  5099. }
  5100. fclose(fptr1);
  5101. //Stacking Charging Profiles
  5102. for(int l=0; l <(j-1) ;l++)
  5103. {
  5104. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5105. {
  5106. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5107. {
  5108. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5109. {
  5110. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5111. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5112. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5113. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5114. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5115. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5116. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5117. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5118. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5119. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5120. }
  5121. else
  5122. {
  5123. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5124. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5125. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5126. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5127. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5128. }
  5129. }
  5130. }
  5131. }
  5132. //end of Stacking Charging Profiles
  5133. }
  5134. }// the end of ACCESS TxDefaultProfile
  5135. //****************************TxProfile************************************************/
  5136. switch(connectorIdInt)
  5137. {
  5138. case 0:
  5139. break;
  5140. case 1:
  5141. strcpy(fname, TxProfile_1_JSON );
  5142. break;
  5143. case 2:
  5144. strcpy(fname, TxProfile_2_JSON );
  5145. break;
  5146. default:
  5147. strcpy(fname, TxProfile_1_JSON );
  5148. break;
  5149. }
  5150. TxProfileIsNull=TRUE;
  5151. if((access(fname,F_OK))!=-1)
  5152. {
  5153. fptr1 = fopen(fname, "r");
  5154. c = 0;
  5155. c = fgetc(fptr1);
  5156. //DEBUG_INFO("c:%d\n",c);
  5157. rewind(fptr1);
  5158. if(c == EOF)
  5159. {
  5160. DEBUG_INFO("\n End of file reached.");
  5161. TxProfileIsNull=TRUE;
  5162. fclose(fptr1);
  5163. }
  5164. else
  5165. {
  5166. TxProfileIsNull=FALSE;
  5167. while(fscanf(fptr1, "%s", word) != EOF)
  5168. {
  5169. if(strcmp(word, "chargingProfileId") == 0)
  5170. {
  5171. n_chargingProfile = n_chargingProfile + 1;
  5172. }
  5173. }
  5174. rewind(fptr1);
  5175. //search Charging Profile Element
  5176. int i= 0;
  5177. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5178. #if 0
  5179. /***********connectorId****************/
  5180. c = 0;
  5181. loc = strstr(sLineWord, "connectorId");
  5182. memset(sstr ,0, sizeof(sstr) );
  5183. while (loc[strlen("connectorId")+2+c] != ',')
  5184. {
  5185. sstr[c] = loc[strlen("connectorId")+2+c];
  5186. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5187. c++;
  5188. }
  5189. sstr[c] = '\0';
  5190. tempconnectorIdInt = atoi(sstr);
  5191. #endif
  5192. //***********validFrom**************/
  5193. c = 0;
  5194. loc = strstr(sLineWord, "validFrom");
  5195. if(loc != NULL)
  5196. {
  5197. memset(sstr ,0, sizeof(sstr) );
  5198. while (loc[3+strlen("validFrom")+c] != '\"')
  5199. {
  5200. sstr[c] = loc[3+strlen("validFrom")+c];
  5201. c++;
  5202. }
  5203. sstr[c] = '\0';
  5204. strcpy(tempvalidFromStr,sstr);
  5205. }
  5206. else
  5207. {
  5208. strcpy(tempvalidFromStr,"");
  5209. }
  5210. //**********startSchedule**********/
  5211. c = 0;
  5212. loc = strstr(sLineWord, "startSchedule");
  5213. memset(sstr ,0, sizeof(sstr) );
  5214. while (loc[3+strlen("startSchedule")+c] != '\"')
  5215. {
  5216. sstr[c] = loc[3+strlen("startSchedule")+c];
  5217. c++;
  5218. }
  5219. sstr[c] = '\0';
  5220. strcpy(tempstartScheduleStr, sstr);
  5221. strcpy(TxProfileScheduleStr, sstr);
  5222. //**********chargingRateUnit**********/
  5223. c = 0;
  5224. loc = strstr(sLineWord, "chargingRateUnit");
  5225. memset(sstr ,0, sizeof(sstr) );
  5226. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5227. {
  5228. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5229. c++;
  5230. }
  5231. sstr[c] = '\0';
  5232. strcpy(tempchargingRateUnitStr, sstr);
  5233. //**********minChargingRate*******/
  5234. c = 0;
  5235. loc = strstr(sLineWord, "minChargingRate");
  5236. if(loc != NULL)
  5237. {
  5238. memset(sstr ,0, sizeof(sstr) );
  5239. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5240. {
  5241. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5242. c++;
  5243. }
  5244. sstr[c] = '\0';
  5245. tempminChargingRateFloat = atof(sstr);
  5246. }
  5247. else
  5248. {
  5249. tempminChargingRateFloat = 0.0;
  5250. }
  5251. #if 0
  5252. //
  5253. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5254. tp.tm_isdst = -1;
  5255. time_t utc = mktime(&tp);
  5256. time_t t = time(NULL);
  5257. //diff_t = difftime(t, utc);
  5258. #endif
  5259. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5260. //parsing strings to words
  5261. i = 0;
  5262. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5263. loc = loc+3+strlen("chargingSchedulePeriod");
  5264. pch = strtok(loc ,"{");
  5265. while (pch != NULL)
  5266. {
  5267. strcpy(SchedulePeriodList[i], pch);
  5268. pch = strtok (NULL, "{");
  5269. i = i + 1;
  5270. }
  5271. n_SchedulePeriods = i;
  5272. for(int i=0;i<n_SchedulePeriods;i++)
  5273. {
  5274. //*************startPeriod****************/
  5275. c = 0;
  5276. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5277. memset(sstr ,0, sizeof(sstr) );
  5278. while (loc[strlen("startPeriod")+2+c] != ',')
  5279. {
  5280. sstr[c] = loc[strlen("startPeriod")+2+c];
  5281. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5282. c++;
  5283. }
  5284. sstr[c] = '\0';
  5285. tempStartPeriodInt = atoi(sstr);
  5286. //*************limit****************/
  5287. c = 0;
  5288. loc = strstr(SchedulePeriodList[i], "limit");
  5289. memset(sstr ,0, sizeof(sstr) );
  5290. while (loc[strlen("limit")+2+c] != ',')
  5291. {
  5292. sstr[c] = loc[strlen("limit")+2+c];
  5293. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5294. c++;
  5295. }
  5296. sstr[c] = '\0';
  5297. tempLimitInt = atof(sstr);
  5298. //*************numberPhases****************/
  5299. c = 0;
  5300. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5301. memset(sstr ,0, sizeof(sstr) );
  5302. while (loc[strlen("numberPhases")+2+c] != '}')
  5303. {
  5304. sstr[c] = loc[strlen("numberPhases")+2+c];
  5305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5306. c++;
  5307. }
  5308. sstr[c] = '\0';
  5309. tempNumberPhasesInt = atoi(sstr);
  5310. TxProfile.Duration = durationInt;
  5311. TxProfile.TotalPeriod = n_SchedulePeriods;
  5312. TxProfile.Period[i].Limit = tempLimitInt;
  5313. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5314. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5315. }
  5316. if(MinChargingRate < tempminChargingRateFloat)
  5317. MinChargingRate = tempminChargingRateFloat;
  5318. if(confirmPeriods < n_SchedulePeriods)
  5319. confirmPeriods = n_SchedulePeriods;
  5320. }
  5321. fclose(fptr1);
  5322. }
  5323. }// the end of ACCESS TxProfile
  5324. //CompositeSchedule
  5325. int period=0;
  5326. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5327. {
  5328. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5329. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5330. {
  5331. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5332. {
  5333. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5334. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5335. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5336. period = period + 1;
  5337. }
  5338. else
  5339. {
  5340. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5341. {
  5342. }
  5343. else
  5344. {
  5345. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5346. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5347. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5348. period = period + 1;
  5349. }
  5350. }
  5351. }
  5352. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5353. {
  5354. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5355. {
  5356. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5357. {
  5358. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5359. }
  5360. else
  5361. {
  5362. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5363. }
  5364. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5365. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5366. period = period + 1;
  5367. }
  5368. }
  5369. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5370. {
  5371. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5372. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5373. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5374. period = period + 1;
  5375. }
  5376. }
  5377. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5378. {
  5379. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5380. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5381. {
  5382. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5383. {
  5384. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5385. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5386. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5387. period = period + 1;
  5388. }
  5389. else
  5390. {
  5391. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5392. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5393. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5394. period = period + 1;
  5395. }
  5396. }
  5397. }
  5398. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5399. {
  5400. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5401. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5402. {
  5403. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5404. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5405. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5406. period = period + 1;
  5407. }
  5408. }
  5409. confirmPeriods = period;
  5410. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5411. //* Define temporary variables */
  5412. struct tm *gtime;
  5413. time_t now;
  5414. char buf[28];
  5415. //* Read the current system time */
  5416. time(&now);
  5417. //* Convert the system time to GMT (now UTC) */
  5418. gtime = gmtime(&now);
  5419. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5420. // make .conf
  5421. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5422. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5423. //DEBUG_INFO(" debug 11\n");
  5424. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5425. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5426. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5427. }
  5428. else
  5429. {
  5430. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5431. }
  5432. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5433. return result;
  5434. }
  5435. int handleGetConfigurationRequest(char *uuid, char *payload)
  5436. {
  5437. mtrace();
  5438. int result = FAIL;
  5439. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5440. //struct json_object *jsonitem;
  5441. int MaxKeySupported = 0;
  5442. int n_keys = 0;
  5443. char requestKey[43][50]={0};
  5444. char search[]="[";
  5445. char sstr[500]={ 0 };
  5446. //int pos;
  5447. int l, c = 0;
  5448. int i = 0;
  5449. char *delim = "\",\"";
  5450. char * pch;
  5451. char *loc = strstr(payload, search);
  5452. //********************* Parsing String ***********************************/
  5453. if(loc == NULL) {
  5454. DEBUG_INFO("no key match in Configuration \n");
  5455. }
  5456. else {
  5457. //pos = loc - payload;
  5458. l = strlen(loc)-4;
  5459. while (c < l)
  5460. {
  5461. sstr[c] = loc[c+2];
  5462. c++;
  5463. }
  5464. sstr[c] = '\0';
  5465. //parsing strings to words
  5466. pch = strtok(sstr,delim);
  5467. if(pch == NULL)
  5468. {
  5469. strcpy(requestKey[0], sstr);
  5470. }
  5471. else
  5472. {
  5473. while (pch != NULL)
  5474. {
  5475. strcpy(requestKey[i], pch);
  5476. pch = strtok (NULL, delim);
  5477. i = i + 1;
  5478. }
  5479. n_keys = i;
  5480. }
  5481. }
  5482. UnknownKeynum = 0;
  5483. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5484. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5485. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5486. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5487. if(n_keys != 0)
  5488. {
  5489. for(int i=0;i<n_keys;i++)
  5490. {
  5491. getKeyValue(requestKey[i]);
  5492. //json_object_put(jsonitem);
  5493. }
  5494. }
  5495. else
  5496. {
  5497. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5498. getKeyValue("");
  5499. }
  5500. processUnkownKey();
  5501. sendGetConfigurationConfirmation(uuid);
  5502. return result;
  5503. }
  5504. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5505. {
  5506. mtrace();
  5507. int result = FAIL;
  5508. //void *ret; //
  5509. char fnamePlusPath[50]="";
  5510. char fname[16]="";
  5511. pthread_t t; // pthread 變數
  5512. time_t rawtime;
  5513. struct tm * timeinfo;
  5514. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5515. system("exec /root/logPackTools 'log' 6");
  5516. //char buffer [128];
  5517. time (&rawtime);
  5518. //printf("%ld\n", rawtime);
  5519. timeinfo = localtime (&rawtime);
  5520. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5521. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5522. if((access(fnamePlusPath,F_OK))!=-1)
  5523. {
  5524. DEBUG_INFO("fnamePlusPath exist.\n");
  5525. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5526. }
  5527. else
  5528. {
  5529. DEBUG_INFO("fnamePlusPath not exist!\n");
  5530. }
  5531. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5532. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5533. // pthread_join(t, NULL/*&ret*/);
  5534. return result;
  5535. }
  5536. void* GetDiagnosticsProcess(void* data)
  5537. {
  5538. pthread_detach(pthread_self());
  5539. mtrace();
  5540. int retriesInt=0, retryIntervalInt=0;
  5541. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5542. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5543. 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};
  5544. int port=0;
  5545. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5546. char fname[16]="";
  5547. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5548. int c = 0;
  5549. char *loc;
  5550. int isSuccess = FALSE;
  5551. char ftpbuf[200]={0};
  5552. //char temp[100]={0};
  5553. char * pch;
  5554. // [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"}]
  5555. char *str = (char*) data; // ? ?輸入資 ?
  5556. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5557. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5558. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5559. //****************location*******************/
  5560. c = 0;
  5561. memset(sstr ,0, sizeof(sstr) );
  5562. loc = strstr(str, "location");
  5563. while (loc[3+strlen("location")+c] != '\"')
  5564. {
  5565. sstr[c] = loc[3+strlen("location")+c];
  5566. c++;
  5567. }
  5568. sstr[c] = '\0';
  5569. strcpy(locationstr,sstr);
  5570. if(strcmp(locationstr,"")==0)
  5571. {
  5572. DEBUG_INFO("location is <Empty>!\n");
  5573. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5574. goto end;
  5575. }
  5576. //****************retries*******************/
  5577. c = 0;
  5578. loc = strstr(str, "retries");
  5579. if(loc == NULL)
  5580. {
  5581. retriesIsNULL = TRUE;
  5582. }
  5583. else
  5584. {
  5585. while (loc[strlen("retries")+2+c] != ',')
  5586. {
  5587. sstr[c] = loc[strlen("retries")+2+c];
  5588. c++;
  5589. }
  5590. sstr[c] = '\0';
  5591. retriesInt = atoi(sstr);
  5592. }
  5593. if(retriesIsNULL == TRUE)
  5594. {
  5595. retriesInt = 0;
  5596. }
  5597. //****************retryInterval*******************/
  5598. c = 0;
  5599. loc = strstr(str, "retryInterval");
  5600. if(loc == NULL)
  5601. {
  5602. retryIntervalIsNULL = TRUE;
  5603. }
  5604. else
  5605. {
  5606. while (loc[strlen("retryInterval")+2+c] != ',')
  5607. {
  5608. sstr[c] = loc[strlen("retryInterval")+2+c];
  5609. c++;
  5610. }
  5611. sstr[c] = '\0';
  5612. retryIntervalInt = atoi(sstr);
  5613. }
  5614. //****************startTime*******************/
  5615. c = 0;
  5616. memset(sstr ,0, sizeof(sstr) );
  5617. loc = strstr(str, "startTime");
  5618. if(loc == NULL)
  5619. {
  5620. startTimeIsNULL = TRUE;
  5621. }
  5622. else
  5623. {
  5624. while (loc[3+strlen("startTime")+c] != '\"')
  5625. {
  5626. sstr[c] = loc[3+strlen("startTime")+c];
  5627. c++;
  5628. }
  5629. sstr[c] = '\0';
  5630. strcpy(startTimestr,sstr);
  5631. }
  5632. //****************stopTime*******************/
  5633. c = 0;
  5634. memset(sstr ,0, sizeof(sstr) );
  5635. loc = strstr(str, "stopTime");
  5636. if(loc == NULL)
  5637. {
  5638. stopTimeIsNULL = TRUE;
  5639. }
  5640. else
  5641. {
  5642. while (loc[3+strlen("stopTime")+c] != '\"')
  5643. {
  5644. sstr[c] = loc[3+strlen("stopTime")+c];
  5645. c++;
  5646. }
  5647. sstr[c] = '\0';
  5648. strcpy(stopTimestr,sstr);
  5649. }
  5650. memset(protocol, 0, sizeof(protocol));
  5651. memset(user, 0, sizeof(user) );
  5652. memset(password, 0, sizeof(password));
  5653. memset(host, 0, sizeof(host));
  5654. memset(path, 0, sizeof(path));
  5655. memset(ftppath, 0, sizeof(ftppath));
  5656. memset(host1, 0, sizeof(host1));
  5657. memset(path1, 0, sizeof(path1));
  5658. /*location: ftp://user:password@host:port/path*/
  5659. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5660. // protocol, user, password, host, &port, path);
  5661. #if 0 // remove for temporally
  5662. //zip files in /Storage
  5663. system("exec /root/logPackTools 'log' 6");
  5664. #endif
  5665. // system("exec /root/Module_WebService 'log' 6");
  5666. time_t rawtime;
  5667. struct tm * timeinfo;
  5668. //char buffer [128];
  5669. time (&rawtime);
  5670. //printf("%ld\n", rawtime);
  5671. timeinfo = localtime (&rawtime);
  5672. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5673. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5674. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5675. if((access(fnamePlusPath,F_OK))!=-1)
  5676. {
  5677. DEBUG_INFO("fnamePlusPath exist.\n");
  5678. }
  5679. else
  5680. {
  5681. DEBUG_INFO("fnamePlusPath not exist!\n");
  5682. goto end;
  5683. }
  5684. pch=strchr(locationstr,'@');
  5685. if(pch==NULL)
  5686. {
  5687. sscanf(locationstr,
  5688. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5689. protocol, host, &port, path);
  5690. strcpy(user,"anonymous");
  5691. strcpy(password,"");
  5692. }
  5693. else
  5694. {
  5695. DEBUG_INFO("pch=%s\n", pch);
  5696. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5697. protocol, user, password, host, &port, path);
  5698. }
  5699. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5700. {
  5701. DEBUG_INFO("protocol is not ftp/http ! \n");
  5702. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5703. goto end;
  5704. }
  5705. if(strncmp(locationstr,"http", 4) == 0)
  5706. {
  5707. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  5708. protocol, host, path);
  5709. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  5710. // protocol, user, password, host, path);
  5711. sprintf(ftppath,"/%s", path);
  5712. DEBUG_INFO("protocol =%s\n",protocol);
  5713. DEBUG_INFO("host =%s\n",host);
  5714. DEBUG_INFO("path =%s\n",path);
  5715. DEBUG_INFO("ftppath=%s\n",ftppath);
  5716. int ftppathlen=strlen(ftppath);
  5717. int i=1;
  5718. char filenametemp[50];
  5719. while(i < ftppathlen)
  5720. {
  5721. int len=ftppathlen-i;
  5722. if(ftppath[len]== 47) // '/' ascll code: 47
  5723. {
  5724. DEBUG_INFO("compare '/' all right\n");
  5725. break;
  5726. }
  5727. i=i+1;
  5728. }
  5729. memset(filenametemp, 0, sizeof(filenametemp));
  5730. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5731. filenametemp[i+1] = 0;
  5732. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  5733. do{
  5734. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5735. sleep(retryIntervalInt);
  5736. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5737. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  5738. if(!isSuccess)
  5739. {
  5740. //BulldogUtil.sleepMs(interval*1000);
  5741. DEBUG_INFO("Diagnostics fail.\n");
  5742. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5743. }
  5744. else
  5745. {
  5746. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5747. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5748. //isUpdateRequest = TRUE;
  5749. }
  5750. }
  5751. else
  5752. {
  5753. sscanf(host,"%[^/]%s",host1, path1);
  5754. sprintf(ftppath,"%s", path1);
  5755. DEBUG_INFO("protocol =%s\n",protocol);
  5756. DEBUG_INFO("user =%s\n",user);
  5757. DEBUG_INFO("password =%s\n",password);
  5758. DEBUG_INFO("host1 =%s\n",host1);
  5759. DEBUG_INFO("port =%d\n",port);
  5760. DEBUG_INFO("path1 =%s\n",path1);
  5761. DEBUG_INFO("ftppath=%s\n",ftppath);
  5762. int ftppathlen=strlen(ftppath);
  5763. int i=1;
  5764. char filenametemp[50];
  5765. while(i < ftppathlen)
  5766. {
  5767. int len=ftppathlen-i;
  5768. if(ftppath[len]== 47) // '/' ascll code: 47
  5769. {
  5770. DEBUG_INFO("find '/' all right\n");
  5771. break;
  5772. }
  5773. i=i+1;
  5774. }
  5775. memset(filenametemp, 0, sizeof(filenametemp));
  5776. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5777. filenametemp[i+1] = 0;
  5778. memset(ftpbuf, 0, sizeof(ftpbuf));
  5779. if(port == 0)
  5780. port = 21;
  5781. do{
  5782. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5783. sleep(retryIntervalInt);
  5784. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5785. if(!isSuccess)
  5786. {
  5787. //BulldogUtil.sleepMs(interval*1000);
  5788. DEBUG_INFO("Diagnostics fail.\n");
  5789. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5790. }
  5791. else
  5792. {
  5793. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5794. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5795. //isUpdateRequest = TRUE;
  5796. }
  5797. }
  5798. end:
  5799. // json_object_put(obj);
  5800. DiagnosticsStatusNotificationStatus = 0; //Idle
  5801. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5802. }
  5803. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5804. {
  5805. mtrace();
  5806. int result = FAIL;
  5807. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5808. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5809. {
  5810. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5811. localversion = -1;
  5812. }
  5813. else
  5814. {
  5815. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5816. OCPP_getListVerion();
  5817. }
  5818. //from db.OCPP_getListVerion
  5819. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5820. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5821. sendGetLocalListVersionConfirmation(uuid,"");
  5822. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5823. return result;
  5824. }
  5825. int handleRemoteStartRequest(char *uuid, char *payload)
  5826. {
  5827. mtrace();
  5828. int result = FAIL;
  5829. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5830. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5831. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5832. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5833. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5834. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5835. int chargingSchedulePeriodCount = 0;
  5836. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5837. int c = 0;
  5838. char *loc;
  5839. char comfirmstr[20]={0};
  5840. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5841. if(server_pending == TRUE)
  5842. {
  5843. return 0;
  5844. }
  5845. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5846. //**********connectorId****************/
  5847. c = 0;
  5848. memset(sstr ,0, sizeof(sstr) );
  5849. loc = strstr(payload, "connectorId");
  5850. if(loc == NULL)
  5851. {
  5852. connectorIdIsNULL = TRUE;
  5853. }
  5854. else
  5855. {
  5856. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5857. {
  5858. sstr[c] = loc[strlen("connectorId")+2+c];
  5859. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5860. c++;
  5861. }
  5862. sstr[c] = '\0';
  5863. connectorIdInt = atoi(sstr);
  5864. }
  5865. if(connectorIdIsNULL == TRUE) // need to discussion
  5866. {
  5867. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5868. goto end;
  5869. }
  5870. //****************idTag*******************/
  5871. c = 0;
  5872. memset(sstr ,0, sizeof(sstr) );
  5873. loc = strstr(payload, "idTag");
  5874. while (loc[3+strlen("idTag")+c] != '\"')
  5875. {
  5876. sstr[c] = loc[3+strlen("idTag")+c];
  5877. c++;
  5878. }
  5879. sstr[c] = '\0';
  5880. strcpy(idTagstr,sstr);
  5881. //****************chargingProfile*******************/
  5882. c = 0;
  5883. memset(sstr ,0, sizeof(sstr) );
  5884. loc = strstr(payload, "chargingProfile");
  5885. if(loc == NULL)
  5886. {
  5887. chargingProfileIsNULL = TRUE;
  5888. }
  5889. else
  5890. {
  5891. //****************chargingProfileId*******************/
  5892. c=0;
  5893. loc = strstr(payload, "chargingProfileId");
  5894. memset(sstr ,0, sizeof(sstr) );
  5895. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5896. {
  5897. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5898. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5899. c++;
  5900. }
  5901. sstr[c] = '\0';
  5902. chargingProfileIdInt = atoi(sstr);
  5903. //****************transactionId*******************/
  5904. loc = strstr(payload, "transactionId");
  5905. if(loc == NULL)
  5906. {
  5907. transactionIdIsNULL = TRUE;
  5908. }
  5909. else
  5910. {
  5911. c=0;
  5912. memset(sstr ,0, sizeof(sstr) );
  5913. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5914. {
  5915. sstr[c] = loc[strlen("transactionId")+2+c];
  5916. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5917. c++;
  5918. }
  5919. sstr[c] = '\0';
  5920. transactionIdInt = atoi(sstr);
  5921. }
  5922. //****************stackLevel*******************/
  5923. c=0;
  5924. loc = strstr(payload, "stackLevel");
  5925. memset(sstr ,0, sizeof(sstr) );
  5926. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5927. {
  5928. sstr[c] = loc[strlen("stackLevel")+2+c];
  5929. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5930. c++;
  5931. }
  5932. sstr[c] = '\0';
  5933. stackLevelInt = atoi(sstr);
  5934. //****************chargingProfilePurpose*******************/
  5935. c = 0;
  5936. memset(sstr ,0, sizeof(sstr) );
  5937. loc = strstr(payload, "chargingProfilePurpose");
  5938. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5939. {
  5940. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5941. c++;
  5942. }
  5943. sstr[c] = '\0';
  5944. strcpy(chargingProfilePurposestr,sstr);
  5945. //****************chargingProfileKind*******************/
  5946. c = 0;
  5947. memset(sstr ,0, sizeof(sstr) );
  5948. loc = strstr(payload, "chargingProfileKind");
  5949. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5950. {
  5951. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5952. c++;
  5953. }
  5954. sstr[c] = '\0';
  5955. strcpy(chargingProfileKindstr,sstr);
  5956. //****************recurrencyKind*******************/
  5957. loc = strstr(payload, "recurrencyKind");
  5958. if(loc == NULL)
  5959. {
  5960. recurrencyKindIsNULL = TRUE;
  5961. }
  5962. else
  5963. {
  5964. c = 0;
  5965. memset(sstr ,0, sizeof(sstr) );
  5966. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5967. {
  5968. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5969. c++;
  5970. }
  5971. sstr[c] = '\0';
  5972. strcpy(recurrencyKindstr,sstr);
  5973. }
  5974. //****************validFrom*******************/
  5975. loc = strstr(payload, "validFrom");
  5976. if(loc == NULL)
  5977. {
  5978. validFromIsNULL = TRUE;
  5979. }
  5980. else
  5981. {
  5982. c = 0;
  5983. memset(sstr ,0, sizeof(sstr) );
  5984. while (loc[3+strlen("validFrom")+c] != '\"')
  5985. {
  5986. sstr[c] = loc[3+strlen("validFrom")+c];
  5987. c++;
  5988. }
  5989. sstr[c] = '\0';
  5990. strcpy(validFromstr,sstr);
  5991. }
  5992. //****************validTo*******************/
  5993. loc = strstr(payload, "validTo");
  5994. if(loc == NULL)
  5995. {
  5996. validToIsNULL = TRUE;
  5997. }
  5998. else
  5999. {
  6000. c = 0;
  6001. memset(sstr ,0, sizeof(sstr) );
  6002. while (loc[3+strlen("validTo")+c] != '\"')
  6003. {
  6004. sstr[c] = loc[3+strlen("validTo")+c];
  6005. c++;
  6006. }
  6007. sstr[c] = '\0';
  6008. strcpy(validTostr,sstr);
  6009. }
  6010. //****************chargingSchedule*******************/
  6011. loc = strstr(payload, "chargingSchedule");
  6012. if(loc != NULL)
  6013. {
  6014. //****************duration*******************/
  6015. loc = strstr(payload, "duration");
  6016. if(loc == NULL)
  6017. {
  6018. durationIsNULL = TRUE;
  6019. }
  6020. else
  6021. {
  6022. c=0;
  6023. memset(sstr ,0, sizeof(sstr) );
  6024. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6025. {
  6026. sstr[c] = loc[strlen("duration")+2+c];
  6027. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6028. c++;
  6029. }
  6030. sstr[c] = '\0';
  6031. durationInt = atoi(sstr);
  6032. }
  6033. //****************startSchedule******************/
  6034. loc = strstr(payload, "startSchedule");
  6035. if(loc == NULL)
  6036. {
  6037. startScheduleIsNULL = TRUE;
  6038. }
  6039. else
  6040. {
  6041. c = 0;
  6042. memset(sstr ,0, sizeof(sstr) );
  6043. while (loc[3+strlen("startSchedule")+c] != '\"')
  6044. {
  6045. sstr[c] = loc[3+strlen("startSchedule")+c];
  6046. c++;
  6047. }
  6048. sstr[c] = '\0';
  6049. strcpy(startSchedulestr,sstr);
  6050. }
  6051. //****************chargingRateUnit*******************/
  6052. c = 0;
  6053. memset(sstr ,0, sizeof(sstr) );
  6054. loc = strstr(payload, "chargingRateUnit");
  6055. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6056. {
  6057. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6058. c++;
  6059. }
  6060. sstr[c] = '\0';
  6061. strcpy(chargingRateUnitstr,sstr);
  6062. //****************minChargingRate*******************/
  6063. loc = strstr(payload, "minChargingRate");
  6064. if(loc == NULL)
  6065. {
  6066. minChargingRateIsNULL = TRUE;
  6067. }
  6068. else
  6069. {
  6070. c=0;
  6071. memset(sstr ,0, sizeof(sstr) );
  6072. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6073. {
  6074. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6075. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6076. c++;
  6077. }
  6078. sstr[c] = '\0';
  6079. minChargingRateflaot = atof(sstr);
  6080. }
  6081. //****************chargingSchedulePeriod count*******************/
  6082. int what_len = strlen("startPeriod");
  6083. char *where = payload;
  6084. while ((where = strstr(where, "startPeriod"))) {
  6085. where += what_len;
  6086. chargingSchedulePeriodCount++;
  6087. }
  6088. where = payload;
  6089. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6090. {
  6091. //****************startPeriod*******************/
  6092. c=0;
  6093. loc = strstr(where, "startPeriod");
  6094. memset(sstr ,0, sizeof(sstr) );
  6095. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6096. {
  6097. sstr[c] = loc[strlen("startPeriod")+2+c];
  6098. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6099. c++;
  6100. }
  6101. sstr[c] = '\0';
  6102. startPeriodInt[periodNums] = atoi(sstr);
  6103. //****************limit*******************/
  6104. c=0;
  6105. loc = strstr(where, "limit");
  6106. memset(sstr ,0, sizeof(sstr) );
  6107. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6108. {
  6109. sstr[c] = loc[strlen("limit")+2+c];
  6110. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6111. c++;
  6112. }
  6113. sstr[c] = '\0';
  6114. limitflaot[periodNums] = atof(sstr);
  6115. //****************numberPhases*******************/
  6116. loc = strstr(where, "numberPhases");
  6117. if(loc == NULL)
  6118. {
  6119. numberPhasesIsNULL = TRUE;
  6120. }
  6121. else
  6122. {
  6123. c=0;
  6124. memset(sstr ,0, sizeof(sstr) );
  6125. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6126. {
  6127. sstr[c] = loc[strlen("numberPhases")+2+c];
  6128. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6129. c++;
  6130. }
  6131. sstr[c] = '\0';
  6132. numberPhasesInt[periodNums] = atoi(sstr);
  6133. }
  6134. where = loc;
  6135. }
  6136. }
  6137. }
  6138. /*
  6139. enum _SYSTEM_STATUS
  6140. {
  6141. S_BOOTING = 0,
  6142. S_IDLE, = 1
  6143. S_AUTHORIZING, =2
  6144. S_REASSIGN_CHECK, =3
  6145. S_REASSIGN, =4
  6146. S_PRECHARGE, =5
  6147. S_PREPARING_FOR_EV, =6
  6148. S_PREPARING_FOR_EVSE, =7
  6149. S_CHARGING, =8
  6150. S_TERMINATING, =9
  6151. S_COMPLETE, =10
  6152. S_ALARM, =11
  6153. S_FAULT =12
  6154. }
  6155. */
  6156. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6157. {
  6158. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6159. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6160. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6161. //check Transaction active
  6162. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6163. {
  6164. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6165. {
  6166. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6167. {
  6168. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6169. {
  6170. //Reserved
  6171. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6172. }
  6173. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6174. {
  6175. //Reserved
  6176. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6177. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6178. goto end;
  6179. }
  6180. else
  6181. {
  6182. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6183. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6184. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6185. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6186. {
  6187. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6188. goto end;
  6189. }
  6190. }//END FOR ELSE
  6191. }
  6192. }// END FOR CHAdeMO_QUANTITY
  6193. for (int index = 0; index < CCS_QUANTITY; index++)
  6194. {
  6195. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6196. {
  6197. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6198. {
  6199. //Reserved
  6200. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6201. }
  6202. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6203. {
  6204. //Reserved
  6205. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6206. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6207. goto end;
  6208. }
  6209. else
  6210. {
  6211. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6212. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6213. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6214. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6215. {
  6216. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6217. goto end;
  6218. }
  6219. }// END FOR ELSE
  6220. }
  6221. }// END FOR CCS_QUANTITY
  6222. for (int index = 0; index < GB_QUANTITY; index++)
  6223. {
  6224. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6225. {
  6226. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6227. {
  6228. //Reserved
  6229. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6230. }
  6231. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6232. {
  6233. //Reserved
  6234. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6236. goto end;
  6237. }
  6238. else
  6239. {
  6240. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6241. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6242. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6243. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6244. {
  6245. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6246. goto end;
  6247. }
  6248. }// END FOR ELSE
  6249. }
  6250. } // END FOR GB_QUANTITY
  6251. }
  6252. else
  6253. {
  6254. for (int index = 0; index < AC_QUANTITY; index++)
  6255. {
  6256. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6257. {
  6258. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6259. {
  6260. //Reserved
  6261. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6262. }
  6263. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6264. {
  6265. //Reserved
  6266. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6267. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6268. goto end;
  6269. }
  6270. else
  6271. {
  6272. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6273. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6274. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6275. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6276. {
  6277. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6278. goto end;
  6279. }
  6280. }//END FOR ELSE
  6281. }
  6282. }// END FOR AC_QUANTITY
  6283. }
  6284. if(chargingProfileIsNULL == FALSE)
  6285. {
  6286. //ChargingProfile
  6287. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6288. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6289. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6290. if(recurrencyKindIsNULL == FALSE) //OPTION
  6291. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6292. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6293. if(transactionIdIsNULL == FALSE) // OPTION
  6294. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6295. if(validFromIsNULL == FALSE) // OPTION
  6296. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6297. if(validToIsNULL == FALSE) //OPTION
  6298. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6299. //ChargingSchedule
  6300. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6301. if(durationIsNULL == FALSE) //OPTION
  6302. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6303. if(minChargingRateIsNULL == FALSE) //OPTION
  6304. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6305. if(startScheduleIsNULL == FALSE) //OPTION
  6306. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6307. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6308. {
  6309. //ChargingSchedulePeriod
  6310. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6311. if(numberPhasesIsNULL == FALSE)
  6312. {
  6313. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6314. }
  6315. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6316. }
  6317. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6318. {
  6319. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6320. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6321. //memset idTag
  6322. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6323. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6324. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6325. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6326. }
  6327. else
  6328. {
  6329. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6330. }
  6331. }
  6332. else
  6333. {
  6334. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6335. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6336. //memset idTag
  6337. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6338. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6339. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6340. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6341. }
  6342. }
  6343. else
  6344. {
  6345. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6346. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6347. }
  6348. end:
  6349. if(connectorIdIsNULL == FALSE)
  6350. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6351. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6352. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6353. //OCPP send RemoteStartConfirmation by first.
  6354. sendRemoteStartConfirmation(uuid, comfirmstr);
  6355. return result;
  6356. }
  6357. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6358. {
  6359. mtrace();
  6360. int result = FAIL;
  6361. int match = FALSE;
  6362. int GunNO = 0;
  6363. int transactionIdInt=0;
  6364. int transactionIdIsNULL= FALSE;
  6365. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6366. int c = 0;
  6367. char *loc;
  6368. char comfirmstr[20];
  6369. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6370. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6371. if(server_pending == TRUE)
  6372. {
  6373. return 0;
  6374. }
  6375. c=0;
  6376. loc = strstr(payload, "transactionId");
  6377. if(loc == NULL)
  6378. {
  6379. transactionIdIsNULL= TRUE;
  6380. }
  6381. else
  6382. {
  6383. memset(sstr ,0, sizeof(sstr) );
  6384. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6385. {
  6386. sstr[c] = loc[strlen("transactionId")+2+c];
  6387. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6388. c++;
  6389. }
  6390. sstr[c] = '\0';
  6391. transactionIdInt = atoi(sstr);
  6392. }
  6393. if(transactionIdIsNULL == FALSE)
  6394. {
  6395. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6396. {
  6397. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6398. {
  6399. //check Transaction active
  6400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6401. {
  6402. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6403. {
  6404. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6405. {
  6406. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6407. {
  6408. match = TRUE;
  6409. GunNO = gun_index;
  6410. }
  6411. }
  6412. }// END FOR CHAdeMO_QUANTITY
  6413. for (int index = 0; index < CCS_QUANTITY; index++)
  6414. {
  6415. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6416. {
  6417. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6418. {
  6419. match = TRUE;
  6420. GunNO = gun_index;
  6421. }
  6422. }
  6423. }// END FOR CCS_QUANTITY
  6424. for (int index = 0; index < GB_QUANTITY; index++)
  6425. {
  6426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6427. {
  6428. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6429. {
  6430. match = TRUE;
  6431. GunNO = gun_index;
  6432. }
  6433. }
  6434. }// END FOR GB_QUANTITY
  6435. }
  6436. else
  6437. {
  6438. for (int index = 0; index < AC_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6441. {
  6442. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6443. {
  6444. match = TRUE;
  6445. GunNO = gun_index;
  6446. }
  6447. }
  6448. }// END FOR CHAdeMO_QUANTITY
  6449. }// END FOR AC ELSE
  6450. }// CHECK IF ResponseTransactionId == transactionIdInt
  6451. }//END FOR
  6452. if( match == TRUE)
  6453. {
  6454. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6455. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6456. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6457. }
  6458. else
  6459. {
  6460. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6461. }
  6462. }
  6463. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6464. return result;
  6465. }
  6466. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6467. {
  6468. mtrace();
  6469. int result = FAIL;
  6470. int connectorIdInt=0, reservationIdInt=0;
  6471. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6472. char comfirmstr[20]={0};
  6473. char sstr[180]={ 0 };
  6474. int c = 0;
  6475. char *loc;
  6476. //char *ptr;
  6477. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6478. //***(1)connectorId ****/
  6479. c=0;
  6480. loc = strstr(payload, "connectorId");
  6481. memset(sstr ,0, sizeof(sstr) );
  6482. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6483. {
  6484. sstr[c] = loc[strlen("connectorId")+2+c];
  6485. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6486. c++;
  6487. }
  6488. sstr[c] = '\0';
  6489. connectorIdInt = atoi(sstr);
  6490. //***(2)expiryDate ****/
  6491. loc = strstr(payload, "expiryDate");
  6492. memset(sstr ,0, sizeof(sstr) );
  6493. c = 0;
  6494. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6495. {
  6496. sstr[c] = loc[3+strlen("expiryDate")+c];
  6497. c++;
  6498. }
  6499. sstr[c] = '\0';
  6500. strcpy(expiryDatestr, sstr);
  6501. //***(3)idTag ****/
  6502. loc = strstr(payload, "idTag");
  6503. memset(sstr ,0, sizeof(sstr) );
  6504. c = 0;
  6505. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6506. {
  6507. sstr[c] = loc[3+strlen("idTag")+c];
  6508. c++;
  6509. }
  6510. sstr[c] = '\0';
  6511. strcpy(idTagstr, sstr);
  6512. //***(4)parentIdTag ****/
  6513. loc = strstr(payload, "parentIdTag");
  6514. memset(sstr ,0, sizeof(sstr) );
  6515. c = 0;
  6516. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6517. {
  6518. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6519. c++;
  6520. }
  6521. sstr[c] = '\0';
  6522. strcpy(parentIdTagstr, sstr);
  6523. //***(5)reservationId ****/
  6524. c=0;
  6525. loc = strstr(payload, "reservationId");
  6526. memset(sstr ,0, sizeof(sstr) );
  6527. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6528. {
  6529. sstr[c] = loc[strlen("reservationId")+2+c];
  6530. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6531. c++;
  6532. }
  6533. sstr[c] = '\0';
  6534. reservationIdInt = atoi(sstr);
  6535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6536. /*
  6537. enum _SYSTEM_STATUS
  6538. {
  6539. S_BOOTING = 0,
  6540. S_IDLE, = 1
  6541. S_AUTHORIZING, =2
  6542. S_REASSIGN_CHECK, =3
  6543. S_REASSIGN, =4
  6544. S_PRECHARGE, =5
  6545. S_PREPARING_FOR_EV, =6
  6546. S_PREPARING_FOR_EVSE, =7
  6547. S_CHARGING, =8
  6548. S_TERMINATING, =9
  6549. S_COMPLETE, =10
  6550. S_ALARM, =11
  6551. S_FAULT =12
  6552. }
  6553. */
  6554. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6555. {
  6556. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6557. goto end;
  6558. }
  6559. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6560. {
  6561. //check Transaction active
  6562. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6563. {
  6564. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6567. {
  6568. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6569. {
  6570. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6571. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6572. {
  6573. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6574. {
  6575. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6577. }
  6578. 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'))
  6579. {
  6580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6581. }
  6582. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6583. {
  6584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6585. }
  6586. else
  6587. {
  6588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6589. }
  6590. }
  6591. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6592. {
  6593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6594. }
  6595. }
  6596. else
  6597. {
  6598. //replace reservation
  6599. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6601. }
  6602. }
  6603. } // END FOR CHAdeMO_QUANTITY
  6604. for (int index = 0; index < CCS_QUANTITY; index++)
  6605. {
  6606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6607. {
  6608. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6609. {
  6610. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6611. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6612. {
  6613. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6614. {
  6615. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6617. }
  6618. 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'))
  6619. {
  6620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6621. }
  6622. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6623. {
  6624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6625. }
  6626. else
  6627. {
  6628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6629. }
  6630. }
  6631. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6632. {
  6633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6634. }
  6635. }
  6636. else
  6637. {
  6638. //replace reservation
  6639. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6641. }
  6642. }
  6643. } // END FOR CCS_QUANTITY
  6644. for (int index = 0; index < GB_QUANTITY; index++)
  6645. {
  6646. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6647. {
  6648. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6649. {
  6650. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6651. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6652. {
  6653. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6654. {
  6655. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6657. }
  6658. 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'))
  6659. {
  6660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6661. }
  6662. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6663. {
  6664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6665. }
  6666. else
  6667. {
  6668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6669. }
  6670. }
  6671. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6672. {
  6673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6674. }
  6675. }
  6676. else
  6677. {
  6678. //replace reservation
  6679. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6681. }
  6682. }
  6683. }// END FOR GB_QUANTITY
  6684. }
  6685. else
  6686. {
  6687. for (int index = 0; index < AC_QUANTITY; index++)
  6688. {
  6689. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6690. {
  6691. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6692. {
  6693. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6694. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6695. {
  6696. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6697. {
  6698. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6700. }
  6701. 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'))
  6702. {
  6703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6704. }
  6705. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6706. {
  6707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6708. }
  6709. else
  6710. {
  6711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6712. }
  6713. }
  6714. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6715. {
  6716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6717. }
  6718. }
  6719. else
  6720. {
  6721. //replace reservation
  6722. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6724. }
  6725. }
  6726. } // END FOR AC_QUANTITY
  6727. }//END FOR AC ELSE
  6728. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6729. }
  6730. else if(connectorIdInt == 0)
  6731. {
  6732. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6733. {
  6734. //check Transaction active
  6735. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6736. {
  6737. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6738. {
  6739. 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'))
  6740. {
  6741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6742. goto end;
  6743. }
  6744. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6745. {
  6746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6747. goto end;
  6748. }
  6749. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6750. {
  6751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6752. goto end;
  6753. }
  6754. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6755. {
  6756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6757. goto end;
  6758. }
  6759. }
  6760. }// END FOR CHAdeMO_QUANTITY
  6761. for (int index = 0; index < CCS_QUANTITY; index++)
  6762. {
  6763. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6764. {
  6765. 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'))
  6766. {
  6767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6768. }
  6769. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6770. {
  6771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6772. }
  6773. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6774. {
  6775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6776. }
  6777. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6778. {
  6779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6780. }
  6781. }
  6782. } // END FOR CCS_QUANTITY
  6783. for (int index = 0; index < GB_QUANTITY; index++)
  6784. {
  6785. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6786. {
  6787. 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'))
  6788. {
  6789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6790. }
  6791. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6792. {
  6793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6794. }
  6795. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6796. {
  6797. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6798. }
  6799. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6800. {
  6801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6802. }
  6803. }
  6804. } // END FOR GB_QUANTITY
  6805. }
  6806. else
  6807. {
  6808. for (int index = 0; index < AC_QUANTITY; index++)
  6809. {
  6810. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6811. {
  6812. 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'))
  6813. {
  6814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6815. goto end;
  6816. }
  6817. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6818. {
  6819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6820. goto end;
  6821. }
  6822. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6823. {
  6824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6825. goto end;
  6826. }
  6827. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6828. {
  6829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6830. goto end;
  6831. }
  6832. }
  6833. }// END FOR AC_QUANTITY
  6834. }
  6835. //The connectorId is 0
  6836. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6838. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6839. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6840. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6841. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6842. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6843. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6844. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6845. result = TRUE;
  6846. return result;
  6847. }
  6848. else
  6849. {
  6850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6851. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6852. }
  6853. if(strcmp(comfirmstr,"Accepted") == 0)
  6854. {
  6855. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6856. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6857. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6858. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6859. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6860. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6861. result = TRUE;
  6862. return result;
  6863. }
  6864. end:
  6865. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6866. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6867. return result;
  6868. }
  6869. int handleResetRequest(char *uuid, char *payload)
  6870. {
  6871. mtrace();
  6872. int result = FAIL;
  6873. char sstr[10]={0};
  6874. char typestr[10]={0};
  6875. char comfirmstr[20]={0};
  6876. int c = 0;
  6877. char *loc;
  6878. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6879. DEBUG_INFO("handleResetRequest ...\n");
  6880. loc = strstr(payload, "type");
  6881. memset(sstr ,0, sizeof(sstr) );
  6882. c = 0;
  6883. while (loc[3+strlen("type")+c] != '\"')
  6884. {
  6885. sstr[c] = loc[3+strlen("type")+c];
  6886. c++;
  6887. }
  6888. sstr[c] = '\0';
  6889. strcpy(typestr,sstr);
  6890. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6891. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6892. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6893. {
  6894. //check Transaction active
  6895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6896. {
  6897. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6898. {
  6899. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6900. {
  6901. //0: unplug, 1: Plug-in
  6902. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6903. }
  6904. }
  6905. for (int index = 0; index < CCS_QUANTITY; index++)
  6906. {
  6907. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6908. {
  6909. //0: unplug, 1: Plug-in
  6910. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6911. }
  6912. }
  6913. for (int index = 0; index < GB_QUANTITY; index++)
  6914. {
  6915. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6916. {
  6917. //0: unplug, 1: Plug-in
  6918. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6919. }
  6920. }
  6921. }
  6922. else
  6923. {
  6924. for (int index = 0; index < AC_QUANTITY; index++)
  6925. {
  6926. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6927. {
  6928. //0: unplug, 1: Plug-in
  6929. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6930. }
  6931. }
  6932. }// END FOR AC ELSE
  6933. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6934. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6935. result = TRUE;
  6936. return result;
  6937. }
  6938. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6939. {
  6940. //check Transaction active
  6941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6942. {
  6943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6944. {
  6945. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6946. {
  6947. //0: unplug, 1: Plug-in
  6948. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6949. }
  6950. }
  6951. for (int index = 0; index < CCS_QUANTITY; index++)
  6952. {
  6953. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6954. {
  6955. //0: unplug, 1: Plug-in
  6956. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6957. }
  6958. }
  6959. for (int index = 0; index < GB_QUANTITY; index++)
  6960. {
  6961. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6962. {
  6963. //0: unplug, 1: Plug-in
  6964. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6965. }
  6966. }
  6967. }
  6968. else
  6969. {
  6970. for (int index = 0; index < AC_QUANTITY; index++)
  6971. {
  6972. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6973. {
  6974. //0: unplug, 1: Plug-in
  6975. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6976. }
  6977. }
  6978. }// END FOR AC ELSE
  6979. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6980. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6981. result = TRUE;
  6982. return result;
  6983. }
  6984. else
  6985. {
  6986. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6987. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6988. goto errorend;
  6989. }
  6990. errorend:
  6991. sendResetConfirmation(uuid, comfirmstr);
  6992. return result;
  6993. }
  6994. int handleSendLocalListRequest(char *uuid, char *payload)
  6995. {
  6996. mtrace();
  6997. int result = FAIL;
  6998. int listVersionInt;
  6999. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7000. char listsearch[]="listVersion";
  7001. char updateTypesearch[]="updateType";
  7002. char localAuthorizationListsearch[]="localAuthorizationList";
  7003. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7004. char CardList[500][160]={0};
  7005. char updateTypestr[15]={0};
  7006. char idTagstr[20]={0};
  7007. char parentIdTag[20]={0};
  7008. char expiryDate[30]={0};
  7009. char idTagstatus[16]={0};
  7010. int c = 0;
  7011. int i = 0;
  7012. char *delim1 = "}";
  7013. char * pch;
  7014. char *loc;
  7015. //char *ptr;
  7016. char comfirmstr[20];
  7017. //int n_localAuthorizations = 0;
  7018. int checkState_Faulted = FALSE;
  7019. DEBUG_INFO("handleSendLocalListRequest\n");
  7020. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7021. {
  7022. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7023. goto end;
  7024. }
  7025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7026. {
  7027. //check Charge Point state
  7028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7029. {
  7030. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7031. {
  7032. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7033. }
  7034. }
  7035. for (int index = 0; index < CCS_QUANTITY; index++)
  7036. {
  7037. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7038. {
  7039. checkState_Faulted = TRUE; //OCPP Status
  7040. }
  7041. }
  7042. for (int index = 0; index < GB_QUANTITY; index++)
  7043. {
  7044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7045. {
  7046. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7047. }
  7048. }
  7049. }
  7050. else
  7051. {
  7052. //check Charge Point state
  7053. for (int index = 0; index < AC_QUANTITY; index++)
  7054. {
  7055. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7056. {
  7057. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7058. }
  7059. }
  7060. }// END FOR AC ELSE
  7061. if(checkState_Faulted == TRUE)
  7062. {
  7063. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7064. goto end;
  7065. }
  7066. //listVersion
  7067. c = 0;
  7068. loc = strstr(payload, listsearch);
  7069. while (loc[strlen("listVersion")+2+c] != ',')
  7070. {
  7071. sstr[c] = loc[strlen("listVersion")+2+c];
  7072. c++;
  7073. }
  7074. sstr[c] = '\0';
  7075. listVersionInt = atoi(sstr);
  7076. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7077. //updateType
  7078. loc = strstr(payload, updateTypesearch);
  7079. c = 0;
  7080. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7081. {
  7082. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7083. c++;
  7084. }
  7085. sstr[c] = '\0';
  7086. strcpy(updateTypestr, sstr);
  7087. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7088. //localAuthorizationList
  7089. memset(sstr ,0, sizeof(sstr) );
  7090. loc = strstr(payload, localAuthorizationListsearch);
  7091. if(loc != NULL) // localAuthorizationList is not NULL
  7092. {
  7093. //Check UpdateType
  7094. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7095. {
  7096. //Local list full update
  7097. printf("Local list full update.\n");
  7098. OCPP_cleanLocalList();
  7099. }
  7100. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7101. {
  7102. //Local list different update
  7103. printf("Local list different update.\n");
  7104. OCPP_getListVerion();
  7105. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7106. {
  7107. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7108. goto end;
  7109. }
  7110. }
  7111. else
  7112. {
  7113. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7114. goto end;
  7115. }
  7116. c = 0;
  7117. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7118. {
  7119. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7120. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7121. c++;
  7122. }
  7123. sstr[c] = '\0';
  7124. //parsing strings to words
  7125. i = 0;
  7126. pch = strtok(sstr,delim1);
  7127. while (pch != NULL)
  7128. {
  7129. strcpy(CardList[i], pch);
  7130. pch = strtok (NULL, delim1);
  7131. i = i + 1;
  7132. }
  7133. //local Authorizations List Numbers
  7134. //n_localAuthorizations = i;
  7135. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7136. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7137. c= 0;
  7138. while(c < i)
  7139. {
  7140. //Search "IdToken"
  7141. memset(sstr ,0, sizeof(sstr) );
  7142. loc = strstr(CardList[c], "idTag");
  7143. int j = 0;
  7144. while (loc[3+strlen("idTag")+j] != '\"')
  7145. {
  7146. sstr[j] = loc[3+strlen("idTag")+j];
  7147. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7148. j++;
  7149. }
  7150. sstr[j] = '\0';
  7151. strcpy(idTagstr, sstr);
  7152. //Search "expiryDate"
  7153. memset(sstr ,0, sizeof(sstr) );
  7154. loc = strstr(CardList[c], "expiryDate");
  7155. j = 0;
  7156. while (loc[3+strlen("expiryDate")+j] != '\"')
  7157. {
  7158. sstr[j] = loc[3+strlen("expiryDate")+j];
  7159. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7160. j++;
  7161. }
  7162. sstr[j] = '\0';
  7163. strcpy(expiryDate, sstr);
  7164. //Search "parentIdTag"
  7165. memset(sstr ,0, sizeof(sstr) );
  7166. loc = strstr(CardList[c], "parentIdTag");
  7167. j = 0;
  7168. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7169. {
  7170. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7171. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7172. j++;
  7173. }
  7174. sstr[j] = '\0';
  7175. strcpy(parentIdTag, sstr);
  7176. //Search "status"
  7177. memset(sstr ,0, sizeof(sstr) );
  7178. loc = strstr(CardList[c], "status");
  7179. j = 0;
  7180. while (loc[3+strlen("status")+j] != '\"')
  7181. {
  7182. sstr[j] = loc[3+strlen("status")+j];
  7183. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7184. j++;
  7185. }
  7186. sstr[j] = '\0';
  7187. strcpy(idTagstatus, sstr);
  7188. OCPP_getIdTag(idTagstr);
  7189. //OCPP_getIdTag("test"); For Test
  7190. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7191. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7192. {
  7193. //Local list full update
  7194. DEBUG_INFO("Local list full update.\n");
  7195. // update list
  7196. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7197. OCPP_get_TableAuthlocalAllData();
  7198. }
  7199. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7200. {
  7201. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7202. {
  7203. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7204. }
  7205. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7206. {
  7207. OCPP_deleteIdTag(idTagstr);
  7208. }
  7209. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7210. {
  7211. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7212. }
  7213. }
  7214. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7215. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7216. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7217. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7218. c++;
  7219. }
  7220. }
  7221. else
  7222. {
  7223. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7224. {
  7225. //Local list different update
  7226. DEBUG_INFO("Local list different update.\n");
  7227. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7228. goto end;
  7229. }
  7230. }
  7231. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7232. end:
  7233. sendSendLocalListConfirmation(uuid, comfirmstr);
  7234. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7235. #if 0
  7236. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7237. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7238. #endif
  7239. return result;
  7240. }
  7241. /*
  7242. enum _SYSTEM_STATUS
  7243. {
  7244. S_BOOTING = 0,
  7245. S_IDLE, =1
  7246. S_AUTHORIZING, =2
  7247. S_REASSIGN_CHECK, =3
  7248. S_REASSIGN, =4
  7249. S_PRECHARGE, =5
  7250. S_PREPARING_FOR_EV, =6
  7251. S_PREPARING_FOR_EVSE, =7
  7252. S_CHARGING, =8
  7253. S_TERMINATING, =9
  7254. S_COMPLETE, =10
  7255. S_ALARM, =11
  7256. S_FAULT =12
  7257. };
  7258. */
  7259. #define MAX 200
  7260. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7261. {
  7262. mtrace();
  7263. int result = FAIL;
  7264. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7265. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7266. char chargingProfilePurposeStr[30]={0};
  7267. char chargingProfileKindStr[16]={0};
  7268. char recurrencyKindStr[10]={0};
  7269. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7270. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7271. int chargingSchedulePeriodCount = 0;
  7272. //int updateflag = FALSE;
  7273. char comfirmstr[20]={0};
  7274. int meet= FALSE;
  7275. char sstr[10]={0};
  7276. int c = 0;
  7277. char *loc;
  7278. FILE *fptr1;//, *fptr2;
  7279. //int lno=0;//, linectr = 0;
  7280. //int modifyflag = FALSE;
  7281. char filename[MAX]={0};
  7282. char tempfile[] = "../Storage/OCPP/temp.json";
  7283. //int resultRename=0;
  7284. char rmFileCmd[50]={0};
  7285. char tempchargingProfilePurposeStr[30]={0};
  7286. //[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}}}]
  7287. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7288. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7289. //*********************connectorId***************************/
  7290. loc = strstr(payload, "connectorId");
  7291. c = 0;
  7292. memset(sstr ,0, sizeof(sstr) );
  7293. while (loc[strlen("connectorId")+2+c] != ',')
  7294. {
  7295. sstr[c] = loc[strlen("connectorId")+2+c];
  7296. c++;
  7297. }
  7298. sstr[c] = '\0';
  7299. connectorIdInt = atoi(sstr);
  7300. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7301. {
  7302. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7303. }
  7304. else
  7305. {
  7306. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7307. }
  7308. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7309. //*********************chargingProfileId***************************/
  7310. loc = strstr(payload, "chargingProfileId");
  7311. c = 0;
  7312. memset(sstr ,0, sizeof(sstr) );
  7313. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7314. {
  7315. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7316. c++;
  7317. }
  7318. sstr[c] = '\0';
  7319. chargingProfileIdInt = atoi(sstr);
  7320. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7321. {
  7322. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7323. }
  7324. else
  7325. {
  7326. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7327. }
  7328. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7329. //*********************transactionId***************************/
  7330. loc = strstr(payload, "transactionId");
  7331. if(loc != NULL)
  7332. {
  7333. c = 0;
  7334. memset(sstr ,0, sizeof(sstr) );
  7335. while (loc[strlen("transactionId")+2+c] != ',')
  7336. {
  7337. sstr[c] = loc[strlen("transactionId")+2+c];
  7338. c++;
  7339. }
  7340. sstr[c] = '\0';
  7341. transactionIdInt = atoi(sstr);
  7342. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7343. {
  7344. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7345. }
  7346. else
  7347. {
  7348. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7349. }
  7350. }
  7351. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7352. //*********************stackLevel***************************/
  7353. loc = strstr(payload, "stackLevel");
  7354. c = 0;
  7355. memset(sstr ,0, sizeof(sstr) );
  7356. while (loc[strlen("stackLevel")+2+c] != ',')
  7357. {
  7358. sstr[c] = loc[strlen("stackLevel")+2+c];
  7359. c++;
  7360. }
  7361. sstr[c] = '\0';
  7362. stackLevelInt = atoi(sstr);
  7363. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7364. {
  7365. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7366. }
  7367. else
  7368. {
  7369. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7370. }
  7371. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7372. //*********************chargingProfilePurpose***************************/
  7373. loc = strstr(payload, "chargingProfilePurpose");
  7374. c = 0;
  7375. memset(sstr ,0, sizeof(sstr) );
  7376. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7377. {
  7378. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7379. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7380. c++;
  7381. }
  7382. sstr[c] = '\0';
  7383. strcpy(chargingProfilePurposeStr,sstr);
  7384. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7385. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7386. {
  7387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7388. }
  7389. else
  7390. {
  7391. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7392. }
  7393. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7394. //*********************chargingProfileKind***************************/
  7395. loc = strstr(payload, "chargingProfileKind");
  7396. c = 0;
  7397. memset(sstr ,0, sizeof(sstr) );
  7398. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7399. {
  7400. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7401. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7402. c++;
  7403. }
  7404. sstr[c] = '\0';
  7405. strcpy(chargingProfileKindStr,sstr);
  7406. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7407. {
  7408. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7409. }
  7410. else
  7411. {
  7412. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7413. }
  7414. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7415. //*********************recurrencyKind***************************/
  7416. loc = strstr(payload, "recurrencyKind");
  7417. if(loc != NULL)
  7418. {
  7419. c = 0;
  7420. memset(sstr ,0, sizeof(sstr) );
  7421. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7422. {
  7423. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7424. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7425. c++;
  7426. }
  7427. sstr[c] = '\0';
  7428. strcpy(recurrencyKindStr,sstr);
  7429. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7430. {
  7431. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7432. }
  7433. else
  7434. {
  7435. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7436. }
  7437. }
  7438. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7439. //*********************validFrom***************************/
  7440. loc = strstr(payload, "validFrom");
  7441. if(loc != NULL)
  7442. {
  7443. c = 0;
  7444. memset(sstr ,0, sizeof(sstr) );
  7445. while (loc[3+strlen("validFrom")+c] != '\"')
  7446. {
  7447. sstr[c] = loc[3+strlen("validFrom")+c];
  7448. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7449. c++;
  7450. }
  7451. sstr[c] = '\0';
  7452. strcpy(validFromStr,sstr);
  7453. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7454. {
  7455. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7456. }
  7457. else
  7458. {
  7459. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7460. }
  7461. }
  7462. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7463. //*********************validTo***************************/
  7464. loc = strstr(payload, "validTo");
  7465. if(loc != NULL)
  7466. {
  7467. c = 0;
  7468. memset(sstr ,0, sizeof(sstr) );
  7469. while (loc[3+strlen("validTo")+c] != '\"')
  7470. {
  7471. sstr[c] = loc[3+strlen("validTo")+c];
  7472. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7473. c++;
  7474. }
  7475. sstr[c] = '\0';
  7476. strcpy(validToStr,sstr);
  7477. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7478. {
  7479. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7480. }
  7481. else
  7482. {
  7483. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7484. }
  7485. }
  7486. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7487. //*********************duration***************************/
  7488. loc = strstr(payload, "duration");
  7489. if(loc != NULL)
  7490. {
  7491. c = 0;
  7492. memset(sstr ,0, sizeof(sstr) );
  7493. while (loc[strlen("duration")+2+c] != ',')
  7494. {
  7495. sstr[c] = loc[strlen("duration")+2+c];
  7496. c++;
  7497. }
  7498. sstr[c] = '\0';
  7499. durationInt = atoi(sstr);
  7500. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7501. {
  7502. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7503. }
  7504. else
  7505. {
  7506. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7507. }
  7508. }
  7509. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7510. //*********************startSchedule***************************/
  7511. loc = strstr(payload, "startSchedule");
  7512. if(loc != NULL)
  7513. {
  7514. c = 0;
  7515. memset(sstr ,0, sizeof(sstr) );
  7516. while (loc[3+strlen("startSchedule")+c] != '\"')
  7517. {
  7518. sstr[c] = loc[3+strlen("startSchedule")+c];
  7519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7520. c++;
  7521. }
  7522. sstr[c] = '\0';
  7523. strcpy(startScheduleStr,sstr);
  7524. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7525. {
  7526. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7527. }
  7528. else
  7529. {
  7530. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7531. }
  7532. }
  7533. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7534. //*********************chargingRateUnit***************************/
  7535. loc = strstr(payload, "chargingRateUnit");
  7536. if(loc != NULL)
  7537. {
  7538. c = 0;
  7539. memset(sstr ,0, sizeof(sstr) );
  7540. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7541. {
  7542. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7543. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7544. c++;
  7545. }
  7546. sstr[c] = '\0';
  7547. strcpy(chargingRateUnitStr,sstr);
  7548. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7549. {
  7550. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7551. }
  7552. else
  7553. {
  7554. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7555. }
  7556. }
  7557. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7558. //****************chargingSchedulePeriod count start*******************/
  7559. int what_len = strlen("startPeriod");
  7560. char *where = payload;
  7561. if (what_len)
  7562. while ((where = strstr(where, "startPeriod"))) {
  7563. where += what_len;
  7564. chargingSchedulePeriodCount++;
  7565. }
  7566. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7567. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7568. where = payload;
  7569. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7570. {
  7571. //****************startPeriod*******************/
  7572. c=0;
  7573. loc = strstr(where, "startPeriod");
  7574. memset(sstr ,0, sizeof(sstr) );
  7575. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7576. {
  7577. sstr[c] = loc[strlen("startPeriod")+2+c];
  7578. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7579. c++;
  7580. }
  7581. sstr[c] = '\0';
  7582. startPeriodInt[periodNums] = atoi(sstr);
  7583. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7584. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7585. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7586. {
  7587. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7588. }
  7589. else
  7590. {
  7591. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7592. }
  7593. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7594. //****************limit*******************/
  7595. c=0;
  7596. loc = strstr(where, "limit");
  7597. memset(sstr ,0, sizeof(sstr) );
  7598. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7599. {
  7600. sstr[c] = loc[strlen("limit")+2+c];
  7601. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7602. c++;
  7603. }
  7604. sstr[c] = '\0';
  7605. limitflaot[periodNums] = atof(sstr);
  7606. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7607. {
  7608. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7609. }
  7610. else
  7611. {
  7612. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7613. }
  7614. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7615. //****************numberPhases*******************/
  7616. loc = strstr(where, "numberPhases");
  7617. if(loc != NULL)
  7618. {
  7619. c=0;
  7620. memset(sstr ,0, sizeof(sstr) );
  7621. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7622. {
  7623. sstr[c] = loc[strlen("numberPhases")+2+c];
  7624. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7625. c++;
  7626. }
  7627. sstr[c] = '\0';
  7628. numberPhasesInt[periodNums] = atoi(sstr);
  7629. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7630. {
  7631. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7632. }
  7633. else
  7634. {
  7635. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7636. }
  7637. }
  7638. where = loc;
  7639. }
  7640. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7641. //****************chargingSchedulePeriod count end*******************/
  7642. //*********************minChargingRate***************************/
  7643. loc = strstr(payload, "minChargingRate");
  7644. if(loc != NULL)
  7645. {
  7646. c = 0;
  7647. memset(sstr ,0, sizeof(sstr) );
  7648. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7649. {
  7650. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7651. c++;
  7652. }
  7653. sstr[c] = '\0';
  7654. minChargingRateFloat = atof(sstr);
  7655. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7656. {
  7657. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7658. }
  7659. else
  7660. {
  7661. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7662. }
  7663. }
  7664. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7665. {
  7666. //printf("set chargingProfile 1-2\n");
  7667. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7668. if(connectorIdInt != 0)
  7669. {
  7670. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7671. goto end;
  7672. }
  7673. strcpy(filename, ChargePointMaxProfile_JSON );
  7674. fptr1 = fopen(filename, "r");
  7675. if (!fptr1)
  7676. {
  7677. //file not exist
  7678. DEBUG_INFO("Unable to open the input file!!\n");
  7679. fptr1 = fopen(filename, "w+");
  7680. }
  7681. fclose(fptr1);
  7682. }
  7683. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7684. {
  7685. //printf("set chargingProfile 1-3\n");
  7686. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7687. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7688. {
  7689. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7690. goto end;
  7691. }
  7692. switch(connectorIdInt)
  7693. {
  7694. case 0:
  7695. strcpy(filename, TxDefaultProfile_0_JSON );
  7696. break;
  7697. case 1:
  7698. strcpy(filename, TxDefaultProfile_1_JSON );
  7699. break;
  7700. case 2:
  7701. strcpy(filename, TxDefaultProfile_2_JSON );
  7702. break;
  7703. default:
  7704. strcpy(filename, TxDefaultProfile_0_JSON );
  7705. break;
  7706. }
  7707. fptr1 = fopen(filename, "r");
  7708. if (!fptr1)
  7709. {
  7710. //file not exist
  7711. //DEBUG_INFO("Unable to open the input file!!\n");
  7712. fptr1 = fopen(filename, "w+");
  7713. }
  7714. fclose(fptr1);
  7715. }
  7716. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7717. {
  7718. //printf("set chargingProfile 1-4\n");
  7719. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7720. //check Transaction active
  7721. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7722. {
  7723. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7724. {
  7725. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7726. {
  7727. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7728. {
  7729. meet = TRUE;
  7730. break;
  7731. }
  7732. }
  7733. }
  7734. }
  7735. for (int index = 0; index < CCS_QUANTITY; index++)
  7736. {
  7737. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7738. {
  7739. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7740. {
  7741. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7742. {
  7743. meet = TRUE;
  7744. break;
  7745. }
  7746. }
  7747. }
  7748. }
  7749. for (int index = 0; index < GB_QUANTITY; index++)
  7750. {
  7751. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7752. {
  7753. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7754. {
  7755. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7756. {
  7757. meet = TRUE;
  7758. break;
  7759. }
  7760. }
  7761. }
  7762. }
  7763. if(meet == FALSE)
  7764. {
  7765. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7766. goto end;
  7767. }
  7768. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7769. {
  7770. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7771. goto end;
  7772. }
  7773. switch(connectorIdInt)
  7774. {
  7775. case 0:
  7776. break;
  7777. case 1:
  7778. strcpy(filename, TxProfile_1_JSON);
  7779. break;
  7780. case 2:
  7781. strcpy(filename, TxProfile_2_JSON);
  7782. break;
  7783. default:
  7784. strcpy(filename, TxProfile_1_JSON);
  7785. break;
  7786. }
  7787. fptr1 = fopen(filename, "r");
  7788. if (!fptr1)
  7789. {
  7790. //file not exist
  7791. DEBUG_INFO("Unable to open the input file!!\n");
  7792. fptr1 = fopen(filename, "w+");
  7793. }
  7794. fclose(fptr1);
  7795. }
  7796. //**********************************Write to File********************************************************/
  7797. FILE *infile;
  7798. FILE *outfile;
  7799. // open file for writing
  7800. infile = fopen (filename, "r");
  7801. outfile = fopen (tempfile, "w");
  7802. int d =0;
  7803. d = fgetc(infile);
  7804. //DEBUG_INFO("d:%d\n",d);
  7805. rewind(infile);
  7806. //*检测到文件结束标识返回1,否则返回0。*/
  7807. if(d == EOF)
  7808. {
  7809. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7810. fprintf(outfile,"%s\n",payload);
  7811. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7812. fclose(infile);
  7813. fclose(outfile);
  7814. sprintf(rmFileCmd,"rm -f %s",filename);
  7815. system(rmFileCmd);
  7816. rename(tempfile, filename);
  7817. #if 0
  7818. resultRename = rename(tempfile, filename);
  7819. if(resultRename == 0)
  7820. {
  7821. DEBUG_INFO("File chargingProfile renamed successfully");
  7822. }
  7823. else
  7824. {
  7825. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7826. }
  7827. #endif
  7828. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7829. //system(rmFileCmd);
  7830. }
  7831. else
  7832. {
  7833. char buf[1000]={0};
  7834. int ChargingProfileAdded = FALSE;
  7835. while (fgets(buf, sizeof(buf), infile) != NULL)
  7836. {
  7837. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7838. //*************************tempconnectorIdInt*********************************/
  7839. loc = strstr(buf, "connectorId");
  7840. c = 0;
  7841. memset(sstr ,0, sizeof(sstr) );
  7842. while (loc[strlen("connectorId")+2+c] != ',')
  7843. {
  7844. sstr[c] = loc[strlen("connectorId")+2+c];
  7845. c++;
  7846. }
  7847. sstr[c] = '\0';
  7848. tempconnectorIdInt = atoi(sstr);
  7849. //*************************tempchargingProfileIdInt*********************************/
  7850. loc = strstr(buf, "chargingProfileId");
  7851. c = 0;
  7852. memset(sstr ,0, sizeof(sstr) );
  7853. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7854. {
  7855. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7856. c++;
  7857. }
  7858. sstr[c] = '\0';
  7859. tempchargingProfileIdInt = atoi(sstr);
  7860. //*************************tempstackLevelInt*********************************/
  7861. loc = strstr(buf, "stackLevel");
  7862. c = 0;
  7863. memset(sstr ,0, sizeof(sstr) );
  7864. while (loc[strlen("stackLevel")+2+c] != ',')
  7865. {
  7866. sstr[c] = loc[strlen("stackLevel")+2+c];
  7867. c++;
  7868. }
  7869. sstr[c] = '\0';
  7870. tempstackLevelInt = atoi(sstr);
  7871. //*************************tempchargingProfilePurposeStr*********************************/
  7872. loc = strstr(payload, "chargingProfilePurpose");
  7873. c = 0;
  7874. memset(sstr ,0, sizeof(sstr) );
  7875. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7876. {
  7877. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7878. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7879. c++;
  7880. }
  7881. sstr[c] = '\0';
  7882. strcpy(tempchargingProfilePurposeStr,sstr);
  7883. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7884. {
  7885. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7886. {
  7887. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7888. if(ChargingProfileAdded == FALSE)
  7889. {
  7890. fprintf(outfile,"%s\n",payload);
  7891. ChargingProfileAdded = TRUE;
  7892. }
  7893. }
  7894. else
  7895. {
  7896. if(tempstackLevelInt < stackLevelInt)
  7897. {
  7898. if(ChargingProfileAdded == FALSE)
  7899. {
  7900. fprintf(outfile,"%s\n",payload);
  7901. ChargingProfileAdded = TRUE;
  7902. fprintf(outfile,"%s\n",buf);
  7903. }
  7904. else
  7905. {
  7906. fprintf(outfile,"%s\n",buf);
  7907. }
  7908. }
  7909. else
  7910. {
  7911. if(ChargingProfileAdded == FALSE)
  7912. {
  7913. fprintf(outfile,"%s\n",buf);
  7914. fprintf(outfile,"%s\n",payload);
  7915. ChargingProfileAdded = TRUE;
  7916. }
  7917. else
  7918. {
  7919. fprintf(outfile,"%s\n",buf);
  7920. }
  7921. }
  7922. }
  7923. }
  7924. else
  7925. {
  7926. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7927. {
  7928. if(ChargingProfileAdded == FALSE)
  7929. {
  7930. fprintf(outfile,"%s\n",payload);
  7931. ChargingProfileAdded = TRUE;
  7932. fprintf(outfile,"%s\n",buf);
  7933. }
  7934. else
  7935. {
  7936. fprintf(outfile,"%s\n",buf);
  7937. }
  7938. }
  7939. else if(tempstackLevelInt < stackLevelInt)
  7940. {
  7941. if(ChargingProfileAdded == FALSE)
  7942. {
  7943. fprintf(outfile,"%s\n",payload);
  7944. ChargingProfileAdded = TRUE;
  7945. fprintf(outfile,"%s\n",buf);
  7946. }
  7947. else
  7948. {
  7949. fprintf(outfile,"%s\n",buf);
  7950. }
  7951. }
  7952. else
  7953. {
  7954. if(ChargingProfileAdded == FALSE)
  7955. {
  7956. fprintf(outfile,"%s\n",buf);
  7957. fprintf(outfile,"%s\n",payload);
  7958. ChargingProfileAdded = TRUE;
  7959. }
  7960. else
  7961. {
  7962. fprintf(outfile,"%s\n",buf);
  7963. }
  7964. }
  7965. }
  7966. } // end of while loop
  7967. fclose(infile);
  7968. fclose(outfile);
  7969. sprintf(rmFileCmd,"rm -f %s",filename);
  7970. system(rmFileCmd);
  7971. rename(tempfile, filename);
  7972. #if 0
  7973. resultRename = rename(tempfile, filename);
  7974. if(resultRename == 0)
  7975. {
  7976. DEBUG_INFO("File chargingProfile renamed successfully");
  7977. }
  7978. else
  7979. {
  7980. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7981. }
  7982. #endif
  7983. result = TRUE;
  7984. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7985. }
  7986. end:
  7987. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7988. return result;
  7989. return result;
  7990. }
  7991. int handleTriggerMessageRequest(char *uuid, char *payload)
  7992. {
  7993. mtrace();
  7994. int result = FAIL;
  7995. int connectorIdIsNULL = FALSE;
  7996. int connectorIdInt =0;
  7997. char sstr[40]={0};
  7998. char requestedMessagestr[40]={0};
  7999. char comfirmstr[20]={0};
  8000. int c = 0;
  8001. char *loc;
  8002. DEBUG_INFO("handleTriggerMessageRequest\n");
  8003. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8004. c = 0;
  8005. loc = strstr(payload, "requestedMessage");
  8006. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8007. {
  8008. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8009. c++;
  8010. }
  8011. sstr[c] = '\0';
  8012. strcpy(requestedMessagestr, sstr);
  8013. c = 0;
  8014. loc = strstr(payload, "connectorId");
  8015. if(loc == NULL)
  8016. {
  8017. connectorIdIsNULL = TRUE;
  8018. }
  8019. else
  8020. {
  8021. memset(sstr ,0, sizeof(sstr) );
  8022. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8023. {
  8024. sstr[c] = loc[strlen("connectorId")+2+c];
  8025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8026. c++;
  8027. }
  8028. sstr[c] = '\0';
  8029. connectorIdInt = atoi(sstr);
  8030. }
  8031. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8032. {
  8033. //connectorIdInt = json_object_get_int(connectorId);
  8034. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8035. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8036. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8037. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8038. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8039. }
  8040. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8041. {
  8042. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8043. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8044. return TRUE;
  8045. }
  8046. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8047. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8048. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8049. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8050. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8051. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8052. {
  8053. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8054. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8055. return TRUE;
  8056. }
  8057. else
  8058. {
  8059. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8060. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8061. }
  8062. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8063. {
  8064. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8065. {
  8066. FirmwareStatusNotificationStatus = 3;
  8067. }
  8068. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8069. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8070. }
  8071. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8072. {
  8073. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8074. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8075. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8076. }
  8077. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8078. {
  8079. sendBootNotificationRequest();
  8080. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8081. }
  8082. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8083. {
  8084. sendHeartbeatRequest(connectorIdInt);
  8085. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8086. }
  8087. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8088. {
  8089. if(connectorIdIsNULL == FALSE)
  8090. {
  8091. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8092. {
  8093. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8094. sendMeterValuesRequest(connectorIdInt -1);
  8095. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8096. }
  8097. }
  8098. else
  8099. {
  8100. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8101. {
  8102. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8103. sendMeterValuesRequest(idx);
  8104. }
  8105. }
  8106. }
  8107. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8108. {
  8109. if(connectorIdIsNULL == FALSE)
  8110. {
  8111. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8112. {
  8113. sendStatusNotificationRequest(connectorIdInt -1);
  8114. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8115. }
  8116. }
  8117. else
  8118. {
  8119. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8120. sendStatusNotificationRequest(idx);
  8121. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8122. }
  8123. }
  8124. return result;
  8125. }
  8126. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8127. {
  8128. mtrace();
  8129. int result = FAIL;
  8130. char sstr[6]={0};
  8131. int connectorIdInt =0;
  8132. char comfirmstr[20]={0};
  8133. int c = 0;
  8134. char *loc;
  8135. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8136. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8137. c = 0;
  8138. loc = strstr(payload, "connectorId");
  8139. memset(sstr ,0, sizeof(sstr) );
  8140. while (loc[strlen("connectorId")+2+c] != '}')
  8141. {
  8142. sstr[c] = loc[strlen("connectorId")+2+c];
  8143. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8144. c++;
  8145. }
  8146. sstr[c] = '\0';
  8147. connectorIdInt = atoi(sstr);
  8148. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8149. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8150. {
  8151. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8152. goto end;
  8153. }
  8154. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8155. {
  8156. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8157. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8158. goto end;
  8159. }
  8160. else
  8161. {
  8162. //check Transaction active
  8163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8164. {
  8165. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8166. {
  8167. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8168. {
  8169. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8170. }
  8171. }
  8172. for (int index = 0; index < CCS_QUANTITY; index++)
  8173. {
  8174. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8175. {
  8176. //stop Transaction
  8177. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8178. }
  8179. }
  8180. for (int index = 0; index < GB_QUANTITY; index++)
  8181. {
  8182. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8183. {
  8184. //stop Transaction
  8185. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8186. }
  8187. }
  8188. }
  8189. else
  8190. {
  8191. for (int index = 0; index < AC_QUANTITY; index++)
  8192. {
  8193. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8194. {
  8195. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8196. }
  8197. }
  8198. }// END FOR AC ELSE
  8199. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8200. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8201. result = TRUE;
  8202. return result;
  8203. }
  8204. end:
  8205. //json_object_put(obj); --- remove temporally
  8206. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8207. return result;
  8208. }
  8209. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8210. {
  8211. mtrace();
  8212. int result = FAIL;
  8213. pthread_t t;
  8214. sendUpdateFirmwareConfirmation(uuid);
  8215. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8216. ////pthread_join(t, NULL); //
  8217. //pthread_detach(t);
  8218. //sendUpdateFirmwareConfirmation(uuid);
  8219. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8220. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8221. return result;
  8222. }
  8223. void *UpdateFirmwareProcess(void *data)
  8224. {
  8225. pthread_detach(pthread_self());
  8226. mtrace();
  8227. int retriesInt =0, retryIntervalInt=0;
  8228. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8229. int port=0;
  8230. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8231. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8232. //char comfirmstr[20];
  8233. int isSuccess = 0;
  8234. char ftpbuf[200];
  8235. char temp[100];
  8236. char * pch;
  8237. int retriesISNULL=FALSE;
  8238. int retryInterval=FALSE;
  8239. int c = 0;
  8240. //int i = 0;
  8241. char *loc;
  8242. char sstr[300]={ 0 };
  8243. char *str = (char*) data; // ? ?輸入資 ?
  8244. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8245. //***************location **************/
  8246. loc = strstr(str, "location");
  8247. memset(sstr ,0, sizeof(sstr) );
  8248. c = 0;
  8249. while (loc[3+strlen("location")+c] != '\"')
  8250. {
  8251. sstr[c] = loc[3+strlen("location")+c];
  8252. c++;
  8253. }
  8254. sstr[c] = '\0';
  8255. strcpy(locationstr, sstr);
  8256. //***************retries**************/
  8257. c = 0;
  8258. loc = strstr(str, "retries");
  8259. if(loc == NULL)
  8260. {
  8261. retriesISNULL=TRUE;
  8262. }
  8263. else
  8264. {
  8265. memset(sstr ,0, sizeof(sstr) );
  8266. while (loc[strlen("retries")+2+c] != ',')
  8267. {
  8268. sstr[c] = loc[strlen("retries")+2+c];
  8269. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8270. c++;
  8271. }
  8272. sstr[c] = '\0';
  8273. }
  8274. if(retriesISNULL == FALSE)
  8275. {
  8276. retriesInt = atoi(sstr);
  8277. }
  8278. //***************retrieveDate **************/
  8279. loc = strstr(str, "retrieveDate");
  8280. memset(sstr ,0, sizeof(sstr) );
  8281. c = 0;
  8282. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8283. {
  8284. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8285. c++;
  8286. }
  8287. sstr[c] = '\0';
  8288. strcpy(retrieveDatestr, sstr);
  8289. //***************retryInterval **************/
  8290. c = 0;
  8291. loc = strstr(str, "retryInterval");
  8292. memset(sstr ,0, sizeof(sstr) );
  8293. if(loc == NULL)
  8294. {
  8295. retryInterval=TRUE;
  8296. }
  8297. else
  8298. {
  8299. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8300. {
  8301. sstr[c] = loc[strlen("retryInterval")+2+c];
  8302. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8303. c++;
  8304. }
  8305. sstr[c] = '\0';
  8306. }
  8307. if(retryInterval==FALSE)
  8308. {
  8309. retryIntervalInt = atoi(sstr);
  8310. }
  8311. memset(ftppath, 0, sizeof(ftppath));
  8312. memset(path, 0, sizeof(path));
  8313. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8314. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8315. if(strncmp(locationstr,"http", 4) == 0)
  8316. {
  8317. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8318. protocol, host, path);
  8319. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8320. // protocol, user, password, host, path);
  8321. sprintf(ftppath,"/%s", path);
  8322. DEBUG_INFO("protocol =%s\n",protocol);
  8323. DEBUG_INFO("host =%s\n",host);
  8324. DEBUG_INFO("path =%s\n",path);
  8325. DEBUG_INFO("ftppath=%s\n",ftppath);
  8326. int ftppathlen=strlen(ftppath);
  8327. int i=1;
  8328. char filenametemp[50];
  8329. while(i < ftppathlen)
  8330. {
  8331. int len=ftppathlen-i;
  8332. if(ftppath[len]== 47) // '/' ascll code: 47
  8333. {
  8334. DEBUG_INFO("compare '/' all right\n");
  8335. break;
  8336. }
  8337. i=i+1;
  8338. }
  8339. memset(filenametemp, 0, sizeof(filenametemp));
  8340. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8341. filenametemp[i+1] = 0;
  8342. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8343. do{
  8344. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8345. sleep(retryIntervalInt);
  8346. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8347. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8348. if(!isSuccess)
  8349. {
  8350. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8351. }
  8352. else
  8353. {
  8354. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8355. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8356. isUpdateRequest = TRUE;
  8357. }
  8358. }
  8359. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8360. {
  8361. memset(ftpbuf, 0, sizeof(ftpbuf));
  8362. memset(temp, 0, sizeof(temp));
  8363. DEBUG_INFO("locationstr=%s\n",locationstr);
  8364. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8365. int ftppathlen=strlen(ftpbuf);
  8366. int i=1;
  8367. char filenametemp[50];
  8368. while(i < ftppathlen)
  8369. {
  8370. int len=ftppathlen-i;
  8371. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8372. {
  8373. DEBUG_INFO(" compare '/' all right\n");
  8374. break;
  8375. }
  8376. i=i+1;
  8377. }
  8378. memset(filenametemp, 0, sizeof(filenametemp));
  8379. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8380. filenametemp[i+1] = 0;
  8381. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8382. pch=strchr(temp,'@');
  8383. if(pch==NULL)
  8384. {
  8385. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8386. protocol, host, &port, path);
  8387. strcpy(user,"anonymous");
  8388. strcpy(password,"");
  8389. }
  8390. else
  8391. {
  8392. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8393. protocol, user, password, host, &port, path);
  8394. }
  8395. sscanf(host,"%[^/]%s",host1, path1);
  8396. sprintf(ftppath,"%s", path1);
  8397. DEBUG_INFO("protocol =%s\n",protocol);
  8398. DEBUG_INFO("user =%s\n",user);
  8399. DEBUG_INFO("password =%s\n",password);
  8400. DEBUG_INFO("host1 =%s\n",host1);
  8401. DEBUG_INFO("port =%d\n",port);
  8402. DEBUG_INFO("path1 =%s\n",path1);
  8403. DEBUG_INFO("ftppath=%s\n",ftppath);
  8404. //ftpFile(host, user, password, port, ftppath, fname);
  8405. //download firmware pthred
  8406. if(port == 0)
  8407. {
  8408. port = 21;
  8409. }
  8410. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8411. do{
  8412. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8413. sleep(retryIntervalInt);
  8414. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8415. if(!isSuccess)
  8416. {
  8417. //BulldogUtil.sleepMs(interval*1000);
  8418. DEBUG_INFO("Update firmware request and download file fail.\n");
  8419. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8420. }
  8421. else
  8422. {
  8423. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8424. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8425. isUpdateRequest = TRUE;
  8426. }
  8427. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8428. }
  8429. else
  8430. {
  8431. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8432. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8433. }
  8434. pthread_exit(NULL);
  8435. }
  8436. //==========================================
  8437. // Handle server response routine
  8438. //==========================================
  8439. void handleAuthorizeResponse(char *payload, int gun_index)
  8440. {
  8441. mtrace();
  8442. char expiryDatestr[30]={0};
  8443. char parentIdTagstr[20]={0};
  8444. char statusstr[20]={0};
  8445. char expiryDatestrtemp[30]={0};
  8446. char parentIdTagstrtemp[20]={0};
  8447. char IdTagstrtemp[20]={0};
  8448. char statusstrtemp[20]={0};
  8449. int expiryDateISNULL=FALSE;
  8450. int parentIdTagISNULL=FALSE;
  8451. char sstr[160]={ 0 };
  8452. char* filename = AuthorizationCache_JSON;
  8453. char tempfile[] = "../Storage/OCPP/temp.json";
  8454. int c = 0;
  8455. char *loc;
  8456. int resultRename=0;
  8457. int responseIdTagInfoAsZero= 0;
  8458. char rmFileCmd[50]={0};
  8459. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8460. //***********expiryDate*************/
  8461. loc = strstr(payload, "expiryDate");
  8462. memset(sstr ,0, sizeof(sstr) );
  8463. c = 0;
  8464. if(loc == NULL)
  8465. {
  8466. expiryDateISNULL = TRUE;
  8467. }
  8468. else
  8469. {
  8470. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8471. {
  8472. sstr[c] = loc[3+strlen("expiryDate")+c];
  8473. c++;
  8474. }
  8475. sstr[c] = '\0';
  8476. strcpy(expiryDatestr, sstr);
  8477. }
  8478. //***********parentIdTag*************/
  8479. loc = strstr(payload, "parentIdTag");
  8480. memset(sstr ,0, sizeof(sstr) );
  8481. c = 0;
  8482. if(loc == NULL)
  8483. {
  8484. parentIdTagISNULL = TRUE;
  8485. }
  8486. else
  8487. {
  8488. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8489. {
  8490. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8491. c++;
  8492. }
  8493. sstr[c] = '\0';
  8494. strcpy(parentIdTagstr, sstr);
  8495. }
  8496. //***********status*************/
  8497. loc = strstr(payload, "status");
  8498. memset(sstr ,0, sizeof(sstr) );
  8499. c = 0;
  8500. while (loc[3+strlen("status")+c] != '\"')
  8501. {
  8502. sstr[c] = loc[3+strlen("status")+c];
  8503. c++;
  8504. }
  8505. sstr[c] = '\0';
  8506. strcpy(statusstr, sstr);
  8507. //#ifdef SystemLogMessage
  8508. // if(expiryDateISNULL == FALSE)
  8509. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8510. // if(parentIdTagISNULL == FALSE)
  8511. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8512. // DEBUG_INFO("status: %s\n", statusstr);
  8513. //#endif
  8514. if(expiryDateISNULL == FALSE)
  8515. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8516. if(parentIdTagISNULL == FALSE)
  8517. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8518. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8519. //Update idTag information to authorization cache if supproted
  8520. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8521. {
  8522. if((access(filename,F_OK))!=-1)
  8523. {
  8524. DEBUG_INFO("AuthorizationCache exist.\n");
  8525. }
  8526. else
  8527. {
  8528. DEBUG_INFO("AuthorizationCache not exist\n");
  8529. FILE *log = fopen(filename, "w+");
  8530. if(log == NULL)
  8531. {
  8532. DEBUG_INFO("log is NULL\n");
  8533. goto out;
  8534. }
  8535. else
  8536. {
  8537. fclose(log);
  8538. }
  8539. }
  8540. FILE *infile;
  8541. FILE *outfile;
  8542. // open file for writing
  8543. infile = fopen (filename, "r");
  8544. outfile = fopen (tempfile, "w");
  8545. //*检测到文件结束标识返回1,否则返回0。*/
  8546. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8547. int c;
  8548. c = fgetc(infile);
  8549. //DEBUG_INFO("c:%d\n",c);
  8550. rewind(infile);
  8551. if(c == EOF)
  8552. {
  8553. DEBUG_INFO("Orignal File is NULL\n");
  8554. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8555. {
  8556. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8557. }
  8558. else
  8559. {
  8560. strcpy(expiryDatestrtemp, "");
  8561. }
  8562. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8563. {
  8564. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8565. }
  8566. else
  8567. {
  8568. //write Authorize IdTag
  8569. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8570. }
  8571. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8572. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8573. fclose(infile);
  8574. fclose(outfile);
  8575. sprintf(rmFileCmd,"rm -f %s",filename);
  8576. system(rmFileCmd);
  8577. resultRename = rename(tempfile, filename);
  8578. if(resultRename == 0)
  8579. {
  8580. DEBUG_INFO("File renamed successfully");
  8581. }
  8582. else
  8583. {
  8584. DEBUG_INFO("Error: unable to rename the file");
  8585. }
  8586. }
  8587. else
  8588. {
  8589. char buf[160]={0};
  8590. //DEBUG_INFO("Orignal File is not NULL\n");
  8591. while (fgets(buf, sizeof(buf), infile) != NULL)
  8592. {
  8593. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8594. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8595. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8596. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8597. memset(statusstr, 0, sizeof(statusstrtemp));
  8598. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8599. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8600. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8601. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8602. //------------------IdTag-----------------------
  8603. loc = strstr(buf, "idTag");
  8604. memset(sstr ,0, sizeof(sstr) );
  8605. c = 0;
  8606. while (loc[3+strlen("idTag")+c] != '\"')
  8607. {
  8608. sstr[c] = loc[3+strlen("idTag")+c];
  8609. c++;
  8610. }
  8611. sstr[c] = '\0';
  8612. strcpy(IdTagstrtemp,sstr);
  8613. //*********************expiryDate***************/
  8614. loc = strstr(buf, "expiryDate");
  8615. memset(sstr ,0, sizeof(sstr) );
  8616. c = 0;
  8617. while (loc[3+strlen("expiryDate")+c] != '\"')
  8618. {
  8619. sstr[c] = loc[3+strlen("expiryDate")+c];
  8620. c++;
  8621. }
  8622. sstr[c] = '\0';
  8623. strcpy(expiryDatestr,sstr);
  8624. //*********************parentIdTag***************/
  8625. loc = strstr(buf, "parentIdTag");
  8626. memset(sstr ,0, sizeof(sstr) );
  8627. c = 0;
  8628. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8629. {
  8630. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8631. c++;
  8632. }
  8633. sstr[c] = '\0';
  8634. strcpy(parentIdTagstr,sstr);
  8635. //*********************status***************/
  8636. loc = strstr(buf, "status");
  8637. memset(sstr ,0, sizeof(sstr) );
  8638. c = 0;
  8639. while (loc[3+strlen("status")+c] != '\"')
  8640. {
  8641. sstr[c] = loc[3+strlen("status")+c];
  8642. c++;
  8643. }
  8644. sstr[c] = '\0';
  8645. strcpy(statusstr,sstr);
  8646. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8647. {
  8648. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8649. responseIdTagInfoAsZero = 1;
  8650. }
  8651. else
  8652. {
  8653. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8654. }
  8655. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8656. {
  8657. //modify item
  8658. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8659. {
  8660. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8661. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8662. }
  8663. else
  8664. {
  8665. strcpy(expiryDatestrtemp, "");
  8666. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8667. }
  8668. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8669. {
  8670. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8671. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8672. }
  8673. else
  8674. {
  8675. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8676. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8677. }
  8678. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8679. }
  8680. else
  8681. {
  8682. //wrie original item
  8683. strcpy(expiryDatestrtemp, expiryDatestr);
  8684. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8685. strcpy(statusstrtemp, statusstr);
  8686. }
  8687. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8688. }
  8689. fclose(infile);
  8690. fclose(outfile);
  8691. sprintf(rmFileCmd,"rm -f %s",filename);
  8692. system(rmFileCmd);
  8693. resultRename = rename(tempfile, filename);
  8694. if(resultRename == 0)
  8695. {
  8696. DEBUG_INFO("File renamed successfully");
  8697. }
  8698. else
  8699. {
  8700. DEBUG_INFO("Error: unable to rename the file");
  8701. }
  8702. }
  8703. }
  8704. out:
  8705. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8706. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8707. authorizeRetryTimes = 0;
  8708. }
  8709. void handleBootNotificationResponse(char *payload, int gun_index)
  8710. {
  8711. mtrace();
  8712. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8713. char statusStr[12]={0};
  8714. char currentTimeStr[30]={0};
  8715. char *loc;
  8716. int intervalInt = 0;
  8717. int c = 0;
  8718. //double diff_t;
  8719. struct tm tp;
  8720. char buf[28]={0};
  8721. char timebuf[50]={0};
  8722. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8723. //*** interval ****/
  8724. c = 0;
  8725. loc = strstr(payload, "interval");
  8726. //printf("loc=%s\n",loc);
  8727. memset(sstr ,0, sizeof(sstr) );
  8728. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8729. {
  8730. sstr[c] = loc[strlen("interval")+2+c];
  8731. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8732. c++;
  8733. }
  8734. sstr[c] = '\0';
  8735. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8736. intervalInt = atoi(sstr);
  8737. //***status ****/
  8738. loc = strstr(payload, "status");
  8739. memset(sstr ,0, sizeof(sstr) );
  8740. c = 0;
  8741. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8742. {
  8743. sstr[c] = loc[3+strlen("status")+c];
  8744. c++;
  8745. }
  8746. sstr[c] = '\0';
  8747. strcpy(statusStr, sstr);
  8748. //***currentTime ****/
  8749. loc = strstr(payload, "currentTime");
  8750. //printf("loc=%s\n",loc);
  8751. memset(sstr ,0, sizeof(sstr) );
  8752. c = 0;
  8753. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8754. {
  8755. sstr[c] = loc[3+strlen("currentTime")+c];
  8756. c++;
  8757. }
  8758. sstr[c] = '\0';
  8759. strcpy(currentTimeStr, sstr);
  8760. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8761. HeartBeatWaitTime = BootNotificationInterval;
  8762. //#ifdef SystemLogMessage
  8763. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8764. // DEBUG_INFO("interval: %d\n", intervalInt);
  8765. // DEBUG_INFO("status: %s\n", statusStr);
  8766. //#endif
  8767. //write back to ShmOCPP16Data->BootNotification
  8768. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8769. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8770. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8771. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8772. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8773. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8774. {
  8775. server_sign = TRUE;
  8776. server_pending =FALSE;
  8777. }
  8778. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8779. {
  8780. server_pending = TRUE;
  8781. }
  8782. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8783. tp.tm_isdst = -1;
  8784. //time_t utc = mktime(&tp);
  8785. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8786. memset(timebuf, 0, sizeof timebuf);
  8787. sprintf(timebuf,"date -s '%s'",buf);
  8788. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8789. system(timebuf);
  8790. //==============================================
  8791. // RTC sync
  8792. //==============================================
  8793. system("/sbin/hwclock -w --systohc");
  8794. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8795. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8796. }
  8797. void handleDataTransferResponse(char *payload, int gun_index)
  8798. {
  8799. char sstr[160]={0};//sstr[200]={ 0 };
  8800. int c = 0;
  8801. char *loc;
  8802. DEBUG_INFO("handleDataTransferResponse ...\n");
  8803. loc = strstr(payload, "status");
  8804. printf("loc=%s\n",loc);
  8805. c = 0;
  8806. while (loc[3+strlen("status")+c] != '\"')
  8807. {
  8808. sstr[c] = loc[3+strlen("status")+c];
  8809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8810. c++;
  8811. }
  8812. sstr[c] = '\0';
  8813. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8814. //#ifdef SystemLogMessage
  8815. //DEBUG_INFO("data: %s\n", payload);
  8816. //#endif
  8817. }
  8818. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8819. {
  8820. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8821. //struct json_object *obj;
  8822. // obj = json_tokener_parse(payload);
  8823. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8824. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8825. //No fields are defined.
  8826. }
  8827. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8828. {
  8829. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8830. //struct json_object *obj;
  8831. // obj = json_tokener_parse(payload);
  8832. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8833. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8834. //No fields are defined.
  8835. }
  8836. void handleHeartbeatResponse(char *payload, int gun_index)
  8837. {
  8838. mtrace();
  8839. //double diff_t;
  8840. struct tm tp;
  8841. char buf[28]={0};
  8842. char timebuf[50]={0};
  8843. char sstr[30]={ 0 };
  8844. int c = 0;
  8845. char *loc;
  8846. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8847. if((HeartBeatCount%360) == 0)
  8848. {
  8849. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8850. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8851. }
  8852. HeartBeatCount = HeartBeatCount + 1;
  8853. c = 0;
  8854. loc = strstr(payload, "currentTime");
  8855. memset(sstr ,0, sizeof(sstr) );
  8856. while (loc[3+strlen("currentTime")+c] != '\"')
  8857. {
  8858. sstr[c] = loc[3+strlen("currentTime")+c];
  8859. c++;
  8860. }
  8861. sstr[c] = '\0';
  8862. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8863. // #ifdef SystemLogMessage
  8864. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8865. // #endif
  8866. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8867. tp.tm_isdst = -1;
  8868. //time_t utc = mktime(&tp);
  8869. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8870. memset(timebuf, 0, sizeof timebuf);
  8871. sprintf(timebuf,"date -s '%s'",buf);
  8872. system(timebuf);
  8873. //==============================================
  8874. // RTC sync
  8875. //==============================================
  8876. system("/sbin/hwclock -w --systohc");
  8877. if(FirstHeartBeat == 0)
  8878. {
  8879. FirstHeartBeat = 1;
  8880. }
  8881. HeartBeatWithNOResponse = 0;
  8882. }
  8883. void handleMeterValuesResponse(char *payload, int gun_index)
  8884. {
  8885. mtrace();
  8886. //struct json_object *obj;
  8887. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8888. //No fields are defined.
  8889. }
  8890. void handleStartTransactionResponse(char *payload, int gun_index)
  8891. {
  8892. mtrace();
  8893. char sstr[28]={ 0 };
  8894. int c = 0;
  8895. char *loc;
  8896. int transactionIdInt = 0;
  8897. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8898. DEBUG_INFO("handleStartTransactionResponse\n");
  8899. //****************expiryDate********************/
  8900. loc = strstr(payload, "expiryDate");
  8901. if(loc == NULL)
  8902. {
  8903. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8904. }
  8905. else
  8906. {
  8907. c = 0;
  8908. memset(sstr ,0, sizeof(sstr) );
  8909. while (loc[3+strlen("expiryDate")+c] != '\"')
  8910. {
  8911. sstr[c] = loc[3+strlen("expiryDate")+c];
  8912. c++;
  8913. }
  8914. sstr[c] = '\0';
  8915. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8916. }
  8917. //****************parentIdTag********************/
  8918. loc = strstr(payload, "parentIdTag");
  8919. if(loc == NULL)
  8920. {
  8921. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8922. }
  8923. else
  8924. {
  8925. c = 0;
  8926. memset(sstr ,0, sizeof(sstr) );
  8927. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8928. {
  8929. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8930. c++;
  8931. }
  8932. sstr[c] = '\0';
  8933. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8934. }
  8935. //****************status********************/
  8936. loc = strstr(payload, "status");
  8937. if(loc == NULL)
  8938. {
  8939. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8940. }
  8941. else
  8942. {
  8943. c = 0;
  8944. memset(sstr ,0, sizeof(sstr) );
  8945. while (loc[3+strlen("status")+c] != '\"')
  8946. {
  8947. sstr[c] = loc[3+strlen("status")+c];
  8948. c++;
  8949. }
  8950. sstr[c] = '\0';
  8951. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8952. }
  8953. //****************transactionId********************/
  8954. c=0;
  8955. loc = strstr(payload, "transactionId");
  8956. memset(sstr ,0, sizeof(sstr) );
  8957. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8958. {
  8959. sstr[c] = loc[strlen("transactionId")+2+c];
  8960. c++;
  8961. }
  8962. sstr[c] = '\0';
  8963. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8964. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8965. TransactionId[gun_index] = transactionIdInt;
  8966. DEBUG_INFO("gun_index: %d\n", gun_index);
  8967. DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8968. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8969. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8970. #ifdef SystemLogMessage
  8971. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8972. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8973. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8974. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8975. #endif
  8976. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8977. {
  8978. //add Charging Record
  8979. SettingChargingRecord(gun_index, transactionIdInt);
  8980. }
  8981. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8982. }
  8983. void handleStatusNotificationResponse(char *payload, int gun_index)
  8984. {
  8985. mtrace();
  8986. printf("handleStatusNotificationResponse\n");
  8987. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8988. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8989. }
  8990. void handleStopTransactionnResponse(char *payload, int gun_index)
  8991. {
  8992. mtrace();
  8993. char sstr[30]={ 0 };
  8994. int c = 0;
  8995. char *loc;
  8996. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8997. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8998. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8999. loc = strstr(payload, "idTagInfo");
  9000. //***********************idTagInfo************************/
  9001. if(loc != NULL)
  9002. {
  9003. //***********************expiryDate************************/
  9004. loc = strstr(payload, "expiryDate");
  9005. if(loc != NULL)
  9006. {
  9007. memset(sstr ,0, sizeof(sstr) );
  9008. c = 0;
  9009. while (loc[3+strlen("expiryDate")+c] != '\"')
  9010. {
  9011. sstr[c] = loc[3+strlen("expiryDate")+c];
  9012. c++;
  9013. }
  9014. sstr[c] = '\0';
  9015. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9016. }
  9017. //***********************parentIdTag************************/
  9018. loc = strstr(payload, "parentIdTag");
  9019. if(loc != NULL)
  9020. {
  9021. memset(sstr ,0, sizeof(sstr) );
  9022. c = 0;
  9023. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9024. {
  9025. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9026. c++;
  9027. }
  9028. sstr[c] = '\0';
  9029. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9030. }
  9031. //***********************status************************/
  9032. loc = strstr(payload, "status");
  9033. memset(sstr ,0, sizeof(sstr) );
  9034. c = 0;
  9035. while (loc[3+strlen("status")+c] != '\"')
  9036. {
  9037. sstr[c] = loc[3+strlen("status")+c];
  9038. c++;
  9039. }
  9040. sstr[c] = '\0';
  9041. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9042. }
  9043. #ifdef SystemLogMessage
  9044. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9045. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9046. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9047. #endif
  9048. }
  9049. //==========================================
  9050. // Handle Error routine
  9051. //==========================================
  9052. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9053. {
  9054. mtrace();
  9055. #ifdef SystemLogMessage
  9056. DEBUG_INFO("errorCode: %s\n", errorCode);
  9057. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9058. DEBUG_INFO("errorDetails: %s\n", payload);
  9059. #endif
  9060. }
  9061. //===============================================
  9062. // Common routine
  9063. //===============================================
  9064. int initialConfigurationTable(void)
  9065. {
  9066. printf("initialConfigurationTable \n");
  9067. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9068. /*Core Profile*/
  9069. //AllowOfflineTxForUnknownId
  9070. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9071. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9074. //AuthorizationCacheEnabled
  9075. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9078. //AuthorizeRemoteTxRequests
  9079. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9082. //BlinkRepeat
  9083. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9086. //ClockAlignedDataInterval
  9087. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9090. //ConnectionTimeOut
  9091. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9094. //GetConfigurationMaxKeys
  9095. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9098. // HeartbeatInterval
  9099. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9102. // LightIntensity
  9103. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9106. // LocalAuthorizeOffline
  9107. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9110. // LocalPreAuthorize
  9111. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9114. // MaxEnergyOnInvalidId
  9115. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9118. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9119. // MeterValuesAlignedData
  9120. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9123. // MeterValuesAlignedDataMaxLength
  9124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9127. // MeterValuesSampledData
  9128. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9131. // MeterValuesSampledDataMaxLength
  9132. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9135. // MeterValueSampleInterval
  9136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9139. // MinimumStatusDuration
  9140. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9143. // NumberOfConnectors
  9144. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9147. {
  9148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9149. }
  9150. else
  9151. {
  9152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9153. }
  9154. // ResetRetries
  9155. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9158. // ConnectorPhaseRotation
  9159. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9162. // ConnectorPhaseRotationMaxLength
  9163. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9166. // StopTransactionOnEVSideDisconnect
  9167. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9170. // StopTransactionOnInvalidId
  9171. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9174. // StopTxnAlignedData
  9175. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9178. // StopTxnAlignedDataMaxLength
  9179. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9182. // StopTxnSampledData
  9183. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9186. // StopTxnSampledDataMaxLength
  9187. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9190. // SupportedFeatureProfiles
  9191. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9194. // SupportedFeatureProfilesMaxLength
  9195. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9198. // TransactionMessageAttempts
  9199. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9202. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9203. // TransactionMessageRetryInterval
  9204. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9207. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9208. // UnlockConnectorOnEVSideDisconnect
  9209. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9212. // WebSocketPingInterval
  9213. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9216. //* Local Auth List Management Profile*/
  9217. #if 0
  9218. //For OCTT Test Case
  9219. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9222. #endif
  9223. #if 1
  9224. //LocalAuthListEnabled
  9225. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9228. #endif
  9229. //LocalAuthListMaxLength
  9230. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9233. //SendLocalListMaxLength
  9234. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9237. //ReserveConnectorZeroSupported
  9238. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9241. //* Smart Charging Profile */
  9242. //ChargeProfileMaxStackLevel
  9243. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9246. // ChargingScheduleAllowedChargingRateUnit
  9247. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9250. // ChargingScheduleMaxPeriods
  9251. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9254. // ConnectorSwitch3to1PhaseSupported
  9255. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9258. // MaxChargingProfilesInstalled
  9259. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9262. return 0;
  9263. }
  9264. void getKeyValue(char *keyReq)
  9265. {
  9266. int isEmpty = FALSE;
  9267. int isKnowKey = FALSE;
  9268. //int unKnowIndex = 0;
  9269. DEBUG_INFO("getKeyValue \n");
  9270. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9271. isEmpty = TRUE;
  9272. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9273. {
  9274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9277. {
  9278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9279. }
  9280. else
  9281. {
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9283. }
  9284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9285. isKnowKey = TRUE;
  9286. }
  9287. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9288. {
  9289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9292. {
  9293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9294. }
  9295. else
  9296. {
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9298. }
  9299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9300. isKnowKey = TRUE;
  9301. }
  9302. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9303. {
  9304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9307. {
  9308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9309. }
  9310. else
  9311. {
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9313. }
  9314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9315. isKnowKey = TRUE;
  9316. }
  9317. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9318. {
  9319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9322. {
  9323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9324. }
  9325. else
  9326. {
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9328. }
  9329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9330. isKnowKey = TRUE;
  9331. }
  9332. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9333. {
  9334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9337. {
  9338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9339. }
  9340. else
  9341. {
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9343. }
  9344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9345. isKnowKey = TRUE;
  9346. }
  9347. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9348. {
  9349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9352. {
  9353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9354. }
  9355. else
  9356. {
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9358. }
  9359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9360. isKnowKey = TRUE;
  9361. }
  9362. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9363. {
  9364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9367. {
  9368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9369. }
  9370. else
  9371. {
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9373. }
  9374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9375. isKnowKey = TRUE;
  9376. }
  9377. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9378. {
  9379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9382. {
  9383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9384. }
  9385. else
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9388. }
  9389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9390. isKnowKey = TRUE;
  9391. }
  9392. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9393. {
  9394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9397. {
  9398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9399. }
  9400. else
  9401. {
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9403. }
  9404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9405. isKnowKey = TRUE;
  9406. }
  9407. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9408. {
  9409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9412. {
  9413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9414. }
  9415. else
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9418. }
  9419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9420. isKnowKey = TRUE;
  9421. }
  9422. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9423. {
  9424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9427. {
  9428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9429. }
  9430. else
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9433. }
  9434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9435. isKnowKey = TRUE;
  9436. }
  9437. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9438. {
  9439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9442. {
  9443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9444. }
  9445. else
  9446. {
  9447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9448. }
  9449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9450. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  9451. isKnowKey = TRUE;
  9452. }
  9453. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9454. {
  9455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9458. {
  9459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9460. }
  9461. else
  9462. {
  9463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9464. }
  9465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9466. isKnowKey = TRUE;
  9467. }
  9468. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9469. {
  9470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9473. {
  9474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9475. }
  9476. else
  9477. {
  9478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9479. }
  9480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9481. isKnowKey = TRUE;
  9482. }
  9483. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9484. {
  9485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9488. {
  9489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9490. }
  9491. else
  9492. {
  9493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9494. }
  9495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9496. isKnowKey = TRUE;
  9497. }
  9498. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9499. {
  9500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9503. {
  9504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9505. }
  9506. else
  9507. {
  9508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9509. }
  9510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9511. isKnowKey = TRUE;
  9512. }
  9513. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9514. {
  9515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9518. {
  9519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9520. }
  9521. else
  9522. {
  9523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9524. }
  9525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9526. isKnowKey = TRUE;
  9527. }
  9528. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9529. {
  9530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9533. {
  9534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9535. }
  9536. else
  9537. {
  9538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9539. }
  9540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9541. isKnowKey = TRUE;
  9542. }
  9543. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9544. {
  9545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9548. {
  9549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9550. }
  9551. else
  9552. {
  9553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9554. }
  9555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9556. isKnowKey = TRUE;
  9557. }
  9558. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9559. {
  9560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9563. {
  9564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9565. }
  9566. else
  9567. {
  9568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9569. }
  9570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9571. isKnowKey = TRUE;
  9572. }
  9573. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9574. {
  9575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9578. {
  9579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9580. }
  9581. else
  9582. {
  9583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9584. }
  9585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9586. isKnowKey = TRUE;
  9587. }
  9588. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9589. {
  9590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9593. {
  9594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9595. }
  9596. else
  9597. {
  9598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9599. }
  9600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9601. isKnowKey = TRUE;
  9602. }
  9603. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9604. {
  9605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9608. {
  9609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9610. }
  9611. else
  9612. {
  9613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9614. }
  9615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9616. isKnowKey = TRUE;
  9617. }
  9618. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9619. {
  9620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9623. {
  9624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9625. }
  9626. else
  9627. {
  9628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9629. }
  9630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9631. isKnowKey = TRUE;
  9632. }
  9633. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9634. {
  9635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9638. {
  9639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9640. }
  9641. else
  9642. {
  9643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9644. }
  9645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9646. isKnowKey = TRUE;
  9647. }
  9648. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9649. {
  9650. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9653. {
  9654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9655. }
  9656. else
  9657. {
  9658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9659. }
  9660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9661. isKnowKey = TRUE;
  9662. }
  9663. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9664. {
  9665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9668. {
  9669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9670. }
  9671. else
  9672. {
  9673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9674. }
  9675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9676. isKnowKey = TRUE;
  9677. }
  9678. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9679. {
  9680. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9683. {
  9684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9685. }
  9686. else
  9687. {
  9688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9689. }
  9690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9691. isKnowKey = TRUE;
  9692. }
  9693. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9694. {
  9695. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9698. {
  9699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9700. }
  9701. else
  9702. {
  9703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9704. }
  9705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9706. isKnowKey = TRUE;
  9707. }
  9708. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9709. {
  9710. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9713. {
  9714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9715. }
  9716. else
  9717. {
  9718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9719. }
  9720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9721. isKnowKey = TRUE;
  9722. }
  9723. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9724. {
  9725. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9728. {
  9729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9730. }
  9731. else
  9732. {
  9733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9734. }
  9735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9736. isKnowKey = TRUE;
  9737. }
  9738. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9739. {
  9740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9742. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9743. {
  9744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9745. }
  9746. else
  9747. {
  9748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9749. }
  9750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9751. isKnowKey = TRUE;
  9752. }
  9753. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9754. {
  9755. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9758. {
  9759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9760. }
  9761. else
  9762. {
  9763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9764. }
  9765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9766. isKnowKey = TRUE;
  9767. }
  9768. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9769. {
  9770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9773. {
  9774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9775. }
  9776. else
  9777. {
  9778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9779. }
  9780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9781. isKnowKey = TRUE;
  9782. }
  9783. #if 0
  9784. //For OCTT Test Case
  9785. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9786. {
  9787. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9789. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9790. {
  9791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9792. }
  9793. else
  9794. {
  9795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9796. }
  9797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9798. isKnowKey = TRUE;
  9799. }
  9800. #endif
  9801. #if 1
  9802. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9803. {
  9804. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9806. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9807. {
  9808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9809. }
  9810. else
  9811. {
  9812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9813. }
  9814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9815. isKnowKey = TRUE;
  9816. }
  9817. #endif
  9818. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9819. {
  9820. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9822. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9823. {
  9824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9825. }
  9826. else
  9827. {
  9828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9829. }
  9830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9831. isKnowKey = TRUE;
  9832. }
  9833. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9834. {
  9835. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9837. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9838. {
  9839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9840. }
  9841. else
  9842. {
  9843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9844. }
  9845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9846. isKnowKey = TRUE;
  9847. }
  9848. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9849. {
  9850. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9852. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9853. {
  9854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9855. }
  9856. else
  9857. {
  9858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9859. }
  9860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9861. isKnowKey = TRUE;
  9862. }
  9863. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9864. {
  9865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9867. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9868. {
  9869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9870. }
  9871. else
  9872. {
  9873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9874. }
  9875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9876. isKnowKey = TRUE;
  9877. }
  9878. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9879. {
  9880. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9882. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9883. {
  9884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9885. }
  9886. else
  9887. {
  9888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9889. }
  9890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9891. isKnowKey = TRUE;
  9892. }
  9893. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9894. {
  9895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9897. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9898. {
  9899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9900. }
  9901. else
  9902. {
  9903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9904. }
  9905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9906. isKnowKey = TRUE;
  9907. }
  9908. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9909. {
  9910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9912. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9913. {
  9914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9915. }
  9916. else
  9917. {
  9918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9919. }
  9920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9921. isKnowKey = TRUE;
  9922. }
  9923. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9924. {
  9925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9927. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9928. {
  9929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9930. }
  9931. else
  9932. {
  9933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9934. }
  9935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9936. isKnowKey = TRUE;
  9937. }
  9938. //=========================================================
  9939. if(!isEmpty && !isKnowKey)
  9940. {
  9941. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9942. strcpy(unknownkey[UnknownKeynum], keyReq);
  9943. UnknownKeynum = UnknownKeynum + 1;
  9944. }
  9945. }
  9946. void processUnkownKey(void)
  9947. {
  9948. DEBUG_INFO("processUnkownKey\n");
  9949. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9950. for(int index=0; index < UnknownKeynum; index++)
  9951. {
  9952. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9953. {
  9954. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9955. }
  9956. }
  9957. }
  9958. int setKeyValue(char *key, char *value)
  9959. {
  9960. int isSuccess = NotSupported;
  9961. int check_ascii=0;
  9962. #ifdef Debug
  9963. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9964. #endif
  9965. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9966. {
  9967. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9969. {
  9970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9971. isSuccess = ConfigurationStatus_Accepted;
  9972. }
  9973. else
  9974. {
  9975. isSuccess = ConfigurationStatus_Rejected;
  9976. }
  9977. }
  9978. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9979. {
  9980. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9982. {
  9983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9984. isSuccess = ConfigurationStatus_Accepted;
  9985. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9986. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9987. }
  9988. else
  9989. {
  9990. isSuccess = ConfigurationStatus_Rejected;
  9991. }
  9992. }
  9993. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9994. {
  9995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9996. {
  9997. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9999. isSuccess = ConfigurationStatus_Accepted;
  10000. }
  10001. else
  10002. {
  10003. isSuccess = ConfigurationStatus_Rejected;
  10004. }
  10005. }
  10006. if(strcmp(key, "BlinkRepeat") == 0)
  10007. {
  10008. //Charger.BlinkRepeat = Integer.parseInt(value);
  10009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10010. {
  10011. check_ascii = value[0];
  10012. if( (check_ascii < 48) || (check_ascii > 57) )
  10013. {
  10014. isSuccess = ConfigurationStatus_Rejected;
  10015. }
  10016. else
  10017. {
  10018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10019. isSuccess = ConfigurationStatus_Accepted;
  10020. }
  10021. }
  10022. else
  10023. {
  10024. isSuccess = ConfigurationStatus_Rejected;
  10025. }
  10026. }
  10027. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10028. {
  10029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10030. {
  10031. check_ascii = value[0];
  10032. if( (check_ascii < 48) || (check_ascii > 57) )
  10033. {
  10034. isSuccess = ConfigurationStatus_Rejected;
  10035. }
  10036. else
  10037. {
  10038. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  10040. isSuccess = ConfigurationStatus_Accepted;
  10041. }
  10042. }
  10043. else
  10044. {
  10045. isSuccess = ConfigurationStatus_Rejected;
  10046. }
  10047. }
  10048. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10049. {
  10050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10051. {
  10052. check_ascii = value[0];
  10053. if( (check_ascii < 48) || (check_ascii > 57) )
  10054. {
  10055. isSuccess = ConfigurationStatus_Rejected;
  10056. }
  10057. else
  10058. {
  10059. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10061. isSuccess = ConfigurationStatus_Accepted;
  10062. }
  10063. }
  10064. else
  10065. {
  10066. isSuccess = ConfigurationStatus_Rejected;
  10067. }
  10068. }
  10069. if(strcmp(key, "HeartbeatInterval") == 0)
  10070. {
  10071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10072. {
  10073. check_ascii = value[0];
  10074. if( (check_ascii < 48) || (check_ascii > 57) )
  10075. {
  10076. isSuccess = ConfigurationStatus_Rejected;
  10077. }
  10078. else
  10079. {
  10080. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  10082. HeartBeatWaitTime = atoi(value);
  10083. isSuccess = ConfigurationStatus_Accepted;
  10084. }
  10085. }
  10086. else
  10087. {
  10088. isSuccess = ConfigurationStatus_Rejected;
  10089. }
  10090. }
  10091. if(strcmp(key, "LightIntensity") == 0)
  10092. {
  10093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10094. {
  10095. check_ascii = value[0];
  10096. if( (check_ascii < 48) || (check_ascii > 57) )
  10097. {
  10098. isSuccess = ConfigurationStatus_Rejected;
  10099. }
  10100. else
  10101. {
  10102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10103. isSuccess = ConfigurationStatus_Accepted;
  10104. }
  10105. }
  10106. else
  10107. {
  10108. isSuccess = ConfigurationStatus_Rejected;
  10109. }
  10110. }
  10111. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10112. {
  10113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10114. {
  10115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10116. isSuccess = ConfigurationStatus_Accepted;
  10117. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10118. }
  10119. else
  10120. {
  10121. isSuccess = ConfigurationStatus_Rejected;
  10122. }
  10123. }
  10124. if(strcmp(key, "LocalPreAuthorize") == 0)
  10125. {
  10126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10127. {
  10128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10129. isSuccess = ConfigurationStatus_Accepted;
  10130. }
  10131. else
  10132. {
  10133. isSuccess = ConfigurationStatus_Rejected;
  10134. }
  10135. }
  10136. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10137. {
  10138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10139. {
  10140. check_ascii = value[0];
  10141. if( (check_ascii < 48) || (check_ascii > 57) )
  10142. {
  10143. isSuccess = ConfigurationStatus_Rejected;
  10144. }
  10145. else
  10146. {
  10147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10148. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10149. isSuccess = ConfigurationStatus_Accepted;
  10150. }
  10151. }
  10152. else
  10153. {
  10154. isSuccess = ConfigurationStatus_Rejected;
  10155. }
  10156. }
  10157. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10158. {
  10159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10160. {
  10161. //int valueLength = strlen(value);
  10162. for(int i = 0; value[i]; i++){
  10163. value[i] = tolower(value[i]);
  10164. }
  10165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10166. isSuccess = ConfigurationStatus_Accepted;
  10167. }
  10168. else
  10169. {
  10170. isSuccess = ConfigurationStatus_Rejected;
  10171. }
  10172. }
  10173. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10174. {
  10175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10176. {
  10177. //int valueLength = strlen(value);
  10178. for(int i = 0; value[i]; i++){
  10179. value[i] = tolower(value[i]);
  10180. }
  10181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10182. isSuccess = ConfigurationStatus_Accepted;
  10183. }
  10184. else
  10185. {
  10186. isSuccess = ConfigurationStatus_Rejected;
  10187. }
  10188. }
  10189. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10190. {
  10191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10192. {
  10193. check_ascii = value[0];
  10194. if( (check_ascii < 48) || (check_ascii > 57) )
  10195. {
  10196. isSuccess = ConfigurationStatus_Rejected;
  10197. }
  10198. else
  10199. {
  10200. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10202. isSuccess = ConfigurationStatus_Accepted;
  10203. }
  10204. #ifdef Debug
  10205. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10206. #endif
  10207. }
  10208. else
  10209. {
  10210. isSuccess = ConfigurationStatus_Rejected;
  10211. #ifdef Debug
  10212. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10213. #endif
  10214. }
  10215. }
  10216. if(strcmp(key, "MinimumStatusDuration") == 0)
  10217. {
  10218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10219. {
  10220. check_ascii = value[0];
  10221. if( (check_ascii < 48) || (check_ascii > 57) )
  10222. {
  10223. isSuccess = ConfigurationStatus_Rejected;
  10224. }
  10225. else
  10226. {
  10227. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10229. isSuccess = ConfigurationStatus_Accepted;
  10230. }
  10231. }
  10232. else
  10233. {
  10234. isSuccess = ConfigurationStatus_Rejected;
  10235. }
  10236. }
  10237. if(strcmp(key, "ResetRetries") == 0)
  10238. {
  10239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10240. {
  10241. check_ascii = value[0];
  10242. if( (check_ascii < 48) || (check_ascii > 57) )
  10243. {
  10244. isSuccess = ConfigurationStatus_Rejected;
  10245. }
  10246. else
  10247. {
  10248. //Charger.ResetRetries = Integer.parseInt(value);
  10249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10250. isSuccess = ConfigurationStatus_Accepted;
  10251. }
  10252. }
  10253. else
  10254. {
  10255. isSuccess = ConfigurationStatus_Rejected;
  10256. }
  10257. }
  10258. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10259. {
  10260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10261. {
  10262. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10263. //int valueLength = strlen(value);
  10264. for(int i = 0; value[i]; i++){
  10265. value[i] = tolower(value[i]);
  10266. }
  10267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10268. isSuccess = ConfigurationStatus_Accepted;
  10269. }
  10270. else
  10271. {
  10272. isSuccess = ConfigurationStatus_Rejected;
  10273. }
  10274. }
  10275. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10276. {
  10277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10278. {
  10279. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10281. isSuccess = ConfigurationStatus_Accepted;
  10282. }
  10283. else
  10284. {
  10285. isSuccess = ConfigurationStatus_Rejected;
  10286. }
  10287. }
  10288. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10289. {
  10290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10291. {
  10292. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10294. isSuccess = ConfigurationStatus_Accepted;
  10295. }
  10296. else
  10297. {
  10298. isSuccess = ConfigurationStatus_Rejected;
  10299. }
  10300. }
  10301. if(strcmp(key, "StopTxnAlignedData") == 0)
  10302. {
  10303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10304. {
  10305. //Charger.StopTxnAlignedData = value.toLowerCase();
  10306. //int valueLength = strlen(value);
  10307. for(int i = 0; value[i]; i++){
  10308. value[i] = tolower(value[i]);
  10309. }
  10310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10311. isSuccess = ConfigurationStatus_Accepted;
  10312. }
  10313. else
  10314. {
  10315. isSuccess = ConfigurationStatus_Rejected;
  10316. }
  10317. }
  10318. if(strcmp(key, "StopTxnSampledData") == 0)
  10319. {
  10320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10321. {
  10322. //Charger.StopTxnSampledData = value.toLowerCase();
  10323. //int valueLength = strlen(value);
  10324. for(int i = 0; value[i]; i++){
  10325. value[i] = tolower(value[i]);
  10326. }
  10327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10328. isSuccess = ConfigurationStatus_Accepted;
  10329. }
  10330. else
  10331. {
  10332. isSuccess = ConfigurationStatus_Rejected;
  10333. }
  10334. }
  10335. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10336. {
  10337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10338. {
  10339. check_ascii = value[0];
  10340. if( (check_ascii < 48) || (check_ascii > 57) )
  10341. {
  10342. isSuccess = ConfigurationStatus_Rejected;
  10343. }
  10344. else
  10345. {
  10346. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10348. TransactionMessageAttemptsValue = atoi(value);
  10349. isSuccess = ConfigurationStatus_Accepted;
  10350. }
  10351. }
  10352. else
  10353. {
  10354. isSuccess = ConfigurationStatus_Rejected;
  10355. }
  10356. }
  10357. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10358. {
  10359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10360. {
  10361. check_ascii = value[0];
  10362. if( (check_ascii < 48) || (check_ascii > 57) )
  10363. {
  10364. isSuccess = ConfigurationStatus_Rejected;
  10365. }
  10366. else
  10367. {
  10368. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10370. TransactionMessageRetryIntervalValue = atoi(value);
  10371. isSuccess = ConfigurationStatus_Accepted;
  10372. }
  10373. }
  10374. else
  10375. {
  10376. isSuccess = ConfigurationStatus_Rejected;
  10377. }
  10378. }
  10379. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10380. {
  10381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10382. {
  10383. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10385. isSuccess = ConfigurationStatus_Accepted;
  10386. }
  10387. else
  10388. {
  10389. isSuccess = ConfigurationStatus_Rejected;
  10390. }
  10391. }
  10392. if(strcmp(key, "WebSocketPingInterval") == 0)
  10393. {
  10394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10395. {
  10396. check_ascii = value[0];
  10397. if( (check_ascii < 48) || (check_ascii > 57) )
  10398. {
  10399. isSuccess = ConfigurationStatus_Rejected;
  10400. }
  10401. else
  10402. {
  10403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10404. isSuccess = ConfigurationStatus_Accepted;
  10405. }
  10406. }
  10407. else
  10408. {
  10409. isSuccess = ConfigurationStatus_Rejected;
  10410. }
  10411. }
  10412. #if 0
  10413. //For OCPP Test Case
  10414. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10415. {
  10416. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10417. {
  10418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10419. isSuccess = ConfigurationStatus_Accepted;
  10420. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10421. }
  10422. else
  10423. {
  10424. isSuccess = ConfigurationStatus_Rejected;
  10425. }
  10426. }
  10427. #endif
  10428. #if 1
  10429. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10430. {
  10431. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10432. {
  10433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10434. isSuccess = ConfigurationStatus_Accepted;
  10435. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10436. }
  10437. else
  10438. {
  10439. isSuccess = ConfigurationStatus_Rejected;
  10440. }
  10441. }
  10442. #endif
  10443. return isSuccess;
  10444. }
  10445. int updateSetting(char *key, char *value)
  10446. {
  10447. mtrace();
  10448. int isSuccess = FALSE;
  10449. char string[1000]={0}, buffer[1000]={0};
  10450. char strtemp[50]={0};
  10451. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10452. int pos, c = 0;
  10453. char *loc;
  10454. int pos1=0;
  10455. FILE *f = fopen("/var/www/settings1", "r");
  10456. if(f == NULL)
  10457. {
  10458. #ifdef Debug
  10459. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10460. #endif
  10461. return isSuccess;
  10462. }
  10463. fseek(f, 0, SEEK_END);
  10464. long fsize = ftell(f);
  10465. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10466. fread(string, 1, fsize, f);
  10467. fclose(f);
  10468. string[fsize] = 0;
  10469. loc = strstr(string, key);
  10470. if(loc != NULL)
  10471. {
  10472. DEBUG_INFO("key exist!\n");
  10473. pos = loc - string-1;
  10474. f = fopen("/var/www/settings1", "w");
  10475. strncpy(buffer, string, pos);
  10476. fprintf(f, "%s", buffer);
  10477. memset(sstr ,0, sizeof(sstr) );
  10478. c = 0;
  10479. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10480. {
  10481. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10483. c++;
  10484. }
  10485. sstr[c] = '\0';
  10486. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10487. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10488. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10489. memset(buffer ,0, sizeof(buffer) );
  10490. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10491. //printf("buffer=%s",buffer);
  10492. fprintf(f, "%s", buffer);
  10493. fclose(f);
  10494. }
  10495. else
  10496. {
  10497. printf("key not exist!\n");
  10498. f = fopen("/var/www/settings1", "w+");
  10499. fputs(string, f);
  10500. fseek(f, -1, SEEK_CUR);
  10501. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10502. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10503. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10504. fclose(f);
  10505. }
  10506. isSuccess = TRUE;
  10507. return isSuccess;
  10508. }
  10509. int TransactionMessageAttemptsGet(void)
  10510. {
  10511. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10512. }
  10513. int FirstHeartBeatResponse(void)
  10514. {
  10515. return FirstHeartBeat;
  10516. }
  10517. int TransactionMessageRetryIntervalGet(void)
  10518. {
  10519. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10520. }
  10521. #define SA struct sockaddr
  10522. #define MAXBUF 1024
  10523. //static int m_socket_data;
  10524. //static int sockfd;
  10525. int ReadHttpStatus(int sock){
  10526. //char c;
  10527. char buff[1024]="",*ptr=buff+1;
  10528. int bytes_received, status;
  10529. DEBUG_INFO("Begin Response ..\n");
  10530. while((bytes_received = recv(sock, ptr, 1, 0))){
  10531. if(bytes_received==-1){
  10532. perror("ReadHttpStatus");
  10533. exit(1);
  10534. }
  10535. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10536. ptr++;
  10537. }
  10538. *ptr=0;
  10539. ptr=buff+1;
  10540. sscanf(ptr,"%*s %d ", &status);
  10541. DEBUG_INFO("%s\n",ptr);
  10542. DEBUG_INFO("status=%d\n",status);
  10543. DEBUG_INFO("End Response ..\n");
  10544. return (bytes_received>0)?status:0;
  10545. }
  10546. //the only filed that it parsed is 'Content-Length'
  10547. int ParseHeader(int sock){
  10548. //char c;
  10549. char buff[1024]="",*ptr=buff+4;
  10550. int bytes_received;
  10551. DEBUG_INFO("Begin HEADER ..\n");
  10552. while((bytes_received = recv(sock, ptr, 1, 0))){
  10553. if(bytes_received==-1){
  10554. perror("Parse Header");
  10555. exit(1);
  10556. }
  10557. if(
  10558. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10559. (ptr[-1]=='\r') && (*ptr=='\n' )
  10560. ) break;
  10561. ptr++;
  10562. }
  10563. *ptr=0;
  10564. ptr=buff+4;
  10565. //printf("%s",ptr);
  10566. if(bytes_received){
  10567. ptr=strstr(ptr,"Content-Length:");
  10568. if(ptr){
  10569. sscanf(ptr,"%*s %d",&bytes_received);
  10570. }else
  10571. bytes_received=-1; //unknown size
  10572. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10573. }
  10574. DEBUG_INFO("End HEADER ..\n");
  10575. return bytes_received ;
  10576. }
  10577. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10578. {
  10579. char rmFileCmd[100]={0};
  10580. char FilePath[100]={0};
  10581. char ftpbuf[200];
  10582. int systemresult;
  10583. DEBUG_INFO("filename=%s\n",filename);
  10584. DEBUG_INFO("url=%s\n",url);
  10585. sprintf(FilePath,"../mnt/%s",filename);
  10586. if((access(FilePath,F_OK))!=-1)
  10587. {
  10588. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10589. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10590. system(rmFileCmd);
  10591. }
  10592. memset(ftpbuf, 0, sizeof(ftpbuf));
  10593. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10594. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10595. systemresult = system(ftpbuf);
  10596. DEBUG_INFO("systemresult=%d\n",systemresult);
  10597. if(systemresult != 0)
  10598. {
  10599. DEBUG_INFO("http DownLoad error!\n");
  10600. return FALSE;
  10601. }
  10602. return TRUE;
  10603. }
  10604. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10605. {
  10606. char rmFileCmd[100]={0};
  10607. char FilePath[100]={0};
  10608. char ftpbuf[200];
  10609. int systemresult;
  10610. //char temp[100];
  10611. #if 0
  10612. struct hostent* server;
  10613. char *IPbuffer;
  10614. server = gethostbyname(location);
  10615. // To convert an Internet network
  10616. // address into ASCII string
  10617. IPbuffer = inet_ntoa(*((struct in_addr*)
  10618. server->h_addr_list[0]));
  10619. #endif
  10620. sprintf(FilePath,"../mnt/%s",filename);
  10621. if((access(FilePath,F_OK))!=-1)
  10622. {
  10623. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10624. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10625. system(rmFileCmd);
  10626. }
  10627. memset(ftpbuf, 0, sizeof(ftpbuf));
  10628. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10629. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10630. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10631. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10632. systemresult = system(ftpbuf);
  10633. DEBUG_INFO("systemresult=%d\n",systemresult);
  10634. if(systemresult != 0)
  10635. {
  10636. printf("ftpget error!\n");
  10637. return FALSE;
  10638. }
  10639. return TRUE;
  10640. }
  10641. int httpUploadFile(char *location, char *path, char *filename,char *url)
  10642. {
  10643. char rmFileCmd[100]={0};
  10644. char FilePath[100]={0};
  10645. char ftpbuf[200];
  10646. int systemresult;
  10647. DEBUG_INFO("filename=%s\n",filename);
  10648. DEBUG_INFO("url=%s\n",url);
  10649. sprintf(FilePath,"%s","../mnt/upload_file.txt");
  10650. if((access(FilePath,F_OK))!=-1)
  10651. {
  10652. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10653. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10654. system(rmFileCmd);
  10655. }
  10656. FILE *fp = fopen("../mnt/upload_file.txt", "w+");
  10657. if(fp == NULL)
  10658. {
  10659. DEBUG_INFO("log is NULL\n");
  10660. return 0;
  10661. }
  10662. else
  10663. {
  10664. fprintf(fp, "%s\n", url);
  10665. fprintf(fp, "%s\n", filename);
  10666. fclose(fp);
  10667. }
  10668. memset(ftpbuf, 0, sizeof(ftpbuf));
  10669. sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
  10670. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10671. systemresult = system(ftpbuf);
  10672. DEBUG_INFO("systemresult=%d\n",systemresult);
  10673. if(systemresult != 0)
  10674. {
  10675. DEBUG_INFO("http DownLoad error!\n");
  10676. return FALSE;
  10677. }
  10678. return TRUE;
  10679. }
  10680. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10681. {
  10682. struct hostent* server;
  10683. char *IPbuffer;
  10684. char ftpbuf[200];
  10685. int systemresult;
  10686. // To retrieve host information
  10687. server = gethostbyname(location);
  10688. // To convert an Internet network
  10689. // address into ASCII string
  10690. IPbuffer = inet_ntoa(*((struct in_addr*)
  10691. server->h_addr_list[0]));
  10692. memset(ftpbuf, 0, sizeof(ftpbuf));
  10693. /* format : ftpput -u username -p passwd IP target source*/
  10694. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10695. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10696. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10697. systemresult = system(ftpbuf);
  10698. DEBUG_INFO("systemresult=%d\n",systemresult);
  10699. if(systemresult != 0)
  10700. {
  10701. DEBUG_INFO("ftpput error!\n");
  10702. return FALSE;
  10703. }
  10704. return TRUE;
  10705. }
  10706. int SettingChargingRecord(int target, int transactionId)
  10707. {
  10708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10709. {
  10710. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10711. {
  10712. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10713. {
  10714. addBuff(target, transactionId, 0);
  10715. return TRUE;
  10716. }
  10717. }
  10718. for (int index = 0; index < CCS_QUANTITY; index++)
  10719. {
  10720. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10721. {
  10722. addBuff(target, transactionId, 0);
  10723. return TRUE;
  10724. }
  10725. }
  10726. for (int index = 0; index < GB_QUANTITY; index++)
  10727. {
  10728. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10729. {
  10730. addBuff(target, transactionId, 0);
  10731. return TRUE;
  10732. }
  10733. }
  10734. }
  10735. else
  10736. {
  10737. for (int index = 0; index < AC_QUANTITY; index++)
  10738. {
  10739. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10740. {
  10741. addBuff(target, transactionId, 0);
  10742. return TRUE;
  10743. }
  10744. }
  10745. }
  10746. return FALSE;
  10747. }
  10748. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10749. {
  10750. int isSuccess = FALSE;
  10751. //char *query = NULL;
  10752. sqlite3_stmt *stmt;
  10753. int rc; // return code
  10754. char str[20];
  10755. sprintf(str,"%d",user_id);
  10756. 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 */
  10757. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10758. rc = sqlite3_step(stmt); /* 3 */
  10759. if (rc != SQLITE_DONE) {
  10760. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10761. goto out;
  10762. }
  10763. sqlite3_finalize(stmt);
  10764. // free(query);
  10765. out:
  10766. //----------------------
  10767. // close SQLite database
  10768. //----------------------
  10769. sqlite3_close(db);
  10770. printf("database closed.\n");
  10771. return isSuccess;
  10772. }
  10773. /**
  10774. * Place the contents of the specified file into a memory buffer
  10775. *
  10776. * @param[in] filename The path and name of the file to read
  10777. * @param[out] filebuffer A pointer to the contents in memory
  10778. * @return status 0 success, 1 on failure
  10779. */
  10780. int get_file_contents(const char* filename, char** outbuffer) {
  10781. FILE* file = NULL;
  10782. long filesize;
  10783. const int blocksize = 1;
  10784. size_t readsize;
  10785. char* filebuffer;
  10786. // Open the file
  10787. file = fopen(filename, "r");
  10788. if (NULL == file)
  10789. {
  10790. printf("'%s' not opened\n", filename);
  10791. exit(EXIT_FAILURE);
  10792. }
  10793. // Determine the file size
  10794. fseek(file, 0, SEEK_END);
  10795. filesize = ftell(file);
  10796. rewind (file);
  10797. // Allocate memory for the file contents
  10798. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10799. *outbuffer = filebuffer;
  10800. if (filebuffer == NULL)
  10801. {
  10802. fputs ("malloc out-of-memory", stderr);
  10803. exit(EXIT_FAILURE);
  10804. }
  10805. // Read in the file
  10806. readsize = fread(filebuffer, blocksize, filesize, file);
  10807. if (readsize != filesize)
  10808. {
  10809. fputs ("didn't read file completely",stderr);
  10810. exit(EXIT_FAILURE);
  10811. }
  10812. // Clean exit
  10813. fclose(file);
  10814. return EXIT_SUCCESS;
  10815. }
  10816. static int selectSqlCount = 0;
  10817. static int callback(void *data, int argc, char **argv, char **azColName){
  10818. int i;
  10819. printf("%s: ", (const char*)data);
  10820. selectSqlCount = argc;
  10821. for(i = 0; i<argc; i++){
  10822. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10823. }
  10824. printf("\n");
  10825. return 0;
  10826. }
  10827. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10828. //int i;
  10829. //printf("%s:\n", (const char*)data);
  10830. localversion = argv[5] ? atoi(argv[5]) : 0;
  10831. printf("localversion=%d\n", localversion);
  10832. return 0;
  10833. }
  10834. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10835. //int i;
  10836. //printf("%s:\n", (const char*)data);
  10837. //idTag
  10838. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10839. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10840. //parentIdTag
  10841. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10842. //expir_date
  10843. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10844. //status
  10845. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10846. //version
  10847. idTagQuery.listVersionInt = atoi(argv[5]);
  10848. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10849. return 0;
  10850. }
  10851. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10852. int i;
  10853. //printf("%s:\n", (const char*)data);
  10854. #if 1
  10855. for(i=0; i<argc; i++){
  10856. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10857. }
  10858. //printf("");
  10859. #endif
  10860. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10861. // printf("localversion=%d\n", localversion);
  10862. return 0;
  10863. }
  10864. /** sqlite3_exec的回调。
  10865. *
  10866. * 向控制台打印查询的结果。
  10867. *
  10868. * @param in data 传递给回调函数的数据。
  10869. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10870. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10871. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10872. * @return 状态码。
  10873. */
  10874. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10875. {
  10876. for (int i = 0; i < n_columns; i++)
  10877. {
  10878. DEBUG_INFO("%s/t", col_values[i]);
  10879. }
  10880. DEBUG_INFO("/n");
  10881. return 0;
  10882. }
  10883. void OCPP_getListVerion()
  10884. {
  10885. int rc = 0;
  10886. // const char* data = "Callback function called";
  10887. char sql[100];
  10888. char zErrMsg[100];
  10889. memset(sql, 0, 100);
  10890. memset(zErrMsg, 0, 100);
  10891. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10892. /* Execute SQL statement */
  10893. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10894. DEBUG_INFO("rc=%d\n",rc);
  10895. if( rc != SQLITE_OK ){
  10896. DEBUG_INFO("SQL error: %s", zErrMsg);
  10897. //sqlite3_free(zErrMsg);
  10898. }else{
  10899. DEBUG_INFO("Operation done successfully");
  10900. }
  10901. }
  10902. void OCPP_getIdTag(char *idTag)
  10903. {
  10904. int rc = 0;
  10905. // const char* data = "Callback function called";
  10906. char sql[100];
  10907. char zErrMsg[100];
  10908. memset(sql, 0, 100);
  10909. memset(zErrMsg, 0, 100);
  10910. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10911. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10912. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10913. /* Execute SQL statement */
  10914. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10915. if( rc != SQLITE_OK ){
  10916. DEBUG_INFO("SQL error: %s", zErrMsg);
  10917. //sqlite3_free(zErrMsg);
  10918. }else{
  10919. printf("Operation done successfully");
  10920. }
  10921. //return ver;
  10922. }
  10923. void OCPP_get_TableAuthlocalAllData(void)
  10924. {
  10925. int rc = 0;
  10926. // const char* data = "Callback function called";
  10927. char sql[100];
  10928. char zErrMsg[100];
  10929. memset(sql, 0, 100);
  10930. memset(zErrMsg, 0, 100);
  10931. sprintf(sql,"select * from ocpp_auth_local ");
  10932. /* Execute SQL statement */
  10933. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10934. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10935. if( rc != SQLITE_OK ){
  10936. DEBUG_INFO("SQL error: %s", zErrMsg);
  10937. //sqlite3_free(zErrMsg);
  10938. }else{
  10939. DEBUG_INFO("Operation done successfully");
  10940. }
  10941. //return ver;
  10942. }
  10943. int OCPP_cleanLocalList()
  10944. {
  10945. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10946. char *errMsg = 0;
  10947. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10948. if (SQLITE_OK != rc)
  10949. {
  10950. DEBUG_INFO("%s\n",errMsg);
  10951. return FALSE;
  10952. }
  10953. else
  10954. {
  10955. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10956. }
  10957. return TRUE;
  10958. }
  10959. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10960. {
  10961. int isSuccess = FALSE;
  10962. int ret = 0;
  10963. //const char* data = "Callback function called";
  10964. char sql[200];
  10965. char zErrMsg[100];
  10966. memset(sql, 0, 200);
  10967. memset(zErrMsg, 0, 100);
  10968. 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);
  10969. //* Execute SQL statement */
  10970. //zErrMsg = 0;
  10971. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10972. if( ret != SQLITE_OK ){
  10973. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10974. // free(zErrMsg);
  10975. // free(sql);
  10976. return isSuccess;
  10977. }
  10978. DEBUG_INFO("successfully Insert records created\n");
  10979. isSuccess = TRUE;
  10980. return isSuccess;
  10981. }
  10982. void OCPP_deleteIdTag(char *idTag)
  10983. {
  10984. //int ver = 0;
  10985. //int isSuccess = FALSE;
  10986. int rc = 0;
  10987. char sql[100];
  10988. char zErrMsg[100];
  10989. memset(sql, 0, 100);
  10990. memset(zErrMsg, 0, 100);
  10991. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10992. //* Execute SQL statement */
  10993. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10994. if( rc != SQLITE_OK ){
  10995. DEBUG_INFO("SQL error: %s", zErrMsg);
  10996. //sqlite3_free(zErrMsg);
  10997. }else{
  10998. DEBUG_INFO("Operation done successfully");
  10999. }
  11000. }
  11001. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11002. {
  11003. int isSuccess = FALSE;
  11004. int ret = 0;
  11005. const char* data = "Callback function called";
  11006. char sql[200];
  11007. char zErrMsg[100];
  11008. memset(sql, 0, 200);
  11009. memset(zErrMsg, 0, 100);
  11010. //* selectFromTable */
  11011. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11012. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11013. //* Execute SQL statement */
  11014. selectSqlCount = 0;
  11015. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11016. if( ret != SQLITE_OK ){
  11017. printf("Error SQL: %s\n", zErrMsg);
  11018. }
  11019. printf("successfully select operation done\n");
  11020. memset(sql, 0, 200);
  11021. memset(zErrMsg, 0, 100);
  11022. if(selectSqlCount == 0)
  11023. {
  11024. //Insert
  11025. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11026. 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);
  11027. DEBUG_INFO("sql:%s\n", sql);
  11028. //* Execute SQL statement */
  11029. //zErrMsg = 0;
  11030. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11031. if( ret != SQLITE_OK ){
  11032. printf("SQL error: %s\n", zErrMsg);
  11033. return isSuccess;
  11034. }
  11035. DEBUG_INFO("successfully Insert records created\n");
  11036. isSuccess = TRUE;
  11037. }
  11038. else
  11039. {
  11040. //Update
  11041. //* Create merged SQL statement */
  11042. 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);
  11043. /* Execute SQL statement */
  11044. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11045. if( ret != SQLITE_OK ){
  11046. printf("SQL error: %s\n", zErrMsg);
  11047. //sqlite3_free(zErrMsg);
  11048. //sqlite3_free(sql);
  11049. return isSuccess;
  11050. }
  11051. DEBUG_INFO("Successfully operation done \n");
  11052. isSuccess = TRUE;
  11053. }
  11054. return isSuccess;
  11055. }
  11056. int GetOcppServerURL()
  11057. {
  11058. int result = FALSE;
  11059. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  11060. memset(OcppHost, 0, sizeof(OcppHost));
  11061. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  11062. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  11063. {
  11064. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  11065. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  11066. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11067. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11068. result = TRUE;
  11069. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11070. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11071. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11072. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11073. goto End;
  11074. }
  11075. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  11076. {
  11077. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  11078. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  11079. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11080. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11081. result = TRUE;
  11082. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11083. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11084. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11085. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11086. goto End;
  11087. }
  11088. else
  11089. {
  11090. strcpy(OcppHost,"");
  11091. }
  11092. End:
  11093. return result;
  11094. }
  11095. int GetOcppPath()
  11096. {
  11097. int result = FALSE;
  11098. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  11099. {
  11100. if(OcppTempPath == NULL)
  11101. {
  11102. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  11103. }
  11104. else
  11105. {
  11106. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  11107. }
  11108. result = TRUE;
  11109. goto End;
  11110. }
  11111. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  11112. {
  11113. if(OcppTempPath == NULL)
  11114. {
  11115. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  11116. }
  11117. else
  11118. {
  11119. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  11120. }
  11121. result = TRUE;
  11122. goto End;
  11123. }
  11124. else
  11125. {
  11126. strcpy(OcppPath,"");
  11127. }
  11128. End:
  11129. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  11130. return result;
  11131. }
  11132. int GetOcppPort()
  11133. {
  11134. return OcppPort;
  11135. }
  11136. int GetOcppConnStatus(void)
  11137. {
  11138. return ShmOCPP16Data->OcppConnStatus;
  11139. }
  11140. void SetOcppConnStatus(uint8_t status)
  11141. {
  11142. ShmOCPP16Data->OcppConnStatus = status;
  11143. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  11144. if(status == FALSE)
  11145. {
  11146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11147. {
  11148. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  11149. }
  11150. else
  11151. {
  11152. SystemInitial = AC_QUANTITY;
  11153. }
  11154. }
  11155. }
  11156. int GetHeartBeatWithNOResponse(void)
  11157. {
  11158. return HeartBeatWithNOResponse;
  11159. }
  11160. void SetHeartBeatWithNOResponse(void)
  11161. {
  11162. HeartBeatWithNOResponse = 0;
  11163. }
  11164. int GetTransactionId(int gunindex)
  11165. {
  11166. return TransactionId[gunindex];
  11167. }
  11168. void SetTransactionIdZero(int gunindex)
  11169. {
  11170. TransactionId[gunindex] = 0;
  11171. }
  11172. int InternetDisconnect(void)
  11173. {
  11174. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  11175. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  11176. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  11177. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  11178. }
  11179. void GetChargingProfileRequest(int gunindex)
  11180. {
  11181. mtrace();
  11182. //int connectorIdInt, durationInt;
  11183. //char chargingRateUnitStr[4]={0};
  11184. int tempdurationInt = 0;
  11185. int tempchargingProfileId = 0;
  11186. int tempstackLevel = 0;
  11187. int temptransactionId = 0;
  11188. float tempminChargingRateFloat = 0.0;
  11189. char tempchargingProfilePurposeStr[24]={0};
  11190. char tempchargingProfileKindStr[12]={0};
  11191. char temprecurrencyKindStr[8]={0};
  11192. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  11193. char tempvalidToStr[28]={0};
  11194. int tempStartPeriodInt = 0;
  11195. float tempLimitInt = 0.0;//0.1;
  11196. int tempNumberPhasesInt=0;
  11197. char fname[200];
  11198. //char comfirmstr[20];
  11199. float MinChargingRate =0.0;
  11200. double diff_t;
  11201. struct tm tp;
  11202. FILE *fptr1;//, *fptr2;
  11203. int c = 0;
  11204. char * pch;
  11205. char *loc;
  11206. char sstr[200]={ 0 };
  11207. int n_chargingProfile = 0;
  11208. int n_SchedulePeriods = 0;
  11209. char SchedulePeriodList[10][200]={0};
  11210. char sLineWord[800]={0};
  11211. char word[1000]={0};
  11212. int confirmPeriods = 0;
  11213. struct StructProfile ChargePointMaxProfile;
  11214. struct StructProfile TxDefaultProfile;
  11215. struct StructProfile TxProfile;
  11216. struct StructProfile TxDefaultProfiletemp[2]={0};
  11217. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  11218. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  11219. struct StructChargingProfile TxProfile_TEMP={0};
  11220. int TxDefaultProfileFileIsNull=FALSE;
  11221. int ChargePointMaxProfileIsNull=FALSE;
  11222. int TxProfileIsNull=FALSE;
  11223. // int CompositeSceduleIndex = 0;
  11224. char ChargePointMaxProfileScheduleStr[30]={0};
  11225. char TxDefaultProfileScheduleStr[30]={0};
  11226. char TxProfileScheduleStr[30]={0};
  11227. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  11228. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  11229. memset(&TxProfile,0,sizeof(struct StructProfile));
  11230. DEBUG_INFO("GetChargingProfileRequest\n");
  11231. //*****************************ChargePointMaxProfile******************************************/
  11232. strcpy(fname, ChargePointMaxProfile_JSON);
  11233. ChargePointMaxProfileIsNull=TRUE;
  11234. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  11235. {
  11236. fptr1 = fopen(fname, "r");
  11237. int c;
  11238. c = fgetc(fptr1);
  11239. //DEBUG_INFO("c:%d\n",c);
  11240. rewind(fptr1);
  11241. if(c == EOF)
  11242. {
  11243. DEBUG_INFO("\n End of file reached.");
  11244. ChargePointMaxProfileIsNull=TRUE;
  11245. fclose(fptr1);
  11246. }
  11247. else
  11248. {
  11249. ChargePointMaxProfileIsNull=FALSE;
  11250. while(fscanf(fptr1, "%s", word) != EOF)
  11251. {
  11252. if(strcmp(word, "chargingProfileId") == 0)
  11253. {
  11254. n_chargingProfile = n_chargingProfile + 1;
  11255. }
  11256. }
  11257. rewind(fptr1);
  11258. //search Charging Profile Element
  11259. int i = 0;
  11260. int j = 0;
  11261. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11262. //***********chargingProfileId**************/
  11263. c = 0;
  11264. loc = strstr(sLineWord, "chargingProfileId");
  11265. //DEBUG_INFO("loc=%s\n",loc);
  11266. memset(sstr ,0, sizeof(sstr) );
  11267. if(loc != NULL)
  11268. {
  11269. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11270. {
  11271. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11272. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11273. c++;
  11274. }
  11275. sstr[c] = '\0';
  11276. tempchargingProfileId = atoi(sstr);
  11277. }
  11278. else
  11279. {
  11280. tempchargingProfileId = 0;
  11281. }
  11282. //***********stackLevel**************/
  11283. c = 0;
  11284. loc = strstr(sLineWord, "stackLevel");
  11285. //DEBUG_INFO("loc=%s\n",loc);
  11286. memset(sstr ,0, sizeof(sstr) );
  11287. if(loc != NULL)
  11288. {
  11289. while (loc[2+strlen("stackLevel")+c] != '\"')
  11290. {
  11291. sstr[c] = loc[2+strlen("stackLevel")+c];
  11292. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11293. c++;
  11294. }
  11295. sstr[c] = '\0';
  11296. tempstackLevel = atoi(sstr);
  11297. }
  11298. else
  11299. {
  11300. tempstackLevel = 0;
  11301. }
  11302. //***********chargingProfilePurpose **************/
  11303. c = 0;
  11304. loc = strstr(sLineWord, "chargingProfilePurpose");
  11305. //DEBUG_INFO("loc=%s\n",loc);
  11306. memset(sstr ,0, sizeof(sstr) );
  11307. if(loc != NULL)
  11308. {
  11309. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11310. {
  11311. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11312. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11313. c++;
  11314. }
  11315. sstr[c] = '\0';
  11316. strcpy(tempchargingProfilePurposeStr,sstr);
  11317. }
  11318. else
  11319. {
  11320. strcpy(tempchargingProfilePurposeStr,"");
  11321. }
  11322. //***********chargingProfileKind **************/
  11323. c = 0;
  11324. loc = strstr(sLineWord, "chargingProfileKind");
  11325. //DEBUG_INFO("loc=%s\n",loc);
  11326. memset(sstr ,0, sizeof(sstr) );
  11327. if(loc != NULL)
  11328. {
  11329. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11330. {
  11331. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11332. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11333. c++;
  11334. }
  11335. sstr[c] = '\0';
  11336. strcpy(tempchargingProfileKindStr,sstr);
  11337. }
  11338. else
  11339. {
  11340. strcpy(tempchargingProfileKindStr,"");
  11341. }
  11342. //***********recurrencyKind **************/
  11343. c = 0;
  11344. loc = strstr(sLineWord, "recurrencyKind");
  11345. //DEBUG_INFO("loc=%s\n",loc);
  11346. memset(sstr ,0, sizeof(sstr) );
  11347. if(loc != NULL)
  11348. {
  11349. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11350. {
  11351. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11352. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11353. c++;
  11354. }
  11355. sstr[c] = '\0';
  11356. strcpy(temprecurrencyKindStr,sstr);
  11357. }
  11358. else
  11359. {
  11360. strcpy(temprecurrencyKindStr,"");
  11361. }
  11362. //***********validFrom**************/
  11363. c = 0;
  11364. loc = strstr(sLineWord, "validFrom");
  11365. //DEBUG_INFO("loc=%s\n",loc);
  11366. memset(sstr ,0, sizeof(sstr) );
  11367. if(loc != NULL)
  11368. {
  11369. while (loc[3+strlen("validFrom")+c] != '\"')
  11370. {
  11371. sstr[c] = loc[3+strlen("validFrom")+c];
  11372. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11373. c++;
  11374. }
  11375. sstr[c] = '\0';
  11376. strcpy(tempvalidFromStr,sstr);
  11377. }
  11378. else
  11379. {
  11380. strcpy(tempvalidFromStr,"");
  11381. }
  11382. //***********validTo **************/
  11383. c = 0;
  11384. loc = strstr(sLineWord, "validTo");
  11385. //DEBUG_INFO("loc=%s\n",loc);
  11386. memset(sstr ,0, sizeof(sstr) );
  11387. if(loc != NULL)
  11388. {
  11389. while (loc[3+strlen("validTo")+c] != '\"')
  11390. {
  11391. sstr[c] = loc[3+strlen("validTo")+c];
  11392. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11393. c++;
  11394. }
  11395. sstr[c] = '\0';
  11396. strcpy(tempvalidToStr,sstr);
  11397. }
  11398. else
  11399. {
  11400. strcpy(tempvalidToStr,"");
  11401. }
  11402. //***********validFrom**************/
  11403. c = 0;
  11404. loc = strstr(sLineWord, "validFrom");
  11405. if(loc != NULL)
  11406. {
  11407. memset(sstr ,0, sizeof(sstr) );
  11408. while (loc[3+strlen("validFrom")+c] != '\"')
  11409. {
  11410. sstr[c] = loc[3+strlen("validFrom")+c];
  11411. c++;
  11412. }
  11413. sstr[c] = '\0';
  11414. strcpy(tempvalidFromStr,sstr);
  11415. }
  11416. else
  11417. {
  11418. strcpy(tempvalidFromStr,"");
  11419. }
  11420. //***********duration**************/
  11421. c = 0;
  11422. loc = strstr(sLineWord, "duration");
  11423. if(loc != NULL)
  11424. {
  11425. memset(sstr ,0, sizeof(sstr) );
  11426. while (loc[2+strlen("duration")+c] != ',')
  11427. {
  11428. sstr[c] = loc[2+strlen("duration")+c];
  11429. c++;
  11430. }
  11431. sstr[c] = '\0';
  11432. tempdurationInt = atoi(sstr);
  11433. }
  11434. else
  11435. {
  11436. tempdurationInt = 0;
  11437. }
  11438. //**********startSchedule**********/
  11439. c = 0;
  11440. loc = strstr(sLineWord, "startSchedule");
  11441. memset(sstr ,0, sizeof(sstr) );
  11442. while (loc[3+strlen("startSchedule")+c] != '\"')
  11443. {
  11444. sstr[c] = loc[3+strlen("startSchedule")+c];
  11445. c++;
  11446. }
  11447. sstr[c] = '\0';
  11448. strcpy(tempstartScheduleStr, sstr);
  11449. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  11450. //**********chargingRateUnit**********/
  11451. c = 0;
  11452. loc = strstr(sLineWord, "chargingRateUnit");
  11453. memset(sstr ,0, sizeof(sstr) );
  11454. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11455. {
  11456. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11457. c++;
  11458. }
  11459. sstr[c] = '\0';
  11460. strcpy(tempchargingRateUnitStr, sstr);
  11461. //**********minChargingRate*******/
  11462. c = 0;
  11463. loc = strstr(sLineWord, "minChargingRate");
  11464. if(loc != NULL)
  11465. {
  11466. memset(sstr ,0, sizeof(sstr) );
  11467. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11468. {
  11469. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11470. c++;
  11471. }
  11472. sstr[c] = '\0';
  11473. tempminChargingRateFloat = atof(sstr);
  11474. }
  11475. else
  11476. {
  11477. tempminChargingRateFloat = 0.0;
  11478. }
  11479. //
  11480. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11481. tp.tm_isdst = -1;
  11482. time_t utc = mktime(&tp);
  11483. time_t t = time(NULL);
  11484. diff_t = difftime(t, utc);
  11485. //DEBUG_INFO("diff_t=%f\n",diff_t);
  11486. //parsing strings to words
  11487. i = 0;
  11488. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11489. loc = loc+3+strlen("chargingSchedulePeriod");
  11490. pch = strtok(loc ,"{");
  11491. while (pch != NULL)
  11492. {
  11493. strcpy(SchedulePeriodList[i], pch);
  11494. pch = strtok (NULL, "{");
  11495. i = i + 1;
  11496. }
  11497. n_SchedulePeriods = i;
  11498. for(int i=0;i<n_SchedulePeriods;i++)
  11499. {
  11500. //*************startPeriod****************/
  11501. c = 0;
  11502. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11503. memset(sstr ,0, sizeof(sstr) );
  11504. while (loc[strlen("startPeriod")+2+c] != ',')
  11505. {
  11506. sstr[c] = loc[strlen("startPeriod")+2+c];
  11507. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11508. c++;
  11509. }
  11510. sstr[c] = '\0';
  11511. tempStartPeriodInt = atoi(sstr);
  11512. //*************limit****************/
  11513. c = 0;
  11514. loc = strstr(SchedulePeriodList[i], "limit");
  11515. memset(sstr ,0, sizeof(sstr) );
  11516. while (loc[strlen("limit")+2+c] != ',')
  11517. {
  11518. sstr[c] = loc[strlen("limit")+2+c];
  11519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11520. c++;
  11521. }
  11522. sstr[c] = '\0';
  11523. tempLimitInt = atof(sstr);
  11524. //*************numberPhases****************/
  11525. c = 0;
  11526. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11527. memset(sstr ,0, sizeof(sstr) );
  11528. while (loc[strlen("numberPhases")+2+c] != '}')
  11529. {
  11530. sstr[c] = loc[strlen("numberPhases")+2+c];
  11531. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11532. c++;
  11533. }
  11534. sstr[c] = '\0';
  11535. tempNumberPhasesInt = atoi(sstr);
  11536. if(j == 0)
  11537. {
  11538. ChargePointMaxProfile.Duration = tempdurationInt;
  11539. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  11540. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  11541. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11542. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11543. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11544. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  11545. ChargePointMaxProfile_TEMP.TransactionId = 0;
  11546. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11547. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11548. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11549. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11550. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11551. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11552. }
  11553. }
  11554. if(MinChargingRate < tempminChargingRateFloat)
  11555. {
  11556. MinChargingRate = tempminChargingRateFloat;
  11557. }
  11558. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  11559. if(confirmPeriods < n_SchedulePeriods)
  11560. {
  11561. confirmPeriods = n_SchedulePeriods;
  11562. }
  11563. j = j + 1;
  11564. }
  11565. fclose(fptr1);
  11566. }
  11567. }// the end of access file ChargePointMaxProfile
  11568. //****************************TxDefaultProfile************************************************/
  11569. switch(gunindex + 1)
  11570. {
  11571. case 0:
  11572. break;
  11573. case 1:
  11574. strcpy(fname, TxDefaultProfile_1_JSON );
  11575. break;
  11576. case 2:
  11577. strcpy(fname, TxDefaultProfile_2_JSON );
  11578. break;
  11579. default:
  11580. strcpy(fname, TxDefaultProfile_1_JSON );
  11581. break;
  11582. }
  11583. TxDefaultProfileFileIsNull=TRUE;
  11584. if((access(fname,F_OK))!=-1)
  11585. {
  11586. fptr1 = fopen(fname, "r");
  11587. c = 0;
  11588. c = fgetc(fptr1);
  11589. //DEBUG_INFO("c:%d\n",c);
  11590. rewind(fptr1);
  11591. if(c == EOF)
  11592. {
  11593. DEBUG_INFO("\n End of file reached.");
  11594. TxDefaultProfileFileIsNull=TRUE;
  11595. fclose(fptr1);
  11596. }
  11597. else
  11598. {
  11599. TxDefaultProfileFileIsNull=FALSE;
  11600. while(fscanf(fptr1, "%s", word) != EOF)
  11601. {
  11602. if(strcmp(word, "chargingProfileId") == 0)
  11603. {
  11604. n_chargingProfile = n_chargingProfile + 1;
  11605. }
  11606. }
  11607. rewind(fptr1);
  11608. //search Charging Profile Element
  11609. int i = 0;
  11610. int j = 0;
  11611. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11612. #if 0
  11613. /***********connectorId****************/
  11614. c = 0;
  11615. loc = strstr(sLineWord, "connectorId");
  11616. memset(sstr ,0, sizeof(sstr) );
  11617. while (loc[strlen("connectorId")+2+c] != ',')
  11618. {
  11619. sstr[c] = loc[strlen("connectorId")+2+c];
  11620. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11621. c++;
  11622. }
  11623. sstr[c] = '\0';
  11624. tempconnectorIdInt = atoi(sstr);
  11625. #endif
  11626. //***********chargingProfileId**************/
  11627. c = 0;
  11628. loc = strstr(sLineWord, "chargingProfileId");
  11629. //DEBUG_INFO("loc=%s\n",loc);
  11630. memset(sstr ,0, sizeof(sstr) );
  11631. if(loc != NULL)
  11632. {
  11633. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11634. {
  11635. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11636. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11637. c++;
  11638. }
  11639. sstr[c] = '\0';
  11640. tempchargingProfileId = atoi(sstr);
  11641. }
  11642. else
  11643. {
  11644. tempchargingProfileId = 0;
  11645. }
  11646. //***********stackLevel**************/
  11647. c = 0;
  11648. loc = strstr(sLineWord, "stackLevel");
  11649. //DEBUG_INFO("loc=%s\n",loc);
  11650. memset(sstr ,0, sizeof(sstr) );
  11651. if(loc != NULL)
  11652. {
  11653. while (loc[2+strlen("stackLevel")+c] != '\"')
  11654. {
  11655. sstr[c] = loc[2+strlen("stackLevel")+c];
  11656. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11657. c++;
  11658. }
  11659. sstr[c] = '\0';
  11660. tempstackLevel = atoi(sstr);
  11661. }
  11662. else
  11663. {
  11664. tempstackLevel = 0;
  11665. }
  11666. //***********chargingProfilePurpose **************/
  11667. c = 0;
  11668. loc = strstr(sLineWord, "chargingProfilePurpose");
  11669. //DEBUG_INFO("loc=%s\n",loc);
  11670. memset(sstr ,0, sizeof(sstr) );
  11671. if(loc != NULL)
  11672. {
  11673. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11674. {
  11675. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11676. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11677. c++;
  11678. }
  11679. sstr[c] = '\0';
  11680. strcpy(tempchargingProfilePurposeStr,sstr);
  11681. }
  11682. else
  11683. {
  11684. strcpy(tempchargingProfilePurposeStr,"");
  11685. }
  11686. //***********chargingProfileKind **************/
  11687. c = 0;
  11688. loc = strstr(sLineWord, "chargingProfileKind");
  11689. //DEBUG_INFO("loc=%s\n",loc);
  11690. memset(sstr ,0, sizeof(sstr) );
  11691. if(loc != NULL)
  11692. {
  11693. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11694. {
  11695. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11696. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11697. c++;
  11698. }
  11699. sstr[c] = '\0';
  11700. strcpy(tempchargingProfileKindStr,sstr);
  11701. }
  11702. else
  11703. {
  11704. strcpy(tempchargingProfileKindStr,"");
  11705. }
  11706. //***********recurrencyKind **************/
  11707. c = 0;
  11708. loc = strstr(sLineWord, "recurrencyKind");
  11709. //DEBUG_INFO("loc=%s\n",loc);
  11710. memset(sstr ,0, sizeof(sstr) );
  11711. if(loc != NULL)
  11712. {
  11713. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11714. {
  11715. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11716. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11717. c++;
  11718. }
  11719. sstr[c] = '\0';
  11720. strcpy(temprecurrencyKindStr,sstr);
  11721. }
  11722. else
  11723. {
  11724. strcpy(temprecurrencyKindStr,"");
  11725. }
  11726. //***********validFrom**************/
  11727. c = 0;
  11728. loc = strstr(sLineWord, "validFrom");
  11729. if(loc != NULL)
  11730. {
  11731. memset(sstr ,0, sizeof(sstr) );
  11732. while (loc[3+strlen("validFrom")+c] != '\"')
  11733. {
  11734. sstr[c] = loc[3+strlen("validFrom")+c];
  11735. c++;
  11736. }
  11737. sstr[c] = '\0';
  11738. strcpy(tempvalidFromStr,sstr);
  11739. }
  11740. else
  11741. {
  11742. strcpy(tempvalidFromStr,"");
  11743. }
  11744. //***********validFrom**************/
  11745. c = 0;
  11746. loc = strstr(sLineWord, "duration");
  11747. if(loc != NULL)
  11748. {
  11749. memset(sstr ,0, sizeof(sstr) );
  11750. while (loc[2+strlen("duration")+c] != ',')
  11751. {
  11752. sstr[c] = loc[2+strlen("duration")+c];
  11753. c++;
  11754. }
  11755. sstr[c] = '\0';
  11756. tempdurationInt = atoi(sstr);
  11757. }
  11758. else
  11759. {
  11760. tempdurationInt = 0;
  11761. }
  11762. //**********startSchedule**********/
  11763. c = 0;
  11764. loc = strstr(sLineWord, "startSchedule");
  11765. memset(sstr ,0, sizeof(sstr) );
  11766. while (loc[3+strlen("startSchedule")+c] != '\"')
  11767. {
  11768. sstr[c] = loc[3+strlen("startSchedule")+c];
  11769. c++;
  11770. }
  11771. sstr[c] = '\0';
  11772. strcpy(tempstartScheduleStr, sstr);
  11773. strcpy(TxDefaultProfileScheduleStr, sstr);
  11774. //**********chargingRateUnit**********/
  11775. c = 0;
  11776. loc = strstr(sLineWord, "chargingRateUnit");
  11777. memset(sstr ,0, sizeof(sstr) );
  11778. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11779. {
  11780. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11781. c++;
  11782. }
  11783. sstr[c] = '\0';
  11784. strcpy(tempchargingRateUnitStr, sstr);
  11785. //**********minChargingRate*******/
  11786. c = 0;
  11787. loc = strstr(sLineWord, "minChargingRate");
  11788. if(loc != NULL)
  11789. {
  11790. memset(sstr ,0, sizeof(sstr) );
  11791. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11792. {
  11793. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11794. c++;
  11795. }
  11796. sstr[c] = '\0';
  11797. tempminChargingRateFloat = atof(sstr);
  11798. }
  11799. else
  11800. {
  11801. tempminChargingRateFloat = 0.0;
  11802. }
  11803. //
  11804. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11805. tp.tm_isdst = -1;
  11806. time_t utc = mktime(&tp);
  11807. time_t t = time(NULL);
  11808. diff_t = difftime(t, utc);
  11809. printf("diff between startScheduleStr and now =%f\n",diff_t);
  11810. //parsing strings to words
  11811. i = 0;
  11812. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11813. loc = loc+3+strlen("chargingSchedulePeriod");
  11814. pch = strtok(loc ,"{");
  11815. while (pch != NULL)
  11816. {
  11817. strcpy(SchedulePeriodList[i], pch);
  11818. pch = strtok (NULL, "{");
  11819. i = i + 1;
  11820. }
  11821. n_SchedulePeriods = i;
  11822. for(int i=0;i<n_SchedulePeriods;i++)
  11823. {
  11824. //*************startPeriod****************/
  11825. c = 0;
  11826. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11827. memset(sstr ,0, sizeof(sstr) );
  11828. while (loc[strlen("startPeriod")+2+c] != ',')
  11829. {
  11830. sstr[c] = loc[strlen("startPeriod")+2+c];
  11831. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11832. c++;
  11833. }
  11834. sstr[c] = '\0';
  11835. tempStartPeriodInt = atoi(sstr);
  11836. //*************limit****************/
  11837. c = 0;
  11838. loc = strstr(SchedulePeriodList[i], "limit");
  11839. memset(sstr ,0, sizeof(sstr) );
  11840. while (loc[strlen("limit")+2+c] != ',')
  11841. {
  11842. sstr[c] = loc[strlen("limit")+2+c];
  11843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11844. c++;
  11845. }
  11846. sstr[c] = '\0';
  11847. tempLimitInt = atof(sstr);
  11848. //*************numberPhases****************/
  11849. c = 0;
  11850. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11851. memset(sstr ,0, sizeof(sstr) );
  11852. while (loc[strlen("numberPhases")+2+c] != '}')
  11853. {
  11854. sstr[c] = loc[strlen("numberPhases")+2+c];
  11855. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11856. c++;
  11857. }
  11858. sstr[c] = '\0';
  11859. tempNumberPhasesInt = atoi(sstr);
  11860. if(j == 0)
  11861. {
  11862. TxDefaultProfile.Duration = tempdurationInt;
  11863. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  11864. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  11865. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11866. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11867. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11868. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  11869. TxDefaultProfile_TEMP.TransactionId = 0;
  11870. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  11871. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  11872. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11873. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11874. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11875. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11876. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11877. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11878. }
  11879. else
  11880. {
  11881. //other stack level charging Profile
  11882. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  11883. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  11884. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  11885. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  11886. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  11887. }
  11888. }
  11889. if(MinChargingRate < tempminChargingRateFloat)
  11890. {
  11891. MinChargingRate = tempminChargingRateFloat;
  11892. }
  11893. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  11894. if(confirmPeriods < n_SchedulePeriods)
  11895. confirmPeriods = n_SchedulePeriods;
  11896. j = j + 1;
  11897. }
  11898. fclose(fptr1);
  11899. //Stacking Charging Profiles
  11900. for(int l=0; l <(j-1) ;l++)
  11901. {
  11902. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  11903. {
  11904. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  11905. {
  11906. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  11907. {
  11908. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  11909. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  11910. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  11911. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11912. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11913. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11914. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11915. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11916. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11917. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11918. }
  11919. else
  11920. {
  11921. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11922. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11923. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11924. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11925. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11926. }
  11927. }
  11928. }
  11929. }
  11930. //end of Stacking Charging Profiles
  11931. }
  11932. }// the end of ACCESS TxDefaultProfile
  11933. //****************************TxProfile************************************************/
  11934. switch(gunindex + 1)
  11935. {
  11936. case 0:
  11937. break;
  11938. case 1:
  11939. strcpy(fname, TxProfile_1_JSON );
  11940. break;
  11941. case 2:
  11942. strcpy(fname, TxProfile_2_JSON );
  11943. break;
  11944. default:
  11945. strcpy(fname, TxProfile_1_JSON );
  11946. break;
  11947. }
  11948. TxProfileIsNull=TRUE;
  11949. if((access(fname,F_OK))!=-1)
  11950. {
  11951. fptr1 = fopen(fname, "r");
  11952. c = 0;
  11953. c = fgetc(fptr1);
  11954. //DEBUG_INFO("c:%d\n",c);
  11955. rewind(fptr1);
  11956. if(c == EOF)
  11957. {
  11958. DEBUG_INFO("\n End of file reached.");
  11959. TxProfileIsNull=TRUE;
  11960. fclose(fptr1);
  11961. }
  11962. else
  11963. {
  11964. TxProfileIsNull=FALSE;
  11965. while(fscanf(fptr1, "%s", word) != EOF)
  11966. {
  11967. if(strcmp(word, "chargingProfileId") == 0)
  11968. {
  11969. n_chargingProfile = n_chargingProfile + 1;
  11970. }
  11971. }
  11972. rewind(fptr1);
  11973. //search Charging Profile Element
  11974. int i= 0;
  11975. int j= 0;
  11976. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11977. #if 0
  11978. /***********connectorId****************/
  11979. c = 0;
  11980. loc = strstr(sLineWord, "connectorId");
  11981. memset(sstr ,0, sizeof(sstr) );
  11982. while (loc[strlen("connectorId")+2+c] != ',')
  11983. {
  11984. sstr[c] = loc[strlen("connectorId")+2+c];
  11985. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11986. c++;
  11987. }
  11988. sstr[c] = '\0';
  11989. tempconnectorIdInt = atoi(sstr);
  11990. #endif
  11991. //***********chargingProfileId**************/
  11992. c = 0;
  11993. loc = strstr(sLineWord, "chargingProfileId");
  11994. memset(sstr ,0, sizeof(sstr) );
  11995. if(loc != NULL)
  11996. {
  11997. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11998. {
  11999. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12000. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12001. c++;
  12002. }
  12003. sstr[c] = '\0';
  12004. tempchargingProfileId = atoi(sstr);
  12005. }
  12006. else
  12007. {
  12008. tempchargingProfileId = 0;
  12009. }
  12010. //***********transactionId **************/
  12011. c = 0;
  12012. loc = strstr(sLineWord, "transactionId");
  12013. //DEBUG_INFO("loc=%s\n",loc);
  12014. memset(sstr ,0, sizeof(sstr) );
  12015. if(loc != NULL)
  12016. {
  12017. while (loc[2+strlen("transactionId")+c] != '\"')
  12018. {
  12019. sstr[c] = loc[2+strlen("transactionId")+c];
  12020. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12021. c++;
  12022. }
  12023. sstr[c] = '\0';
  12024. temptransactionId = atoi(sstr);
  12025. }
  12026. else
  12027. {
  12028. temptransactionId = 0;
  12029. }
  12030. //***********stackLevel**************/
  12031. c = 0;
  12032. loc = strstr(sLineWord, "stackLevel");
  12033. //DEBUG_INFO("loc=%s\n",loc);
  12034. memset(sstr ,0, sizeof(sstr) );
  12035. if(loc != NULL)
  12036. {
  12037. while (loc[2+strlen("stackLevel")+c] != '\"')
  12038. {
  12039. sstr[c] = loc[2+strlen("stackLevel")+c];
  12040. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12041. c++;
  12042. }
  12043. sstr[c] = '\0';
  12044. tempstackLevel = atoi(sstr);
  12045. }
  12046. else
  12047. {
  12048. tempstackLevel = 0;
  12049. }
  12050. //***********chargingProfilePurpose **************/
  12051. c = 0;
  12052. loc = strstr(sLineWord, "chargingProfilePurpose");
  12053. //DEBUG_INFO("loc=%s\n",loc);
  12054. memset(sstr ,0, sizeof(sstr) );
  12055. if(loc != NULL)
  12056. {
  12057. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12058. {
  12059. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12061. c++;
  12062. }
  12063. sstr[c] = '\0';
  12064. strcpy(tempchargingProfilePurposeStr,sstr);
  12065. }
  12066. else
  12067. {
  12068. strcpy(tempchargingProfilePurposeStr,"");
  12069. }
  12070. //***********chargingProfileKind **************/
  12071. c = 0;
  12072. loc = strstr(sLineWord, "chargingProfileKind");
  12073. //DEBUG_INFO("loc=%s\n",loc);
  12074. memset(sstr ,0, sizeof(sstr) );
  12075. if(loc != NULL)
  12076. {
  12077. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12078. {
  12079. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12080. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12081. c++;
  12082. }
  12083. sstr[c] = '\0';
  12084. strcpy(tempchargingProfileKindStr,sstr);
  12085. }
  12086. else
  12087. {
  12088. strcpy(tempchargingProfileKindStr,"");
  12089. }
  12090. //***********recurrencyKind **************/
  12091. c = 0;
  12092. loc = strstr(sLineWord, "recurrencyKind");
  12093. //DEBUG_INFO("loc=%s\n",loc);
  12094. memset(sstr ,0, sizeof(sstr) );
  12095. if(loc != NULL)
  12096. {
  12097. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12098. {
  12099. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12100. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12101. c++;
  12102. }
  12103. sstr[c] = '\0';
  12104. strcpy(temprecurrencyKindStr,sstr);
  12105. }
  12106. else
  12107. {
  12108. strcpy(temprecurrencyKindStr,"");
  12109. }
  12110. //***********validFrom**************/
  12111. c = 0;
  12112. loc = strstr(sLineWord, "validFrom");
  12113. if(loc != NULL)
  12114. {
  12115. memset(sstr ,0, sizeof(sstr) );
  12116. while (loc[3+strlen("validFrom")+c] != '\"')
  12117. {
  12118. sstr[c] = loc[3+strlen("validFrom")+c];
  12119. c++;
  12120. }
  12121. sstr[c] = '\0';
  12122. strcpy(tempvalidFromStr,sstr);
  12123. }
  12124. else
  12125. {
  12126. strcpy(tempvalidFromStr,"");
  12127. }
  12128. //***********duration**************/
  12129. c = 0;
  12130. loc = strstr(sLineWord, "duration");
  12131. //DEBUG_INFO("loc=%s\n",loc);
  12132. memset(sstr ,0, sizeof(sstr) );
  12133. if(loc != NULL)
  12134. {
  12135. while (loc[2+strlen("duration")+c] != '\"')
  12136. {
  12137. sstr[c] = loc[2+strlen("duration")+c];
  12138. c++;
  12139. }
  12140. sstr[c] = '\0';
  12141. tempdurationInt = atoi(sstr);
  12142. }
  12143. else
  12144. {
  12145. tempdurationInt = 0;
  12146. }
  12147. //**********startSchedule**********/
  12148. c = 0;
  12149. loc = strstr(sLineWord, "startSchedule");
  12150. memset(sstr ,0, sizeof(sstr) );
  12151. while (loc[3+strlen("startSchedule")+c] != '\"')
  12152. {
  12153. sstr[c] = loc[3+strlen("startSchedule")+c];
  12154. c++;
  12155. }
  12156. sstr[c] = '\0';
  12157. strcpy(tempstartScheduleStr, sstr);
  12158. strcpy(TxProfileScheduleStr, sstr);
  12159. //**********chargingRateUnit**********/
  12160. c = 0;
  12161. loc = strstr(sLineWord, "chargingRateUnit");
  12162. memset(sstr ,0, sizeof(sstr) );
  12163. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12164. {
  12165. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12166. c++;
  12167. }
  12168. sstr[c] = '\0';
  12169. strcpy(tempchargingRateUnitStr, sstr);
  12170. //**********minChargingRate*******/
  12171. c = 0;
  12172. loc = strstr(sLineWord, "minChargingRate");
  12173. if(loc != NULL)
  12174. {
  12175. memset(sstr ,0, sizeof(sstr) );
  12176. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12177. {
  12178. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12179. c++;
  12180. }
  12181. sstr[c] = '\0';
  12182. tempminChargingRateFloat = atof(sstr);
  12183. }
  12184. else
  12185. {
  12186. tempminChargingRateFloat = 0.0;
  12187. }
  12188. //
  12189. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12190. tp.tm_isdst = -1;
  12191. time_t utc = mktime(&tp);
  12192. time_t t = time(NULL);
  12193. diff_t = difftime(t, utc);
  12194. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12195. //parsing strings to words
  12196. i = 0;
  12197. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12198. loc = loc+3+strlen("chargingSchedulePeriod");
  12199. pch = strtok(loc ,"{");
  12200. while (pch != NULL)
  12201. {
  12202. strcpy(SchedulePeriodList[i], pch);
  12203. pch = strtok (NULL, "{");
  12204. i = i + 1;
  12205. }
  12206. n_SchedulePeriods = i;
  12207. for(int i=0;i<n_SchedulePeriods;i++)
  12208. {
  12209. //*************startPeriod****************/
  12210. c = 0;
  12211. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12212. memset(sstr ,0, sizeof(sstr) );
  12213. while (loc[strlen("startPeriod")+2+c] != ',')
  12214. {
  12215. sstr[c] = loc[strlen("startPeriod")+2+c];
  12216. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12217. c++;
  12218. }
  12219. sstr[c] = '\0';
  12220. tempStartPeriodInt = atoi(sstr);
  12221. //*************limit****************/
  12222. c = 0;
  12223. loc = strstr(SchedulePeriodList[i], "limit");
  12224. memset(sstr ,0, sizeof(sstr) );
  12225. while (loc[strlen("limit")+2+c] != ',')
  12226. {
  12227. sstr[c] = loc[strlen("limit")+2+c];
  12228. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12229. c++;
  12230. }
  12231. sstr[c] = '\0';
  12232. tempLimitInt = atof(sstr);
  12233. //*************numberPhases****************/
  12234. c = 0;
  12235. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12236. memset(sstr ,0, sizeof(sstr) );
  12237. while (loc[strlen("numberPhases")+2+c] != '}')
  12238. {
  12239. sstr[c] = loc[strlen("numberPhases")+2+c];
  12240. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12241. c++;
  12242. }
  12243. sstr[c] = '\0';
  12244. tempNumberPhasesInt = atoi(sstr);
  12245. //TxProfile.Duration = durationInt;
  12246. TxProfile.TotalPeriod = n_SchedulePeriods;
  12247. TxProfile.Period[i].Limit = tempLimitInt;
  12248. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12249. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12250. }
  12251. if(MinChargingRate < tempminChargingRateFloat)
  12252. {
  12253. MinChargingRate = tempminChargingRateFloat;
  12254. }
  12255. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12256. if(confirmPeriods < n_SchedulePeriods)
  12257. confirmPeriods = n_SchedulePeriods;
  12258. if(j == 0)
  12259. {
  12260. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12261. TxProfile_TEMP.StackLevel = tempstackLevel;
  12262. TxProfile_TEMP.TransactionId = 0;
  12263. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12264. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12265. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12266. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12267. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12268. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12269. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12270. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12271. }
  12272. }
  12273. fclose(fptr1);
  12274. }
  12275. }// the end of ACCESS TxProfile
  12276. //CompositeSchedule
  12277. int period=0;
  12278. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  12279. {
  12280. //TxProfile
  12281. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  12282. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  12283. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  12284. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  12285. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  12286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12287. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  12288. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  12289. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  12290. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  12291. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  12292. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  12293. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  12294. for(int k=0; k < TxProfile.TotalPeriod;k++)
  12295. {
  12296. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  12297. {
  12298. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12299. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12300. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12301. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12302. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12303. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12304. period = period + 1;
  12305. }
  12306. else
  12307. {
  12308. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  12309. {
  12310. }
  12311. else
  12312. {
  12313. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12314. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12315. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12316. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12317. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12318. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12319. period = period + 1;
  12320. }
  12321. }
  12322. }
  12323. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12324. {
  12325. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  12326. {
  12327. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12328. {
  12329. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12330. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12331. }
  12332. else
  12333. {
  12334. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12335. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12336. }
  12337. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12338. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12339. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12340. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12341. period = period + 1;
  12342. }
  12343. }
  12344. }
  12345. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  12346. {
  12347. //TxDefaultProfile
  12348. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12349. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12350. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12351. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12352. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  12353. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  12354. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  12355. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12356. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12357. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12358. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12359. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12360. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12361. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12362. {
  12363. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12364. {
  12365. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12366. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12367. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12368. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12369. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12370. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12371. period = period + 1;
  12372. }
  12373. else
  12374. {
  12375. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12376. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12377. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12378. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12379. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12380. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12381. period = period + 1;
  12382. }
  12383. }
  12384. }
  12385. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  12386. {
  12387. //TxDefaultProfile
  12388. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12390. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12391. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  12393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  12394. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12395. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12396. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12397. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12398. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12399. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12400. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12401. {
  12402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12405. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12406. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12407. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12408. period = period + 1;
  12409. }
  12410. }
  12411. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  12412. {
  12413. //ChargePointMaxProfile
  12414. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  12415. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  12416. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12417. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  12418. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  12419. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12420. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  12421. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  12422. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  12423. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  12424. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  12425. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  12426. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  12427. {
  12428. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  12429. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  12430. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  12431. period = period + 1;
  12432. }
  12433. }
  12434. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  12435. {
  12436. //TxProfile
  12437. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  12438. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  12439. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  12440. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  12441. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  12442. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12443. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  12444. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  12445. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  12446. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  12447. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  12448. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  12449. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  12450. for(int k=0; k < TxProfile.TotalPeriod;k++)
  12451. {
  12452. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  12453. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  12454. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  12455. }
  12456. }
  12457. confirmPeriods = period;
  12458. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  12459. 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,"
  12460. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  12461. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  12462. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  12463. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  12464. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  12465. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  12466. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  12467. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  12468. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  12469. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  12470. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  12471. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  12472. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  12473. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  12474. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  12475. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  12476. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  12477. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  12478. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  12479. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  12480. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  12481. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  12482. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  12483. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  12484. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  12485. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  12486. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  12487. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  12488. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  12489. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  12490. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  12491. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  12492. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  12493. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  12494. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  12495. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  12496. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  12497. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  12498. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  12499. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  12500. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  12501. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  12502. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  12503. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  12504. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  12505. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  12506. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  12507. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  12508. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  12509. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  12510. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  12511. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  12512. }
  12513. void LWS_Send(char * str)
  12514. {
  12515. //=====================================================
  12516. // Check InternetConn 0: disconnected, 1: connected
  12517. //====================================================
  12518. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  12519. {
  12520. DEBUG_INFO("\n offline now !!!\n");
  12521. return;
  12522. }
  12523. pthread_mutex_lock(&lock);
  12524. memset(SendBuffer,0,SendBufLen);
  12525. sprintf((char *)SendBuffer, "%s", str);
  12526. pthread_mutex_unlock(&lock);
  12527. lws_callback_on_writable(wsi_client);
  12528. lws_service(context, 10000);//timeout_ms
  12529. }