MessageHandler.c 506 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409
  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. char OcppPath[160]={};
  98. char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP other variables
  115. //===============================
  116. int isUpdateRequest = FALSE;
  117. static int HeartBeatWaitTime = 10;
  118. static int FirstHeartBeat = 0;
  119. static int FirmwareStatusNotificationStatus = 3; // Idle
  120. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  121. static char CurrentChargingProfileScheduleStr[30]={0};
  122. //========================================
  123. // OCPP status/previous related variables
  124. //========================================
  125. static int GunStatusInterval = 10;
  126. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  127. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  128. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  129. static int GbPreviousSystemStatus[GB_QUANTITY];
  130. static int AcPreviousSystemStatus[AC_QUANTITY];
  131. int TransactionMessageAttemptsValue = 0;
  132. int TransactionMessageRetryIntervalValue = 0;
  133. static struct OCPPAuthLocalElemet
  134. {
  135. int listVersionInt;
  136. char idTagstr[20];
  137. char parentIdTag[20];
  138. char expiryDate[30];
  139. char idTagstatus[16];
  140. }idTagQuery;
  141. //=============================================
  142. // OCPP HeartBeat Response Not Receive Counts
  143. //============================================
  144. static int HeartBeatWithNOResponse = 0;
  145. extern struct lws *wsi_client;
  146. extern struct lws_context *context;
  147. #if 0
  148. extern unsigned char *SendBuffer;
  149. #endif
  150. extern unsigned char SendBuffer[4096];
  151. extern int SendBufLen;
  152. //extern map_t hashMap;
  153. //extern data_struct_t* mapItem; --- remove for temporally
  154. //extern data_struct_t mapItem[0];
  155. extern char *random_uuid( char buf[37] );
  156. extern void split(char **arr, char *str, const char *del);
  157. extern pthread_mutex_t mutex1;
  158. extern struct Charger_Info Charger;
  159. extern sqlite3 *db;
  160. int TransactionMessageAttemptsGet(void);
  161. int TransactionMessageRetryIntervalGet(void);
  162. int GetOcppConnStatus(void);
  163. void SetOcppConnStatus(uint8_t status);
  164. int updateSetting(char *key, char *value);
  165. int setKeyValue(char *key, char *value);
  166. void OCPP_get_TableAuthlocalAllData(void);
  167. void processUnkownKey(void);
  168. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  169. struct StructOCPPMeterValue
  170. {
  171. unsigned char TimeStamp[28];
  172. struct StructSampledValue SampledValue[10];
  173. };
  174. struct ClientTime
  175. {
  176. unsigned int Heartbeat;
  177. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  178. unsigned int StartTransaction;
  179. unsigned int StopTransaction;
  180. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  181. }clientTime;
  182. typedef union
  183. {
  184. //Operations Initiated by Central System
  185. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  186. struct
  187. {
  188. //CsMsgValue[0]
  189. unsigned char StatusNotificationReq :1; //bit 0,
  190. unsigned char StatusNotificationConf :1; //bit 0,
  191. unsigned char :6; //bit 2~7
  192. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  193. }CpinitiateMsg;
  194. CpinitiateMsg cpinitateMsg;
  195. //==========================================
  196. // Init all Enumeration & Mapping String
  197. //==========================================
  198. /*ChargePointErrorCode*/
  199. typedef enum {
  200. ConnectorLockFailure,
  201. EVCommunicationError,
  202. GroundFailure,
  203. HighTemperature,
  204. InternalError,
  205. LocalListConflict,
  206. NoError,
  207. OtherError,
  208. OverCurrentFailure,
  209. OverVoltage,
  210. PowerMeterFailure,
  211. PowerSwitchFailure,
  212. ReaderFailure,
  213. ResetFailure,
  214. UnderVoltage,
  215. WeakSignal
  216. } ChargePointErrorCode;
  217. #if 0
  218. static char *ChargePointErrorCodeStr[] = {
  219. MACROSTR(ConnectorLockFailure),
  220. MACROSTR(EVCommunicationError),
  221. MACROSTR(GroundFailure),
  222. MACROSTR(HighTemperature),
  223. MACROSTR(InternalError),
  224. MACROSTR(LocalListConflict),
  225. MACROSTR(NoError),
  226. MACROSTR(OtherError),
  227. MACROSTR(OverCurrentFailure),
  228. MACROSTR(OverVoltage),
  229. MACROSTR(PowerMeterFailure),
  230. MACROSTR(PowerSwitchFailure),
  231. MACROSTR(ReaderFailure),
  232. MACROSTR(ResetFailure),
  233. MACROSTR(UnderVoltage),
  234. MACROSTR(WeakSignal)
  235. };
  236. #endif
  237. /*ChargePointStatus*/
  238. typedef enum {
  239. Available =0,
  240. Preparing,
  241. Charging,
  242. SuspendedEVSE,
  243. SuspendedEV,
  244. Finishing,
  245. Reserved,
  246. Unavailable,
  247. Faulted
  248. } ChargePointStatus;
  249. static char * ChargePointStatusStr[] = {
  250. MACROSTR(Available),
  251. MACROSTR(Preparing),
  252. MACROSTR(Charging),
  253. MACROSTR(SuspendedEVSE),
  254. MACROSTR(SuspendedEV),
  255. MACROSTR(Finishing),
  256. MACROSTR(Reserved),
  257. MACROSTR(Unavailable),
  258. MACROSTR(Faulted)
  259. };
  260. /*AvailabilityType*/
  261. typedef enum {
  262. RegistrationStatus_Accepted,
  263. RegistrationStatus_Pending,
  264. RegistrationStatus_Rejected
  265. } RegistrationStatus;
  266. static char *RegistrationStatusStr[] = {
  267. MACROSTR(Accepted),
  268. MACROSTR(Pending),
  269. MACROSTR(Rejected)
  270. };
  271. /*AvailabilityType*/
  272. typedef enum {
  273. Inoperative,
  274. Operative
  275. } AvailabilityType;
  276. static char *AvailabilityTypeStr[] = {
  277. MACROSTR(Inoperative),
  278. MACROSTR(Operative)
  279. };
  280. /*AvailabilityStatus*/
  281. typedef enum {
  282. Accepted,
  283. Rejected,
  284. Scheduled
  285. } AvailabilityStatus;
  286. static char *AvailabilityStatusStr[] = {
  287. MACROSTR(Accepted),
  288. MACROSTR(Rejected),
  289. MACROSTR(Scheduled)
  290. };
  291. /*ConfigurationStatus*/
  292. typedef enum {
  293. ConfigurationStatus_Accepted,
  294. ConfigurationStatus_Rejected,
  295. RebootRequired,
  296. NotSupported
  297. } ConfigurationStatus;
  298. static char *ConfigurationStatusStr[] = {
  299. MACROSTR(Accepted),
  300. MACROSTR(Rejected),
  301. MACROSTR(RebootRequired),
  302. MACROSTR(NotSupported)
  303. };
  304. /*ClearCacheStatus*/
  305. typedef enum {
  306. ClearCacheStatus_Accepted,
  307. ClearCacheStatus_Rejected
  308. } ClearCacheStatus;
  309. static char *ClearCacheStatusStr[] = {
  310. MACROSTR(Accepted),
  311. MACROSTR(Rejected)
  312. };
  313. /*ChargingProfilePurposeType*/
  314. typedef enum {
  315. ChargePointMaxProfile,
  316. TxDefaultProfile,
  317. TxProfile
  318. } ChargingProfilePurposeType;
  319. static char *ChargingProfilePurposeTypeStr[] = {
  320. MACROSTR(ChargePointMaxProfile),
  321. MACROSTR(TxDefaultProfile),
  322. MACROSTR(TxProfile)
  323. };
  324. /*ChargingProfileStatus*/
  325. typedef enum {
  326. ChargingProfileStatus_Accepted,
  327. ChargingProfileStatus_Rejected,
  328. ChargingProfileStatus_NotSupported
  329. } ChargingProfileStatus;
  330. static char *ChargingProfileStatusStr[] = {
  331. MACROSTR(Accepted),
  332. MACROSTR(Rejected),
  333. MACROSTR(NotSupported)
  334. };
  335. /*ClearChargingProfileStatus*/
  336. typedef enum {
  337. ClearChargingProfileStatus_Accepted,
  338. ClearChargingProfileStatus_Unknown
  339. } ClearChargingProfileStatus;
  340. static char *ClearChargingProfileStatusStr[] = {
  341. MACROSTR(Accepted),
  342. MACROSTR(Unknown)
  343. };
  344. /*GetCompositeScheduleStatus*/
  345. typedef enum {
  346. GetCompositeScheduleStatus_Accepted,
  347. GetCompositeScheduleStatus_Rejected
  348. } GetCompositeScheduleStatus;
  349. static char *GetCompositeScheduleStatusStr[] = {
  350. MACROSTR(Accepted),
  351. MACROSTR(Rejected)
  352. };
  353. /*ChargingRateUnitType*/
  354. typedef enum {
  355. ChargingRateUnitType_W,
  356. ChargingRateUnitType_A
  357. } ChargingRateUnitType;
  358. /*AuthorizationStatus*/
  359. typedef enum {
  360. AuthorizationStatus_Accepted ,
  361. AuthorizationStatus_Blocked ,
  362. AuthorizationStatus_Expired ,
  363. AuthorizationStatus_Invalid ,
  364. AuthorizationStatus_ConcurrentTx
  365. } AuthorizationStatus;
  366. /*UpdateType*/
  367. typedef enum {
  368. Differential ,
  369. Full
  370. } UpdateType;
  371. static char *UpdateTypeStr[] = {
  372. MACROSTR(Differential),
  373. MACROSTR(Full)
  374. };
  375. /*UpdateStatus*/
  376. typedef enum {
  377. UpdateStatus_Accepted ,
  378. UpdateStatus_Failed ,
  379. UpdateStatus_NotSupported ,
  380. UpdateStatus_VersionMismatch
  381. } UpdateStatus;
  382. static char *UpdateStatusStr[] = {
  383. MACROSTR(Accepted),
  384. MACROSTR(Failed),
  385. MACROSTR(NotSupported),
  386. MACROSTR(VersionMismatch)
  387. };
  388. /*RemoteStartStopStatus*/
  389. typedef enum {
  390. RemoteStartStopStatus_Accepted,
  391. RemoteStartStopStatus_Rejected
  392. } RemoteStartStopStatus;
  393. static char *RemoteStartStopStatusStr[] = {
  394. MACROSTR(Accepted),
  395. MACROSTR(Rejected)
  396. };
  397. /*ReservationStatus*/
  398. typedef enum {
  399. ReservationStatus_Accepted,
  400. ReservationStatus_Faulted,
  401. ReservationStatus_Occupied,
  402. ReservationStatus_Rejected,
  403. ReservationStatus_Unavailable
  404. } ReservationStatus;
  405. static char *ReservationStatusStr[] = {
  406. MACROSTR(Accepted),
  407. MACROSTR(Faulted),
  408. MACROSTR(Occupied),
  409. MACROSTR(Rejected),
  410. MACROSTR(Unavailable)
  411. };
  412. /*ResetType*/
  413. typedef enum {
  414. Hard,
  415. Soft
  416. } ResetType;
  417. static char *ResetTypeStr[] = {
  418. MACROSTR(Hard),
  419. MACROSTR(Soft)
  420. };
  421. /*ResetStatus*/
  422. typedef enum {
  423. ResetStatus_Accepted,
  424. ResetStatus_Rejected
  425. } ResetStatus;
  426. static char *ResetStatusStr[] = {
  427. MACROSTR(Accepted),
  428. MACROSTR(Rejected)
  429. };
  430. /*DiagnosticsStatus*/
  431. typedef enum {
  432. DiagnosticsStatus_Idle,
  433. DiagnosticsStatus_Uploaded,
  434. DiagnosticsStatus_UploadFailed,
  435. DiagnosticsStatus_Uploading
  436. } DiagnosticsStatus;
  437. static char * DiagnosticsStatusStr[] = {
  438. MACROSTR(Idle),
  439. MACROSTR(Uploaded),
  440. MACROSTR(UploadFailed),
  441. MACROSTR(Uploading)
  442. };
  443. /*FirmwareStatus*/
  444. typedef enum {
  445. FirmwareStatus_Downloaded,
  446. FirmwareStatus_DownloadFailed,
  447. FirmwareStatus_Downloading,
  448. FirmwareStatus_Idle,
  449. FirmwareStatus_InstallationFailed,
  450. FirmwareStatus_Installing,
  451. FirmwareStatus_Installed
  452. } FirmwareStatus;
  453. static char * FirmwareStatusStr[] = {
  454. MACROSTR(Downloaded),
  455. MACROSTR(DownloadFailed),
  456. MACROSTR(Downloading),
  457. MACROSTR(Idle),
  458. MACROSTR(InstallationFailed),
  459. MACROSTR(Installing),
  460. MACROSTR(Installed)
  461. };
  462. /*MessageTrigger*/
  463. typedef enum {
  464. BootNotification,
  465. DiagnosticsStatusNotification,
  466. FirmwareStatusNotification,
  467. Heartbeat,
  468. MeterValues,
  469. StatusNotification
  470. } MessageTrigger;
  471. static char * MessageTriggerStr[] = {
  472. MACROSTR(BootNotification),
  473. MACROSTR(DiagnosticsStatusNotification),
  474. MACROSTR(FirmwareStatusNotification),
  475. MACROSTR(Heartbeat),
  476. MACROSTR(MeterValues),
  477. MACROSTR(StatusNotification)
  478. };
  479. /*TriggerMessageStatus*/
  480. typedef enum {
  481. TriggerMessageStatus_Accepted ,
  482. TriggerMessageStatus_Rejected ,
  483. TriggerMessageStatus_NotImplemented
  484. } TriggerMessageStatus;
  485. static char * TriggerMessageStatusStr[] = {
  486. MACROSTR(Accepted),
  487. MACROSTR(Rejected),
  488. MACROSTR(NotImplemented)
  489. };
  490. /*UnlockStatus*/
  491. typedef enum {
  492. Unlocked,
  493. UnlockFailed,
  494. UnlockStatus_NotSupported
  495. } UnlockStatus;
  496. static char * UnlockStatusStr[] = {
  497. MACROSTR(Unlocked),
  498. MACROSTR(UnlockFailed),
  499. MACROSTR(NotSupported)
  500. };
  501. /*StopTransactionReason*/
  502. typedef enum {
  503. EmergencyStop,
  504. EVDisconnected,
  505. HardReset,
  506. Local,
  507. Other,
  508. PowerLoss,
  509. Reboot,
  510. Remote,
  511. SoftReset,
  512. UnlockCommand,
  513. DeAuthorized
  514. } StopTransactionReason;
  515. static char * StopTransactionReasonStr[] = {
  516. MACROSTR(EmergencyStop),
  517. MACROSTR(EVDisconnected),
  518. MACROSTR(HardReset),
  519. MACROSTR(Local),
  520. MACROSTR(Other),
  521. MACROSTR(PowerLoss),
  522. MACROSTR(Reboot),
  523. MACROSTR(Remote),
  524. MACROSTR(SoftReset),
  525. MACROSTR(UnlockCommand),
  526. MACROSTR(DeAuthorized)
  527. };
  528. /*CancelReservationStatus*/
  529. typedef enum {
  530. CancelReservationStatus_Accepted,
  531. CancelReservationStatus_Rejected
  532. } CancelReservationStatus;
  533. static char * CancelReservationStatusStr[] = {
  534. MACROSTR(Accepted),
  535. MACROSTR(Rejected)
  536. };
  537. /*ReadingContext*/
  538. typedef enum {
  539. ReadingContext_Interruption_Begin,
  540. ReadingContext_Interruption_End,
  541. ReadingContext_Other,
  542. ReadingContext_Sample_Clock,
  543. ReadingContext_Sample_Periodic ,
  544. ReadingContext_Transaction_Begin ,
  545. ReadingContext_Transaction_End,
  546. ReadingContext_Trigger
  547. } ReadingContext;
  548. static char * ReadingContextStr[] = {
  549. MACROSTR(Interruption.Begin),
  550. MACROSTR(Interruption.End),
  551. MACROSTR(Other),
  552. MACROSTR(Sample.Clock),
  553. MACROSTR(Sample.Periodic),
  554. MACROSTR(Transaction.Begin),
  555. MACROSTR(Transaction.End),
  556. MACROSTR(Trigger)
  557. };
  558. /*ValueFormat*/
  559. typedef enum {
  560. Raw,
  561. SignedData
  562. } ValueFormat;
  563. static char * ValueFormatStr[] = {
  564. MACROSTR(Raw),
  565. MACROSTR(SignedData)
  566. };
  567. /*Measurand*/
  568. typedef enum {
  569. Current_Export ,
  570. Current_Import,
  571. Current_Offered,
  572. Energy_Active_Export_Register,
  573. Energy_Active_Import_Register,
  574. Energy_Reactive_Export_Register,
  575. Energy_Reactive_Import_Register,
  576. Energy_Active_Export_Interval,
  577. Energy_Active_Import_Interval,
  578. Energy_Reactive_Export_Interval,
  579. Energy_Reactive_Import_Interval,
  580. Frequency,
  581. Power_Active_Export ,
  582. Power_Active_Import,
  583. Power_Factor,
  584. Power_Offered,
  585. Power_Reactive_Export,
  586. Power_Reactive_Import,
  587. RPM,
  588. SoC,
  589. Temperature ,
  590. Voltage
  591. } Measurand;
  592. static char * MeasurandStr[] = {
  593. MACROSTR(Current.Export),
  594. MACROSTR(Current.Import),
  595. MACROSTR(Current.Offered),
  596. MACROSTR(Energy.Active.Export.Register),
  597. MACROSTR(Energy.Active.Import.Register),
  598. MACROSTR(Energy.Reactive.Export.Register),
  599. MACROSTR(Energy.Reactive.Import.Register),
  600. MACROSTR(Energy.Active.Export.Interval),
  601. MACROSTR(Energy.Active.Import.Interval),
  602. MACROSTR(Energy.Reactive.Export.Interval),
  603. MACROSTR(Energy.Reactive.Import.Interval),
  604. MACROSTR(Frequency),
  605. MACROSTR(Power.Active.Export),
  606. MACROSTR(Power.Active.Import),
  607. MACROSTR(Power.Factor),
  608. MACROSTR(Power.Offered),
  609. MACROSTR(Power.Reactive.ExportMACROSTR),
  610. MACROSTR(Power.Reactive.Import),
  611. MACROSTR(RPM),
  612. MACROSTR(SoC),
  613. MACROSTR(Temperature),
  614. MACROSTR(Voltage)
  615. };
  616. /*Location*/
  617. typedef enum {
  618. Location_Body,
  619. Location_Cable,
  620. Location_EV,
  621. Location_Inlet ,
  622. Location_Outlet
  623. } Location;
  624. static char * LocationStr[] = {
  625. MACROSTR(Body),
  626. MACROSTR(Cable),
  627. MACROSTR(EV),
  628. MACROSTR(Inlet),
  629. MACROSTR(Outlet)
  630. };
  631. /*Phase*/
  632. typedef enum {
  633. L1,
  634. L2,
  635. L3,
  636. N,
  637. L1_N,
  638. L2_N,
  639. L3_N,
  640. L1_L2,
  641. L2_L3,
  642. L3_L1
  643. } Phase;
  644. static char * PhaseStr[] = {
  645. MACROSTR(L1),
  646. MACROSTR(L2),
  647. MACROSTR(L3),
  648. MACROSTR(N),
  649. MACROSTR(L1-N),
  650. MACROSTR(L2-N),
  651. MACROSTR(L3-N),
  652. MACROSTR(L1-L2),
  653. MACROSTR(L2-L3),
  654. MACROSTR(L3-L1)
  655. };
  656. /*UnitOfMeasure*/
  657. typedef enum {
  658. UnitOfMeasure_Wh,
  659. UnitOfMeasure_kWh ,
  660. UnitOfMeasure_varh ,
  661. UnitOfMeasure_kvarh ,
  662. UnitOfMeasure_W ,
  663. UnitOfMeasure_kW ,
  664. UnitOfMeasure_VA ,
  665. UnitOfMeasure_kVA ,
  666. UnitOfMeasure_var ,
  667. UnitOfMeasure_kvar ,
  668. UnitOfMeasure_A ,
  669. UnitOfMeasure_V ,
  670. UnitOfMeasure_Celsius ,
  671. UnitOfMeasure_Fahrenheit ,
  672. UnitOfMeasure_K ,
  673. UnitOfMeasure_Percent
  674. } UnitOfMeasure;
  675. static char * UnitOfMeasureStr[] = {
  676. MACROSTR(Wh),
  677. MACROSTR(kWh),
  678. MACROSTR(varh),
  679. MACROSTR(kvarh),
  680. MACROSTR(W),
  681. MACROSTR(kW),
  682. MACROSTR(VA),
  683. MACROSTR(kVA),
  684. MACROSTR(var),
  685. MACROSTR(kvar),
  686. MACROSTR(A),
  687. MACROSTR(V),
  688. MACROSTR(Celsius),
  689. MACROSTR(Fahrenheit),
  690. MACROSTR(K),
  691. MACROSTR(Percent)
  692. };
  693. /*Configuration enum*/
  694. enum CoreProfile {
  695. AllowOfflineTxForUnknownId=0,
  696. AuthorizationCacheEnabled,
  697. AuthorizeRemoteTxRequests,
  698. BlinkRepeat,
  699. ClockAlignedDataInterval,
  700. ConnectionTimeOut,
  701. GetConfigurationMaxKeys,
  702. HeartbeatInterval,
  703. LightIntensity,
  704. LocalAuthorizeOffline,
  705. LocalPreAuthorize,
  706. MaxEnergyOnInvalidId,
  707. MeterValuesAlignedData,
  708. MeterValuesAlignedDataMaxLength,
  709. MeterValuesSampledData,
  710. MeterValuesSampledDataMaxLength,
  711. MeterValueSampleInterval,
  712. MinimumStatusDuration,
  713. NumberOfConnectors,
  714. ResetRetries,
  715. ConnectorPhaseRotation,
  716. ConnectorPhaseRotationMaxLength,
  717. StopTransactionOnEVSideDisconnect,
  718. StopTransactionOnInvalidId,
  719. StopTxnAlignedData,
  720. StopTxnAlignedDataMaxLength,
  721. StopTxnSampledData,
  722. StopTxnSampledDataMaxLength,
  723. SupportedFeatureProfiles,
  724. SupportedFeatureProfilesMaxLength,
  725. TransactionMessageAttempts,
  726. TransactionMessageRetryInterval,
  727. UnlockConnectorOnEVSideDisconnect,
  728. WebSocketPingInterval,
  729. _CoreProfile_CNT
  730. };
  731. enum LocalAuthListManagementProfile{
  732. LocalAuthListEnabled=0,
  733. LocalAuthListMaxLength,
  734. SendLocalListMaxLength,
  735. _LocalAuthListManagementProfile_CNT
  736. };
  737. enum ReservationProfile{
  738. ReserveConnectorZeroSupported
  739. };
  740. enum SmartChargingProfile{
  741. ChargeProfileMaxStackLevel,
  742. ChargingScheduleAllowedChargingRateUnit,
  743. ChargingScheduleMaxPeriods,
  744. ConnectorSwitch3to1PhaseSupported,
  745. MaxChargingProfilesInstalled
  746. };
  747. enum ChargerSystemStatus{
  748. ChargerSystemStatus_Booting,
  749. ChargerSystemStatus_Idle,
  750. ChargerSystemStatus_Authorizing,
  751. ChargerSystemStatus_Preparing,
  752. ChargerSystemStatus_Charging,
  753. ChargerSystemStatus_Terminating,
  754. ChargerSystemStatus_Alarm,
  755. ChargerSystemStatus_Fault
  756. };
  757. enum GetConfigurationKey {
  758. GetConfiguration_AllowOfflineTxForUnknownId=0,
  759. GetConfiguration_AuthorizationCacheEnabled,
  760. GetConfiguration_AuthorizeRemoteTxRequests,
  761. GetConfiguration_BlinkRepeat,
  762. GetConfiguration_ClockAlignedDataInterval,
  763. GetConfiguration_ConnectionTimeOut,
  764. GetConfiguration_GetConfigurationMaxKeys,
  765. GetConfiguration_HeartbeatInterval,
  766. GetConfiguration_LightIntensity,
  767. GetConfiguration_LocalAuthorizeOffline,
  768. GetConfiguration_LocalPreAuthorize,
  769. GetConfiguration_MaxEnergyOnInvalidId,
  770. GetConfiguration_MeterValuesAlignedData,
  771. GetConfiguration_MeterValuesAlignedDataMaxLength,
  772. GetConfiguration_MeterValuesSampledData,
  773. GetConfiguration_MeterValuesSampledDataMaxLength,
  774. GetConfiguration_MeterValueSampleInterval,
  775. GetConfiguration_MinimumStatusDuration,
  776. GetConfiguration_NumberOfConnectors,
  777. GetConfiguration_ResetRetries,
  778. GetConfiguration_ConnectorPhaseRotation,
  779. GetConfiguration_ConnectorPhaseRotationMaxLength,
  780. GetConfiguration_StopTransactionOnEVSideDisconnect,
  781. GetConfiguration_StopTransactionOnInvalidId,
  782. GetConfiguration_StopTxnAlignedData,
  783. GetConfiguration_StopTxnAlignedDataMaxLength,
  784. GetConfiguration_StopTxnSampledData,
  785. GetConfiguration_StopTxnSampledDataMaxLength,
  786. GetConfiguration_SupportedFeatureProfiles,
  787. GetConfiguration_SupportedFeatureProfilesMaxLength,
  788. GetConfiguration_TransactionMessageAttempts,
  789. GetConfiguration_TransactionMessageRetryInterval,
  790. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  791. GetConfiguration_WebSocketPingInterval,
  792. GetConfiguration_LocalAuthListEnabled,
  793. GetConfiguration_LocalAuthListMaxLength,
  794. GetConfiguration_SendLocalListMaxLength,
  795. GetConfiguration_ReserveConnectorZeroSupported,
  796. GetConfiguration_ChargeProfileMaxStackLevel,
  797. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  798. GetConfiguration_ChargingScheduleMaxPeriods,
  799. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  800. GetConfiguration_MaxChargingProfilesInstalled,
  801. };
  802. //GetConfiguration Array
  803. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  804. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  805. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  806. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  807. //==========================================
  808. // Init all share memory
  809. //==========================================
  810. int InitShareMemory()
  811. {
  812. int result = PASS;
  813. int MeterSMId;
  814. //printf("1\n");
  815. //creat ShmSysConfigAndInfo
  816. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  817. {
  818. #ifdef SystemLogMessage
  819. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  820. #endif
  821. result = FAIL;
  822. }
  823. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  824. {
  825. #ifdef SystemLogMessage
  826. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  827. #endif
  828. result = FAIL;
  829. }
  830. else
  831. {}
  832. //printf("2\n");
  833. //creat ShmStatusCodeData
  834. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  835. {
  836. #ifdef SystemLogMessage
  837. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  838. #endif
  839. result = FAIL;
  840. }
  841. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else
  849. {}
  850. //printf("3\n");
  851. //creat ShmPsuData
  852. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  853. {
  854. #ifdef SystemLogMessage
  855. DEBUG_ERROR("shmget ShmPsuData NG\n");
  856. #endif
  857. result = FAIL;
  858. }
  859. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  860. {
  861. #ifdef SystemLogMessage
  862. DEBUG_ERROR("shmat ShmPsuData NG\n");
  863. #endif
  864. result = FAIL;
  865. }
  866. else
  867. {}
  868. //creat ShmOCPP16Data
  869. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  870. {
  871. #ifdef SystemLogMessage
  872. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  873. #endif
  874. result = FAIL;
  875. }
  876. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  877. {
  878. #ifdef SystemLogMessage
  879. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  880. #endif
  881. result = FAIL;
  882. }
  883. else
  884. {}
  885. /****************************** For Initial Settings************************************************/
  886. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  887. //memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  888. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  889. {
  890. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  891. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  892. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  893. }
  894. // Charger PRE_SYS_MODE
  895. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  896. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  897. clientTime.Heartbeat=time((time_t*)NULL);
  898. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  899. {
  900. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  901. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  902. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  903. }
  904. //HeartBeatWaitTime = 10;
  905. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  907. // allocate Configuration memory address
  908. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  909. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  910. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  911. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  913. {
  914. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  915. DEBUG_INFO("DC ...\n");
  916. }
  917. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  918. {
  919. SystemInitial = AC_QUANTITY;
  920. DEBUG_INFO("AC ...\n");
  921. }
  922. //Status Setting
  923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  924. {
  925. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  926. }
  927. for (int index = 0; index < CCS_QUANTITY; index++)
  928. {
  929. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  930. }
  931. for (int index = 0; index < GB_QUANTITY; index++)
  932. {
  933. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  934. }
  935. for (int index = 0; index < AC_QUANTITY; index++)
  936. {
  937. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  938. }
  939. //memset(unknownkey, 0, 10);
  940. return result;
  941. }
  942. int ProcessShareMemory()
  943. {
  944. if(InitShareMemory() == FAIL)
  945. {
  946. #ifdef SystemLogMessage
  947. DEBUG_ERROR("InitShareMemory NG\n");
  948. #endif
  949. if(ShmStatusCodeData!=NULL)
  950. {
  951. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  952. }
  953. sleep(5);
  954. return FAIL;
  955. }
  956. return PASS;
  957. }
  958. //---------------------------------------------
  959. // new:
  960. // enum SYSTEM_STATUS
  961. // {
  962. // SYS_MODE_BOOTING = 0,
  963. // SYS_MODE_IDLE = 1,
  964. // SYS_MODE_AUTHORIZING = 2,
  965. // SYS_MODE_PREPARING = 3,
  966. // SYS_MODE_CHARGING = 4,
  967. // SYS_MODE_TERMINATING = 5,
  968. // SYS_MODE_ALARM = 6,
  969. // SYS_MODE_FAULT = 7,
  970. // SYS_MODE_RESERVATION = 8,
  971. // SYS_MODE_BOOKING = 9,
  972. // SYS_MODE_MAINTAIN = 10,
  973. // SYS_MODE_DEBUG = 11,
  974. // SYS_MODE_REASSIGN_CHECK = 12,
  975. // SYS_MODE_REASSIGN = 13,
  976. // SYS_MODE_PRECHARGE = 14,
  977. // SYS_MODE_PREPARING_EV = 15,
  978. // SYS_MODE_PREPARING_EVSE = 16,
  979. // SYS_MODE_COMPLETE = 17
  980. // };
  981. //
  982. // old:
  983. // enum _SYSTEM_STATUS
  984. // {
  985. // S_BOOTING = 0,
  986. // S_IDLE, =1
  987. // S_AUTHORIZING, =2
  988. // S_REASSIGN_CHECK, =3
  989. // S_REASSIGN, =4
  990. // S_PRECHARGE, =5
  991. // S_PREPARING_FOR_EV, =6
  992. // S_PREPARING_FOR_EVSE, =7
  993. // S_CHARGING, =8
  994. // S_TERMINATING, =9
  995. // S_COMPLETE, =10
  996. // S_ALARM, =11
  997. // S_FAULT =12
  998. // };
  999. //
  1000. //-----------------------------------------
  1001. void CheckSystemValue(void)
  1002. {
  1003. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1004. int IdleModeCnt = 0;
  1005. char filenmae[100]={0};
  1006. char str[100]={0};
  1007. //===============================
  1008. // send Heartbeat
  1009. //===============================
  1010. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1011. {
  1012. //parameter for test
  1013. sendHeartbeatRequest(0);
  1014. //==============================================
  1015. // Reset Waiting Time
  1016. //==============================================
  1017. clientTime.Heartbeat=time((time_t*)NULL);
  1018. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1019. }
  1020. //==============================================
  1021. // Update firmware request
  1022. //==============================================
  1023. if(isUpdateRequest == TRUE )
  1024. {
  1025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1026. {
  1027. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1028. {
  1029. //check SystemStatus
  1030. /*************************DC*******************************/
  1031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1032. {
  1033. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1034. {
  1035. IdleModeCnt = IdleModeCnt + 1;
  1036. }
  1037. }
  1038. for (int index = 0; index < CCS_QUANTITY; index++)
  1039. {
  1040. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1041. {
  1042. IdleModeCnt = IdleModeCnt + 1;
  1043. }
  1044. }
  1045. for (int index = 0; index < GB_QUANTITY; index++)
  1046. {
  1047. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1048. {
  1049. IdleModeCnt = IdleModeCnt + 1;
  1050. }
  1051. }
  1052. }
  1053. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1054. {
  1055. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1056. isUpdateRequest = FALSE;
  1057. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1058. }
  1059. }
  1060. else
  1061. {
  1062. /*************************AC*******************************/
  1063. for (int index = 0; index < AC_QUANTITY; index++)
  1064. {
  1065. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1066. {
  1067. IdleModeCnt = IdleModeCnt + 1;
  1068. }
  1069. }
  1070. if(IdleModeCnt == AC_QUANTITY)
  1071. {
  1072. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1073. isUpdateRequest = FALSE;
  1074. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1075. }
  1076. }
  1077. }
  1078. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1079. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1080. {
  1081. //===============================
  1082. // CSU Trigger Reset Conf
  1083. //===============================
  1084. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1085. {
  1086. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1087. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1088. {
  1089. server_sign = FALSE;
  1090. }
  1091. }
  1092. //===============================
  1093. // CSU Trigger Authorize Request
  1094. //===============================
  1095. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1096. {
  1097. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1098. {
  1099. sendAuthorizeRequest(0);
  1100. authorizeRetryTimes = authorizeRetryTimes + 1;
  1101. // authenrequest = TRUE
  1102. if(authorizeRetryTimes < 3)
  1103. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1104. }
  1105. }
  1106. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1107. {
  1108. authorizeRetryTimes = 0;
  1109. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1110. server_sign = FALSE;
  1111. }
  1112. //===============================
  1113. // CSU Trigger Smart Charging Profilw
  1114. //===============================
  1115. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1116. {
  1117. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1118. GetChargingProfileRequest(gun_index);
  1119. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1120. }
  1121. //==============================================
  1122. // Charger start transaction
  1123. //==============================================
  1124. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1125. {
  1126. sendStartTransactionRequest(gun_index);
  1127. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1128. clientTime.StartTransaction = time((time_t*)NULL);
  1129. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1130. }
  1131. //==============================================
  1132. // Charger stop transaction
  1133. //==============================================
  1134. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1135. {
  1136. sendStopTransactionRequest(gun_index);
  1137. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1138. clientTime.StopTransaction = time((time_t*)NULL);
  1139. }
  1140. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1141. //==============================================
  1142. // Charger status report
  1143. //==============================================
  1144. /* Check Mode Change */
  1145. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1146. {
  1147. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1148. {
  1149. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1150. {
  1151. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1152. {
  1153. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1154. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1155. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1156. statusModeChage[gun_index] = TRUE;
  1157. }
  1158. }
  1159. }
  1160. for (int index = 0; index < CCS_QUANTITY; index++)
  1161. {
  1162. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1163. {
  1164. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1165. {
  1166. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1167. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1168. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1169. statusModeChage[gun_index] = TRUE;
  1170. }
  1171. }
  1172. }
  1173. for (int index = 0; index < GB_QUANTITY; index++)
  1174. {
  1175. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1176. {
  1177. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1178. {
  1179. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1180. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1181. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1182. statusModeChage[gun_index] = TRUE;
  1183. }
  1184. }
  1185. }
  1186. }
  1187. else //AC
  1188. {
  1189. for (int index = 0; index < AC_QUANTITY; index++)
  1190. {
  1191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1192. {
  1193. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1194. {
  1195. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1196. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1198. statusModeChage[gun_index] = TRUE;
  1199. }
  1200. }
  1201. }// END OF FOR
  1202. }// END OF ELSE
  1203. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1204. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1205. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1206. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1207. {
  1208. if(SystemInitial != 0)
  1209. SystemInitial = SystemInitial -1;
  1210. //GunStatusInterval= GunStatusInterval* gun_index;
  1211. sendStatusNotificationRequest(gun_index);
  1212. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1213. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1214. statusModeChage[gun_index] = FALSE;
  1215. //sleep(30); // sleep for 30 seconds
  1216. }
  1217. //==============================================
  1218. // Meter report
  1219. //==============================================
  1220. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1221. {
  1222. //check Transaction active
  1223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1224. {
  1225. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1226. {
  1227. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1228. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1229. {
  1230. meterValueSend[gun_index] =1;
  1231. }
  1232. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1233. {
  1234. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1235. if((access(filenmae,F_OK))!=-1)
  1236. {
  1237. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1238. sprintf(str,"rm -f %s",filenmae);
  1239. system(str);
  1240. }
  1241. }
  1242. }// End for CHAdeMO
  1243. for (int index = 0; index < CCS_QUANTITY; index++)
  1244. {
  1245. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1246. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1247. {
  1248. meterValueSend[gun_index] =1;
  1249. }
  1250. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1251. {
  1252. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1253. if((access(filenmae,F_OK))!=-1)
  1254. {
  1255. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1256. sprintf(str,"rm -f %s",filenmae);
  1257. system(str);
  1258. }
  1259. }
  1260. } // End for CCS
  1261. for (int index = 0; index < GB_QUANTITY; index++)
  1262. {
  1263. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1264. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1265. {
  1266. meterValueSend[gun_index] =1;
  1267. }
  1268. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1269. {
  1270. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1271. if((access(filenmae,F_OK))!=-1)
  1272. {
  1273. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1274. sprintf(str,"rm -f %s",filenmae);
  1275. system(str);
  1276. }
  1277. }
  1278. }// End for GB
  1279. }
  1280. else
  1281. {
  1282. for (int index = 0; index < AC_QUANTITY; index++)
  1283. {
  1284. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1285. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1286. {
  1287. meterValueSend[gun_index] =1;
  1288. }
  1289. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1290. {
  1291. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1292. if((access(filenmae,F_OK))!=-1)
  1293. {
  1294. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1295. sprintf(str,"rm -f %s",filenmae);
  1296. system(str);
  1297. }
  1298. }
  1299. }//End for AC
  1300. }//END OF ELSE
  1301. // sleep(1);
  1302. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1303. if(meterValueSend[gun_index] == 1)
  1304. sendMeterValuesRequest(gun_index);
  1305. }
  1306. //==============================================
  1307. // Check Connector reserved
  1308. //==============================================
  1309. //===============================
  1310. // Check if Reserve is expired
  1311. //===============================
  1312. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1313. {
  1314. double diff_t;
  1315. struct tm tp;
  1316. // current time
  1317. time_t t = time(NULL);
  1318. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1319. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1320. tp.tm_isdst = -1;
  1321. time_t utc = mktime(&tp);
  1322. diff_t = difftime(utc, t);
  1323. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1324. if(diff_t <= 0)
  1325. {
  1326. DEBUG_INFO("reserve expired !!! \n");
  1327. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1328. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1329. }
  1330. #if 0
  1331. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1332. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1333. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1334. {
  1335. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1336. }
  1337. else
  1338. {
  1339. //check Transaction active
  1340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1341. {
  1342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1343. {
  1344. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1345. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1346. {
  1347. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1348. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1349. {
  1350. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1351. }
  1352. }
  1353. }
  1354. for (int index = 0; index < CCS_QUANTITY; index++)
  1355. {
  1356. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1357. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1358. {
  1359. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1360. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1361. {
  1362. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1363. }
  1364. }
  1365. }
  1366. for (int index = 0; index < GB_QUANTITY; index++)
  1367. {
  1368. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1369. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1370. {
  1371. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1372. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1373. {
  1374. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1375. }
  1376. }
  1377. }
  1378. }
  1379. else //AC
  1380. {
  1381. for (int index = 0; index < AC_QUANTITY; index++)
  1382. {
  1383. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1384. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1385. {
  1386. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1387. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1388. {
  1389. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1390. }
  1391. }
  1392. }
  1393. }// END OF ELSE
  1394. }// END OF check Transaction active
  1395. #endif
  1396. }//END OF Check if Reserve is expired
  1397. //==========================================
  1398. // csu trigger FirmwareStatusNotificationReq
  1399. //==========================================
  1400. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1401. {
  1402. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1403. }
  1404. //==========================================
  1405. // csu trigger CancelReservationConf
  1406. //==========================================
  1407. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1408. {
  1409. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1410. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1411. }
  1412. //==========================================
  1413. // csu trigger ChangeAvailabilityConf
  1414. //==========================================
  1415. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1416. {
  1417. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1418. }
  1419. //==========================================
  1420. // csu trigger UnlockConnectorConf
  1421. //==========================================
  1422. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1423. {
  1424. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1425. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1426. }
  1427. //==========================================
  1428. // csu trigger ReserveNowConf
  1429. //==========================================
  1430. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1431. {
  1432. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1433. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1434. }
  1435. //==========================================
  1436. // csu trigger DataTransferReq
  1437. //==========================================
  1438. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1439. {
  1440. sendDataTransferRequest(gun_index);
  1441. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1442. }
  1443. }
  1444. }
  1445. //==========================================
  1446. // send request routine
  1447. //==========================================
  1448. int sendAuthorizeRequest(int gun_index)
  1449. {
  1450. mtrace();
  1451. int result = FAIL;
  1452. char message[100]={0};
  1453. char guid[37];
  1454. char tempdata[65]={0};
  1455. DEBUG_INFO("sendAuthorizeRequest \n");
  1456. //Local Authorize
  1457. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1458. {
  1459. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1460. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1461. {
  1462. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1463. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1464. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1465. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1466. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1467. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1468. authorizeRetryTimes = 0;
  1469. return result;
  1470. }
  1471. else
  1472. {
  1473. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1474. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1475. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1476. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1477. result = PASS;
  1478. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1479. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1480. authorizeRetryTimes = 0;
  1481. return result;
  1482. }
  1483. }
  1484. //initailize struct Authorize
  1485. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1486. //get data from shared memory
  1487. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1488. random_uuid(guid);
  1489. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1490. LWS_Send(message);
  1491. sprintf(tempdata, "Authorize,%d", gun_index);
  1492. if(hashmap_operation(0, guid, tempdata) == 1)
  1493. {
  1494. result = PASS;
  1495. DEBUG_ERROR("Authorize mapItem pass\n");
  1496. }
  1497. //#ifdef SystemLogMessage
  1498. //DEBUG_INFO(">>>>>Authorize request\n");
  1499. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1500. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1501. //#endif
  1502. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1503. return result;
  1504. }
  1505. int sendBootNotificationRequest(void)
  1506. {
  1507. mtrace();
  1508. int result = FAIL;
  1509. char message[500]={0}, payload[700]={0};
  1510. char guid[37]={0};
  1511. char tempdata[65]={0};
  1512. int IsGunCharging = FALSE;
  1513. //check Transaction active
  1514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1515. {
  1516. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1517. {
  1518. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1519. {
  1520. IsGunCharging = TRUE;
  1521. }
  1522. }
  1523. for (int index = 0; index < CCS_QUANTITY; index++)
  1524. {
  1525. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1526. {
  1527. IsGunCharging = TRUE;
  1528. }
  1529. }
  1530. for (int index = 0; index < GB_QUANTITY; index++)
  1531. {
  1532. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1533. {
  1534. IsGunCharging = TRUE;
  1535. }
  1536. }
  1537. }
  1538. else
  1539. {
  1540. for (int index = 0; index < AC_QUANTITY; index++)
  1541. {
  1542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1543. {
  1544. IsGunCharging = TRUE;
  1545. }
  1546. }
  1547. }
  1548. if(IsGunCharging == TRUE)
  1549. {
  1550. server_sign = TRUE;
  1551. return result;
  1552. }
  1553. // Fill BootNotification fields
  1554. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1555. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1556. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1557. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1558. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1559. ShmOCPP16Data->ChargeBoxId
  1560. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1561. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1562. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1563. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1564. ,ShmOCPP16Data->BootNotification.CpIccid
  1565. ,ShmOCPP16Data->BootNotification.CpImsi
  1566. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1567. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1568. random_uuid(guid);
  1569. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1570. LWS_Send(message);
  1571. sprintf(tempdata, "BootNotification,0");
  1572. 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*/)
  1573. {
  1574. result = PASS;
  1575. }
  1576. memset(queuedata, 0, sizeof(queuedata));
  1577. strcpy(queuedata,message);
  1578. //#ifdef SystemLogMessage
  1579. //DEBUG_INFO(">>>>>BootNotification request\n");
  1580. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1581. //#endif
  1582. return result;
  1583. }
  1584. int sendDataTransferRequest(int gun_index)
  1585. {
  1586. mtrace();
  1587. char message[1000]={0};
  1588. char guid[37]={0};
  1589. char tempdata[65]={0};
  1590. int result = FAIL;
  1591. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1592. random_uuid(guid);
  1593. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1594. MESSAGE_TYPE_CALL,
  1595. guid,
  1596. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1597. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1598. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1599. LWS_Send(message);
  1600. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1601. 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*/)
  1602. {
  1603. result = PASS;
  1604. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1605. }
  1606. //#ifdef SystemLogMessage
  1607. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1608. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1609. //#endif
  1610. return result;
  1611. }
  1612. int sendDiagnosticsStatusNotificationRequest(char *status)
  1613. {
  1614. mtrace();
  1615. int result = FAIL;
  1616. char message[110]={0};
  1617. char guid[37]={0};
  1618. char tempdata[65]={0};
  1619. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1620. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1621. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1622. random_uuid(guid);
  1623. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1624. LWS_Send(message);
  1625. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1626. if(hashmap_operation(0, guid, tempdata) == 1)
  1627. {
  1628. result = PASS;
  1629. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1630. }
  1631. //#ifdef SystemLogMessage
  1632. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1633. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1634. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1635. //#endif
  1636. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1637. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1638. //record status
  1639. if(strcmp(status,"Idle")==0)
  1640. {
  1641. DiagnosticsStatusNotificationStatus = 0;
  1642. }
  1643. else if(strcmp(status,"Uploaded")==0)
  1644. {
  1645. DiagnosticsStatusNotificationStatus = 1;
  1646. }
  1647. else if(strcmp(status,"UploadFailed")==0)
  1648. {
  1649. DiagnosticsStatusNotificationStatus = 2;
  1650. }
  1651. else if(strcmp(status,"Uploading")==0)
  1652. {
  1653. DiagnosticsStatusNotificationStatus = 3;
  1654. }
  1655. return result;
  1656. }
  1657. int sendFirmwareStatusNotificationRequest(char *status)
  1658. {
  1659. mtrace();
  1660. int result = FAIL;
  1661. char message[110]={0};
  1662. char guid[37]={0};
  1663. char tempdata[65]={0};
  1664. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1665. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1666. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1667. random_uuid(guid);
  1668. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1669. LWS_Send(message);
  1670. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1671. 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*/)
  1672. {
  1673. result = PASS;
  1674. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1675. }
  1676. //#ifdef SystemLogMessage
  1677. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1678. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1679. //#endif
  1680. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1681. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1682. //record status
  1683. if(strcmp(status,"Downloaded")==0)
  1684. {
  1685. FirmwareStatusNotificationStatus = 0;
  1686. }
  1687. else if(strcmp(status,"DownloadFailed")==0)
  1688. {
  1689. FirmwareStatusNotificationStatus = 1;
  1690. }
  1691. else if(strcmp(status,"Downloading")==0)
  1692. {
  1693. FirmwareStatusNotificationStatus = 2;
  1694. }
  1695. else if(strcmp(status,"Idle")==0)
  1696. {
  1697. FirmwareStatusNotificationStatus = 3;
  1698. }
  1699. else if(strcmp(status,"InstallationFailed")==0)
  1700. {
  1701. FirmwareStatusNotificationStatus = 4;
  1702. }
  1703. else if(strcmp(status,"Installing")==0)
  1704. {
  1705. FirmwareStatusNotificationStatus = 5;
  1706. }
  1707. else if(strcmp(status,"Installed")==0)
  1708. {
  1709. FirmwareStatusNotificationStatus = 6;
  1710. }
  1711. return result;
  1712. }
  1713. int sendHeartbeatRequest(int gun_index)
  1714. {
  1715. mtrace();
  1716. int result = FAIL;
  1717. char message[80]={0};
  1718. char guid[37]={0};
  1719. char tempdata[65]={0};
  1720. random_uuid(guid);
  1721. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1722. , MESSAGE_TYPE_CALL
  1723. , guid );
  1724. LWS_Send(message);
  1725. sprintf(tempdata, "Heartbeat,%d", 0);
  1726. 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*/)
  1727. {
  1728. result = PASS;
  1729. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1730. }
  1731. //#ifdef SystemLogMessage
  1732. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1733. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1734. //#endif
  1735. return result;
  1736. }
  1737. int sendStartTransactionRequest(int gun_index)
  1738. {
  1739. mtrace();
  1740. int result = FAIL;
  1741. char message[250]={0};
  1742. char guid[37]={0};
  1743. struct timeval tmnow;
  1744. struct tm *tm;
  1745. char buf[28];//, usec_buf[6];
  1746. char tempdata[65]={0};
  1747. DEBUG_INFO("sendStartTransactionRequest...");
  1748. gettimeofday(&tmnow, NULL);
  1749. time_t t;
  1750. t = time(NULL);
  1751. /*UTC time and date*/
  1752. tm = gmtime(&t);
  1753. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1754. #if 0 // remove temporally
  1755. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1756. strcat(buf,".");
  1757. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1758. strcat(buf,usec_buf);
  1759. #endif
  1760. //printf("Start Charging Time :%s",buf);
  1761. // set value
  1762. //if(ShmOCPP16Data->OcppConnStatus == 1 )
  1763. //{
  1764. //memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1765. //}
  1766. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1767. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1768. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1769. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1770. {
  1771. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1772. {
  1773. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1774. {
  1775. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1776. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1777. }
  1778. }
  1779. for (int index = 0; index < CCS_QUANTITY; index++)
  1780. {
  1781. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1782. {
  1783. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1784. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1785. }
  1786. }
  1787. for (int index = 0; index < GB_QUANTITY; index++)
  1788. {
  1789. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1790. {
  1791. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1792. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1793. }
  1794. }
  1795. }
  1796. else
  1797. {
  1798. for (int index = 0; index < AC_QUANTITY; index++)
  1799. {
  1800. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1801. {
  1802. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1803. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1804. }
  1805. }
  1806. }//END OF ELSE
  1807. random_uuid(guid);
  1808. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1809. , MESSAGE_TYPE_CALL
  1810. , guid
  1811. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1812. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1813. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1814. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1815. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1816. LWS_Send(message);
  1817. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1818. 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*/)
  1819. {
  1820. result = PASS;
  1821. }
  1822. strcpy(queuedata, message);
  1823. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1824. //#ifdef SystemLogMessage
  1825. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1826. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1827. //#endif
  1828. return result;
  1829. }
  1830. int sendStatusNotificationRequest(int gun_index)
  1831. {
  1832. mtrace();
  1833. int result = FAIL;
  1834. char message[600]={0};
  1835. char guid[37];
  1836. int currentStatus = 0;
  1837. struct timeval tmnow;
  1838. struct tm *tm;
  1839. char buf[28];//, usec_buf[6];
  1840. char tempdata[65]={0};
  1841. gettimeofday(&tmnow, NULL);
  1842. time_t t;
  1843. t = time(NULL);
  1844. /*UTC time and date*/
  1845. tm = gmtime(&t);
  1846. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1847. #if 0 // remove temporally
  1848. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1849. strcat(buf,".");
  1850. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1851. strcat(buf,usec_buf);
  1852. #endif
  1853. printf("%s",buf);
  1854. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1855. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1856. // it's option
  1857. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1858. /*
  1859. enum _SYSTEM_STATUS
  1860. {
  1861. S_BOOTING = 0,
  1862. S_IDLE, = 1
  1863. S_AUTHORIZING, =2
  1864. S_REASSIGN_CHECK, =3
  1865. S_REASSIGN, =4
  1866. S_PRECHARGE, =5
  1867. S_PREPARING_FOR_EV, =6
  1868. S_PREPARING_FOR_EVSE, =7
  1869. S_CHARGING, =8
  1870. S_TERMINATING, =9
  1871. S_COMPLETE, =10
  1872. S_ALARM, =11
  1873. S_FAULT =12
  1874. }
  1875. */
  1876. //check Transaction active
  1877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1878. {
  1879. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1880. {
  1881. //printf("gun_index=%d\n",gun_index);
  1882. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1883. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1884. {
  1885. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1886. currentStatus = 0; //OCPP Status
  1887. }
  1888. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1889. {
  1890. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1891. currentStatus = 1; //OCPP Status
  1892. }
  1893. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1894. {
  1895. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1896. currentStatus = 2; //OCPP Status
  1897. }
  1898. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1899. {
  1900. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1901. currentStatus = 5; //OCPP Status
  1902. }
  1903. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1904. {
  1905. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1906. currentStatus = 4; //OCPP Status
  1907. }
  1908. 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
  1909. {
  1910. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1911. currentStatus = 7; //OCPP Status: Unavailable
  1912. }
  1913. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1914. {
  1915. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1916. currentStatus = 8; //OCPP Status: Faulted
  1917. }
  1918. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1919. {
  1920. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1921. currentStatus = 6; //OCPP Status: Reserved
  1922. }
  1923. }//end of for CHAdeMO_QUANTITY
  1924. for (int index = 0; index < CCS_QUANTITY; index++)
  1925. {
  1926. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1927. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1928. {
  1929. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1930. currentStatus = 0; //OCPP Status
  1931. }
  1932. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1933. {
  1934. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1935. currentStatus = 1; //OCPP Status
  1936. }
  1937. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1938. {
  1939. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1940. currentStatus = 2; //OCPP Status
  1941. }
  1942. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1943. {
  1944. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1945. currentStatus = 5; //OCPP Status
  1946. }
  1947. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1948. {
  1949. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1950. currentStatus = 4; //OCPP Status
  1951. }
  1952. 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
  1953. {
  1954. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1955. currentStatus = 7; //OCPP Status
  1956. }
  1957. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1958. {
  1959. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1960. currentStatus = 8; //OCPP Status
  1961. }
  1962. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1963. {
  1964. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1965. currentStatus = 6; //OCPP Status
  1966. }
  1967. }
  1968. for (int index = 0; index < GB_QUANTITY; index++)
  1969. {
  1970. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1971. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1972. {
  1973. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1974. currentStatus = 0; //OCPP Status
  1975. }
  1976. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1977. {
  1978. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1979. currentStatus = 1; //OCPP Status
  1980. }
  1981. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1982. {
  1983. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1984. currentStatus = 2; //OCPP Status
  1985. }
  1986. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1987. {
  1988. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1989. currentStatus = 5; //OCPP Status
  1990. }
  1991. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1992. {
  1993. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1994. currentStatus = 4; //OCPP Status
  1995. }
  1996. 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
  1997. {
  1998. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1999. currentStatus = 7; //OCPP Status: Unavailable
  2000. }
  2001. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2002. {
  2003. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2004. currentStatus = 8; //OCPP Status: Faulted
  2005. }
  2006. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2007. {
  2008. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2009. currentStatus = 6; //OCPP Status: Faulted
  2010. }
  2011. }
  2012. }
  2013. else
  2014. {
  2015. for (int index = 0; index < AC_QUANTITY; index++)
  2016. {
  2017. //printf("gun_index=%d\n",gun_index);
  2018. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2019. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2020. {
  2021. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2022. currentStatus = 0; //OCPP Status
  2023. }
  2024. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2025. {
  2026. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2027. currentStatus = 1; //OCPP Status
  2028. }
  2029. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2030. {
  2031. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2032. currentStatus = 2; //OCPP Status
  2033. }
  2034. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2035. {
  2036. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2037. currentStatus = 5; //OCPP Status
  2038. }
  2039. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2040. {
  2041. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2042. currentStatus = 4; //OCPP Status
  2043. }
  2044. 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
  2045. {
  2046. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2047. currentStatus = 7; //OCPP Status: Unavailable
  2048. }
  2049. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2050. {
  2051. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2052. currentStatus = 8; //OCPP Status: Faulted
  2053. }
  2054. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2055. {
  2056. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2057. currentStatus = 6; //OCPP Status: Reserved
  2058. }
  2059. }//end of for AC_QUANTITY
  2060. }//END OF ELSE
  2061. //it's option
  2062. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2063. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2064. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2065. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2066. random_uuid(guid);
  2067. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2068. , MESSAGE_TYPE_CALL
  2069. , guid
  2070. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2071. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2072. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2073. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2074. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2075. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2076. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2077. LWS_Send(message);
  2078. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2079. 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*/)
  2080. {
  2081. //DEBUG_ERROR("statusNotification mapitem pass");
  2082. result = PASS;
  2083. }
  2084. //#ifdef SystemLogMessage
  2085. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2086. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2087. //#endif
  2088. return result;
  2089. }
  2090. int sendStopTransactionRequest(int gun_index)
  2091. {
  2092. mtrace();
  2093. int result = FAIL;
  2094. //char message[1500]={0};
  2095. char guid[37]={0};
  2096. char tempdata[65]={0};
  2097. //int idx_sample=0;
  2098. DEBUG_ERROR("sendStopTransactionRequest \n");
  2099. memset(queuedata, 0, sizeof(queuedata));
  2100. //ENERGY_ACTIVE_IMPORT_REGISTER
  2101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2102. {
  2103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2104. {
  2105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2106. {
  2107. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2108. //Check Status
  2109. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2110. {
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2112. }
  2113. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2114. }
  2115. }// END OF CHAdeMO_QUANTITY
  2116. for (int index = 0; index < CCS_QUANTITY; index++)
  2117. {
  2118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2119. {
  2120. //for test
  2121. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2122. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2123. //Check Status
  2124. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2125. {
  2126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2127. }
  2128. else
  2129. {
  2130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2131. }
  2132. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2133. }
  2134. }// END OF CCS_QUANTITY
  2135. for (int index = 0; index < GB_QUANTITY; index++)
  2136. {
  2137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2138. {
  2139. // for test
  2140. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2141. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2142. //Check Status
  2143. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2144. {
  2145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2146. }
  2147. else
  2148. {
  2149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2150. }
  2151. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2152. }
  2153. }// END OF GB_QUANTITY
  2154. }
  2155. else
  2156. {
  2157. for (int index = 0; index < AC_QUANTITY; index++)
  2158. {
  2159. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2160. {
  2161. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2162. //Check Status
  2163. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2164. {
  2165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2166. }
  2167. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2168. }
  2169. }// END OF AC_QUANTITY
  2170. }//END OF ELSE
  2171. //Stop Transaction Time
  2172. struct timeval tmnow;
  2173. struct tm *tm;
  2174. char buf[28];//, usec_buf[6];
  2175. gettimeofday(&tmnow, NULL);
  2176. time_t t;
  2177. t = time(NULL);
  2178. /*UTC time and date*/
  2179. tm = gmtime(&t);
  2180. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2181. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2183. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2184. random_uuid(guid);
  2185. /***********************************transactionData******************************************************/
  2186. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2187. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2188. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2190. //=================================
  2191. // Transaction_Begin
  2192. //=================================
  2193. // Energy.Active.Export.Interval
  2194. //idx_sample=0;
  2195. 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
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2198. 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*/]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2202. //=================================
  2203. // Transaction_End
  2204. //=================================
  2205. //Current.Export
  2206. //idx_sample=1;
  2207. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2208. {
  2209. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2210. {
  2211. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2212. {
  2213. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2214. }
  2215. }
  2216. for (int index = 0; index < CCS_QUANTITY; index++)
  2217. {
  2218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2219. {
  2220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2221. }
  2222. }
  2223. for (int index = 0; index < GB_QUANTITY; index++)
  2224. {
  2225. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2226. {
  2227. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2228. }
  2229. }
  2230. }
  2231. else
  2232. {
  2233. for (int index = 0; index < AC_QUANTITY; index++)
  2234. {
  2235. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2236. {
  2237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2238. }
  2239. }
  2240. }// END FOR AC ELSE
  2241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2247. //Energy.Active.Export.Interval
  2248. //idx_sample=2;
  2249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2250. {
  2251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2252. {
  2253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2254. {
  2255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2256. }
  2257. }
  2258. for (int index = 0; index < CCS_QUANTITY; index++)
  2259. {
  2260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2261. {
  2262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2263. }
  2264. }
  2265. for (int index = 0; index < GB_QUANTITY; index++)
  2266. {
  2267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2268. {
  2269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2270. }
  2271. }
  2272. }
  2273. else
  2274. {
  2275. for (int index = 0; index < AC_QUANTITY; index++)
  2276. {
  2277. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2278. {
  2279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2280. }
  2281. }
  2282. }// END FOR AC ELSE
  2283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2289. //Power.Active.Export
  2290. //idx_sample=3;
  2291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2292. {
  2293. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2294. {
  2295. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2296. {
  2297. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2298. }
  2299. }
  2300. for (int index = 0; index < CCS_QUANTITY; index++)
  2301. {
  2302. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2303. {
  2304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2305. }
  2306. }
  2307. for (int index = 0; index < GB_QUANTITY; index++)
  2308. {
  2309. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2310. {
  2311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2312. }
  2313. }
  2314. }
  2315. else
  2316. {
  2317. for (int index = 0; index < AC_QUANTITY; index++)
  2318. {
  2319. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2320. {
  2321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2322. }
  2323. }
  2324. }// END FOR AC ELSE
  2325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2331. //Voltage
  2332. //idx_sample=4;
  2333. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2334. {
  2335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2336. {
  2337. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2338. {
  2339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2340. }
  2341. }
  2342. for (int index = 0; index < CCS_QUANTITY; index++)
  2343. {
  2344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2345. {
  2346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2347. }
  2348. }
  2349. for (int index = 0; index < GB_QUANTITY; index++)
  2350. {
  2351. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2352. {
  2353. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2354. }
  2355. }
  2356. }
  2357. else
  2358. {
  2359. for (int index = 0; index < AC_QUANTITY; index++)
  2360. {
  2361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2362. {
  2363. 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
  2364. }
  2365. }
  2366. }// END FOR AC ELSE
  2367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2373. //SoC
  2374. //idx_sample=5;
  2375. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2376. {
  2377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2378. {
  2379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2380. {
  2381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2382. }
  2383. }
  2384. for (int index = 0; index < CCS_QUANTITY; index++)
  2385. {
  2386. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2387. {
  2388. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2389. }
  2390. }
  2391. for (int index = 0; index < GB_QUANTITY; index++)
  2392. {
  2393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2394. {
  2395. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2396. }
  2397. }
  2398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L1_N]);
  2402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2404. } // END FOR DC CASE
  2405. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2406. {
  2407. 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\" } ] } ] } ]"
  2408. ,MESSAGE_TYPE_CALL
  2409. ,guid
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2414. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2415. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2420. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2421. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2427. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2428. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2429. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2446. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2447. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2448. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2449. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2450. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2451. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2452. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2453. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2454. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2455. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2456. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2457. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2458. );
  2459. }
  2460. else
  2461. {
  2462. 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\" } ] } ] } ]"
  2463. ,MESSAGE_TYPE_CALL
  2464. ,guid
  2465. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2466. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2467. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2468. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2469. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2470. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2471. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2472. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2473. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2474. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2475. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2476. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2477. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2478. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2479. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2480. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2481. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2482. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2483. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2484. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2485. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2486. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2487. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2488. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2489. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2490. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2491. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2492. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2493. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2494. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2495. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2496. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2497. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2498. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2499. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2500. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2501. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2502. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2503. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2504. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2505. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2506. );
  2507. }
  2508. LWS_Send(queuedata);
  2509. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2510. if(hashmap_operation(0, guid, tempdata) == 1)
  2511. {
  2512. result = PASS;
  2513. DEBUG_INFO("StopTransaction mapitem pass\n");
  2514. }
  2515. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2516. //for test
  2517. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2518. return result;
  2519. }
  2520. int sendMeterValuesRequest(int gun_index)
  2521. {
  2522. mtrace();
  2523. int result = FAIL;
  2524. // char message[1500]={0};
  2525. char guid[37]={0};
  2526. //int idx_sample=0;
  2527. //int length = 0;
  2528. char tempdata[65]={0};
  2529. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2530. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2531. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2532. {
  2533. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2534. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2535. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2536. return result;
  2537. }
  2538. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2539. {
  2540. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2541. }
  2542. memset(queuedata, 0, sizeof(queuedata));
  2543. //set value
  2544. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2545. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2546. random_uuid(guid);
  2547. //UTC Date time
  2548. struct timeval tmnow;
  2549. struct tm *tm;
  2550. char buf[28];//, usec_buf[6];
  2551. gettimeofday(&tmnow, NULL);
  2552. time_t t;
  2553. t = time(NULL);
  2554. /*UTC time and date*/
  2555. tm = gmtime(&t);
  2556. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2558. //idx_sample=0;
  2559. //********************************(1)Current.Export************************************************/
  2560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2561. {
  2562. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2563. {
  2564. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2565. {
  2566. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2567. }
  2568. }
  2569. for (int index = 0; index < CCS_QUANTITY; index++)
  2570. {
  2571. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2572. {
  2573. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2574. }
  2575. }
  2576. for (int index = 0; index < GB_QUANTITY; index++)
  2577. {
  2578. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2579. {
  2580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2581. }
  2582. }
  2583. }
  2584. else
  2585. {
  2586. for (int index = 0; index < AC_QUANTITY; index++)
  2587. {
  2588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2589. {
  2590. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2591. }
  2592. }
  2593. }// END FOR AC ELSE
  2594. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2595. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2598. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2600. //idx_sample=1;
  2601. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2602. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2603. {
  2604. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2605. {
  2606. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2607. {
  2608. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2609. }
  2610. }
  2611. for (int index = 0; index < CCS_QUANTITY; index++)
  2612. {
  2613. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2614. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2615. {
  2616. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2617. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2618. }
  2619. }
  2620. for (int index = 0; index < GB_QUANTITY; index++)
  2621. {
  2622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2623. {
  2624. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2625. }
  2626. }
  2627. }
  2628. else
  2629. {
  2630. for (int index = 0; index < AC_QUANTITY; index++)
  2631. {
  2632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2633. {
  2634. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2635. }
  2636. }
  2637. }//END FOR AC ELSE
  2638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1]);
  2642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2644. //idx_sample=2;
  2645. //********************************(4)Power.Active.Export************************************************/
  2646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2647. {
  2648. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2649. {
  2650. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2651. {
  2652. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2653. }
  2654. }
  2655. for (int index = 0; index < CCS_QUANTITY; index++)
  2656. {
  2657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2658. {
  2659. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2660. }
  2661. }
  2662. for (int index = 0; index < GB_QUANTITY; index++)
  2663. {
  2664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2665. {
  2666. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2667. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2668. }
  2669. }
  2670. }
  2671. else
  2672. {
  2673. for (int index = 0; index < AC_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2676. {
  2677. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2678. }
  2679. }
  2680. }// END FOR AC ELSE
  2681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2687. //idx_sample=3;
  2688. //***********************************************(5)VOLTAGE******************************************************/
  2689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2690. {
  2691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2692. {
  2693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2694. {
  2695. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2696. }
  2697. }
  2698. for (int index = 0; index < CCS_QUANTITY; index++)
  2699. {
  2700. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2701. {
  2702. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2703. }
  2704. }
  2705. for (int index = 0; index < GB_QUANTITY; index++)
  2706. {
  2707. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2708. {
  2709. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2710. }
  2711. }
  2712. }
  2713. else
  2714. {
  2715. for (int index = 0; index < AC_QUANTITY; index++)
  2716. {
  2717. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2718. {
  2719. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2720. }
  2721. }
  2722. }//END FOR AC ELSE
  2723. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2724. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2725. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2726. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2727. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2728. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2730. {
  2731. //idx_sample=4;
  2732. //sampledValue = NULL;
  2733. //***********************************************(6)SOC******************************************************/
  2734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2735. {
  2736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2737. {
  2738. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2739. }
  2740. }
  2741. for (int index = 0; index < CCS_QUANTITY; index++)
  2742. {
  2743. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2744. {
  2745. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2746. }
  2747. }
  2748. for (int index = 0; index < GB_QUANTITY; index++)
  2749. {
  2750. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2751. {
  2752. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2753. }
  2754. }
  2755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  2759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2761. }
  2762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2763. {
  2764. 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\"}]}]}]"
  2765. ,MESSAGE_TYPE_CALL
  2766. ,guid
  2767. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2768. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2769. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2805. );
  2806. }
  2807. else
  2808. {
  2809. 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\"}]}]}]"
  2810. ,MESSAGE_TYPE_CALL
  2811. ,guid
  2812. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2813. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2814. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2834. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2835. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2836. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2837. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2838. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2839. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2840. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2841. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2842. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2843. );
  2844. }
  2845. LWS_Send(queuedata);
  2846. // Put request guid to hash map
  2847. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2848. 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*/)
  2849. {
  2850. result = PASS;
  2851. DEBUG_INFO("MeterValues mapitem pass\n");
  2852. }
  2853. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2854. return result;
  2855. }
  2856. //==========================================
  2857. // send confirm routine
  2858. //==========================================
  2859. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2860. {
  2861. mtrace();
  2862. int result = FAIL;
  2863. char message[100]={0};
  2864. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2865. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2866. LWS_Send(message);
  2867. result = TRUE;
  2868. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2869. return result;
  2870. }
  2871. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2872. {
  2873. mtrace();
  2874. int result = FAIL;
  2875. char message[100]={0};
  2876. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2877. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2878. LWS_Send(message);
  2879. result = TRUE;
  2880. return result;
  2881. }
  2882. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2883. {
  2884. mtrace();
  2885. int result = FAIL;
  2886. char message[100]={0};
  2887. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2888. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2889. LWS_Send(message);
  2890. result = TRUE;
  2891. return result;
  2892. }
  2893. int sendClearCacheConfirmation(char *uuid,char *payload)
  2894. {
  2895. mtrace();
  2896. int result = FAIL;
  2897. char message[500]={0};
  2898. // int count = 0;
  2899. // int gun_index = 0;
  2900. // char guid[37];
  2901. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2902. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2903. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2904. LWS_Send(message);
  2905. return result;
  2906. }
  2907. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2908. {
  2909. mtrace();
  2910. int result = FAIL;
  2911. char message[500]={0};
  2912. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2913. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2914. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2915. LWS_Send(message);
  2916. return result;
  2917. }
  2918. int sendDataTransferConfirmation(char *uuid,char *payload)
  2919. {
  2920. mtrace();
  2921. char statusStr[20]={0};
  2922. char dataStr[10]={0};
  2923. char sstr[20]={0};
  2924. int c = 0;
  2925. char *loc;
  2926. int result = FAIL;
  2927. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2928. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2929. /**********************status**************************/
  2930. loc = strstr(payload, "status");
  2931. memset(sstr ,0, sizeof(sstr) );
  2932. c = 0;
  2933. while (loc[3+strlen("status")+c] != '\"')
  2934. {
  2935. sstr[c] = loc[3+strlen("status")+c];
  2936. c++;
  2937. }
  2938. sstr[c] = '\0';
  2939. strcpy(statusStr, sstr);
  2940. /**********************data**************************/
  2941. loc = strstr(payload, "data");
  2942. memset(sstr ,0, sizeof(sstr) );
  2943. c = 0;
  2944. while (loc[3+strlen("data")+c] != '\"')
  2945. {
  2946. sstr[c] = loc[3+strlen("data")+c];
  2947. c++;
  2948. }
  2949. sstr[c] = '\0';
  2950. strcpy(dataStr, sstr);
  2951. return result;
  2952. }
  2953. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2954. {
  2955. mtrace();
  2956. int result = FAIL;
  2957. char message[1000]={0};
  2958. double diff_f = 0.0;
  2959. int diff_i = 0;
  2960. int diffSeconds = 0;
  2961. struct tm tp;
  2962. int TimeZero = FALSE;
  2963. int CompositeScheduleIndex = 0;
  2964. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2965. #if 0
  2966. if(connectorIdInt > 0)
  2967. {
  2968. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2969. {
  2970. TimeZero = TRUE;
  2971. }
  2972. else
  2973. {
  2974. strptime((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2975. }
  2976. }
  2977. else
  2978. {
  2979. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2980. {
  2981. TimeZero = TRUE;
  2982. }
  2983. else
  2984. {
  2985. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2986. }
  2987. }
  2988. DEBUG_INFO("ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule=%s\n",ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule);
  2989. #endif
  2990. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2991. {
  2992. TimeZero = TRUE;
  2993. }
  2994. else
  2995. {
  2996. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2997. }
  2998. if(TimeZero == FALSE)
  2999. {
  3000. tp.tm_isdst = -1;
  3001. time_t utc = mktime(&tp);
  3002. time_t t = time(NULL);
  3003. diff_f = difftime(t, utc);
  3004. diff_i = (int)diff_f;
  3005. diffSeconds = diff_i % 86400;//86400 seconds/day
  3006. }
  3007. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3008. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3009. #if 0 //remove temporally
  3010. 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}"
  3011. ,MESSAGE_TYPE_CALLRESULT
  3012. ,uuid
  3013. ,payload
  3014. ,connectorIdInt
  3015. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3016. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3017. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3018. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3019. #endif
  3020. if(nPeriod == 0)
  3021. {
  3022. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3023. ,MESSAGE_TYPE_CALLRESULT
  3024. ,uuid
  3025. ,payload
  3026. ,connectorIdInt
  3027. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3028. }
  3029. else
  3030. {
  3031. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3032. ,MESSAGE_TYPE_CALLRESULT
  3033. ,uuid
  3034. ,payload
  3035. ,connectorIdInt
  3036. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3037. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3038. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3039. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3040. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3041. #if 1 // remove temporally
  3042. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3043. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  3044. {
  3045. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3046. , 0
  3047. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3048. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3049. }
  3050. else
  3051. {
  3052. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3053. {
  3054. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) || (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  3055. {
  3056. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3057. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3058. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3059. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3060. }
  3061. else
  3062. {
  3063. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3064. , (((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*/))
  3065. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3066. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3067. }
  3068. }
  3069. }
  3070. #endif
  3071. sprintf(message + strlen(message), "]}}]");
  3072. }
  3073. LWS_Send(message);
  3074. result = TRUE;
  3075. return result;
  3076. }
  3077. int sendGetConfigurationConfirmation(char *uuid)
  3078. {
  3079. mtrace();
  3080. int result = FAIL;
  3081. int MaxKeySupported = 0;
  3082. int sentConfigurationNumber= 0;
  3083. int sentunConfigurationNumber= 0;
  3084. char message[4000]={0};
  3085. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3086. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3087. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3088. ,MESSAGE_TYPE_CALLRESULT
  3089. ,uuid );
  3090. //configuration key
  3091. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3092. {
  3093. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3094. {
  3095. if (sentConfigurationNumber == 0)
  3096. {
  3097. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3098. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3099. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3100. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3101. }
  3102. else
  3103. {
  3104. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3105. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3106. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3107. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3108. }
  3109. sentConfigurationNumber = sentConfigurationNumber + 1;
  3110. }
  3111. }
  3112. sprintf(message + strlen(message), "]");
  3113. if(UnknownKeynum != 0)
  3114. {
  3115. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3116. //unkown key
  3117. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3118. {
  3119. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3120. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3121. if(sentunConfigurationNumber == 0)
  3122. {
  3123. sprintf(message + strlen(message), "\"%s\""
  3124. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3125. }
  3126. else
  3127. {
  3128. sprintf(message + strlen(message), ",\"%s\""
  3129. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3130. }
  3131. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3132. }
  3133. sprintf(message + strlen(message), "]");
  3134. }
  3135. sprintf(message + strlen(message), "} ]");
  3136. LWS_Send(message);
  3137. #if 0
  3138. printf("error 1-0\n");
  3139. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3140. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3141. #endif
  3142. return result;
  3143. }
  3144. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3145. {
  3146. mtrace();
  3147. int result = FAIL;
  3148. char message[400]={0};
  3149. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3150. if(strcmp(payload,"")==0)
  3151. {
  3152. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3153. }
  3154. else
  3155. {
  3156. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3157. }
  3158. LWS_Send(message);
  3159. result = TRUE;
  3160. return result;
  3161. }
  3162. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3163. {
  3164. mtrace();
  3165. int result = FAIL;
  3166. char message[80]={0};
  3167. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3168. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3169. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3170. LWS_Send(message);
  3171. result = TRUE;
  3172. return result;
  3173. }
  3174. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3175. {
  3176. mtrace();
  3177. int result = FAIL;
  3178. char message[80]={0};
  3179. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3180. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3181. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3182. LWS_Send(message);
  3183. result = TRUE;
  3184. return result;
  3185. }
  3186. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3187. {
  3188. mtrace();
  3189. int result = FAIL;
  3190. char message[80]={0};
  3191. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3192. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3193. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3194. LWS_Send(message);
  3195. result = TRUE;
  3196. return result;
  3197. }
  3198. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3199. {
  3200. mtrace();
  3201. int result = FAIL;
  3202. char message[80]={0};
  3203. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3204. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3205. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3206. LWS_Send(message);
  3207. result = TRUE;
  3208. return result;
  3209. }
  3210. int sendResetConfirmation(char *uuid,char *payload)
  3211. {
  3212. mtrace();
  3213. int result = FAIL;
  3214. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3215. char message[80]={0};
  3216. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3217. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3218. LWS_Send(message);
  3219. result = TRUE;
  3220. return result;
  3221. }
  3222. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3223. {
  3224. mtrace();
  3225. int result = FAIL;
  3226. char message[500]={0};
  3227. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3228. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3229. LWS_Send(message);
  3230. result = TRUE;
  3231. return result;
  3232. }
  3233. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3234. {
  3235. mtrace();
  3236. int result = FAIL;
  3237. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3238. char message[80]={0};
  3239. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3240. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3241. LWS_Send(message);
  3242. result = TRUE;
  3243. return result;
  3244. }
  3245. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3246. {
  3247. mtrace();
  3248. int result = FAIL;
  3249. char message[80]={0};
  3250. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3251. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3252. LWS_Send(message);
  3253. result = TRUE;
  3254. return result;
  3255. }
  3256. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3257. {
  3258. mtrace();
  3259. int result = FAIL;
  3260. char message[80]={0};
  3261. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3262. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3263. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3264. LWS_Send(message);
  3265. result = TRUE;
  3266. return result;
  3267. }
  3268. int sendUpdateFirmwareConfirmation(char *uuid)
  3269. {
  3270. mtrace();
  3271. int result = FAIL;
  3272. char message[60]={0};
  3273. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3274. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3275. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3276. LWS_Send(message);
  3277. result = TRUE;
  3278. return result;
  3279. }
  3280. //==========================================
  3281. // send CallError routine
  3282. //==========================================
  3283. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3284. {
  3285. mtrace();
  3286. //int result = FAIL;
  3287. char message[220]={0};
  3288. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3289. #ifdef SystemLogMessage
  3290. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3291. uniqueId, action, errorCode, errorDescription);
  3292. #endif
  3293. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3294. LWS_Send(message);
  3295. //result = TRUE;
  3296. }
  3297. //==========================================
  3298. // Handle server request routine Start
  3299. //==========================================
  3300. #define GUN_NUM 1
  3301. int handleCancelReservationRequest(char *uuid, char *payload)
  3302. {
  3303. mtrace();
  3304. int result = FAIL;
  3305. int gunNO = 0;
  3306. int reservationIdInt =0;
  3307. char comfirmstr[20];
  3308. int c = 0;
  3309. char *loc;
  3310. char sstr[100]={0};
  3311. DEBUG_INFO("handle CancelReservationRequest\n");
  3312. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3313. c = 0;
  3314. loc = strstr(payload, "reservationId");
  3315. memset(sstr ,0, sizeof(sstr) );
  3316. while (loc[strlen("reservationId")+2+c] != '}')
  3317. {
  3318. sstr[c] = loc[strlen("reservationId")+2+c];
  3319. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3320. c++;
  3321. }
  3322. sstr[c] = '\0';
  3323. reservationIdInt = atoi(sstr);
  3324. memset(comfirmstr, 0, sizeof comfirmstr);
  3325. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3326. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3327. //check Transaction active
  3328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3329. {
  3330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3331. {
  3332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3333. {
  3334. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3335. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3336. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3337. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3338. goto end;
  3339. }
  3340. }
  3341. for (int index = 0; index < CCS_QUANTITY; index++)
  3342. {
  3343. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3344. {
  3345. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3346. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3347. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3348. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3349. goto end;
  3350. }
  3351. }
  3352. for (int index = 0; index < GB_QUANTITY; index++)
  3353. {
  3354. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3355. {
  3356. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3357. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3358. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3359. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3360. goto end;
  3361. }
  3362. }
  3363. }
  3364. else
  3365. {
  3366. for (int index = 0; index < AC_QUANTITY; index++)
  3367. {
  3368. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3369. {
  3370. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3371. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3372. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3373. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3374. goto end;
  3375. }
  3376. }
  3377. }// END FOR AC ELSE
  3378. //The reservationId does NOT match the reservationId
  3379. sendCancelReservationConfirmation(uuid, comfirmstr);
  3380. end:
  3381. // Fill in ocpp packet uuid
  3382. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3383. return result;
  3384. }
  3385. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3386. {
  3387. mtrace();
  3388. int result = FAIL;
  3389. int gunIndex = 0;
  3390. char sstr[90]={0};
  3391. char typeStr[16]={0};
  3392. char comfirmstr[20];
  3393. int specificId = FALSE;
  3394. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3395. char *loc;
  3396. //int intervalInt = 0;
  3397. int c = 0;
  3398. /*** connectorId ****/
  3399. c = 0;
  3400. loc = strstr(payload, "connectorId");
  3401. memset(sstr ,0, sizeof(sstr) );
  3402. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3403. {
  3404. sstr[c] = loc[strlen("connectorId")+2+c];
  3405. c++;
  3406. }
  3407. sstr[c] = '\0';
  3408. gunIndex = atoi(sstr);
  3409. /***type ****/
  3410. loc = strstr(payload, "type");
  3411. memset(sstr ,0, sizeof(sstr) );
  3412. c = 0;
  3413. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3414. {
  3415. sstr[c] = loc[3+strlen("type")+c];
  3416. c++;
  3417. }
  3418. sstr[c] = '\0';
  3419. strcpy(typeStr, sstr);
  3420. if(gunIndex != 0)
  3421. {
  3422. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3423. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3424. }
  3425. else
  3426. {
  3427. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3428. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3429. }
  3430. memset(comfirmstr, 0, sizeof comfirmstr);
  3431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3432. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3433. {
  3434. specificId = TRUE;
  3435. }
  3436. if(specificId == FALSE)
  3437. goto end;
  3438. if(gunIndex != 0)
  3439. {
  3440. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3441. }
  3442. else
  3443. {
  3444. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3445. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3446. }
  3447. /*
  3448. enum _SYSTEM_STATUS
  3449. {
  3450. S_BOOTING = 0,
  3451. S_IDLE, = 1
  3452. S_AUTHORIZING, =2
  3453. S_REASSIGN_CHECK, =3
  3454. S_REASSIGN, =4
  3455. S_PRECHARGE, =5
  3456. S_PREPARING_FOR_EV, =6
  3457. S_PREPARING_FOR_EVSE, =7
  3458. S_CHARGING, =8
  3459. S_TERMINATING, =9
  3460. S_COMPLETE, =10
  3461. S_ALARM, =11
  3462. S_FAULT =12
  3463. }
  3464. */
  3465. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3466. {
  3467. //check Transaction active
  3468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3469. {
  3470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3471. {
  3472. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3473. {
  3474. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3475. {
  3476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3477. }
  3478. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3479. {
  3480. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3481. }
  3482. else
  3483. {
  3484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3485. }
  3486. goto end;
  3487. }
  3488. }//END FOR CHAdeMO_QUANTITY
  3489. for (int index = 0; index < CCS_QUANTITY; index++)
  3490. {
  3491. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3492. {
  3493. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3494. {
  3495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3496. }
  3497. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3498. {
  3499. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3500. }
  3501. else
  3502. {
  3503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3504. }
  3505. goto end;
  3506. }
  3507. }//END FOR CCS_QUANTITY
  3508. for (int index = 0; index < GB_QUANTITY; index++)
  3509. {
  3510. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3511. {
  3512. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3513. {
  3514. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3515. }
  3516. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3517. {
  3518. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3519. }
  3520. else
  3521. {
  3522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3523. }
  3524. goto end;
  3525. }
  3526. }// END FOR GB_QUANTITY
  3527. }
  3528. else
  3529. {
  3530. for (int index = 0; index < AC_QUANTITY; index++)
  3531. {
  3532. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3533. {
  3534. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3535. {
  3536. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3537. }
  3538. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3539. {
  3540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3541. }
  3542. else
  3543. {
  3544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3545. }
  3546. goto end;
  3547. }
  3548. }//END FOR AC_QUANTITY
  3549. }// END FOR AC ELSE
  3550. }//END FOR AvailabilityTypeStr[Inoperative]
  3551. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3552. {
  3553. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3554. //check Transaction active
  3555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3556. {
  3557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3558. {
  3559. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3560. {
  3561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3562. goto end;
  3563. }
  3564. }//END FOR CHAdeMO_QUANTITY
  3565. for (int index = 0; index < CCS_QUANTITY; index++)
  3566. {
  3567. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3568. {
  3569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3570. goto end;
  3571. }
  3572. }//END FOR CCS_QUANTITY
  3573. for (int index = 0; index < GB_QUANTITY; index++)
  3574. {
  3575. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3576. {
  3577. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3578. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3579. goto end;
  3580. }
  3581. }// END FOR GB_QUANTITY
  3582. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3583. }
  3584. else
  3585. {
  3586. for (int index = 0; index < AC_QUANTITY; index++)
  3587. {
  3588. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3589. {
  3590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3591. goto end;
  3592. }
  3593. }//END FOR CHAdeMO_QUANTITY
  3594. }//END FOR AC ELSE
  3595. }//END FOR AvailabilityTypeStr[Operative]
  3596. end:
  3597. if(gunIndex != 0)
  3598. {
  3599. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3600. }
  3601. else
  3602. {
  3603. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3604. }
  3605. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3606. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3607. return result;
  3608. }
  3609. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3610. {
  3611. mtrace();
  3612. int result = FAIL;
  3613. char sstr[100]={0};
  3614. char keystr[40]={0};
  3615. char valuestr[16]={0};
  3616. char *loc;
  3617. int c = 0;
  3618. char comfirmstr[20];
  3619. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3620. /***key ****/
  3621. loc = strstr(payload, "key");
  3622. memset(sstr ,0, sizeof(sstr) );
  3623. c = 0;
  3624. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3625. {
  3626. sstr[c] = loc[3+strlen("key")+c];
  3627. c++;
  3628. }
  3629. sstr[c] = '\0';
  3630. strcpy(keystr, sstr);
  3631. /***value ****/
  3632. loc = strstr(payload, "value");
  3633. memset(sstr ,0, sizeof(sstr) );
  3634. c = 0;
  3635. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3636. {
  3637. sstr[c] = loc[3+strlen("value")+c];
  3638. c++;
  3639. }
  3640. sstr[c] = '\0';
  3641. strcpy(valuestr, sstr);
  3642. if((uuid==NULL) || (payload ==NULL) )
  3643. {
  3644. #ifdef Debug
  3645. DEBUG_INFO("payload is null\n");
  3646. #endif
  3647. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3648. }
  3649. else
  3650. {
  3651. int status = setKeyValue(keystr, valuestr);
  3652. switch(status)
  3653. {
  3654. case ConfigurationStatus_Accepted:
  3655. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3656. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3657. break;
  3658. case ConfigurationStatus_Rejected:
  3659. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3660. break;
  3661. case RebootRequired:
  3662. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3663. break;
  3664. case NotSupported:
  3665. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3666. break;
  3667. default:
  3668. break;
  3669. }
  3670. }
  3671. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3672. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3673. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3674. return result;
  3675. }
  3676. int handleClearCacheRequest(char *uuid, char *payload)
  3677. {
  3678. mtrace();
  3679. int result = FAIL;
  3680. char comfirmstr[20];
  3681. int fd;
  3682. char rmFileCmd[100]={0};
  3683. struct stat stats;
  3684. DEBUG_ERROR("handle ClearCacheRequest\n");
  3685. stat("../Storage/OCPP", &stats);
  3686. // Check for directory existence
  3687. if (S_ISDIR(stats.st_mode) == 1)
  3688. {
  3689. //DEBUG_ERROR("\n OCPP directory exist \n");
  3690. }
  3691. else
  3692. {
  3693. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3694. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3695. system(rmFileCmd);
  3696. }
  3697. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3698. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3699. {
  3700. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3701. }
  3702. else
  3703. {
  3704. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3705. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3706. if(log == NULL)
  3707. {
  3708. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3709. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3710. goto end;
  3711. }
  3712. else
  3713. {
  3714. fclose(log);
  3715. }
  3716. }
  3717. fd = open(AuthorizationCache_JSON,O_RDWR);
  3718. if(fd < 0)
  3719. {
  3720. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3721. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3722. }
  3723. else
  3724. {
  3725. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3726. //* 清空? 件 */
  3727. ftruncate(fd,0);
  3728. //* ? 新设置? 件? 移??*/
  3729. lseek(fd,0,SEEK_SET);
  3730. close(fd);
  3731. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3732. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3733. }
  3734. end:
  3735. sendClearCacheConfirmation(uuid, comfirmstr);
  3736. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3737. return result;
  3738. }
  3739. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3740. {
  3741. mtrace();
  3742. int result = FAIL;
  3743. int resultRename;
  3744. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3745. char chargingProfilePurposeStr[26]={0};
  3746. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3747. char tempchargingProfilePurposeStr[26]={0};
  3748. char sstr[160]={0};//sstr[200]={ 0 };
  3749. char str[100]={0};
  3750. int c = 0;
  3751. //int i = 0;
  3752. //char * pch;
  3753. char *loc;
  3754. char fname[200];
  3755. char comfirmstr[20]={0};
  3756. char word[1000]={0};
  3757. int clearflag = FALSE;
  3758. int chargingProfileIdIsNULL = FALSE;
  3759. int connectorIsNULL = FALSE;
  3760. int chargingProfilePurposeIsNULL = FALSE;
  3761. int stackLevelIsNULL = FALSE;
  3762. FILE *fptr1, *fptr2;
  3763. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3764. int n_chargingProfile=0;
  3765. char sLineWord[1060]={0};
  3766. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3767. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3768. //***id ****/
  3769. c = 0;
  3770. loc = strstr(payload, "id");
  3771. memset(sstr ,0, sizeof(sstr) );
  3772. if(loc == NULL)
  3773. {
  3774. chargingProfileIdIsNULL = TRUE;
  3775. }
  3776. else
  3777. {
  3778. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3779. {
  3780. sstr[c] = loc[strlen("id")+2+c];
  3781. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3782. c++;
  3783. }
  3784. sstr[c] = '\0';
  3785. chargingProfileIdInt = atoi(sstr);
  3786. }
  3787. //***connectorId ****/
  3788. c=0;
  3789. loc = strstr(payload, "connectorId");
  3790. memset(sstr ,0, sizeof(sstr) );
  3791. if(loc == NULL)
  3792. {
  3793. connectorIsNULL = TRUE;
  3794. }
  3795. else
  3796. {
  3797. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3798. {
  3799. sstr[c] = loc[strlen("connectorId")+2+c];
  3800. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3801. c++;
  3802. }
  3803. sstr[c] = '\0';
  3804. connectorIdInt = atoi(sstr);
  3805. }
  3806. //***chargingProfilePurpose ****/
  3807. loc = strstr(payload, "chargingProfilePurpose");
  3808. memset(sstr ,0, sizeof(sstr) );
  3809. c = 0;
  3810. if(loc == NULL)
  3811. {
  3812. chargingProfilePurposeIsNULL = TRUE;
  3813. }
  3814. else
  3815. {
  3816. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3817. {
  3818. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3819. c++;
  3820. }
  3821. sstr[c] = '\0';
  3822. strcpy(chargingProfilePurposeStr, sstr);
  3823. }
  3824. //***stackLevel ****/
  3825. c=0;
  3826. loc = strstr(payload, "stackLevel");
  3827. memset(sstr ,0, sizeof(sstr) );
  3828. if(loc == NULL)
  3829. {
  3830. stackLevelIsNULL = TRUE;
  3831. }
  3832. else
  3833. {
  3834. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3835. {
  3836. sstr[c] = loc[strlen("stackLevel")+2+c];
  3837. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3838. c++;
  3839. }
  3840. sstr[c] = '\0';
  3841. stackLevelInt = atoi(sstr);
  3842. }
  3843. if(connectorIsNULL == FALSE)
  3844. {
  3845. switch(connectorIdInt)
  3846. {
  3847. case 0:
  3848. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3849. {
  3850. strcpy(fname, ChargePointMaxProfile_JSON);
  3851. }
  3852. // else
  3853. // {
  3854. // strcpy(fname, TxDefaultProfile_0_JSON);
  3855. // }
  3856. break;
  3857. case 1:
  3858. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3859. {
  3860. strcpy(fname, TxDefaultProfile_1_JSON);
  3861. }
  3862. // else
  3863. // {
  3864. // strcpy(fname, TxProfile_1_JSON);
  3865. // }
  3866. break;
  3867. case 2:
  3868. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3869. {
  3870. strcpy(fname, TxDefaultProfile_2_JSON);
  3871. }
  3872. // else
  3873. // {
  3874. // strcpy(fname, TxProfile_2_JSON);
  3875. // }
  3876. break;
  3877. default:
  3878. strcpy(fname, ChargePointMaxProfile_JSON );
  3879. break;
  3880. }
  3881. }
  3882. else
  3883. {
  3884. strcpy(fname, ChargePointMaxProfile_JSON );
  3885. }
  3886. fptr1 = fopen(fname, "r");
  3887. if (!fptr1)
  3888. {
  3889. //file not exist
  3890. DEBUG_ERROR("Unable to open the input file!!\n");
  3891. fptr1 = fopen(fname, "w+");
  3892. }
  3893. fclose(fptr1);
  3894. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3895. {
  3896. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3897. goto end;
  3898. }
  3899. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3900. {
  3901. //clear the whole contents of a file in C
  3902. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3903. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3904. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3905. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3906. fclose(fopen(TxProfile_1_JSON, "w"));
  3907. fclose(fopen(TxProfile_2_JSON, "w"));
  3908. #if 0
  3909. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3910. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3911. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3912. #endif
  3913. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3914. }
  3915. else
  3916. {
  3917. fptr1 = fopen(fname, "r");
  3918. fptr2 = fopen(temp, "w+");
  3919. while(fscanf(fptr1, "%s", word) != EOF)
  3920. {
  3921. //DEBUG_INFO("word=%s\n",word);
  3922. if(strcmp(word, "chargingProfileId") == 0)
  3923. {
  3924. n_chargingProfile = n_chargingProfile + 1;
  3925. DEBUG_INFO("chargingProfileId Found\n");
  3926. }
  3927. }
  3928. rewind(fptr1);
  3929. //search Charging Profile Element
  3930. //int i= 0;
  3931. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3932. {
  3933. //*************************tempconnectorIdInt*********************************/
  3934. loc = strstr(sLineWord, "connectorId");
  3935. c = 0;
  3936. memset(sstr ,0, sizeof(sstr) );
  3937. while (loc[strlen("connectorId")+2+c] != ',')
  3938. {
  3939. sstr[c] = loc[strlen("connectorId")+2+c];
  3940. c++;
  3941. }
  3942. sstr[c] = '\0';
  3943. tempconnectorIdInt = atoi(sstr);
  3944. //chargingProfileId
  3945. c = 0;
  3946. loc = strstr(sLineWord, "chargingProfileId");
  3947. memset(sstr ,0, sizeof(sstr) );
  3948. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3949. {
  3950. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3951. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3952. c++;
  3953. }
  3954. sstr[c] = '\0';
  3955. tempchargingProfileIdInt = atoi(sstr);
  3956. //stackLevel
  3957. c = 0;
  3958. loc = strstr(sLineWord, "stackLevel");
  3959. memset(sstr ,0, sizeof(sstr) );
  3960. while (loc[strlen("stackLevel")+2+c] != ',')
  3961. {
  3962. sstr[c] = loc[strlen("stackLevel")+2+c];
  3963. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3964. c++;
  3965. }
  3966. sstr[c] = '\0';
  3967. tempstackLevelInt = atoi(sstr);
  3968. c = 0;
  3969. loc = strstr(sLineWord, "chargingProfilePurpose");
  3970. memset(sstr ,0, sizeof(sstr) );
  3971. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3972. {
  3973. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3974. c++;
  3975. }
  3976. sstr[c] = '\0';
  3977. strcpy(tempchargingProfilePurposeStr, sstr);
  3978. if(chargingProfileIdIsNULL == FALSE)
  3979. {
  3980. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3981. {
  3982. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3983. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3984. clearflag = TRUE;
  3985. continue;
  3986. }
  3987. else
  3988. {
  3989. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3990. //json_object_array_add(newHeatMap, jsonitem);
  3991. fprintf(fptr2, sLineWord);//writing data into file
  3992. }
  3993. }
  3994. else
  3995. {
  3996. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3997. {
  3998. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3999. {
  4000. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4001. clearflag = TRUE;
  4002. continue;
  4003. }
  4004. }
  4005. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4006. {
  4007. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  4008. {
  4009. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  4010. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  4011. {
  4012. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4013. clearflag = TRUE;
  4014. continue;
  4015. }
  4016. }
  4017. }
  4018. else
  4019. {
  4020. //json_object_array_add(newHeatMap, jsonitem);
  4021. fprintf(fptr2, sLineWord);//writing data into file
  4022. }
  4023. }
  4024. memset(sLineWord, 0, sizeof sLineWord);
  4025. }
  4026. if(clearflag == FALSE)
  4027. {
  4028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4029. goto end;
  4030. }
  4031. fclose(fptr1);
  4032. fclose(fptr2);
  4033. sprintf(str,"rm -f %s",fname);
  4034. system(str);
  4035. resultRename = rename(temp, fname);
  4036. if(resultRename == 0)
  4037. {
  4038. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4039. }
  4040. else
  4041. {
  4042. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4043. }
  4044. }
  4045. end:
  4046. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4047. return result;
  4048. }
  4049. int handleDataTransferRequest(char *uuid, char *payload)
  4050. {
  4051. mtrace();
  4052. int result = FAIL;
  4053. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4054. char tempvendorId[255]={0};
  4055. char tempmessageId[50]={0};
  4056. char tempdata[50]={0};
  4057. char sstr[160]={0};//sstr[200]={ 0 };
  4058. char message[80]={0};
  4059. int c = 0;
  4060. char *loc;
  4061. DEBUG_INFO("handle DataTransferRequest\n");
  4062. if((uuid != NULL) && (payload != NULL))
  4063. {
  4064. //===============================
  4065. // vendorId
  4066. //===============================
  4067. c = 0;
  4068. loc = strstr(payload, "vendorId");
  4069. while (loc[strlen("vendorId")+3+c] != '\"')
  4070. {
  4071. sstr[c] = loc[strlen("vendorId")+3+c];
  4072. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4073. c++;
  4074. }
  4075. sstr[c] = '\0';
  4076. strcpy(tempvendorId,sstr);
  4077. //===============================
  4078. // messageId
  4079. //===============================
  4080. memset(sstr ,0, sizeof(sstr) );
  4081. c = 0;
  4082. loc = strstr(payload, "messageId");
  4083. while (loc[strlen("messageId")+3+c] != '\"')
  4084. {
  4085. sstr[c] = loc[strlen("messageId")+3+c];
  4086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4087. c++;
  4088. }
  4089. sstr[c] = '\0';
  4090. strcpy(tempmessageId,sstr);
  4091. //===============================
  4092. // data
  4093. //===============================
  4094. memset(sstr ,0, sizeof(sstr) );
  4095. c = 0;
  4096. loc = strstr(payload, "data");
  4097. printf("loc=%s\n",loc);
  4098. while (loc[strlen("data")+3+c] != '\"')
  4099. {
  4100. sstr[c] = loc[strlen("data")+3+c];
  4101. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4102. c++;
  4103. }
  4104. sstr[c] = '\0';
  4105. strcpy(tempdata,sstr);
  4106. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4107. }
  4108. else
  4109. {
  4110. char guid[37]={0};
  4111. random_uuid(guid);
  4112. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4113. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4114. }
  4115. LWS_Send(message);
  4116. return result;
  4117. }
  4118. #if 0
  4119. long long diff_tm(struct tm *a, struct tm *b) {
  4120. return a->tm_sec - b->tm_sec
  4121. + 60LL * (a->tm_min - b->tm_min)
  4122. + 3600LL * (a->tm_hour - b->tm_hour)
  4123. + 86400LL * (a->tm_yday - b->tm_yday)
  4124. + (a->tm_year - 70) * 31536000LL
  4125. - (a->tm_year - 69) / 4 * 86400LL
  4126. + (a->tm_year - 1) / 100 * 86400LL
  4127. - (a->tm_year + 299) / 400 * 86400LL
  4128. - (b->tm_year - 70) * 31536000LL
  4129. + (b->tm_year - 69) / 4 * 86400LL
  4130. - (b->tm_year - 1) / 100 * 86400LL
  4131. + (b->tm_year + 299) /400 * 86400LL;
  4132. }
  4133. #endif
  4134. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4135. {
  4136. mtrace();
  4137. int result = FAIL;
  4138. int connectorIdInt, durationInt;
  4139. char chargingRateUnitStr[4]={0};
  4140. //int tempconnectorIdInt,
  4141. int tempdurationInt;
  4142. float tempminChargingRateFloat = 0.0;
  4143. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4144. int tempStartPeriodInt=0;
  4145. float tempLimitInt=0.0;//0.1;
  4146. int tempNumberPhasesInt=0;
  4147. char fname[200];
  4148. char comfirmstr[20];
  4149. //float totallimit =0.0;
  4150. float MinChargingRate =0.0;
  4151. double diff_t;
  4152. struct tm tp;
  4153. //int clearflag = FALSE;
  4154. FILE *fptr1;//, *fptr2;
  4155. //char temp[] = "../Storage/OCPP/temp.json";
  4156. int c = 0;
  4157. //int i = 0;
  4158. char * pch;
  4159. char *loc;
  4160. char sstr[200]={ 0 };
  4161. int n_chargingProfile = 0;
  4162. int n_SchedulePeriods = 0;
  4163. char SchedulePeriodList[10][200]={0};
  4164. char sLineWord[800]={0};
  4165. //int n_periods = 0;
  4166. char word[1000]={0};
  4167. int confirmPeriods = 0;
  4168. struct StructProfile ChargePointMaxProfile;
  4169. struct StructProfile TxDefaultProfile;
  4170. struct StructProfile TxProfile;
  4171. struct StructProfile TxDefaultProfiletemp[2]={0};
  4172. int TxDefaultProfileFileIsNull=FALSE;
  4173. int ChargePointMaxProfileIsNull=FALSE;
  4174. int TxProfileIsNull=FALSE;
  4175. int CompositeSceduleIndex = 0;
  4176. char ChargePointMaxProfileScheduleStr[30]={0};
  4177. char TxDefaultProfileScheduleStr[30]={0};
  4178. char TxProfileScheduleStr[30]={0};
  4179. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4180. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4181. memset(&TxProfile,0,sizeof(struct StructProfile));
  4182. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4183. c=0;
  4184. loc = strstr(payload, "connectorId");
  4185. memset(sstr ,0, sizeof(sstr) );
  4186. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4187. {
  4188. sstr[c] = loc[strlen("connectorId")+2+c];
  4189. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4190. c++;
  4191. }
  4192. sstr[c] = '\0';
  4193. connectorIdInt = atoi(sstr);
  4194. c=0;
  4195. loc = strstr(payload, "duration");
  4196. memset(sstr ,0, sizeof(sstr) );
  4197. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4198. {
  4199. sstr[c] = loc[strlen("duration")+2+c];
  4200. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4201. c++;
  4202. }
  4203. sstr[c] = '\0';
  4204. durationInt = atoi(sstr);
  4205. c = 0;
  4206. loc = strstr(payload, "chargingRateUnit");
  4207. memset(sstr ,0, sizeof(sstr) );
  4208. if(loc == NULL)
  4209. {
  4210. }
  4211. else
  4212. {
  4213. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4214. {
  4215. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4216. c++;
  4217. }
  4218. sstr[c] = '\0';
  4219. strcpy(chargingRateUnitStr, sstr);
  4220. }
  4221. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4222. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4223. if(connectorIdInt==0) // connectorId is 0
  4224. {
  4225. //******************************ChargePointMaxProfile*****************************************************/
  4226. strcpy(fname, ChargePointMaxProfile_JSON );
  4227. char word[30]={0};
  4228. char sLineWord[1060]={0};
  4229. int n_chargingProfile=0;
  4230. ChargePointMaxProfileIsNull=TRUE;
  4231. if((access(fname,F_OK))!=-1)
  4232. {
  4233. fptr1 = fopen(fname, "r");
  4234. int c;
  4235. c = fgetc(fptr1);
  4236. //DEBUG_INFO("c:%d\n",c);
  4237. rewind(fptr1);
  4238. if(c == EOF)
  4239. {
  4240. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4241. ChargePointMaxProfileIsNull=TRUE;
  4242. fclose(fptr1);
  4243. }
  4244. else
  4245. {
  4246. ChargePointMaxProfileIsNull=FALSE;
  4247. while(fscanf(fptr1, "%s", word) != EOF)
  4248. {
  4249. if(strcmp(word, "chargingProfileId") == 0)
  4250. {
  4251. n_chargingProfile = n_chargingProfile + 1;
  4252. printf("Found\n");
  4253. }
  4254. }
  4255. rewind(fptr1);
  4256. //search Charging Profile Element
  4257. int i= 0;
  4258. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4259. #if 0
  4260. /***********connectorId****************/
  4261. c = 0;
  4262. loc = strstr(sLineWord, "connectorId");
  4263. // printf("loc=%s\n",loc);
  4264. memset(sstr ,0, sizeof(sstr) );
  4265. while (loc[strlen("connectorId")+2+c] != ',')
  4266. {
  4267. sstr[c] = loc[strlen("connectorId")+2+c];
  4268. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4269. c++;
  4270. }
  4271. sstr[c] = '\0';
  4272. tempconnectorIdInt = atoi(sstr);
  4273. #endif
  4274. //***********validFrom**************/
  4275. c = 0;
  4276. loc = strstr(sLineWord, "validFrom");
  4277. //DEBUG_INFO("loc=%s\n",loc);
  4278. memset(sstr ,0, sizeof(sstr) );
  4279. if(loc != NULL)
  4280. {
  4281. while (loc[3+strlen("validFrom")+c] != '\"')
  4282. {
  4283. sstr[c] = loc[3+strlen("validFrom")+c];
  4284. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4285. c++;
  4286. }
  4287. sstr[c] = '\0';
  4288. DEBUG_INFO("validFrom=%s\n",sstr);
  4289. strcpy(tempvalidFromStr,sstr);
  4290. }
  4291. else
  4292. {
  4293. strcpy(tempvalidFromStr,"");
  4294. }
  4295. //**********startSchedule**********/
  4296. c = 0;
  4297. loc = strstr(sLineWord, "startSchedule");
  4298. //DEBUG_INFO("loc=%s\n",loc);
  4299. memset(sstr ,0, sizeof(sstr) );
  4300. while (loc[3+strlen("startSchedule")+c] != '\"')
  4301. {
  4302. sstr[c] = loc[3+strlen("startSchedule")+c];
  4303. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4304. c++;
  4305. }
  4306. sstr[c] = '\0';
  4307. strcpy(tempstartScheduleStr, sstr);
  4308. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4309. //**********chargingRateUnit**********/
  4310. c = 0;
  4311. loc = strstr(sLineWord, "chargingRateUnit");
  4312. memset(sstr ,0, sizeof(sstr) );
  4313. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4314. {
  4315. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4316. c++;
  4317. }
  4318. sstr[c] = '\0';
  4319. strcpy(tempchargingRateUnitStr, sstr);
  4320. //**********minChargingRate*******/
  4321. c = 0;
  4322. loc = strstr(sLineWord, "minChargingRate");
  4323. //printf("loc=%s\n",loc);
  4324. if(loc != NULL)
  4325. {
  4326. memset(sstr ,0, sizeof(sstr) );
  4327. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4328. {
  4329. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4330. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4331. c++;
  4332. }
  4333. sstr[c] = '\0';
  4334. tempminChargingRateFloat = atof(sstr);
  4335. }
  4336. else
  4337. {
  4338. tempminChargingRateFloat = 0.0;
  4339. }
  4340. //
  4341. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4342. tp.tm_isdst = -1;
  4343. time_t utc = mktime(&tp);
  4344. // current time
  4345. time_t t = time(NULL);
  4346. diff_t = difftime(t, utc);
  4347. //parsing strings to words
  4348. i = 0;
  4349. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4350. loc = loc+3+strlen("chargingSchedulePeriod");
  4351. pch = strtok(loc ,"{");
  4352. while (pch != NULL)
  4353. {
  4354. strcpy(SchedulePeriodList[i], pch);
  4355. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4356. //printf ("%s\n",pch);
  4357. pch = strtok (NULL, "{");
  4358. i = i + 1;
  4359. }
  4360. n_SchedulePeriods = i;
  4361. for(int i=0;i<n_SchedulePeriods;i++)
  4362. {
  4363. //*************startPeriod****************/
  4364. c = 0;
  4365. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4366. memset(sstr ,0, sizeof(sstr) );
  4367. while (loc[strlen("startPeriod")+2+c] != ',')
  4368. {
  4369. sstr[c] = loc[strlen("startPeriod")+2+c];
  4370. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4371. c++;
  4372. }
  4373. sstr[c] = '\0';
  4374. tempStartPeriodInt = atoi(sstr);
  4375. //*************limit****************/
  4376. c = 0;
  4377. loc = strstr(SchedulePeriodList[i], "limit");
  4378. memset(sstr ,0, sizeof(sstr) );
  4379. while (loc[strlen("limit")+2+c] != ',')
  4380. {
  4381. sstr[c] = loc[strlen("limit")+2+c];
  4382. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4383. c++;
  4384. }
  4385. sstr[c] = '\0';
  4386. tempLimitInt = atof(sstr);
  4387. //*************numberPhases****************/
  4388. c = 0;
  4389. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4390. memset(sstr ,0, sizeof(sstr) );
  4391. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4392. {
  4393. sstr[c] = loc[strlen("numberPhases")+2+c];
  4394. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4395. c++;
  4396. }
  4397. sstr[c] = '\0';
  4398. tempNumberPhasesInt = atoi(sstr);
  4399. ChargePointMaxProfile.Duration = durationInt;
  4400. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4401. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4402. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4403. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4404. }
  4405. if(MinChargingRate < tempminChargingRateFloat)
  4406. MinChargingRate = tempminChargingRateFloat;
  4407. }
  4408. }// End of file ChargingProfile
  4409. } //THE END OF ACCESS ChargePointMaxProfile
  4410. //******************************TxDefaultProfile***********************************************/
  4411. strcpy(fname, TxDefaultProfile_0_JSON);
  4412. memset(word, 0, 30);
  4413. memset(sLineWord, 0, 1060);
  4414. //char word[30]={0};
  4415. //char sLineWord[1060]={0};
  4416. n_chargingProfile=0;
  4417. TxDefaultProfileFileIsNull=TRUE;
  4418. if((access(fname,F_OK))!=-1)
  4419. {
  4420. fptr1 = fopen(fname, "r");
  4421. c = 0;
  4422. c = fgetc(fptr1);
  4423. //DEBUG_INFO("c:%d\n",c);
  4424. rewind(fptr1);
  4425. if(c == EOF)
  4426. {
  4427. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4428. TxDefaultProfileFileIsNull=TRUE;
  4429. fclose(fptr1);
  4430. }
  4431. else
  4432. {
  4433. TxDefaultProfileFileIsNull=FALSE;
  4434. while(fscanf(fptr1, "%s", word) != EOF)
  4435. {
  4436. if(strcmp(word, "chargingProfileId") == 0)
  4437. {
  4438. n_chargingProfile = n_chargingProfile + 1;
  4439. printf("Found\n");
  4440. }
  4441. }
  4442. rewind(fptr1);
  4443. //search Charging Profile Element
  4444. int i= 0;
  4445. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4446. #if 0
  4447. /***********connectorId****************/
  4448. c = 0;
  4449. loc = strstr(sLineWord, "connectorId");
  4450. // printf("loc=%s\n",loc);
  4451. memset(sstr ,0, sizeof(sstr) );
  4452. while (loc[strlen("connectorId")+2+c] != ',')
  4453. {
  4454. sstr[c] = loc[strlen("connectorId")+2+c];
  4455. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4456. c++;
  4457. }
  4458. sstr[c] = '\0';
  4459. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4460. tempconnectorIdInt = atoi(sstr);
  4461. #endif
  4462. //***********validFrom**************/
  4463. c = 0;
  4464. loc = strstr(sLineWord, "validFrom");
  4465. //DEBUG_INFO("loc=%s\n",loc);
  4466. memset(sstr ,0, sizeof(sstr) );
  4467. if(loc != NULL)
  4468. {
  4469. while (loc[3+strlen("validFrom")+c] != '\"')
  4470. {
  4471. sstr[c] = loc[3+strlen("validFrom")+c];
  4472. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4473. c++;
  4474. }
  4475. sstr[c] = '\0';
  4476. DEBUG_INFO("validFrom=%s\n",sstr);
  4477. strcpy(tempvalidFromStr,sstr);
  4478. }
  4479. else
  4480. {
  4481. strcpy(tempvalidFromStr,"");
  4482. }
  4483. //**********startSchedule**********/
  4484. c = 0;
  4485. loc = strstr(sLineWord, "startSchedule");
  4486. //DEBUG_INFO("loc=%s\n",loc);
  4487. memset(sstr ,0, sizeof(sstr) );
  4488. while (loc[3+strlen("startSchedule")+c] != '\"')
  4489. {
  4490. sstr[c] = loc[3+strlen("startSchedule")+c];
  4491. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4492. c++;
  4493. }
  4494. sstr[c] = '\0';
  4495. strcpy(tempstartScheduleStr, sstr);
  4496. strcpy(TxDefaultProfileScheduleStr, sstr);
  4497. DEBUG_INFO(" debug 3-1\n");
  4498. //**********chargingRateUnit**********/
  4499. c = 0;
  4500. loc = strstr(sLineWord, "chargingRateUnit");
  4501. memset(sstr ,0, sizeof(sstr) );
  4502. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4503. {
  4504. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4505. c++;
  4506. }
  4507. sstr[c] = '\0';
  4508. strcpy(tempchargingRateUnitStr, sstr);
  4509. //**********minChargingRate*******/
  4510. c = 0;
  4511. loc = strstr(sLineWord, "minChargingRate");
  4512. //printf("loc=%s\n",loc);
  4513. if(loc != NULL)
  4514. {
  4515. memset(sstr ,0, sizeof(sstr) );
  4516. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4517. {
  4518. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4520. c++;
  4521. }
  4522. sstr[c] = '\0';
  4523. tempminChargingRateFloat = atof(sstr);
  4524. }
  4525. else
  4526. {
  4527. tempminChargingRateFloat = 0.0;
  4528. }
  4529. //
  4530. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4531. tp.tm_isdst = -1;
  4532. time_t utc = mktime(&tp);
  4533. // current time
  4534. time_t t = time(NULL);
  4535. diff_t = difftime(t, utc);
  4536. //parsing strings to words
  4537. i = 0;
  4538. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4539. loc = loc+3+strlen("chargingSchedulePeriod");
  4540. pch = strtok(loc ,"{");
  4541. while (pch != NULL)
  4542. {
  4543. strcpy(SchedulePeriodList[i], pch);
  4544. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4545. //printf ("%s\n",pch);
  4546. pch = strtok (NULL, "{");
  4547. i = i + 1;
  4548. }
  4549. n_SchedulePeriods = i;
  4550. for(int i=0;i<n_SchedulePeriods;i++)
  4551. {
  4552. //*************startPeriod****************/
  4553. c = 0;
  4554. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4555. memset(sstr ,0, sizeof(sstr) );
  4556. while (loc[strlen("startPeriod")+2+c] != ',')
  4557. {
  4558. sstr[c] = loc[strlen("startPeriod")+2+c];
  4559. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4560. c++;
  4561. }
  4562. sstr[c] = '\0';
  4563. tempStartPeriodInt = atoi(sstr);
  4564. //*************limit****************/
  4565. c = 0;
  4566. loc = strstr(SchedulePeriodList[i], "limit");
  4567. memset(sstr ,0, sizeof(sstr) );
  4568. while (loc[strlen("limit")+2+c] != ',')
  4569. {
  4570. sstr[c] = loc[strlen("limit")+2+c];
  4571. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4572. c++;
  4573. }
  4574. sstr[c] = '\0';
  4575. tempLimitInt = atof(sstr);
  4576. //*************numberPhases****************/
  4577. c = 0;
  4578. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4579. memset(sstr ,0, sizeof(sstr) );
  4580. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4581. {
  4582. sstr[c] = loc[strlen("numberPhases")+2+c];
  4583. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4584. c++;
  4585. }
  4586. sstr[c] = '\0';
  4587. tempNumberPhasesInt = atoi(sstr);
  4588. TxDefaultProfile.Duration = durationInt;
  4589. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4590. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4591. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4592. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4593. }
  4594. if(MinChargingRate < tempminChargingRateFloat)
  4595. MinChargingRate = tempminChargingRateFloat;
  4596. }
  4597. }
  4598. }// the end of ACCESS TxDefaultProfile
  4599. // Composite Schedule
  4600. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4601. {
  4602. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4603. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4604. {
  4605. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4606. {
  4607. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4608. }
  4609. else
  4610. {
  4611. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4612. }
  4613. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4614. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4615. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4616. }
  4617. }
  4618. //* Define temporary variables */
  4619. struct tm *gtime;
  4620. time_t now;
  4621. char buf[28];
  4622. /* Read the current system time */
  4623. time(&now);
  4624. /* Convert the system time to GMT (now UTC) */
  4625. gtime = gmtime(&now);
  4626. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4627. // make .conf
  4628. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4629. //MaxChargingProfilesInstalled is 10
  4630. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4631. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4632. //nPeriod = 1;
  4633. if(chargingRateUnitStr[0] != 0)
  4634. {
  4635. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4636. }
  4637. else
  4638. {
  4639. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4640. }
  4641. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4642. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4643. confirmPeriods = 1;
  4644. }
  4645. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4646. {
  4647. //*****************************ChargePointMaxProfile******************************************/
  4648. strcpy(fname, ChargePointMaxProfile_JSON);
  4649. ChargePointMaxProfileIsNull=TRUE;
  4650. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4651. {
  4652. fptr1 = fopen(fname, "r");
  4653. int c;
  4654. c = fgetc(fptr1);
  4655. //DEBUG_INFO("c:%d\n",c);
  4656. rewind(fptr1);
  4657. if(c == EOF)
  4658. {
  4659. DEBUG_INFO("\n End of file reached.");
  4660. ChargePointMaxProfileIsNull=TRUE;
  4661. fclose(fptr1);
  4662. }
  4663. else
  4664. {
  4665. ChargePointMaxProfileIsNull=FALSE;
  4666. while(fscanf(fptr1, "%s", word) != EOF)
  4667. {
  4668. if(strcmp(word, "chargingProfileId") == 0)
  4669. {
  4670. n_chargingProfile = n_chargingProfile + 1;
  4671. }
  4672. }
  4673. rewind(fptr1);
  4674. //search Charging Profile Element
  4675. int i = 0;
  4676. int j = 0;
  4677. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4678. #if 0
  4679. /***********connectorId****************/
  4680. c = 0;
  4681. loc = strstr(sLineWord, "connectorId");
  4682. memset(sstr ,0, sizeof(sstr) );
  4683. while (loc[strlen("connectorId")+2+c] != ',')
  4684. {
  4685. sstr[c] = loc[strlen("connectorId")+2+c];
  4686. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4687. c++;
  4688. }
  4689. sstr[c] = '\0';
  4690. tempconnectorIdInt = atoi(sstr);
  4691. #endif
  4692. //***********validFrom**************/
  4693. c = 0;
  4694. loc = strstr(sLineWord, "validFrom");
  4695. if(loc != NULL)
  4696. {
  4697. memset(sstr ,0, sizeof(sstr) );
  4698. while (loc[3+strlen("validFrom")+c] != '\"')
  4699. {
  4700. sstr[c] = loc[3+strlen("validFrom")+c];
  4701. c++;
  4702. }
  4703. sstr[c] = '\0';
  4704. strcpy(tempvalidFromStr,sstr);
  4705. }
  4706. else
  4707. {
  4708. strcpy(tempvalidFromStr,"");
  4709. }
  4710. //***********validFrom**************/
  4711. c = 0;
  4712. loc = strstr(sLineWord, "duration");
  4713. if(loc != NULL)
  4714. {
  4715. memset(sstr ,0, sizeof(sstr) );
  4716. while (loc[2+strlen("duration")+c] != ',')
  4717. {
  4718. sstr[c] = loc[2+strlen("duration")+c];
  4719. c++;
  4720. }
  4721. sstr[c] = '\0';
  4722. tempdurationInt = atoi(sstr);
  4723. }
  4724. else
  4725. {
  4726. tempdurationInt = 0;
  4727. }
  4728. //**********startSchedule**********/
  4729. c = 0;
  4730. loc = strstr(sLineWord, "startSchedule");
  4731. memset(sstr ,0, sizeof(sstr) );
  4732. while (loc[3+strlen("startSchedule")+c] != '\"')
  4733. {
  4734. sstr[c] = loc[3+strlen("startSchedule")+c];
  4735. c++;
  4736. }
  4737. sstr[c] = '\0';
  4738. strcpy(tempstartScheduleStr, sstr);
  4739. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4740. //**********chargingRateUnit**********/
  4741. c = 0;
  4742. loc = strstr(sLineWord, "chargingRateUnit");
  4743. memset(sstr ,0, sizeof(sstr) );
  4744. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4745. {
  4746. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4747. c++;
  4748. }
  4749. sstr[c] = '\0';
  4750. strcpy(tempchargingRateUnitStr, sstr);
  4751. //**********minChargingRate*******/
  4752. c = 0;
  4753. loc = strstr(sLineWord, "minChargingRate");
  4754. if(loc != NULL)
  4755. {
  4756. memset(sstr ,0, sizeof(sstr) );
  4757. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4758. {
  4759. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4760. c++;
  4761. }
  4762. sstr[c] = '\0';
  4763. tempminChargingRateFloat = atof(sstr);
  4764. }
  4765. else
  4766. {
  4767. tempminChargingRateFloat = 0.0;
  4768. }
  4769. //
  4770. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4771. tp.tm_isdst = -1;
  4772. time_t utc = mktime(&tp);
  4773. time_t t = time(NULL);
  4774. diff_t = difftime(t, utc);
  4775. DEBUG_INFO("diff_t=%f\n",diff_t);
  4776. DEBUG_INFO(" debug 5 -1\n");
  4777. //parsing strings to words
  4778. i = 0;
  4779. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4780. loc = loc+3+strlen("chargingSchedulePeriod");
  4781. pch = strtok(loc ,"{");
  4782. while (pch != NULL)
  4783. {
  4784. strcpy(SchedulePeriodList[i], pch);
  4785. pch = strtok (NULL, "{");
  4786. i = i + 1;
  4787. }
  4788. n_SchedulePeriods = i;
  4789. for(int i=0;i<n_SchedulePeriods;i++)
  4790. {
  4791. //*************startPeriod****************/
  4792. c = 0;
  4793. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4794. memset(sstr ,0, sizeof(sstr) );
  4795. while (loc[strlen("startPeriod")+2+c] != ',')
  4796. {
  4797. sstr[c] = loc[strlen("startPeriod")+2+c];
  4798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4799. c++;
  4800. }
  4801. sstr[c] = '\0';
  4802. tempStartPeriodInt = atoi(sstr);
  4803. //*************limit****************/
  4804. c = 0;
  4805. loc = strstr(SchedulePeriodList[i], "limit");
  4806. memset(sstr ,0, sizeof(sstr) );
  4807. while (loc[strlen("limit")+2+c] != ',')
  4808. {
  4809. sstr[c] = loc[strlen("limit")+2+c];
  4810. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4811. c++;
  4812. }
  4813. sstr[c] = '\0';
  4814. tempLimitInt = atof(sstr);
  4815. //*************numberPhases****************/
  4816. c = 0;
  4817. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4818. memset(sstr ,0, sizeof(sstr) );
  4819. while (loc[strlen("numberPhases")+2+c] != '}')
  4820. {
  4821. sstr[c] = loc[strlen("numberPhases")+2+c];
  4822. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4823. c++;
  4824. }
  4825. sstr[c] = '\0';
  4826. tempNumberPhasesInt = atoi(sstr);
  4827. if(j == 0)
  4828. {
  4829. ChargePointMaxProfile.Duration = tempdurationInt;
  4830. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4831. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4832. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4833. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4834. }
  4835. }
  4836. if(MinChargingRate < tempminChargingRateFloat)
  4837. {
  4838. MinChargingRate = tempminChargingRateFloat;
  4839. }
  4840. if(confirmPeriods < n_SchedulePeriods)
  4841. {
  4842. confirmPeriods = n_SchedulePeriods;
  4843. }
  4844. j = j + 1;
  4845. }
  4846. fclose(fptr1);
  4847. }
  4848. }// the end of access file ChargePointMaxProfile
  4849. //****************************TxDefaultProfile************************************************/
  4850. switch(connectorIdInt)
  4851. {
  4852. case 0:
  4853. break;
  4854. case 1:
  4855. strcpy(fname, TxDefaultProfile_1_JSON );
  4856. break;
  4857. case 2:
  4858. strcpy(fname, TxDefaultProfile_2_JSON );
  4859. break;
  4860. default:
  4861. strcpy(fname, TxDefaultProfile_1_JSON );
  4862. break;
  4863. }
  4864. TxDefaultProfileFileIsNull=TRUE;
  4865. if((access(fname,F_OK))!=-1)
  4866. {
  4867. fptr1 = fopen(fname, "r");
  4868. c = 0;
  4869. c = fgetc(fptr1);
  4870. //DEBUG_INFO("c:%d\n",c);
  4871. rewind(fptr1);
  4872. if(c == EOF)
  4873. {
  4874. DEBUG_INFO("\n End of file reached.");
  4875. TxDefaultProfileFileIsNull=TRUE;
  4876. fclose(fptr1);
  4877. }
  4878. else
  4879. {
  4880. TxDefaultProfileFileIsNull=FALSE;
  4881. while(fscanf(fptr1, "%s", word) != EOF)
  4882. {
  4883. if(strcmp(word, "chargingProfileId") == 0)
  4884. {
  4885. n_chargingProfile = n_chargingProfile + 1;
  4886. }
  4887. }
  4888. rewind(fptr1);
  4889. //search Charging Profile Element
  4890. int i = 0;
  4891. int j = 0;
  4892. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4893. #if 0
  4894. /***********connectorId****************/
  4895. c = 0;
  4896. loc = strstr(sLineWord, "connectorId");
  4897. memset(sstr ,0, sizeof(sstr) );
  4898. while (loc[strlen("connectorId")+2+c] != ',')
  4899. {
  4900. sstr[c] = loc[strlen("connectorId")+2+c];
  4901. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4902. c++;
  4903. }
  4904. sstr[c] = '\0';
  4905. tempconnectorIdInt = atoi(sstr);
  4906. #endif
  4907. //***********validFrom**************/
  4908. c = 0;
  4909. loc = strstr(sLineWord, "validFrom");
  4910. if(loc != NULL)
  4911. {
  4912. memset(sstr ,0, sizeof(sstr) );
  4913. while (loc[3+strlen("validFrom")+c] != '\"')
  4914. {
  4915. sstr[c] = loc[3+strlen("validFrom")+c];
  4916. c++;
  4917. }
  4918. sstr[c] = '\0';
  4919. strcpy(tempvalidFromStr,sstr);
  4920. }
  4921. else
  4922. {
  4923. strcpy(tempvalidFromStr,"");
  4924. }
  4925. //***********validFrom**************/
  4926. c = 0;
  4927. loc = strstr(sLineWord, "duration");
  4928. if(loc != NULL)
  4929. {
  4930. memset(sstr ,0, sizeof(sstr) );
  4931. while (loc[2+strlen("duration")+c] != ',')
  4932. {
  4933. sstr[c] = loc[2+strlen("duration")+c];
  4934. c++;
  4935. }
  4936. sstr[c] = '\0';
  4937. tempdurationInt = atoi(sstr);
  4938. }
  4939. else
  4940. {
  4941. tempdurationInt = 0;
  4942. }
  4943. //**********startSchedule**********/
  4944. c = 0;
  4945. loc = strstr(sLineWord, "startSchedule");
  4946. memset(sstr ,0, sizeof(sstr) );
  4947. while (loc[3+strlen("startSchedule")+c] != '\"')
  4948. {
  4949. sstr[c] = loc[3+strlen("startSchedule")+c];
  4950. c++;
  4951. }
  4952. sstr[c] = '\0';
  4953. strcpy(tempstartScheduleStr, sstr);
  4954. strcpy(TxDefaultProfileScheduleStr, sstr);
  4955. //**********chargingRateUnit**********/
  4956. c = 0;
  4957. loc = strstr(sLineWord, "chargingRateUnit");
  4958. memset(sstr ,0, sizeof(sstr) );
  4959. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4960. {
  4961. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4962. c++;
  4963. }
  4964. sstr[c] = '\0';
  4965. strcpy(tempchargingRateUnitStr, sstr);
  4966. //**********minChargingRate*******/
  4967. c = 0;
  4968. loc = strstr(sLineWord, "minChargingRate");
  4969. if(loc != NULL)
  4970. {
  4971. memset(sstr ,0, sizeof(sstr) );
  4972. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4973. {
  4974. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4975. c++;
  4976. }
  4977. sstr[c] = '\0';
  4978. tempminChargingRateFloat = atof(sstr);
  4979. }
  4980. else
  4981. {
  4982. tempminChargingRateFloat = 0.0;
  4983. }
  4984. //
  4985. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4986. tp.tm_isdst = -1;
  4987. time_t utc = mktime(&tp);
  4988. time_t t = time(NULL);
  4989. diff_t = difftime(t, utc);
  4990. DEBUG_INFO("diff_t=%f\n",diff_t);
  4991. //parsing strings to words
  4992. i = 0;
  4993. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4994. loc = loc+3+strlen("chargingSchedulePeriod");
  4995. pch = strtok(loc ,"{");
  4996. while (pch != NULL)
  4997. {
  4998. strcpy(SchedulePeriodList[i], pch);
  4999. pch = strtok (NULL, "{");
  5000. i = i + 1;
  5001. }
  5002. n_SchedulePeriods = i;
  5003. for(int i=0;i<n_SchedulePeriods;i++)
  5004. {
  5005. //*************startPeriod****************/
  5006. c = 0;
  5007. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5008. memset(sstr ,0, sizeof(sstr) );
  5009. while (loc[strlen("startPeriod")+2+c] != ',')
  5010. {
  5011. sstr[c] = loc[strlen("startPeriod")+2+c];
  5012. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5013. c++;
  5014. }
  5015. sstr[c] = '\0';
  5016. tempStartPeriodInt = atoi(sstr);
  5017. //*************limit****************/
  5018. c = 0;
  5019. loc = strstr(SchedulePeriodList[i], "limit");
  5020. memset(sstr ,0, sizeof(sstr) );
  5021. while (loc[strlen("limit")+2+c] != ',')
  5022. {
  5023. sstr[c] = loc[strlen("limit")+2+c];
  5024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5025. c++;
  5026. }
  5027. sstr[c] = '\0';
  5028. tempLimitInt = atof(sstr);
  5029. //*************numberPhases****************/
  5030. c = 0;
  5031. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5032. memset(sstr ,0, sizeof(sstr) );
  5033. while (loc[strlen("numberPhases")+2+c] != '}')
  5034. {
  5035. sstr[c] = loc[strlen("numberPhases")+2+c];
  5036. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5037. c++;
  5038. }
  5039. sstr[c] = '\0';
  5040. tempNumberPhasesInt = atoi(sstr);
  5041. if(j == 0)
  5042. {
  5043. TxDefaultProfile.Duration = tempdurationInt;
  5044. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5045. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5046. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5047. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5048. }
  5049. else
  5050. {
  5051. //other stack level charging Profile
  5052. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5053. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5054. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5055. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5056. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5057. }
  5058. }
  5059. if(MinChargingRate < tempminChargingRateFloat)
  5060. MinChargingRate = tempminChargingRateFloat;
  5061. if(confirmPeriods < n_SchedulePeriods)
  5062. confirmPeriods = n_SchedulePeriods;
  5063. j = j + 1;
  5064. }
  5065. fclose(fptr1);
  5066. //Stacking Charging Profiles
  5067. for(int l=0; l <(j-1) ;l++)
  5068. {
  5069. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5070. {
  5071. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5072. {
  5073. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5074. {
  5075. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5076. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5077. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5078. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5079. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5080. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5081. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5082. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5083. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5084. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5085. }
  5086. else
  5087. {
  5088. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5089. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5090. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5091. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5092. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5093. }
  5094. }
  5095. }
  5096. }
  5097. //end of Stacking Charging Profiles
  5098. }
  5099. }// the end of ACCESS TxDefaultProfile
  5100. //****************************TxProfile************************************************/
  5101. switch(connectorIdInt)
  5102. {
  5103. case 0:
  5104. break;
  5105. case 1:
  5106. strcpy(fname, TxProfile_1_JSON );
  5107. break;
  5108. case 2:
  5109. strcpy(fname, TxProfile_2_JSON );
  5110. break;
  5111. default:
  5112. strcpy(fname, TxProfile_1_JSON );
  5113. break;
  5114. }
  5115. TxProfileIsNull=TRUE;
  5116. if((access(fname,F_OK))!=-1)
  5117. {
  5118. fptr1 = fopen(fname, "r");
  5119. c = 0;
  5120. c = fgetc(fptr1);
  5121. //DEBUG_INFO("c:%d\n",c);
  5122. rewind(fptr1);
  5123. if(c == EOF)
  5124. {
  5125. DEBUG_INFO("\n End of file reached.");
  5126. TxProfileIsNull=TRUE;
  5127. fclose(fptr1);
  5128. }
  5129. else
  5130. {
  5131. TxProfileIsNull=FALSE;
  5132. while(fscanf(fptr1, "%s", word) != EOF)
  5133. {
  5134. if(strcmp(word, "chargingProfileId") == 0)
  5135. {
  5136. n_chargingProfile = n_chargingProfile + 1;
  5137. }
  5138. }
  5139. rewind(fptr1);
  5140. //search Charging Profile Element
  5141. int i= 0;
  5142. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5143. #if 0
  5144. /***********connectorId****************/
  5145. c = 0;
  5146. loc = strstr(sLineWord, "connectorId");
  5147. memset(sstr ,0, sizeof(sstr) );
  5148. while (loc[strlen("connectorId")+2+c] != ',')
  5149. {
  5150. sstr[c] = loc[strlen("connectorId")+2+c];
  5151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5152. c++;
  5153. }
  5154. sstr[c] = '\0';
  5155. tempconnectorIdInt = atoi(sstr);
  5156. #endif
  5157. //***********validFrom**************/
  5158. c = 0;
  5159. loc = strstr(sLineWord, "validFrom");
  5160. if(loc != NULL)
  5161. {
  5162. memset(sstr ,0, sizeof(sstr) );
  5163. while (loc[3+strlen("validFrom")+c] != '\"')
  5164. {
  5165. sstr[c] = loc[3+strlen("validFrom")+c];
  5166. c++;
  5167. }
  5168. sstr[c] = '\0';
  5169. strcpy(tempvalidFromStr,sstr);
  5170. }
  5171. else
  5172. {
  5173. strcpy(tempvalidFromStr,"");
  5174. }
  5175. //**********startSchedule**********/
  5176. c = 0;
  5177. loc = strstr(sLineWord, "startSchedule");
  5178. memset(sstr ,0, sizeof(sstr) );
  5179. while (loc[3+strlen("startSchedule")+c] != '\"')
  5180. {
  5181. sstr[c] = loc[3+strlen("startSchedule")+c];
  5182. c++;
  5183. }
  5184. sstr[c] = '\0';
  5185. strcpy(tempstartScheduleStr, sstr);
  5186. strcpy(TxProfileScheduleStr, sstr);
  5187. //**********chargingRateUnit**********/
  5188. c = 0;
  5189. loc = strstr(sLineWord, "chargingRateUnit");
  5190. memset(sstr ,0, sizeof(sstr) );
  5191. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5192. {
  5193. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5194. c++;
  5195. }
  5196. sstr[c] = '\0';
  5197. strcpy(tempchargingRateUnitStr, sstr);
  5198. //**********minChargingRate*******/
  5199. c = 0;
  5200. loc = strstr(sLineWord, "minChargingRate");
  5201. if(loc != NULL)
  5202. {
  5203. memset(sstr ,0, sizeof(sstr) );
  5204. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5205. {
  5206. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5207. c++;
  5208. }
  5209. sstr[c] = '\0';
  5210. tempminChargingRateFloat = atof(sstr);
  5211. }
  5212. else
  5213. {
  5214. tempminChargingRateFloat = 0.0;
  5215. }
  5216. //
  5217. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5218. tp.tm_isdst = -1;
  5219. time_t utc = mktime(&tp);
  5220. time_t t = time(NULL);
  5221. diff_t = difftime(t, utc);
  5222. DEBUG_INFO("diff_t=%f\n",diff_t);
  5223. //parsing strings to words
  5224. i = 0;
  5225. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5226. loc = loc+3+strlen("chargingSchedulePeriod");
  5227. pch = strtok(loc ,"{");
  5228. while (pch != NULL)
  5229. {
  5230. strcpy(SchedulePeriodList[i], pch);
  5231. pch = strtok (NULL, "{");
  5232. i = i + 1;
  5233. }
  5234. n_SchedulePeriods = i;
  5235. for(int i=0;i<n_SchedulePeriods;i++)
  5236. {
  5237. //*************startPeriod****************/
  5238. c = 0;
  5239. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5240. memset(sstr ,0, sizeof(sstr) );
  5241. while (loc[strlen("startPeriod")+2+c] != ',')
  5242. {
  5243. sstr[c] = loc[strlen("startPeriod")+2+c];
  5244. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5245. c++;
  5246. }
  5247. sstr[c] = '\0';
  5248. tempStartPeriodInt = atoi(sstr);
  5249. //*************limit****************/
  5250. c = 0;
  5251. loc = strstr(SchedulePeriodList[i], "limit");
  5252. memset(sstr ,0, sizeof(sstr) );
  5253. while (loc[strlen("limit")+2+c] != ',')
  5254. {
  5255. sstr[c] = loc[strlen("limit")+2+c];
  5256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5257. c++;
  5258. }
  5259. sstr[c] = '\0';
  5260. tempLimitInt = atof(sstr);
  5261. //*************numberPhases****************/
  5262. c = 0;
  5263. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5264. memset(sstr ,0, sizeof(sstr) );
  5265. while (loc[strlen("numberPhases")+2+c] != '}')
  5266. {
  5267. sstr[c] = loc[strlen("numberPhases")+2+c];
  5268. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5269. c++;
  5270. }
  5271. sstr[c] = '\0';
  5272. tempNumberPhasesInt = atoi(sstr);
  5273. TxProfile.Duration = durationInt;
  5274. TxProfile.TotalPeriod = n_SchedulePeriods;
  5275. TxProfile.Period[i].Limit = tempLimitInt;
  5276. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5277. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5278. }
  5279. if(MinChargingRate < tempminChargingRateFloat)
  5280. MinChargingRate = tempminChargingRateFloat;
  5281. if(confirmPeriods < n_SchedulePeriods)
  5282. confirmPeriods = n_SchedulePeriods;
  5283. }
  5284. fclose(fptr1);
  5285. }
  5286. }// the end of ACCESS TxProfile
  5287. //CompositeSchedule
  5288. int period=0;
  5289. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5290. {
  5291. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5292. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5293. {
  5294. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5295. {
  5296. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5297. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5298. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5299. period = period + 1;
  5300. }
  5301. else
  5302. {
  5303. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5304. {
  5305. }
  5306. else
  5307. {
  5308. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5309. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5310. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5311. period = period + 1;
  5312. }
  5313. }
  5314. }
  5315. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5316. {
  5317. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5318. {
  5319. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5320. {
  5321. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5322. }
  5323. else
  5324. {
  5325. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5326. }
  5327. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5328. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5329. period = period + 1;
  5330. }
  5331. }
  5332. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5333. {
  5334. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5335. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5336. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5337. period = period + 1;
  5338. }
  5339. }
  5340. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5341. {
  5342. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5343. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5344. {
  5345. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5346. {
  5347. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5348. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5349. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5350. period = period + 1;
  5351. }
  5352. else
  5353. {
  5354. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5355. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5356. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5357. period = period + 1;
  5358. }
  5359. }
  5360. }
  5361. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5362. {
  5363. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5364. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5365. {
  5366. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5367. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5368. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5369. period = period + 1;
  5370. }
  5371. }
  5372. confirmPeriods = period;
  5373. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5374. //* Define temporary variables */
  5375. struct tm *gtime;
  5376. time_t now;
  5377. char buf[28];
  5378. //* Read the current system time */
  5379. time(&now);
  5380. //* Convert the system time to GMT (now UTC) */
  5381. gtime = gmtime(&now);
  5382. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5383. // make .conf
  5384. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5385. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5386. //DEBUG_INFO(" debug 11\n");
  5387. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5388. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5389. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5390. }
  5391. else
  5392. {
  5393. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5394. }
  5395. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5396. return result;
  5397. }
  5398. int handleGetConfigurationRequest(char *uuid, char *payload)
  5399. {
  5400. mtrace();
  5401. int result = FAIL;
  5402. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5403. //struct json_object *jsonitem;
  5404. int MaxKeySupported = 0;
  5405. int n_keys = 0;
  5406. char requestKey[43][50]={0};
  5407. char search[]="[";
  5408. char sstr[500]={ 0 };
  5409. //int pos;
  5410. int l, c = 0;
  5411. int i = 0;
  5412. char *delim = "\",\"";
  5413. char * pch;
  5414. char *loc = strstr(payload, search);
  5415. //********************* Parsing String ***********************************/
  5416. if(loc == NULL) {
  5417. DEBUG_INFO("no key match in Configuration \n");
  5418. }
  5419. else {
  5420. //pos = loc - payload;
  5421. l = strlen(loc)-4;
  5422. while (c < l)
  5423. {
  5424. sstr[c] = loc[c+2];
  5425. c++;
  5426. }
  5427. sstr[c] = '\0';
  5428. //parsing strings to words
  5429. pch = strtok(sstr,delim);
  5430. if(pch == NULL)
  5431. {
  5432. strcpy(requestKey[0], sstr);
  5433. }
  5434. else
  5435. {
  5436. while (pch != NULL)
  5437. {
  5438. strcpy(requestKey[i], pch);
  5439. pch = strtok (NULL, delim);
  5440. i = i + 1;
  5441. }
  5442. n_keys = i;
  5443. }
  5444. }
  5445. UnknownKeynum = 0;
  5446. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5447. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5448. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5449. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5450. if(n_keys != 0)
  5451. {
  5452. for(int i=0;i<n_keys;i++)
  5453. {
  5454. getKeyValue(requestKey[i]);
  5455. //json_object_put(jsonitem);
  5456. }
  5457. }
  5458. else
  5459. {
  5460. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5461. getKeyValue("");
  5462. }
  5463. processUnkownKey();
  5464. sendGetConfigurationConfirmation(uuid);
  5465. return result;
  5466. }
  5467. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5468. {
  5469. mtrace();
  5470. int result = FAIL;
  5471. //void *ret; //
  5472. char fnamePlusPath[50]="";
  5473. char fname[16]="";
  5474. pthread_t t; // pthread 變數
  5475. time_t rawtime;
  5476. struct tm * timeinfo;
  5477. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5478. system("exec /root/logPackTools 'log' 6");
  5479. //char buffer [128];
  5480. time (&rawtime);
  5481. //printf("%ld\n", rawtime);
  5482. timeinfo = localtime (&rawtime);
  5483. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5484. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5485. if((access(fnamePlusPath,F_OK))!=-1)
  5486. {
  5487. DEBUG_INFO("fnamePlusPath exist.\n");
  5488. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5489. }
  5490. else
  5491. {
  5492. DEBUG_INFO("fnamePlusPath not exist!\n");
  5493. }
  5494. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5495. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5496. pthread_join(t, NULL/*&ret*/);
  5497. return result;
  5498. }
  5499. void* GetDiagnosticsProcess(void* data)
  5500. {
  5501. mtrace();
  5502. int retriesInt=0, retryIntervalInt=0;
  5503. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5504. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5505. 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};
  5506. int port=0;
  5507. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5508. char fname[16]="";
  5509. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5510. int c = 0;
  5511. char *loc;
  5512. int isSuccess = FALSE;
  5513. char ftpbuf[200]={0};
  5514. //char temp[100]={0};
  5515. char * pch;
  5516. // [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"}]
  5517. char *str = (char*) data; // ? ?輸入資 ?
  5518. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5519. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5520. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5521. //****************location*******************/
  5522. c = 0;
  5523. memset(sstr ,0, sizeof(sstr) );
  5524. loc = strstr(str, "location");
  5525. while (loc[3+strlen("location")+c] != '\"')
  5526. {
  5527. sstr[c] = loc[3+strlen("location")+c];
  5528. c++;
  5529. }
  5530. sstr[c] = '\0';
  5531. strcpy(locationstr,sstr);
  5532. if(strcmp(locationstr,"")==0)
  5533. {
  5534. DEBUG_INFO("location is <Empty>!\n");
  5535. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5536. goto end;
  5537. }
  5538. //****************retries*******************/
  5539. c = 0;
  5540. loc = strstr(str, "retries");
  5541. if(loc == NULL)
  5542. {
  5543. retriesIsNULL = TRUE;
  5544. }
  5545. else
  5546. {
  5547. while (loc[strlen("retries")+2+c] != ',')
  5548. {
  5549. sstr[c] = loc[strlen("retries")+2+c];
  5550. c++;
  5551. }
  5552. sstr[c] = '\0';
  5553. retriesInt = atoi(sstr);
  5554. }
  5555. if(retriesIsNULL == TRUE)
  5556. {
  5557. retriesInt = 0;
  5558. }
  5559. //****************retryInterval*******************/
  5560. c = 0;
  5561. loc = strstr(str, "retryInterval");
  5562. if(loc == NULL)
  5563. {
  5564. retryIntervalIsNULL = TRUE;
  5565. }
  5566. else
  5567. {
  5568. while (loc[strlen("retryInterval")+2+c] != ',')
  5569. {
  5570. sstr[c] = loc[strlen("retryInterval")+2+c];
  5571. c++;
  5572. }
  5573. sstr[c] = '\0';
  5574. retryIntervalInt = atoi(sstr);
  5575. }
  5576. //****************startTime*******************/
  5577. c = 0;
  5578. memset(sstr ,0, sizeof(sstr) );
  5579. loc = strstr(str, "startTime");
  5580. if(loc == NULL)
  5581. {
  5582. startTimeIsNULL = TRUE;
  5583. }
  5584. else
  5585. {
  5586. while (loc[3+strlen("startTime")+c] != '\"')
  5587. {
  5588. sstr[c] = loc[3+strlen("startTime")+c];
  5589. c++;
  5590. }
  5591. sstr[c] = '\0';
  5592. strcpy(startTimestr,sstr);
  5593. }
  5594. //****************stopTime*******************/
  5595. c = 0;
  5596. memset(sstr ,0, sizeof(sstr) );
  5597. loc = strstr(str, "stopTime");
  5598. if(loc == NULL)
  5599. {
  5600. stopTimeIsNULL = TRUE;
  5601. }
  5602. else
  5603. {
  5604. while (loc[3+strlen("stopTime")+c] != '\"')
  5605. {
  5606. sstr[c] = loc[3+strlen("stopTime")+c];
  5607. c++;
  5608. }
  5609. sstr[c] = '\0';
  5610. strcpy(stopTimestr,sstr);
  5611. }
  5612. memset(protocol, 0, sizeof(protocol));
  5613. memset(user, 0, sizeof(user) );
  5614. memset(password, 0, sizeof(password));
  5615. memset(host, 0, sizeof(host));
  5616. memset(path, 0, sizeof(path));
  5617. memset(ftppath, 0, sizeof(ftppath));
  5618. memset(host1, 0, sizeof(host1));
  5619. memset(path1, 0, sizeof(path1));
  5620. /*location: ftp://user:password@host:port/path*/
  5621. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5622. // protocol, user, password, host, &port, path);
  5623. #if 0 // remove for temporally
  5624. //zip files in /Storage
  5625. system("exec /root/logPackTools 'log' 6");
  5626. #endif
  5627. // system("exec /root/Module_WebService 'log' 6");
  5628. time_t rawtime;
  5629. struct tm * timeinfo;
  5630. //char buffer [128];
  5631. time (&rawtime);
  5632. //printf("%ld\n", rawtime);
  5633. timeinfo = localtime (&rawtime);
  5634. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5635. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5636. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5637. if((access(fnamePlusPath,F_OK))!=-1)
  5638. {
  5639. DEBUG_INFO("fnamePlusPath exist.\n");
  5640. }
  5641. else
  5642. {
  5643. DEBUG_INFO("fnamePlusPath not exist!\n");
  5644. goto end;
  5645. }
  5646. pch=strchr(locationstr,'@');
  5647. if(pch==NULL)
  5648. {
  5649. sscanf(locationstr,
  5650. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5651. protocol, host, &port, path);
  5652. strcpy(user,"anonymous");
  5653. strcpy(password,"");
  5654. }
  5655. else
  5656. {
  5657. DEBUG_INFO("pch=%s\n", pch);
  5658. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5659. protocol, user, password, host, &port, path);
  5660. }
  5661. if(strcmp(protocol,"ftp")!=0)
  5662. {
  5663. DEBUG_INFO("protocol is not ftp!\n");
  5664. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5665. goto end;
  5666. }
  5667. sscanf(host,"%[^/]%s",host1, path1);
  5668. sprintf(ftppath,"%s", path1);
  5669. DEBUG_INFO("protocol =%s\n",protocol);
  5670. DEBUG_INFO("user =%s\n",user);
  5671. DEBUG_INFO("password =%s\n",password);
  5672. DEBUG_INFO("host1 =%s\n",host1);
  5673. DEBUG_INFO("port =%d\n",port);
  5674. DEBUG_INFO("path1 =%s\n",path1);
  5675. DEBUG_INFO("ftppath=%s\n",ftppath);
  5676. int ftppathlen=strlen(ftppath);
  5677. int i=1;
  5678. char filenametemp[50];
  5679. while(i < ftppathlen)
  5680. {
  5681. int len=ftppathlen-i;
  5682. if(ftppath[len]== 47) // '/' ascll code: 47
  5683. {
  5684. DEBUG_INFO("find '/' all right\n");
  5685. break;
  5686. }
  5687. i=i+1;
  5688. }
  5689. memset(filenametemp, 0, sizeof(filenametemp));
  5690. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5691. filenametemp[i+1] = 0;
  5692. //httpDownLoadFile(host, ftppath, fname);
  5693. memset(ftpbuf, 0, sizeof(ftpbuf));
  5694. if(port == 0)
  5695. port = 21;
  5696. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5697. do{
  5698. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5699. sleep(retryIntervalInt);
  5700. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5701. if(!isSuccess)
  5702. {
  5703. //BulldogUtil.sleepMs(interval*1000);
  5704. DEBUG_INFO("Diagnostics fail.\n");
  5705. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5706. }
  5707. else
  5708. {
  5709. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5710. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5711. //isUpdateRequest = TRUE;
  5712. }
  5713. end:
  5714. // json_object_put(obj);
  5715. DiagnosticsStatusNotificationStatus = 0; //Idle
  5716. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5717. }
  5718. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5719. {
  5720. mtrace();
  5721. int result = FAIL;
  5722. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5723. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5724. {
  5725. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5726. localversion = -1;
  5727. }
  5728. else
  5729. {
  5730. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5731. OCPP_getListVerion();
  5732. }
  5733. //from db.OCPP_getListVerion
  5734. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5735. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5736. sendGetLocalListVersionConfirmation(uuid,"");
  5737. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5738. return result;
  5739. }
  5740. int handleRemoteStartRequest(char *uuid, char *payload)
  5741. {
  5742. mtrace();
  5743. int result = FAIL;
  5744. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5745. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5746. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5747. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5748. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5749. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5750. int chargingSchedulePeriodCount = 0;
  5751. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5752. int c = 0;
  5753. char *loc;
  5754. char comfirmstr[20]={0};
  5755. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5756. if(server_pending == TRUE)
  5757. {
  5758. return 0;
  5759. }
  5760. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5761. //**********connectorId****************/
  5762. c = 0;
  5763. memset(sstr ,0, sizeof(sstr) );
  5764. loc = strstr(payload, "connectorId");
  5765. if(loc == NULL)
  5766. {
  5767. connectorIdIsNULL = TRUE;
  5768. }
  5769. else
  5770. {
  5771. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5772. {
  5773. sstr[c] = loc[strlen("connectorId")+2+c];
  5774. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5775. c++;
  5776. }
  5777. sstr[c] = '\0';
  5778. connectorIdInt = atoi(sstr);
  5779. }
  5780. if(connectorIdIsNULL == TRUE) // need to discussion
  5781. {
  5782. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5783. goto end;
  5784. }
  5785. //****************idTag*******************/
  5786. c = 0;
  5787. memset(sstr ,0, sizeof(sstr) );
  5788. loc = strstr(payload, "idTag");
  5789. while (loc[3+strlen("idTag")+c] != '\"')
  5790. {
  5791. sstr[c] = loc[3+strlen("idTag")+c];
  5792. c++;
  5793. }
  5794. sstr[c] = '\0';
  5795. strcpy(idTagstr,sstr);
  5796. //****************chargingProfile*******************/
  5797. c = 0;
  5798. memset(sstr ,0, sizeof(sstr) );
  5799. loc = strstr(payload, "chargingProfile");
  5800. if(loc == NULL)
  5801. {
  5802. chargingProfileIsNULL = TRUE;
  5803. }
  5804. else
  5805. {
  5806. //****************chargingProfileId*******************/
  5807. c=0;
  5808. loc = strstr(payload, "chargingProfileId");
  5809. memset(sstr ,0, sizeof(sstr) );
  5810. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5811. {
  5812. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5813. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5814. c++;
  5815. }
  5816. sstr[c] = '\0';
  5817. chargingProfileIdInt = atoi(sstr);
  5818. //****************transactionId*******************/
  5819. loc = strstr(payload, "transactionId");
  5820. if(loc == NULL)
  5821. {
  5822. transactionIdIsNULL = TRUE;
  5823. }
  5824. else
  5825. {
  5826. c=0;
  5827. memset(sstr ,0, sizeof(sstr) );
  5828. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5829. {
  5830. sstr[c] = loc[strlen("transactionId")+2+c];
  5831. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5832. c++;
  5833. }
  5834. sstr[c] = '\0';
  5835. transactionIdInt = atoi(sstr);
  5836. }
  5837. //****************stackLevel*******************/
  5838. c=0;
  5839. loc = strstr(payload, "stackLevel");
  5840. memset(sstr ,0, sizeof(sstr) );
  5841. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5842. {
  5843. sstr[c] = loc[strlen("stackLevel")+2+c];
  5844. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5845. c++;
  5846. }
  5847. sstr[c] = '\0';
  5848. stackLevelInt = atoi(sstr);
  5849. //****************chargingProfilePurpose*******************/
  5850. c = 0;
  5851. memset(sstr ,0, sizeof(sstr) );
  5852. loc = strstr(payload, "chargingProfilePurpose");
  5853. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5854. {
  5855. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5856. c++;
  5857. }
  5858. sstr[c] = '\0';
  5859. strcpy(chargingProfilePurposestr,sstr);
  5860. //****************chargingProfileKind*******************/
  5861. c = 0;
  5862. memset(sstr ,0, sizeof(sstr) );
  5863. loc = strstr(payload, "chargingProfileKind");
  5864. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5865. {
  5866. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5867. c++;
  5868. }
  5869. sstr[c] = '\0';
  5870. strcpy(chargingProfileKindstr,sstr);
  5871. //****************recurrencyKind*******************/
  5872. loc = strstr(payload, "recurrencyKind");
  5873. if(loc == NULL)
  5874. {
  5875. recurrencyKindIsNULL = TRUE;
  5876. }
  5877. else
  5878. {
  5879. c = 0;
  5880. memset(sstr ,0, sizeof(sstr) );
  5881. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5882. {
  5883. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5884. c++;
  5885. }
  5886. sstr[c] = '\0';
  5887. strcpy(recurrencyKindstr,sstr);
  5888. }
  5889. //****************validFrom*******************/
  5890. loc = strstr(payload, "validFrom");
  5891. if(loc == NULL)
  5892. {
  5893. validFromIsNULL = TRUE;
  5894. }
  5895. else
  5896. {
  5897. c = 0;
  5898. memset(sstr ,0, sizeof(sstr) );
  5899. while (loc[3+strlen("validFrom")+c] != '\"')
  5900. {
  5901. sstr[c] = loc[3+strlen("validFrom")+c];
  5902. c++;
  5903. }
  5904. sstr[c] = '\0';
  5905. strcpy(validFromstr,sstr);
  5906. }
  5907. //****************validTo*******************/
  5908. loc = strstr(payload, "validTo");
  5909. if(loc == NULL)
  5910. {
  5911. validToIsNULL = TRUE;
  5912. }
  5913. else
  5914. {
  5915. c = 0;
  5916. memset(sstr ,0, sizeof(sstr) );
  5917. while (loc[3+strlen("validTo")+c] != '\"')
  5918. {
  5919. sstr[c] = loc[3+strlen("validTo")+c];
  5920. c++;
  5921. }
  5922. sstr[c] = '\0';
  5923. strcpy(validTostr,sstr);
  5924. }
  5925. //****************chargingSchedule*******************/
  5926. loc = strstr(payload, "chargingSchedule");
  5927. if(loc != NULL)
  5928. {
  5929. //****************duration*******************/
  5930. loc = strstr(payload, "duration");
  5931. if(loc == NULL)
  5932. {
  5933. durationIsNULL = TRUE;
  5934. }
  5935. else
  5936. {
  5937. c=0;
  5938. memset(sstr ,0, sizeof(sstr) );
  5939. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5940. {
  5941. sstr[c] = loc[strlen("duration")+2+c];
  5942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5943. c++;
  5944. }
  5945. sstr[c] = '\0';
  5946. durationInt = atoi(sstr);
  5947. }
  5948. //****************startSchedule******************/
  5949. loc = strstr(payload, "startSchedule");
  5950. if(loc == NULL)
  5951. {
  5952. startScheduleIsNULL = TRUE;
  5953. }
  5954. else
  5955. {
  5956. c = 0;
  5957. memset(sstr ,0, sizeof(sstr) );
  5958. while (loc[3+strlen("startSchedule")+c] != '\"')
  5959. {
  5960. sstr[c] = loc[3+strlen("startSchedule")+c];
  5961. c++;
  5962. }
  5963. sstr[c] = '\0';
  5964. strcpy(startSchedulestr,sstr);
  5965. }
  5966. //****************chargingRateUnit*******************/
  5967. c = 0;
  5968. memset(sstr ,0, sizeof(sstr) );
  5969. loc = strstr(payload, "chargingRateUnit");
  5970. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5971. {
  5972. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5973. c++;
  5974. }
  5975. sstr[c] = '\0';
  5976. strcpy(chargingRateUnitstr,sstr);
  5977. //****************minChargingRate*******************/
  5978. loc = strstr(payload, "minChargingRate");
  5979. if(loc == NULL)
  5980. {
  5981. minChargingRateIsNULL = TRUE;
  5982. }
  5983. else
  5984. {
  5985. c=0;
  5986. memset(sstr ,0, sizeof(sstr) );
  5987. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5988. {
  5989. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5991. c++;
  5992. }
  5993. sstr[c] = '\0';
  5994. minChargingRateflaot = atof(sstr);
  5995. }
  5996. //****************chargingSchedulePeriod count*******************/
  5997. int what_len = strlen("startPeriod");
  5998. char *where = payload;
  5999. while ((where = strstr(where, "startPeriod"))) {
  6000. where += what_len;
  6001. chargingSchedulePeriodCount++;
  6002. }
  6003. where = payload;
  6004. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6005. {
  6006. //****************startPeriod*******************/
  6007. c=0;
  6008. loc = strstr(where, "startPeriod");
  6009. memset(sstr ,0, sizeof(sstr) );
  6010. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6011. {
  6012. sstr[c] = loc[strlen("startPeriod")+2+c];
  6013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6014. c++;
  6015. }
  6016. sstr[c] = '\0';
  6017. startPeriodInt[periodNums] = atoi(sstr);
  6018. //****************limit*******************/
  6019. c=0;
  6020. loc = strstr(where, "limit");
  6021. memset(sstr ,0, sizeof(sstr) );
  6022. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6023. {
  6024. sstr[c] = loc[strlen("limit")+2+c];
  6025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6026. c++;
  6027. }
  6028. sstr[c] = '\0';
  6029. limitflaot[periodNums] = atof(sstr);
  6030. //****************numberPhases*******************/
  6031. loc = strstr(where, "numberPhases");
  6032. if(loc == NULL)
  6033. {
  6034. numberPhasesIsNULL = TRUE;
  6035. }
  6036. else
  6037. {
  6038. c=0;
  6039. memset(sstr ,0, sizeof(sstr) );
  6040. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6041. {
  6042. sstr[c] = loc[strlen("numberPhases")+2+c];
  6043. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6044. c++;
  6045. }
  6046. sstr[c] = '\0';
  6047. numberPhasesInt[periodNums] = atoi(sstr);
  6048. }
  6049. where = loc;
  6050. }
  6051. }
  6052. }
  6053. /*
  6054. enum _SYSTEM_STATUS
  6055. {
  6056. S_BOOTING = 0,
  6057. S_IDLE, = 1
  6058. S_AUTHORIZING, =2
  6059. S_REASSIGN_CHECK, =3
  6060. S_REASSIGN, =4
  6061. S_PRECHARGE, =5
  6062. S_PREPARING_FOR_EV, =6
  6063. S_PREPARING_FOR_EVSE, =7
  6064. S_CHARGING, =8
  6065. S_TERMINATING, =9
  6066. S_COMPLETE, =10
  6067. S_ALARM, =11
  6068. S_FAULT =12
  6069. }
  6070. */
  6071. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6072. {
  6073. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6074. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6075. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6076. //check Transaction active
  6077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6078. {
  6079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6080. {
  6081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6082. {
  6083. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6084. {
  6085. //Reserved
  6086. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6087. }
  6088. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6089. {
  6090. //Reserved
  6091. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6092. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6093. goto end;
  6094. }
  6095. else
  6096. {
  6097. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6098. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6099. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6100. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6101. {
  6102. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6103. goto end;
  6104. }
  6105. }//END FOR ELSE
  6106. }
  6107. }// END FOR CHAdeMO_QUANTITY
  6108. for (int index = 0; index < CCS_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6111. {
  6112. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6113. {
  6114. //Reserved
  6115. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6116. }
  6117. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6118. {
  6119. //Reserved
  6120. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6121. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6122. goto end;
  6123. }
  6124. else
  6125. {
  6126. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6127. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6128. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6129. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6130. {
  6131. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6132. goto end;
  6133. }
  6134. }// END FOR ELSE
  6135. }
  6136. }// END FOR CCS_QUANTITY
  6137. for (int index = 0; index < GB_QUANTITY; index++)
  6138. {
  6139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6140. {
  6141. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6142. {
  6143. //Reserved
  6144. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6145. }
  6146. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6147. {
  6148. //Reserved
  6149. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6150. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6151. goto end;
  6152. }
  6153. else
  6154. {
  6155. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6156. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6157. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6158. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6159. {
  6160. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6161. goto end;
  6162. }
  6163. }// END FOR ELSE
  6164. }
  6165. } // END FOR GB_QUANTITY
  6166. }
  6167. else
  6168. {
  6169. for (int index = 0; index < AC_QUANTITY; index++)
  6170. {
  6171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6172. {
  6173. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6174. {
  6175. //Reserved
  6176. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6177. }
  6178. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6179. {
  6180. //Reserved
  6181. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6182. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6183. goto end;
  6184. }
  6185. else
  6186. {
  6187. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6188. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6189. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6190. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6191. {
  6192. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6193. goto end;
  6194. }
  6195. }//END FOR ELSE
  6196. }
  6197. }// END FOR AC_QUANTITY
  6198. }
  6199. if(chargingProfileIsNULL == FALSE)
  6200. {
  6201. //ChargingProfile
  6202. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6203. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6204. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6205. if(recurrencyKindIsNULL == FALSE) //OPTION
  6206. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6207. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6208. if(transactionIdIsNULL == FALSE) // OPTION
  6209. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6210. if(validFromIsNULL == FALSE) // OPTION
  6211. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6212. if(validToIsNULL == FALSE) //OPTION
  6213. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6214. //ChargingSchedule
  6215. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6216. if(durationIsNULL == FALSE) //OPTION
  6217. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6218. if(minChargingRateIsNULL == FALSE) //OPTION
  6219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6220. if(startScheduleIsNULL == FALSE) //OPTION
  6221. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6222. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6223. {
  6224. //ChargingSchedulePeriod
  6225. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6226. if(numberPhasesIsNULL == FALSE)
  6227. {
  6228. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6229. }
  6230. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6231. }
  6232. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6233. {
  6234. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6236. //memset idTag
  6237. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6238. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6239. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6240. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6241. }
  6242. else
  6243. {
  6244. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6245. }
  6246. }
  6247. else
  6248. {
  6249. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6250. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6251. //memset idTag
  6252. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6253. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6254. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6255. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6256. }
  6257. }
  6258. else
  6259. {
  6260. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6261. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6262. }
  6263. end:
  6264. if(connectorIdIsNULL == FALSE)
  6265. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6266. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6267. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6268. //OCPP send RemoteStartConfirmation by first.
  6269. sendRemoteStartConfirmation(uuid, comfirmstr);
  6270. return result;
  6271. }
  6272. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6273. {
  6274. mtrace();
  6275. int result = FAIL;
  6276. int match = FALSE;
  6277. int GunNO = 0;
  6278. int transactionIdInt=0;
  6279. int transactionIdIsNULL= FALSE;
  6280. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6281. int c = 0;
  6282. char *loc;
  6283. char comfirmstr[20];
  6284. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6285. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6286. if(server_pending == TRUE)
  6287. {
  6288. return 0;
  6289. }
  6290. c=0;
  6291. loc = strstr(payload, "transactionId");
  6292. if(loc == NULL)
  6293. {
  6294. transactionIdIsNULL= TRUE;
  6295. }
  6296. else
  6297. {
  6298. memset(sstr ,0, sizeof(sstr) );
  6299. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6300. {
  6301. sstr[c] = loc[strlen("transactionId")+2+c];
  6302. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6303. c++;
  6304. }
  6305. sstr[c] = '\0';
  6306. transactionIdInt = atoi(sstr);
  6307. }
  6308. if(transactionIdIsNULL == FALSE)
  6309. {
  6310. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6311. {
  6312. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6313. {
  6314. //check Transaction active
  6315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6316. {
  6317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6318. {
  6319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6320. {
  6321. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6322. {
  6323. match = TRUE;
  6324. GunNO = gun_index;
  6325. }
  6326. }
  6327. }// END FOR CHAdeMO_QUANTITY
  6328. for (int index = 0; index < CCS_QUANTITY; index++)
  6329. {
  6330. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6331. {
  6332. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6333. {
  6334. match = TRUE;
  6335. GunNO = gun_index;
  6336. }
  6337. }
  6338. }// END FOR CCS_QUANTITY
  6339. for (int index = 0; index < GB_QUANTITY; index++)
  6340. {
  6341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6342. {
  6343. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6344. {
  6345. match = TRUE;
  6346. GunNO = gun_index;
  6347. }
  6348. }
  6349. }// END FOR GB_QUANTITY
  6350. }
  6351. else
  6352. {
  6353. for (int index = 0; index < AC_QUANTITY; index++)
  6354. {
  6355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6356. {
  6357. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6358. {
  6359. match = TRUE;
  6360. GunNO = gun_index;
  6361. }
  6362. }
  6363. }// END FOR CHAdeMO_QUANTITY
  6364. }// END FOR AC ELSE
  6365. }// CHECK IF ResponseTransactionId == transactionIdInt
  6366. }//END FOR
  6367. if( match == TRUE)
  6368. {
  6369. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6370. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6371. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6372. }
  6373. else
  6374. {
  6375. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6376. }
  6377. }
  6378. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6379. return result;
  6380. }
  6381. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6382. {
  6383. mtrace();
  6384. int result = FAIL;
  6385. int connectorIdInt=0, reservationIdInt=0;
  6386. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6387. char comfirmstr[20]={0};
  6388. char sstr[180]={ 0 };
  6389. int c = 0;
  6390. char *loc;
  6391. //char *ptr;
  6392. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6393. //***(1)connectorId ****/
  6394. c=0;
  6395. loc = strstr(payload, "connectorId");
  6396. memset(sstr ,0, sizeof(sstr) );
  6397. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6398. {
  6399. sstr[c] = loc[strlen("connectorId")+2+c];
  6400. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6401. c++;
  6402. }
  6403. sstr[c] = '\0';
  6404. connectorIdInt = atoi(sstr);
  6405. //***(2)expiryDate ****/
  6406. loc = strstr(payload, "expiryDate");
  6407. memset(sstr ,0, sizeof(sstr) );
  6408. c = 0;
  6409. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6410. {
  6411. sstr[c] = loc[3+strlen("expiryDate")+c];
  6412. c++;
  6413. }
  6414. sstr[c] = '\0';
  6415. strcpy(expiryDatestr, sstr);
  6416. //***(3)idTag ****/
  6417. loc = strstr(payload, "idTag");
  6418. memset(sstr ,0, sizeof(sstr) );
  6419. c = 0;
  6420. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6421. {
  6422. sstr[c] = loc[3+strlen("idTag")+c];
  6423. c++;
  6424. }
  6425. sstr[c] = '\0';
  6426. strcpy(idTagstr, sstr);
  6427. //***(4)parentIdTag ****/
  6428. loc = strstr(payload, "parentIdTag");
  6429. memset(sstr ,0, sizeof(sstr) );
  6430. c = 0;
  6431. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6432. {
  6433. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6434. c++;
  6435. }
  6436. sstr[c] = '\0';
  6437. strcpy(parentIdTagstr, sstr);
  6438. //***(5)reservationId ****/
  6439. c=0;
  6440. loc = strstr(payload, "reservationId");
  6441. memset(sstr ,0, sizeof(sstr) );
  6442. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6443. {
  6444. sstr[c] = loc[strlen("reservationId")+2+c];
  6445. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6446. c++;
  6447. }
  6448. sstr[c] = '\0';
  6449. reservationIdInt = atoi(sstr);
  6450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6451. /*
  6452. enum _SYSTEM_STATUS
  6453. {
  6454. S_BOOTING = 0,
  6455. S_IDLE, = 1
  6456. S_AUTHORIZING, =2
  6457. S_REASSIGN_CHECK, =3
  6458. S_REASSIGN, =4
  6459. S_PRECHARGE, =5
  6460. S_PREPARING_FOR_EV, =6
  6461. S_PREPARING_FOR_EVSE, =7
  6462. S_CHARGING, =8
  6463. S_TERMINATING, =9
  6464. S_COMPLETE, =10
  6465. S_ALARM, =11
  6466. S_FAULT =12
  6467. }
  6468. */
  6469. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6470. {
  6471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6472. goto end;
  6473. }
  6474. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6475. {
  6476. //check Transaction active
  6477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6478. {
  6479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6480. {
  6481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6482. {
  6483. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6484. {
  6485. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6486. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6487. {
  6488. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6489. {
  6490. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6492. }
  6493. 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'))
  6494. {
  6495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6496. }
  6497. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6498. {
  6499. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6500. }
  6501. else
  6502. {
  6503. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6504. }
  6505. }
  6506. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6507. {
  6508. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6509. }
  6510. }
  6511. else
  6512. {
  6513. //replace reservation
  6514. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6516. }
  6517. }
  6518. } // END FOR CHAdeMO_QUANTITY
  6519. for (int index = 0; index < CCS_QUANTITY; index++)
  6520. {
  6521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6522. {
  6523. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6524. {
  6525. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6526. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6527. {
  6528. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6529. {
  6530. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6532. }
  6533. 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'))
  6534. {
  6535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6536. }
  6537. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6538. {
  6539. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6540. }
  6541. else
  6542. {
  6543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6544. }
  6545. }
  6546. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6547. {
  6548. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6549. }
  6550. }
  6551. else
  6552. {
  6553. //replace reservation
  6554. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6556. }
  6557. }
  6558. } // END FOR CCS_QUANTITY
  6559. for (int index = 0; index < GB_QUANTITY; index++)
  6560. {
  6561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6562. {
  6563. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6564. {
  6565. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6566. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6567. {
  6568. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6569. {
  6570. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6572. }
  6573. 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'))
  6574. {
  6575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6576. }
  6577. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6578. {
  6579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6580. }
  6581. else
  6582. {
  6583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6584. }
  6585. }
  6586. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6587. {
  6588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6589. }
  6590. }
  6591. else
  6592. {
  6593. //replace reservation
  6594. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6596. }
  6597. }
  6598. }// END FOR GB_QUANTITY
  6599. }
  6600. else
  6601. {
  6602. for (int index = 0; index < AC_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6605. {
  6606. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6607. {
  6608. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6609. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6610. {
  6611. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6612. {
  6613. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6615. }
  6616. 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'))
  6617. {
  6618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6619. }
  6620. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6621. {
  6622. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6623. }
  6624. else
  6625. {
  6626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6627. }
  6628. }
  6629. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6630. {
  6631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6632. }
  6633. }
  6634. else
  6635. {
  6636. //replace reservation
  6637. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6639. }
  6640. }
  6641. } // END FOR AC_QUANTITY
  6642. }//END FOR AC ELSE
  6643. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6644. }
  6645. else if(connectorIdInt == 0)
  6646. {
  6647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6648. {
  6649. //check Transaction active
  6650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6651. {
  6652. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6653. {
  6654. 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'))
  6655. {
  6656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6657. goto end;
  6658. }
  6659. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6660. {
  6661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6662. goto end;
  6663. }
  6664. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6665. {
  6666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6667. goto end;
  6668. }
  6669. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6670. {
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6672. goto end;
  6673. }
  6674. }
  6675. }// END FOR CHAdeMO_QUANTITY
  6676. for (int index = 0; index < CCS_QUANTITY; index++)
  6677. {
  6678. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6679. {
  6680. 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'))
  6681. {
  6682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6683. }
  6684. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6685. {
  6686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6687. }
  6688. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6689. {
  6690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6691. }
  6692. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6693. {
  6694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6695. }
  6696. }
  6697. } // END FOR CCS_QUANTITY
  6698. for (int index = 0; index < GB_QUANTITY; index++)
  6699. {
  6700. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6701. {
  6702. 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'))
  6703. {
  6704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6705. }
  6706. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6707. {
  6708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6709. }
  6710. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6711. {
  6712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6713. }
  6714. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6715. {
  6716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6717. }
  6718. }
  6719. } // END FOR GB_QUANTITY
  6720. }
  6721. else
  6722. {
  6723. for (int index = 0; index < AC_QUANTITY; index++)
  6724. {
  6725. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6726. {
  6727. 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'))
  6728. {
  6729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6730. goto end;
  6731. }
  6732. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6733. {
  6734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6735. goto end;
  6736. }
  6737. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6738. {
  6739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6740. goto end;
  6741. }
  6742. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6743. {
  6744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6745. goto end;
  6746. }
  6747. }
  6748. }// END FOR AC_QUANTITY
  6749. }
  6750. //The connectorId is 0
  6751. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6753. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6754. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6755. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6756. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6757. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6758. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6759. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6760. result = TRUE;
  6761. return result;
  6762. }
  6763. else
  6764. {
  6765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6766. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6767. }
  6768. if(strcmp(comfirmstr,"Accepted") == 0)
  6769. {
  6770. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6771. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6772. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6773. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6774. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6775. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6776. result = TRUE;
  6777. return result;
  6778. }
  6779. end:
  6780. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6781. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6782. return result;
  6783. }
  6784. int handleResetRequest(char *uuid, char *payload)
  6785. {
  6786. mtrace();
  6787. int result = FAIL;
  6788. char sstr[10]={0};
  6789. char typestr[10]={0};
  6790. char comfirmstr[20]={0};
  6791. int c = 0;
  6792. char *loc;
  6793. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6794. DEBUG_INFO("handleResetRequest ...\n");
  6795. loc = strstr(payload, "type");
  6796. memset(sstr ,0, sizeof(sstr) );
  6797. c = 0;
  6798. while (loc[3+strlen("type")+c] != '\"')
  6799. {
  6800. sstr[c] = loc[3+strlen("type")+c];
  6801. c++;
  6802. }
  6803. sstr[c] = '\0';
  6804. strcpy(typestr,sstr);
  6805. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6806. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6807. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6808. {
  6809. //check Transaction active
  6810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6811. {
  6812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6813. {
  6814. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6815. {
  6816. //0: unplug, 1: Plug-in
  6817. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6818. }
  6819. }
  6820. for (int index = 0; index < CCS_QUANTITY; index++)
  6821. {
  6822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6823. {
  6824. //0: unplug, 1: Plug-in
  6825. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6826. }
  6827. }
  6828. for (int index = 0; index < GB_QUANTITY; index++)
  6829. {
  6830. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6831. {
  6832. //0: unplug, 1: Plug-in
  6833. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6834. }
  6835. }
  6836. }
  6837. else
  6838. {
  6839. for (int index = 0; index < AC_QUANTITY; index++)
  6840. {
  6841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6842. {
  6843. //0: unplug, 1: Plug-in
  6844. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6845. }
  6846. }
  6847. }// END FOR AC ELSE
  6848. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6849. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6850. result = TRUE;
  6851. return result;
  6852. }
  6853. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6854. {
  6855. //check Transaction active
  6856. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6857. {
  6858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6859. {
  6860. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6861. {
  6862. //0: unplug, 1: Plug-in
  6863. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6864. }
  6865. }
  6866. for (int index = 0; index < CCS_QUANTITY; index++)
  6867. {
  6868. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6869. {
  6870. //0: unplug, 1: Plug-in
  6871. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6872. }
  6873. }
  6874. for (int index = 0; index < GB_QUANTITY; index++)
  6875. {
  6876. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6877. {
  6878. //0: unplug, 1: Plug-in
  6879. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6880. }
  6881. }
  6882. }
  6883. else
  6884. {
  6885. for (int index = 0; index < AC_QUANTITY; index++)
  6886. {
  6887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6888. {
  6889. //0: unplug, 1: Plug-in
  6890. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6891. }
  6892. }
  6893. }// END FOR AC ELSE
  6894. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6895. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6896. result = TRUE;
  6897. return result;
  6898. }
  6899. else
  6900. {
  6901. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6902. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6903. goto errorend;
  6904. }
  6905. errorend:
  6906. sendResetConfirmation(uuid, comfirmstr);
  6907. return result;
  6908. }
  6909. int handleSendLocalListRequest(char *uuid, char *payload)
  6910. {
  6911. mtrace();
  6912. int result = FAIL;
  6913. int listVersionInt;
  6914. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6915. char listsearch[]="listVersion";
  6916. char updateTypesearch[]="updateType";
  6917. char localAuthorizationListsearch[]="localAuthorizationList";
  6918. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6919. char CardList[500][160]={0};
  6920. char updateTypestr[15]={0};
  6921. char idTagstr[20]={0};
  6922. char parentIdTag[20]={0};
  6923. char expiryDate[30]={0};
  6924. char idTagstatus[16]={0};
  6925. int c = 0;
  6926. int i = 0;
  6927. char *delim1 = "}";
  6928. char * pch;
  6929. char *loc;
  6930. //char *ptr;
  6931. char comfirmstr[20];
  6932. //int n_localAuthorizations = 0;
  6933. int checkState_Faulted = FALSE;
  6934. DEBUG_INFO("handleSendLocalListRequest\n");
  6935. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6936. {
  6937. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6938. goto end;
  6939. }
  6940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6941. {
  6942. //check Charge Point state
  6943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6944. {
  6945. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6946. {
  6947. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6948. }
  6949. }
  6950. for (int index = 0; index < CCS_QUANTITY; index++)
  6951. {
  6952. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6953. {
  6954. checkState_Faulted = TRUE; //OCPP Status
  6955. }
  6956. }
  6957. for (int index = 0; index < GB_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6960. {
  6961. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6962. }
  6963. }
  6964. }
  6965. else
  6966. {
  6967. //check Charge Point state
  6968. for (int index = 0; index < AC_QUANTITY; index++)
  6969. {
  6970. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6971. {
  6972. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6973. }
  6974. }
  6975. }// END FOR AC ELSE
  6976. if(checkState_Faulted == TRUE)
  6977. {
  6978. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6979. goto end;
  6980. }
  6981. //listVersion
  6982. c = 0;
  6983. loc = strstr(payload, listsearch);
  6984. while (loc[strlen("listVersion")+2+c] != ',')
  6985. {
  6986. sstr[c] = loc[strlen("listVersion")+2+c];
  6987. c++;
  6988. }
  6989. sstr[c] = '\0';
  6990. listVersionInt = atoi(sstr);
  6991. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6992. //updateType
  6993. loc = strstr(payload, updateTypesearch);
  6994. c = 0;
  6995. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6996. {
  6997. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6998. c++;
  6999. }
  7000. sstr[c] = '\0';
  7001. strcpy(updateTypestr, sstr);
  7002. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7003. //localAuthorizationList
  7004. memset(sstr ,0, sizeof(sstr) );
  7005. loc = strstr(payload, localAuthorizationListsearch);
  7006. if(loc != NULL) // localAuthorizationList is not NULL
  7007. {
  7008. //Check UpdateType
  7009. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7010. {
  7011. //Local list full update
  7012. printf("Local list full update.\n");
  7013. OCPP_cleanLocalList();
  7014. }
  7015. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7016. {
  7017. //Local list different update
  7018. printf("Local list different update.\n");
  7019. OCPP_getListVerion();
  7020. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7021. {
  7022. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7023. goto end;
  7024. }
  7025. }
  7026. else
  7027. {
  7028. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7029. goto end;
  7030. }
  7031. c = 0;
  7032. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7033. {
  7034. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7035. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7036. c++;
  7037. }
  7038. sstr[c] = '\0';
  7039. //parsing strings to words
  7040. i = 0;
  7041. pch = strtok(sstr,delim1);
  7042. while (pch != NULL)
  7043. {
  7044. strcpy(CardList[i], pch);
  7045. pch = strtok (NULL, delim1);
  7046. i = i + 1;
  7047. }
  7048. //local Authorizations List Numbers
  7049. //n_localAuthorizations = i;
  7050. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7051. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7052. c= 0;
  7053. while(c < i)
  7054. {
  7055. //Search "IdToken"
  7056. memset(sstr ,0, sizeof(sstr) );
  7057. loc = strstr(CardList[c], "idTag");
  7058. int j = 0;
  7059. while (loc[3+strlen("idTag")+j] != '\"')
  7060. {
  7061. sstr[j] = loc[3+strlen("idTag")+j];
  7062. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7063. j++;
  7064. }
  7065. sstr[j] = '\0';
  7066. strcpy(idTagstr, sstr);
  7067. //Search "expiryDate"
  7068. memset(sstr ,0, sizeof(sstr) );
  7069. loc = strstr(CardList[c], "expiryDate");
  7070. j = 0;
  7071. while (loc[3+strlen("expiryDate")+j] != '\"')
  7072. {
  7073. sstr[j] = loc[3+strlen("expiryDate")+j];
  7074. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7075. j++;
  7076. }
  7077. sstr[j] = '\0';
  7078. strcpy(expiryDate, sstr);
  7079. //Search "parentIdTag"
  7080. memset(sstr ,0, sizeof(sstr) );
  7081. loc = strstr(CardList[c], "parentIdTag");
  7082. j = 0;
  7083. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7084. {
  7085. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7086. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7087. j++;
  7088. }
  7089. sstr[j] = '\0';
  7090. strcpy(parentIdTag, sstr);
  7091. //Search "status"
  7092. memset(sstr ,0, sizeof(sstr) );
  7093. loc = strstr(CardList[c], "status");
  7094. j = 0;
  7095. while (loc[3+strlen("status")+j] != '\"')
  7096. {
  7097. sstr[j] = loc[3+strlen("status")+j];
  7098. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7099. j++;
  7100. }
  7101. sstr[j] = '\0';
  7102. strcpy(idTagstatus, sstr);
  7103. OCPP_getIdTag(idTagstr);
  7104. //OCPP_getIdTag("test"); For Test
  7105. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7106. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7107. {
  7108. //Local list full update
  7109. DEBUG_INFO("Local list full update.\n");
  7110. // update list
  7111. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7112. OCPP_get_TableAuthlocalAllData();
  7113. }
  7114. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7115. {
  7116. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7117. {
  7118. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7119. }
  7120. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7121. {
  7122. OCPP_deleteIdTag(idTagstr);
  7123. }
  7124. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7125. {
  7126. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7127. }
  7128. }
  7129. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7130. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7131. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7132. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7133. c++;
  7134. }
  7135. }
  7136. else
  7137. {
  7138. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7139. {
  7140. //Local list different update
  7141. DEBUG_INFO("Local list different update.\n");
  7142. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7143. goto end;
  7144. }
  7145. }
  7146. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7147. end:
  7148. sendSendLocalListConfirmation(uuid, comfirmstr);
  7149. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7150. #if 0
  7151. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7152. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7153. #endif
  7154. return result;
  7155. }
  7156. /*
  7157. enum _SYSTEM_STATUS
  7158. {
  7159. S_BOOTING = 0,
  7160. S_IDLE, =1
  7161. S_AUTHORIZING, =2
  7162. S_REASSIGN_CHECK, =3
  7163. S_REASSIGN, =4
  7164. S_PRECHARGE, =5
  7165. S_PREPARING_FOR_EV, =6
  7166. S_PREPARING_FOR_EVSE, =7
  7167. S_CHARGING, =8
  7168. S_TERMINATING, =9
  7169. S_COMPLETE, =10
  7170. S_ALARM, =11
  7171. S_FAULT =12
  7172. };
  7173. */
  7174. #define MAX 200
  7175. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7176. {
  7177. mtrace();
  7178. int result = FAIL;
  7179. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7180. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7181. char chargingProfilePurposeStr[30]={0};
  7182. char chargingProfileKindStr[16]={0};
  7183. char recurrencyKindStr[10]={0};
  7184. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7185. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7186. int chargingSchedulePeriodCount = 0;
  7187. //int updateflag = FALSE;
  7188. char comfirmstr[20]={0};
  7189. int meet= FALSE;
  7190. char sstr[10]={0};
  7191. int c = 0;
  7192. char *loc;
  7193. FILE *fptr1;//, *fptr2;
  7194. //int lno=0;//, linectr = 0;
  7195. //int modifyflag = FALSE;
  7196. char filename[MAX]={0};
  7197. char tempfile[] = "../Storage/OCPP/temp.json";
  7198. int resultRename=0;
  7199. char rmFileCmd[50]={0};
  7200. char tempchargingProfilePurposeStr[30]={0};
  7201. //[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}}}]
  7202. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7203. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7204. //*********************connectorId***************************/
  7205. loc = strstr(payload, "connectorId");
  7206. c = 0;
  7207. memset(sstr ,0, sizeof(sstr) );
  7208. while (loc[strlen("connectorId")+2+c] != ',')
  7209. {
  7210. sstr[c] = loc[strlen("connectorId")+2+c];
  7211. c++;
  7212. }
  7213. sstr[c] = '\0';
  7214. connectorIdInt = atoi(sstr);
  7215. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7216. {
  7217. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7218. }
  7219. else
  7220. {
  7221. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7222. }
  7223. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7224. //*********************chargingProfileId***************************/
  7225. loc = strstr(payload, "chargingProfileId");
  7226. c = 0;
  7227. memset(sstr ,0, sizeof(sstr) );
  7228. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7229. {
  7230. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7231. c++;
  7232. }
  7233. sstr[c] = '\0';
  7234. chargingProfileIdInt = atoi(sstr);
  7235. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7236. {
  7237. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7238. }
  7239. else
  7240. {
  7241. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7242. }
  7243. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7244. //*********************transactionId***************************/
  7245. loc = strstr(payload, "transactionId");
  7246. if(loc != NULL)
  7247. {
  7248. c = 0;
  7249. memset(sstr ,0, sizeof(sstr) );
  7250. while (loc[strlen("transactionId")+2+c] != ',')
  7251. {
  7252. sstr[c] = loc[strlen("transactionId")+2+c];
  7253. c++;
  7254. }
  7255. sstr[c] = '\0';
  7256. transactionIdInt = atoi(sstr);
  7257. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7258. {
  7259. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7260. }
  7261. else
  7262. {
  7263. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7264. }
  7265. }
  7266. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7267. //*********************stackLevel***************************/
  7268. loc = strstr(payload, "stackLevel");
  7269. c = 0;
  7270. memset(sstr ,0, sizeof(sstr) );
  7271. while (loc[strlen("stackLevel")+2+c] != ',')
  7272. {
  7273. sstr[c] = loc[strlen("stackLevel")+2+c];
  7274. c++;
  7275. }
  7276. sstr[c] = '\0';
  7277. stackLevelInt = atoi(sstr);
  7278. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7279. {
  7280. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7281. }
  7282. else
  7283. {
  7284. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7285. }
  7286. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7287. //*********************chargingProfilePurpose***************************/
  7288. loc = strstr(payload, "chargingProfilePurpose");
  7289. c = 0;
  7290. memset(sstr ,0, sizeof(sstr) );
  7291. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7292. {
  7293. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7295. c++;
  7296. }
  7297. sstr[c] = '\0';
  7298. strcpy(chargingProfilePurposeStr,sstr);
  7299. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7300. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7301. {
  7302. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7303. }
  7304. else
  7305. {
  7306. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7307. }
  7308. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7309. //*********************chargingProfileKind***************************/
  7310. loc = strstr(payload, "chargingProfileKind");
  7311. c = 0;
  7312. memset(sstr ,0, sizeof(sstr) );
  7313. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7314. {
  7315. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7316. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7317. c++;
  7318. }
  7319. sstr[c] = '\0';
  7320. strcpy(chargingProfileKindStr,sstr);
  7321. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7322. {
  7323. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7324. }
  7325. else
  7326. {
  7327. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7328. }
  7329. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7330. //*********************recurrencyKind***************************/
  7331. loc = strstr(payload, "recurrencyKind");
  7332. if(loc != NULL)
  7333. {
  7334. c = 0;
  7335. memset(sstr ,0, sizeof(sstr) );
  7336. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7337. {
  7338. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7339. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7340. c++;
  7341. }
  7342. sstr[c] = '\0';
  7343. strcpy(recurrencyKindStr,sstr);
  7344. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7345. {
  7346. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7347. }
  7348. else
  7349. {
  7350. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7351. }
  7352. }
  7353. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7354. //*********************validFrom***************************/
  7355. loc = strstr(payload, "validFrom");
  7356. if(loc != NULL)
  7357. {
  7358. c = 0;
  7359. memset(sstr ,0, sizeof(sstr) );
  7360. while (loc[3+strlen("validFrom")+c] != '\"')
  7361. {
  7362. sstr[c] = loc[3+strlen("validFrom")+c];
  7363. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7364. c++;
  7365. }
  7366. sstr[c] = '\0';
  7367. strcpy(validFromStr,sstr);
  7368. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7369. {
  7370. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7371. }
  7372. else
  7373. {
  7374. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7375. }
  7376. }
  7377. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7378. //*********************validTo***************************/
  7379. loc = strstr(payload, "validTo");
  7380. if(loc != NULL)
  7381. {
  7382. c = 0;
  7383. memset(sstr ,0, sizeof(sstr) );
  7384. while (loc[3+strlen("validTo")+c] != '\"')
  7385. {
  7386. sstr[c] = loc[3+strlen("validTo")+c];
  7387. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7388. c++;
  7389. }
  7390. sstr[c] = '\0';
  7391. strcpy(validToStr,sstr);
  7392. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7393. {
  7394. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7395. }
  7396. else
  7397. {
  7398. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7399. }
  7400. }
  7401. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7402. //*********************duration***************************/
  7403. loc = strstr(payload, "duration");
  7404. if(loc != NULL)
  7405. {
  7406. c = 0;
  7407. memset(sstr ,0, sizeof(sstr) );
  7408. while (loc[strlen("duration")+2+c] != ',')
  7409. {
  7410. sstr[c] = loc[strlen("duration")+2+c];
  7411. c++;
  7412. }
  7413. sstr[c] = '\0';
  7414. durationInt = atoi(sstr);
  7415. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7416. {
  7417. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7418. }
  7419. else
  7420. {
  7421. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7422. }
  7423. }
  7424. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7425. //*********************startSchedule***************************/
  7426. loc = strstr(payload, "startSchedule");
  7427. if(loc != NULL)
  7428. {
  7429. c = 0;
  7430. memset(sstr ,0, sizeof(sstr) );
  7431. while (loc[3+strlen("startSchedule")+c] != '\"')
  7432. {
  7433. sstr[c] = loc[3+strlen("startSchedule")+c];
  7434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7435. c++;
  7436. }
  7437. sstr[c] = '\0';
  7438. strcpy(startScheduleStr,sstr);
  7439. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7440. {
  7441. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7442. }
  7443. else
  7444. {
  7445. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7446. }
  7447. }
  7448. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7449. //*********************chargingRateUnit***************************/
  7450. loc = strstr(payload, "chargingRateUnit");
  7451. if(loc != NULL)
  7452. {
  7453. c = 0;
  7454. memset(sstr ,0, sizeof(sstr) );
  7455. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7456. {
  7457. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7458. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7459. c++;
  7460. }
  7461. sstr[c] = '\0';
  7462. strcpy(chargingRateUnitStr,sstr);
  7463. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7464. {
  7465. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7466. }
  7467. else
  7468. {
  7469. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7470. }
  7471. }
  7472. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7473. //****************chargingSchedulePeriod count start*******************/
  7474. int what_len = strlen("startPeriod");
  7475. char *where = payload;
  7476. if (what_len)
  7477. while ((where = strstr(where, "startPeriod"))) {
  7478. where += what_len;
  7479. chargingSchedulePeriodCount++;
  7480. }
  7481. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7482. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7483. where = payload;
  7484. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7485. {
  7486. //****************startPeriod*******************/
  7487. c=0;
  7488. loc = strstr(where, "startPeriod");
  7489. memset(sstr ,0, sizeof(sstr) );
  7490. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7491. {
  7492. sstr[c] = loc[strlen("startPeriod")+2+c];
  7493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7494. c++;
  7495. }
  7496. sstr[c] = '\0';
  7497. startPeriodInt[periodNums] = atoi(sstr);
  7498. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7499. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7500. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7501. {
  7502. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7503. }
  7504. else
  7505. {
  7506. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7507. }
  7508. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7509. //****************limit*******************/
  7510. c=0;
  7511. loc = strstr(where, "limit");
  7512. memset(sstr ,0, sizeof(sstr) );
  7513. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7514. {
  7515. sstr[c] = loc[strlen("limit")+2+c];
  7516. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7517. c++;
  7518. }
  7519. sstr[c] = '\0';
  7520. limitflaot[periodNums] = atof(sstr);
  7521. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7522. {
  7523. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7524. }
  7525. else
  7526. {
  7527. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7528. }
  7529. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7530. //****************numberPhases*******************/
  7531. loc = strstr(where, "numberPhases");
  7532. if(loc != NULL)
  7533. {
  7534. c=0;
  7535. memset(sstr ,0, sizeof(sstr) );
  7536. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7537. {
  7538. sstr[c] = loc[strlen("numberPhases")+2+c];
  7539. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7540. c++;
  7541. }
  7542. sstr[c] = '\0';
  7543. numberPhasesInt[periodNums] = atoi(sstr);
  7544. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7545. {
  7546. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7547. }
  7548. else
  7549. {
  7550. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7551. }
  7552. }
  7553. where = loc;
  7554. }
  7555. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7556. //****************chargingSchedulePeriod count end*******************/
  7557. //*********************minChargingRate***************************/
  7558. loc = strstr(payload, "minChargingRate");
  7559. if(loc != NULL)
  7560. {
  7561. c = 0;
  7562. memset(sstr ,0, sizeof(sstr) );
  7563. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7564. {
  7565. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7566. c++;
  7567. }
  7568. sstr[c] = '\0';
  7569. minChargingRateFloat = atof(sstr);
  7570. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7571. {
  7572. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7573. }
  7574. else
  7575. {
  7576. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7577. }
  7578. }
  7579. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7580. DEBUG_INFO("-------------------------------------------------------------\n");
  7581. DEBUG_INFO(" Input the file name to be opened : ");
  7582. //fgets(fname, MAX, stdin);
  7583. //fname[strlen(fname) - 1] = '\0';
  7584. #if 0
  7585. switch(connectorIdInt)
  7586. {
  7587. case 0:
  7588. strcpy(filename, ChargingProfile_0_JSON );
  7589. break;
  7590. case 1:
  7591. strcpy(filename, ChargingProfile_1_JSON );
  7592. break;
  7593. case 2:
  7594. strcpy(filename, ChargingProfile_2_JSON );
  7595. break;
  7596. default:
  7597. strcpy(filename, ChargingProfile_0_JSON );
  7598. break;
  7599. }
  7600. fptr1 = fopen(filename, "r");
  7601. if (!fptr1)
  7602. {
  7603. //file not exist
  7604. DEBUG_INFO("Unable to open the input file!!\n");
  7605. fptr1 = fopen(filename, "w+");
  7606. }
  7607. fclose(fptr1);
  7608. #endif
  7609. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7610. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7611. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7612. {
  7613. //printf("set chargingProfile 1-2\n");
  7614. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7615. if(connectorIdInt != 0)
  7616. {
  7617. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7618. goto end;
  7619. }
  7620. strcpy(filename, ChargePointMaxProfile_JSON );
  7621. fptr1 = fopen(filename, "r");
  7622. if (!fptr1)
  7623. {
  7624. //file not exist
  7625. DEBUG_INFO("Unable to open the input file!!\n");
  7626. fptr1 = fopen(filename, "w+");
  7627. }
  7628. fclose(fptr1);
  7629. }
  7630. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7631. {
  7632. //printf("set chargingProfile 1-3\n");
  7633. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7634. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7635. {
  7636. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7637. goto end;
  7638. }
  7639. switch(connectorIdInt)
  7640. {
  7641. case 0:
  7642. strcpy(filename, TxDefaultProfile_0_JSON );
  7643. break;
  7644. case 1:
  7645. strcpy(filename, TxDefaultProfile_1_JSON );
  7646. break;
  7647. case 2:
  7648. strcpy(filename, TxDefaultProfile_2_JSON );
  7649. break;
  7650. default:
  7651. strcpy(filename, TxDefaultProfile_0_JSON );
  7652. break;
  7653. }
  7654. fptr1 = fopen(filename, "r");
  7655. if (!fptr1)
  7656. {
  7657. //file not exist
  7658. DEBUG_INFO("Unable to open the input file!!\n");
  7659. fptr1 = fopen(filename, "w+");
  7660. }
  7661. fclose(fptr1);
  7662. }
  7663. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7664. {
  7665. //printf("set chargingProfile 1-4\n");
  7666. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7667. //check Transaction active
  7668. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7669. {
  7670. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7671. {
  7672. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7673. {
  7674. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7675. {
  7676. meet = TRUE;
  7677. break;
  7678. }
  7679. }
  7680. }
  7681. }
  7682. for (int index = 0; index < CCS_QUANTITY; index++)
  7683. {
  7684. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7685. {
  7686. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7687. {
  7688. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7689. {
  7690. meet = TRUE;
  7691. break;
  7692. }
  7693. }
  7694. }
  7695. }
  7696. for (int index = 0; index < GB_QUANTITY; index++)
  7697. {
  7698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7699. {
  7700. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7701. {
  7702. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7703. {
  7704. meet = TRUE;
  7705. break;
  7706. }
  7707. }
  7708. }
  7709. }
  7710. if(meet == FALSE)
  7711. {
  7712. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7713. goto end;
  7714. }
  7715. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7716. {
  7717. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7718. goto end;
  7719. }
  7720. switch(connectorIdInt)
  7721. {
  7722. case 0:
  7723. break;
  7724. case 1:
  7725. strcpy(filename, TxProfile_1_JSON);
  7726. break;
  7727. case 2:
  7728. strcpy(filename, TxProfile_2_JSON);
  7729. break;
  7730. default:
  7731. strcpy(filename, TxProfile_1_JSON);
  7732. break;
  7733. }
  7734. fptr1 = fopen(filename, "r");
  7735. if (!fptr1)
  7736. {
  7737. //file not exist
  7738. DEBUG_INFO("Unable to open the input file!!\n");
  7739. fptr1 = fopen(filename, "w+");
  7740. }
  7741. fclose(fptr1);
  7742. }
  7743. //**********************************Write to File********************************************************/
  7744. FILE *infile;
  7745. FILE *outfile;
  7746. // open file for writing
  7747. infile = fopen (filename, "r");
  7748. outfile = fopen (tempfile, "w");
  7749. int d =0;
  7750. d = fgetc(infile);
  7751. DEBUG_INFO("d:%d\n",d);
  7752. rewind(infile);
  7753. //*检测到文件结束标识返回1,否则返回0。*/
  7754. if(d == EOF)
  7755. {
  7756. DEBUG_INFO("ChargingProfile content is NULL\n");
  7757. fprintf(outfile,"[%s]\n",payload);
  7758. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7759. fclose(infile);
  7760. fclose(outfile);
  7761. sprintf(rmFileCmd,"rm -f %s",filename);
  7762. system(rmFileCmd);
  7763. resultRename = rename(tempfile, filename);
  7764. if(resultRename == 0)
  7765. {
  7766. DEBUG_INFO("File chargingProfile renamed successfully");
  7767. }
  7768. else
  7769. {
  7770. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7771. }
  7772. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7773. //system(rmFileCmd);
  7774. }
  7775. else
  7776. {
  7777. char buf[1000]={0};
  7778. while (fgets(buf, sizeof(buf), infile) != NULL)
  7779. {
  7780. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7781. //*************************tempconnectorIdInt*********************************/
  7782. loc = strstr(buf, "connectorId");
  7783. c = 0;
  7784. memset(sstr ,0, sizeof(sstr) );
  7785. while (loc[strlen("connectorId")+2+c] != ',')
  7786. {
  7787. sstr[c] = loc[strlen("connectorId")+2+c];
  7788. c++;
  7789. }
  7790. sstr[c] = '\0';
  7791. tempconnectorIdInt = atoi(sstr);
  7792. //*************************tempchargingProfileIdInt*********************************/
  7793. loc = strstr(buf, "chargingProfileId");
  7794. c = 0;
  7795. memset(sstr ,0, sizeof(sstr) );
  7796. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7797. {
  7798. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7799. c++;
  7800. }
  7801. sstr[c] = '\0';
  7802. tempchargingProfileIdInt = atoi(sstr);
  7803. //*************************tempstackLevelInt*********************************/
  7804. loc = strstr(buf, "stackLevel");
  7805. c = 0;
  7806. memset(sstr ,0, sizeof(sstr) );
  7807. while (loc[strlen("stackLevel")+2+c] != ',')
  7808. {
  7809. sstr[c] = loc[strlen("stackLevel")+2+c];
  7810. c++;
  7811. }
  7812. sstr[c] = '\0';
  7813. tempstackLevelInt = atoi(sstr);
  7814. //*************************tempchargingProfilePurposeStr*********************************/
  7815. loc = strstr(payload, "chargingProfilePurpose");
  7816. c = 0;
  7817. memset(sstr ,0, sizeof(sstr) );
  7818. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7819. {
  7820. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7821. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7822. c++;
  7823. }
  7824. sstr[c] = '\0';
  7825. strcpy(tempchargingProfilePurposeStr,sstr);
  7826. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7827. {
  7828. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7829. {
  7830. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7831. fprintf(outfile,"[%s]\n",payload);
  7832. }
  7833. else
  7834. {
  7835. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7836. if(tempstackLevelInt < stackLevelInt)
  7837. {
  7838. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7839. fprintf(outfile,"[%s]\n",payload);
  7840. fprintf(outfile,"[%s]\n",buf);
  7841. }
  7842. else
  7843. {
  7844. fprintf(outfile,"[%s]\n",buf);
  7845. fprintf(outfile,"[%s]\n",payload);
  7846. }
  7847. }
  7848. DEBUG_INFO("update set chargingProfile to file\n");
  7849. }
  7850. else
  7851. {
  7852. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7853. {
  7854. fprintf(outfile,"[%s]\n",payload);
  7855. fprintf(outfile,"[%s]\n",buf);
  7856. }
  7857. else if(tempstackLevelInt < stackLevelInt)
  7858. {
  7859. fprintf(outfile,"[%s]\n",payload);
  7860. fprintf(outfile,"[%s]\n",buf);
  7861. }
  7862. else
  7863. {
  7864. fprintf(outfile,"[%s]\n",buf);
  7865. fprintf(outfile,"[%s]\n",payload);
  7866. }
  7867. fprintf(outfile,"[%s]\n",buf);
  7868. DEBUG_INFO("add set chargingProfile to file\n");
  7869. }
  7870. } // end of while loop
  7871. fclose(infile);
  7872. fclose(outfile);
  7873. sprintf(rmFileCmd,"rm -f %s",filename);
  7874. system(rmFileCmd);
  7875. resultRename = rename(tempfile, filename);
  7876. if(resultRename == 0)
  7877. {
  7878. DEBUG_INFO("File chargingProfile renamed successfully");
  7879. }
  7880. else
  7881. {
  7882. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7883. }
  7884. result = TRUE;
  7885. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7886. }
  7887. end:
  7888. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7889. return result;
  7890. return result;
  7891. }
  7892. int handleTriggerMessageRequest(char *uuid, char *payload)
  7893. {
  7894. mtrace();
  7895. int result = FAIL;
  7896. int connectorIdIsNULL = FALSE;
  7897. int connectorIdInt =0;
  7898. char sstr[40]={0};
  7899. char requestedMessagestr[40]={0};
  7900. char comfirmstr[20]={0};
  7901. int c = 0;
  7902. char *loc;
  7903. DEBUG_INFO("handleTriggerMessageRequest\n");
  7904. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7905. c = 0;
  7906. loc = strstr(payload, "requestedMessage");
  7907. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7908. {
  7909. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7910. c++;
  7911. }
  7912. sstr[c] = '\0';
  7913. strcpy(requestedMessagestr, sstr);
  7914. c = 0;
  7915. loc = strstr(payload, "connectorId");
  7916. if(loc == NULL)
  7917. {
  7918. connectorIdIsNULL = TRUE;
  7919. }
  7920. else
  7921. {
  7922. memset(sstr ,0, sizeof(sstr) );
  7923. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7924. {
  7925. sstr[c] = loc[strlen("connectorId")+2+c];
  7926. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7927. c++;
  7928. }
  7929. sstr[c] = '\0';
  7930. connectorIdInt = atoi(sstr);
  7931. }
  7932. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7933. {
  7934. //connectorIdInt = json_object_get_int(connectorId);
  7935. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7936. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7937. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7938. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7939. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7940. }
  7941. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7942. {
  7943. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7944. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7945. return TRUE;
  7946. }
  7947. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7948. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7949. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7950. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7951. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7952. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7953. {
  7954. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7955. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7956. return TRUE;
  7957. }
  7958. else
  7959. {
  7960. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7961. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7962. }
  7963. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7964. {
  7965. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7966. {
  7967. FirmwareStatusNotificationStatus = 3;
  7968. }
  7969. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7970. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7971. }
  7972. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7973. {
  7974. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7975. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7976. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7977. }
  7978. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7979. {
  7980. sendBootNotificationRequest();
  7981. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7982. }
  7983. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7984. {
  7985. sendHeartbeatRequest(connectorIdInt);
  7986. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7987. }
  7988. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7989. {
  7990. if(connectorIdIsNULL == FALSE)
  7991. {
  7992. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7993. {
  7994. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7995. sendMeterValuesRequest(connectorIdInt -1);
  7996. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7997. }
  7998. }
  7999. else
  8000. {
  8001. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8002. {
  8003. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8004. sendMeterValuesRequest(idx);
  8005. }
  8006. }
  8007. }
  8008. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8009. {
  8010. if(connectorIdIsNULL == FALSE)
  8011. {
  8012. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8013. {
  8014. sendStatusNotificationRequest(connectorIdInt -1);
  8015. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8016. }
  8017. }
  8018. else
  8019. {
  8020. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8021. sendStatusNotificationRequest(idx);
  8022. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8023. }
  8024. }
  8025. return result;
  8026. }
  8027. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8028. {
  8029. mtrace();
  8030. int result = FAIL;
  8031. char sstr[6]={0};
  8032. int connectorIdInt =0;
  8033. char comfirmstr[20]={0};
  8034. int c = 0;
  8035. char *loc;
  8036. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8037. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8038. c = 0;
  8039. loc = strstr(payload, "connectorId");
  8040. memset(sstr ,0, sizeof(sstr) );
  8041. while (loc[strlen("connectorId")+2+c] != '}')
  8042. {
  8043. sstr[c] = loc[strlen("connectorId")+2+c];
  8044. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8045. c++;
  8046. }
  8047. sstr[c] = '\0';
  8048. connectorIdInt = atoi(sstr);
  8049. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8050. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8051. {
  8052. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8053. goto end;
  8054. }
  8055. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8056. {
  8057. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8058. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8059. goto end;
  8060. }
  8061. else
  8062. {
  8063. //check Transaction active
  8064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8065. {
  8066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8067. {
  8068. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8069. {
  8070. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8071. }
  8072. }
  8073. for (int index = 0; index < CCS_QUANTITY; index++)
  8074. {
  8075. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8076. {
  8077. //stop Transaction
  8078. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8079. }
  8080. }
  8081. for (int index = 0; index < GB_QUANTITY; index++)
  8082. {
  8083. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8084. {
  8085. //stop Transaction
  8086. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8087. }
  8088. }
  8089. }
  8090. else
  8091. {
  8092. for (int index = 0; index < AC_QUANTITY; index++)
  8093. {
  8094. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8095. {
  8096. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8097. }
  8098. }
  8099. }// END FOR AC ELSE
  8100. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8101. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8102. result = TRUE;
  8103. return result;
  8104. }
  8105. end:
  8106. //json_object_put(obj); --- remove temporally
  8107. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8108. return result;
  8109. }
  8110. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8111. {
  8112. mtrace();
  8113. int result = FAIL;
  8114. pthread_t t;
  8115. sendUpdateFirmwareConfirmation(uuid);
  8116. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8117. ////pthread_join(t, NULL); //
  8118. pthread_detach(t);
  8119. //sendUpdateFirmwareConfirmation(uuid);
  8120. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8121. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8122. return result;
  8123. }
  8124. void *UpdateFirmwareProcess(void *data)
  8125. {
  8126. mtrace();
  8127. int retriesInt =0, retryIntervalInt=0;
  8128. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8129. int port=0;
  8130. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8131. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8132. //char comfirmstr[20];
  8133. int isSuccess = 0;
  8134. char ftpbuf[200];
  8135. char temp[100];
  8136. char * pch;
  8137. int retriesISNULL=FALSE;
  8138. int retryInterval=FALSE;
  8139. int c = 0;
  8140. //int i = 0;
  8141. char *loc;
  8142. char sstr[300]={ 0 };
  8143. char *str = (char*) data; // ? ?輸入資 ?
  8144. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8145. //***************location **************/
  8146. loc = strstr(str, "location");
  8147. memset(sstr ,0, sizeof(sstr) );
  8148. c = 0;
  8149. while (loc[3+strlen("location")+c] != '\"')
  8150. {
  8151. sstr[c] = loc[3+strlen("location")+c];
  8152. c++;
  8153. }
  8154. sstr[c] = '\0';
  8155. strcpy(locationstr, sstr);
  8156. //***************retries**************/
  8157. c = 0;
  8158. loc = strstr(str, "retries");
  8159. if(loc == NULL)
  8160. {
  8161. retriesISNULL=TRUE;
  8162. }
  8163. else
  8164. {
  8165. memset(sstr ,0, sizeof(sstr) );
  8166. while (loc[strlen("retries")+2+c] != ',')
  8167. {
  8168. sstr[c] = loc[strlen("retries")+2+c];
  8169. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8170. c++;
  8171. }
  8172. sstr[c] = '\0';
  8173. }
  8174. if(retriesISNULL == FALSE)
  8175. {
  8176. retriesInt = atoi(sstr);
  8177. }
  8178. //***************retrieveDate **************/
  8179. loc = strstr(str, "retrieveDate");
  8180. memset(sstr ,0, sizeof(sstr) );
  8181. c = 0;
  8182. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8183. {
  8184. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8185. c++;
  8186. }
  8187. sstr[c] = '\0';
  8188. strcpy(retrieveDatestr, sstr);
  8189. //***************retryInterval **************/
  8190. c = 0;
  8191. loc = strstr(str, "retryInterval");
  8192. memset(sstr ,0, sizeof(sstr) );
  8193. if(loc == NULL)
  8194. {
  8195. retryInterval=TRUE;
  8196. }
  8197. else
  8198. {
  8199. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8200. {
  8201. sstr[c] = loc[strlen("retryInterval")+2+c];
  8202. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8203. c++;
  8204. }
  8205. sstr[c] = '\0';
  8206. }
  8207. if(retryInterval==FALSE)
  8208. {
  8209. retryIntervalInt = atoi(sstr);
  8210. }
  8211. memset(ftppath, 0, sizeof(ftppath));
  8212. memset(path, 0, sizeof(path));
  8213. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8214. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8215. if(strncmp(locationstr,"http", 4) == 0)
  8216. {
  8217. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8218. protocol, host, path);
  8219. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8220. // protocol, user, password, host, path);
  8221. sprintf(ftppath,"/%s", path);
  8222. DEBUG_INFO("protocol =%s\n",protocol);
  8223. DEBUG_INFO("host =%s\n",host);
  8224. DEBUG_INFO("path =%s\n",path);
  8225. DEBUG_INFO("ftppath=%s\n",ftppath);
  8226. int ftppathlen=strlen(ftppath);
  8227. int i=1;
  8228. char filenametemp[50];
  8229. while(i < ftppathlen)
  8230. {
  8231. int len=ftppathlen-i;
  8232. if(ftppath[len]== 47) // '/' ascll code: 47
  8233. {
  8234. DEBUG_INFO("compare '/' all right\n");
  8235. break;
  8236. }
  8237. i=i+1;
  8238. }
  8239. memset(filenametemp, 0, sizeof(filenametemp));
  8240. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8241. filenametemp[i+1] = 0;
  8242. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8243. do{
  8244. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8245. sleep(retryIntervalInt);
  8246. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8247. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8248. if(!isSuccess)
  8249. {
  8250. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8251. }
  8252. else
  8253. {
  8254. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8255. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8256. isUpdateRequest = TRUE;
  8257. }
  8258. }
  8259. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8260. {
  8261. memset(ftpbuf, 0, sizeof(ftpbuf));
  8262. memset(temp, 0, sizeof(temp));
  8263. DEBUG_INFO("locationstr=%s\n",locationstr);
  8264. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8265. int ftppathlen=strlen(ftpbuf);
  8266. int i=1;
  8267. char filenametemp[50];
  8268. while(i < ftppathlen)
  8269. {
  8270. int len=ftppathlen-i;
  8271. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8272. {
  8273. DEBUG_INFO(" compare '/' all right\n");
  8274. break;
  8275. }
  8276. i=i+1;
  8277. }
  8278. memset(filenametemp, 0, sizeof(filenametemp));
  8279. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8280. filenametemp[i+1] = 0;
  8281. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8282. pch=strchr(temp,'@');
  8283. if(pch==NULL)
  8284. {
  8285. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8286. protocol, host, &port, path);
  8287. strcpy(user,"anonymous");
  8288. strcpy(password,"");
  8289. }
  8290. else
  8291. {
  8292. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8293. protocol, user, password, host, &port, path);
  8294. }
  8295. sscanf(host,"%[^/]%s",host1, path1);
  8296. sprintf(ftppath,"%s", path1);
  8297. DEBUG_INFO("protocol =%s\n",protocol);
  8298. DEBUG_INFO("user =%s\n",user);
  8299. DEBUG_INFO("password =%s\n",password);
  8300. DEBUG_INFO("host1 =%s\n",host1);
  8301. DEBUG_INFO("port =%d\n",port);
  8302. DEBUG_INFO("path1 =%s\n",path1);
  8303. DEBUG_INFO("ftppath=%s\n",ftppath);
  8304. //ftpFile(host, user, password, port, ftppath, fname);
  8305. //download firmware pthred
  8306. if(port == 0)
  8307. {
  8308. port = 21;
  8309. }
  8310. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8311. do{
  8312. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8313. sleep(retryIntervalInt);
  8314. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8315. if(!isSuccess)
  8316. {
  8317. //BulldogUtil.sleepMs(interval*1000);
  8318. DEBUG_INFO("Update firmware request and download file fail.\n");
  8319. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8320. }
  8321. else
  8322. {
  8323. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8324. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8325. isUpdateRequest = TRUE;
  8326. }
  8327. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8328. }
  8329. else
  8330. {
  8331. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8332. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8333. }
  8334. pthread_exit(NULL);
  8335. }
  8336. //==========================================
  8337. // Handle server response routine
  8338. //==========================================
  8339. void handleAuthorizeResponse(char *payload, int gun_index)
  8340. {
  8341. mtrace();
  8342. char expiryDatestr[30]={0};
  8343. char parentIdTagstr[20]={0};
  8344. char statusstr[20]={0};
  8345. char expiryDatestrtemp[30]={0};
  8346. char parentIdTagstrtemp[20]={0};
  8347. char IdTagstrtemp[20]={0};
  8348. char statusstrtemp[20]={0};
  8349. int expiryDateISNULL=FALSE;
  8350. int parentIdTagISNULL=FALSE;
  8351. char sstr[160]={ 0 };
  8352. char* filename = AuthorizationCache_JSON;
  8353. char tempfile[] = "../Storage/OCPP/temp.json";
  8354. int c = 0;
  8355. char *loc;
  8356. int resultRename=0;
  8357. int responseIdTagInfoAsZero= 0;
  8358. char rmFileCmd[50]={0};
  8359. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8360. //***********expiryDate*************/
  8361. loc = strstr(payload, "expiryDate");
  8362. memset(sstr ,0, sizeof(sstr) );
  8363. c = 0;
  8364. if(loc == NULL)
  8365. {
  8366. expiryDateISNULL = TRUE;
  8367. }
  8368. else
  8369. {
  8370. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8371. {
  8372. sstr[c] = loc[3+strlen("expiryDate")+c];
  8373. c++;
  8374. }
  8375. sstr[c] = '\0';
  8376. strcpy(expiryDatestr, sstr);
  8377. }
  8378. //***********parentIdTag*************/
  8379. loc = strstr(payload, "parentIdTag");
  8380. memset(sstr ,0, sizeof(sstr) );
  8381. c = 0;
  8382. if(loc == NULL)
  8383. {
  8384. parentIdTagISNULL = TRUE;
  8385. }
  8386. else
  8387. {
  8388. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8389. {
  8390. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8391. c++;
  8392. }
  8393. sstr[c] = '\0';
  8394. strcpy(parentIdTagstr, sstr);
  8395. }
  8396. //***********status*************/
  8397. loc = strstr(payload, "status");
  8398. memset(sstr ,0, sizeof(sstr) );
  8399. c = 0;
  8400. while (loc[3+strlen("status")+c] != '\"')
  8401. {
  8402. sstr[c] = loc[3+strlen("status")+c];
  8403. c++;
  8404. }
  8405. sstr[c] = '\0';
  8406. strcpy(statusstr, sstr);
  8407. //#ifdef SystemLogMessage
  8408. // if(expiryDateISNULL == FALSE)
  8409. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8410. // if(parentIdTagISNULL == FALSE)
  8411. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8412. // DEBUG_INFO("status: %s\n", statusstr);
  8413. //#endif
  8414. if(expiryDateISNULL == FALSE)
  8415. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8416. if(parentIdTagISNULL == FALSE)
  8417. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8418. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8419. //Update idTag information to authorization cache if supproted
  8420. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8421. {
  8422. if((access(filename,F_OK))!=-1)
  8423. {
  8424. DEBUG_INFO("AuthorizationCache exist.\n");
  8425. }
  8426. else
  8427. {
  8428. DEBUG_INFO("AuthorizationCache not exist\n");
  8429. FILE *log = fopen(filename, "w+");
  8430. if(log == NULL)
  8431. {
  8432. DEBUG_INFO("log is NULL\n");
  8433. goto out;
  8434. }
  8435. else
  8436. {
  8437. fclose(log);
  8438. }
  8439. }
  8440. FILE *infile;
  8441. FILE *outfile;
  8442. // open file for writing
  8443. infile = fopen (filename, "r");
  8444. outfile = fopen (tempfile, "w");
  8445. //*检测到文件结束标识返回1,否则返回0。*/
  8446. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8447. int c;
  8448. c = fgetc(infile);
  8449. //DEBUG_INFO("c:%d\n",c);
  8450. rewind(infile);
  8451. if(c == EOF)
  8452. {
  8453. DEBUG_INFO("Orignal File is NULL\n");
  8454. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8455. {
  8456. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8457. }
  8458. else
  8459. {
  8460. strcpy(expiryDatestrtemp, "");
  8461. }
  8462. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8463. {
  8464. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8465. }
  8466. else
  8467. {
  8468. //write Authorize IdTag
  8469. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8470. }
  8471. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8472. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8473. fclose(infile);
  8474. fclose(outfile);
  8475. sprintf(rmFileCmd,"rm -f %s",filename);
  8476. system(rmFileCmd);
  8477. resultRename = rename(tempfile, filename);
  8478. if(resultRename == 0)
  8479. {
  8480. DEBUG_INFO("File renamed successfully");
  8481. }
  8482. else
  8483. {
  8484. DEBUG_INFO("Error: unable to rename the file");
  8485. }
  8486. }
  8487. else
  8488. {
  8489. char buf[160]={0};
  8490. //DEBUG_INFO("Orignal File is not NULL\n");
  8491. while (fgets(buf, sizeof(buf), infile) != NULL)
  8492. {
  8493. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8494. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8495. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8496. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8497. memset(statusstr, 0, sizeof(statusstrtemp));
  8498. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8499. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8500. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8501. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8502. //------------------IdTag-----------------------
  8503. loc = strstr(buf, "idTag");
  8504. memset(sstr ,0, sizeof(sstr) );
  8505. c = 0;
  8506. while (loc[3+strlen("idTag")+c] != '\"')
  8507. {
  8508. sstr[c] = loc[3+strlen("idTag")+c];
  8509. c++;
  8510. }
  8511. sstr[c] = '\0';
  8512. strcpy(IdTagstrtemp,sstr);
  8513. //*********************expiryDate***************/
  8514. loc = strstr(buf, "expiryDate");
  8515. memset(sstr ,0, sizeof(sstr) );
  8516. c = 0;
  8517. while (loc[3+strlen("expiryDate")+c] != '\"')
  8518. {
  8519. sstr[c] = loc[3+strlen("expiryDate")+c];
  8520. c++;
  8521. }
  8522. sstr[c] = '\0';
  8523. strcpy(expiryDatestr,sstr);
  8524. //*********************parentIdTag***************/
  8525. loc = strstr(buf, "parentIdTag");
  8526. memset(sstr ,0, sizeof(sstr) );
  8527. c = 0;
  8528. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8529. {
  8530. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8531. c++;
  8532. }
  8533. sstr[c] = '\0';
  8534. strcpy(parentIdTagstr,sstr);
  8535. //*********************status***************/
  8536. loc = strstr(buf, "status");
  8537. memset(sstr ,0, sizeof(sstr) );
  8538. c = 0;
  8539. while (loc[3+strlen("status")+c] != '\"')
  8540. {
  8541. sstr[c] = loc[3+strlen("status")+c];
  8542. c++;
  8543. }
  8544. sstr[c] = '\0';
  8545. strcpy(statusstr,sstr);
  8546. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8547. {
  8548. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8549. responseIdTagInfoAsZero = 1;
  8550. }
  8551. else
  8552. {
  8553. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8554. }
  8555. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8556. {
  8557. //modify item
  8558. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8559. {
  8560. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8561. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8562. }
  8563. else
  8564. {
  8565. strcpy(expiryDatestrtemp, "");
  8566. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8567. }
  8568. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8569. {
  8570. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8571. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8572. }
  8573. else
  8574. {
  8575. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8576. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8577. }
  8578. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8579. }
  8580. else
  8581. {
  8582. //wrie original item
  8583. strcpy(expiryDatestrtemp, expiryDatestr);
  8584. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8585. strcpy(statusstrtemp, statusstr);
  8586. }
  8587. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8588. }
  8589. fclose(infile);
  8590. fclose(outfile);
  8591. sprintf(rmFileCmd,"rm -f %s",filename);
  8592. system(rmFileCmd);
  8593. resultRename = rename(tempfile, filename);
  8594. if(resultRename == 0)
  8595. {
  8596. DEBUG_INFO("File renamed successfully");
  8597. }
  8598. else
  8599. {
  8600. DEBUG_INFO("Error: unable to rename the file");
  8601. }
  8602. }
  8603. }
  8604. out:
  8605. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8606. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8607. authorizeRetryTimes = 0;
  8608. }
  8609. void handleBootNotificationResponse(char *payload, int gun_index)
  8610. {
  8611. mtrace();
  8612. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8613. char statusStr[12]={0};
  8614. char currentTimeStr[30]={0};
  8615. char *loc;
  8616. int intervalInt = 0;
  8617. int c = 0;
  8618. //double diff_t;
  8619. struct tm tp;
  8620. char buf[28]={0};
  8621. char timebuf[50]={0};
  8622. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8623. //*** interval ****/
  8624. c = 0;
  8625. loc = strstr(payload, "interval");
  8626. //printf("loc=%s\n",loc);
  8627. memset(sstr ,0, sizeof(sstr) );
  8628. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8629. {
  8630. sstr[c] = loc[strlen("interval")+2+c];
  8631. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8632. c++;
  8633. }
  8634. sstr[c] = '\0';
  8635. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8636. intervalInt = atoi(sstr);
  8637. //***status ****/
  8638. loc = strstr(payload, "status");
  8639. memset(sstr ,0, sizeof(sstr) );
  8640. c = 0;
  8641. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8642. {
  8643. sstr[c] = loc[3+strlen("status")+c];
  8644. c++;
  8645. }
  8646. sstr[c] = '\0';
  8647. strcpy(statusStr, sstr);
  8648. //***currentTime ****/
  8649. loc = strstr(payload, "currentTime");
  8650. //printf("loc=%s\n",loc);
  8651. memset(sstr ,0, sizeof(sstr) );
  8652. c = 0;
  8653. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8654. {
  8655. sstr[c] = loc[3+strlen("currentTime")+c];
  8656. c++;
  8657. }
  8658. sstr[c] = '\0';
  8659. strcpy(currentTimeStr, sstr);
  8660. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8661. HeartBeatWaitTime = BootNotificationInterval;
  8662. //#ifdef SystemLogMessage
  8663. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8664. // DEBUG_INFO("interval: %d\n", intervalInt);
  8665. // DEBUG_INFO("status: %s\n", statusStr);
  8666. //#endif
  8667. //write back to ShmOCPP16Data->BootNotification
  8668. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8669. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8670. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8671. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8672. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8673. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8674. {
  8675. server_sign = TRUE;
  8676. server_pending =FALSE;
  8677. }
  8678. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8679. {
  8680. server_pending = TRUE;
  8681. }
  8682. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8683. tp.tm_isdst = -1;
  8684. //time_t utc = mktime(&tp);
  8685. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8686. memset(timebuf, 0, sizeof timebuf);
  8687. sprintf(timebuf,"date -s '%s'",buf);
  8688. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8689. system(timebuf);
  8690. //==============================================
  8691. // RTC sync
  8692. //==============================================
  8693. system("/sbin/hwclock -w --systohc");
  8694. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8695. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8696. }
  8697. void handleDataTransferResponse(char *payload, int gun_index)
  8698. {
  8699. char sstr[160]={0};//sstr[200]={ 0 };
  8700. int c = 0;
  8701. char *loc;
  8702. DEBUG_INFO("handleDataTransferResponse ...\n");
  8703. loc = strstr(payload, "status");
  8704. printf("loc=%s\n",loc);
  8705. c = 0;
  8706. while (loc[3+strlen("status")+c] != '\"')
  8707. {
  8708. sstr[c] = loc[3+strlen("status")+c];
  8709. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8710. c++;
  8711. }
  8712. sstr[c] = '\0';
  8713. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8714. //#ifdef SystemLogMessage
  8715. //DEBUG_INFO("data: %s\n", payload);
  8716. //#endif
  8717. }
  8718. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8719. {
  8720. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8721. //struct json_object *obj;
  8722. // obj = json_tokener_parse(payload);
  8723. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8724. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8725. //No fields are defined.
  8726. }
  8727. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8728. {
  8729. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8730. //struct json_object *obj;
  8731. // obj = json_tokener_parse(payload);
  8732. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8733. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8734. //No fields are defined.
  8735. }
  8736. void handleHeartbeatResponse(char *payload, int gun_index)
  8737. {
  8738. mtrace();
  8739. //double diff_t;
  8740. struct tm tp;
  8741. char buf[28]={0};
  8742. char timebuf[50]={0};
  8743. char sstr[30]={ 0 };
  8744. int c = 0;
  8745. char *loc;
  8746. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8747. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8748. c = 0;
  8749. loc = strstr(payload, "currentTime");
  8750. memset(sstr ,0, sizeof(sstr) );
  8751. while (loc[3+strlen("currentTime")+c] != '\"')
  8752. {
  8753. sstr[c] = loc[3+strlen("currentTime")+c];
  8754. c++;
  8755. }
  8756. sstr[c] = '\0';
  8757. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8758. // #ifdef SystemLogMessage
  8759. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8760. // #endif
  8761. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8762. tp.tm_isdst = -1;
  8763. //time_t utc = mktime(&tp);
  8764. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8765. memset(timebuf, 0, sizeof timebuf);
  8766. sprintf(timebuf,"date -s '%s'",buf);
  8767. system(timebuf);
  8768. //==============================================
  8769. // RTC sync
  8770. //==============================================
  8771. system("/sbin/hwclock -w --systohc");
  8772. if(FirstHeartBeat == 0)
  8773. {
  8774. FirstHeartBeat = 1;
  8775. }
  8776. HeartBeatWithNOResponse = 0;
  8777. }
  8778. void handleMeterValuesResponse(char *payload, int gun_index)
  8779. {
  8780. mtrace();
  8781. //struct json_object *obj;
  8782. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8783. //No fields are defined.
  8784. }
  8785. void handleStartTransactionResponse(char *payload, int gun_index)
  8786. {
  8787. mtrace();
  8788. char sstr[28]={ 0 };
  8789. int c = 0;
  8790. char *loc;
  8791. int transactionIdInt = 0;
  8792. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8793. DEBUG_INFO("handleStartTransactionResponse\n");
  8794. //****************expiryDate********************/
  8795. loc = strstr(payload, "expiryDate");
  8796. if(loc == NULL)
  8797. {
  8798. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8799. }
  8800. else
  8801. {
  8802. c = 0;
  8803. memset(sstr ,0, sizeof(sstr) );
  8804. while (loc[3+strlen("expiryDate")+c] != '\"')
  8805. {
  8806. sstr[c] = loc[3+strlen("expiryDate")+c];
  8807. c++;
  8808. }
  8809. sstr[c] = '\0';
  8810. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8811. }
  8812. //****************parentIdTag********************/
  8813. loc = strstr(payload, "parentIdTag");
  8814. if(loc == NULL)
  8815. {
  8816. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8817. }
  8818. else
  8819. {
  8820. c = 0;
  8821. memset(sstr ,0, sizeof(sstr) );
  8822. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8823. {
  8824. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8825. c++;
  8826. }
  8827. sstr[c] = '\0';
  8828. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8829. }
  8830. //****************status********************/
  8831. loc = strstr(payload, "status");
  8832. if(loc == NULL)
  8833. {
  8834. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8835. }
  8836. else
  8837. {
  8838. c = 0;
  8839. memset(sstr ,0, sizeof(sstr) );
  8840. while (loc[3+strlen("status")+c] != '\"')
  8841. {
  8842. sstr[c] = loc[3+strlen("status")+c];
  8843. c++;
  8844. }
  8845. sstr[c] = '\0';
  8846. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8847. }
  8848. //****************transactionId********************/
  8849. c=0;
  8850. loc = strstr(payload, "transactionId");
  8851. memset(sstr ,0, sizeof(sstr) );
  8852. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8853. {
  8854. sstr[c] = loc[strlen("transactionId")+2+c];
  8855. c++;
  8856. }
  8857. sstr[c] = '\0';
  8858. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8859. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8860. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8861. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8862. #ifdef SystemLogMessage
  8863. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8864. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8865. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8866. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8867. #endif
  8868. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8869. {
  8870. //add Charging Record
  8871. SettingChargingRecord(gun_index, transactionIdInt);
  8872. }
  8873. DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8874. }
  8875. void handleStatusNotificationResponse(char *payload, int gun_index)
  8876. {
  8877. mtrace();
  8878. printf("handleStatusNotificationResponse\n");
  8879. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8880. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8881. }
  8882. void handleStopTransactionnResponse(char *payload, int gun_index)
  8883. {
  8884. mtrace();
  8885. char sstr[30]={ 0 };
  8886. int c = 0;
  8887. char *loc;
  8888. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8889. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8890. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8891. loc = strstr(payload, "idTagInfo");
  8892. //***********************idTagInfo************************/
  8893. if(loc != NULL)
  8894. {
  8895. //***********************expiryDate************************/
  8896. loc = strstr(payload, "expiryDate");
  8897. if(loc != NULL)
  8898. {
  8899. memset(sstr ,0, sizeof(sstr) );
  8900. c = 0;
  8901. while (loc[3+strlen("expiryDate")+c] != '\"')
  8902. {
  8903. sstr[c] = loc[3+strlen("expiryDate")+c];
  8904. c++;
  8905. }
  8906. sstr[c] = '\0';
  8907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8908. }
  8909. //***********************parentIdTag************************/
  8910. loc = strstr(payload, "parentIdTag");
  8911. if(loc != NULL)
  8912. {
  8913. memset(sstr ,0, sizeof(sstr) );
  8914. c = 0;
  8915. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8916. {
  8917. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8918. c++;
  8919. }
  8920. sstr[c] = '\0';
  8921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8922. }
  8923. //***********************status************************/
  8924. loc = strstr(payload, "status");
  8925. memset(sstr ,0, sizeof(sstr) );
  8926. c = 0;
  8927. while (loc[3+strlen("status")+c] != '\"')
  8928. {
  8929. sstr[c] = loc[3+strlen("status")+c];
  8930. c++;
  8931. }
  8932. sstr[c] = '\0';
  8933. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8934. }
  8935. #ifdef SystemLogMessage
  8936. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8937. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8938. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8939. #endif
  8940. }
  8941. //==========================================
  8942. // Handle Error routine
  8943. //==========================================
  8944. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8945. {
  8946. mtrace();
  8947. #ifdef SystemLogMessage
  8948. DEBUG_INFO("errorCode: %s\n", errorCode);
  8949. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8950. DEBUG_INFO("errorDetails: %s\n", payload);
  8951. #endif
  8952. }
  8953. //===============================================
  8954. // Common routine
  8955. //===============================================
  8956. int initialConfigurationTable(void)
  8957. {
  8958. printf("initialConfigurationTable \n");
  8959. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8960. /*Core Profile*/
  8961. //AllowOfflineTxForUnknownId
  8962. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8963. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8966. //AuthorizationCacheEnabled
  8967. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8970. //AuthorizeRemoteTxRequests
  8971. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8974. //BlinkRepeat
  8975. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8978. //ClockAlignedDataInterval
  8979. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8982. //ConnectionTimeOut
  8983. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8986. //GetConfigurationMaxKeys
  8987. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8990. // HeartbeatInterval
  8991. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8994. // LightIntensity
  8995. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8998. // LocalAuthorizeOffline
  8999. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9002. // LocalPreAuthorize
  9003. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9006. // MaxEnergyOnInvalidId
  9007. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9010. // MeterValuesAlignedData
  9011. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9014. // MeterValuesAlignedDataMaxLength
  9015. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9018. // MeterValuesSampledData
  9019. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9022. // MeterValuesSampledDataMaxLength
  9023. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9026. // MeterValueSampleInterval
  9027. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9030. // MinimumStatusDuration
  9031. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9034. // NumberOfConnectors
  9035. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9038. // ResetRetries
  9039. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9042. // ConnectorPhaseRotation
  9043. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  9046. // ConnectorPhaseRotationMaxLength
  9047. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9050. // StopTransactionOnEVSideDisconnect
  9051. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9054. // StopTransactionOnInvalidId
  9055. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9058. // StopTxnAlignedData
  9059. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9062. // StopTxnAlignedDataMaxLength
  9063. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9066. // StopTxnSampledData
  9067. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9070. // StopTxnSampledDataMaxLength
  9071. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9074. // SupportedFeatureProfiles
  9075. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9078. // SupportedFeatureProfilesMaxLength
  9079. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9082. // TransactionMessageAttempts
  9083. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9086. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9087. // TransactionMessageRetryInterval
  9088. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9091. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9092. // UnlockConnectorOnEVSideDisconnect
  9093. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9096. // WebSocketPingInterval
  9097. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9100. //* Local Auth List Management Profile*/
  9101. #if 0
  9102. //For OCTT Test Case
  9103. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9106. #endif
  9107. #if 1
  9108. //LocalAuthListEnabled
  9109. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9112. #endif
  9113. //LocalAuthListMaxLength
  9114. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9117. //SendLocalListMaxLength
  9118. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9121. //ReserveConnectorZeroSupported
  9122. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9125. //* Smart Charging Profile */
  9126. //ChargeProfileMaxStackLevel
  9127. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9130. // ChargingScheduleAllowedChargingRateUnit
  9131. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9134. // ChargingScheduleMaxPeriods
  9135. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9138. // ConnectorSwitch3to1PhaseSupported
  9139. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9142. // MaxChargingProfilesInstalled
  9143. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9146. return 0;
  9147. }
  9148. void getKeyValue(char *keyReq)
  9149. {
  9150. int isEmpty = FALSE;
  9151. int isKnowKey = FALSE;
  9152. //int unKnowIndex = 0;
  9153. DEBUG_INFO("getKeyValue \n");
  9154. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9155. isEmpty = TRUE;
  9156. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9157. {
  9158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9161. {
  9162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9163. }
  9164. else
  9165. {
  9166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9167. }
  9168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9169. isKnowKey = TRUE;
  9170. }
  9171. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9172. {
  9173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9176. {
  9177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9178. }
  9179. else
  9180. {
  9181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9182. }
  9183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9184. isKnowKey = TRUE;
  9185. }
  9186. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9187. {
  9188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9191. {
  9192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9193. }
  9194. else
  9195. {
  9196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9197. }
  9198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9199. isKnowKey = TRUE;
  9200. }
  9201. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9202. {
  9203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9206. {
  9207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9208. }
  9209. else
  9210. {
  9211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9212. }
  9213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9214. isKnowKey = TRUE;
  9215. }
  9216. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9217. {
  9218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9221. {
  9222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9223. }
  9224. else
  9225. {
  9226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9227. }
  9228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9229. isKnowKey = TRUE;
  9230. }
  9231. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9232. {
  9233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9236. {
  9237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9238. }
  9239. else
  9240. {
  9241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9242. }
  9243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9244. isKnowKey = TRUE;
  9245. }
  9246. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9247. {
  9248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9251. {
  9252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9253. }
  9254. else
  9255. {
  9256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9257. }
  9258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9259. isKnowKey = TRUE;
  9260. }
  9261. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9262. {
  9263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9266. {
  9267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9268. }
  9269. else
  9270. {
  9271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9272. }
  9273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9274. isKnowKey = TRUE;
  9275. }
  9276. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9277. {
  9278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9281. {
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9283. }
  9284. else
  9285. {
  9286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9287. }
  9288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9289. isKnowKey = TRUE;
  9290. }
  9291. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9292. {
  9293. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9296. {
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9298. }
  9299. else
  9300. {
  9301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9302. }
  9303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9304. isKnowKey = TRUE;
  9305. }
  9306. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9307. {
  9308. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9311. {
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9313. }
  9314. else
  9315. {
  9316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9317. }
  9318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9319. isKnowKey = TRUE;
  9320. }
  9321. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9322. {
  9323. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9326. {
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9328. }
  9329. else
  9330. {
  9331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9332. }
  9333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9334. isKnowKey = TRUE;
  9335. }
  9336. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9337. {
  9338. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9341. {
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9343. }
  9344. else
  9345. {
  9346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9347. }
  9348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9349. isKnowKey = TRUE;
  9350. }
  9351. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9352. {
  9353. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9356. {
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9358. }
  9359. else
  9360. {
  9361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9362. }
  9363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9364. isKnowKey = TRUE;
  9365. }
  9366. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9367. {
  9368. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9371. {
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9373. }
  9374. else
  9375. {
  9376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9377. }
  9378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9379. isKnowKey = TRUE;
  9380. }
  9381. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9382. {
  9383. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9388. }
  9389. else
  9390. {
  9391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9392. }
  9393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9394. isKnowKey = TRUE;
  9395. }
  9396. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9397. {
  9398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9401. {
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9403. }
  9404. else
  9405. {
  9406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9407. }
  9408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9409. isKnowKey = TRUE;
  9410. }
  9411. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9412. {
  9413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9418. }
  9419. else
  9420. {
  9421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9422. }
  9423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9424. isKnowKey = TRUE;
  9425. }
  9426. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9427. {
  9428. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9433. }
  9434. else
  9435. {
  9436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9437. }
  9438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9439. isKnowKey = TRUE;
  9440. }
  9441. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9442. {
  9443. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9445. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9446. {
  9447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9448. }
  9449. else
  9450. {
  9451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9452. }
  9453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9454. isKnowKey = TRUE;
  9455. }
  9456. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9457. {
  9458. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9461. {
  9462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9463. }
  9464. else
  9465. {
  9466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9467. }
  9468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9469. isKnowKey = TRUE;
  9470. }
  9471. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9472. {
  9473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9476. {
  9477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9478. }
  9479. else
  9480. {
  9481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9482. }
  9483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9484. isKnowKey = TRUE;
  9485. }
  9486. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9487. {
  9488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9491. {
  9492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9493. }
  9494. else
  9495. {
  9496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9497. }
  9498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9499. isKnowKey = TRUE;
  9500. }
  9501. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9502. {
  9503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9506. {
  9507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9508. }
  9509. else
  9510. {
  9511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9512. }
  9513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9514. isKnowKey = TRUE;
  9515. }
  9516. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9517. {
  9518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9521. {
  9522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9523. }
  9524. else
  9525. {
  9526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9527. }
  9528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9529. isKnowKey = TRUE;
  9530. }
  9531. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9532. {
  9533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9536. {
  9537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9538. }
  9539. else
  9540. {
  9541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9542. }
  9543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9544. isKnowKey = TRUE;
  9545. }
  9546. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9547. {
  9548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9551. {
  9552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9553. }
  9554. else
  9555. {
  9556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9557. }
  9558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9559. isKnowKey = TRUE;
  9560. }
  9561. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9562. {
  9563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9566. {
  9567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9568. }
  9569. else
  9570. {
  9571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9572. }
  9573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9574. isKnowKey = TRUE;
  9575. }
  9576. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9577. {
  9578. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9581. {
  9582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9583. }
  9584. else
  9585. {
  9586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9587. }
  9588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9589. isKnowKey = TRUE;
  9590. }
  9591. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9592. {
  9593. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9596. {
  9597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9598. }
  9599. else
  9600. {
  9601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9602. }
  9603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9604. isKnowKey = TRUE;
  9605. }
  9606. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9607. {
  9608. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9611. {
  9612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9613. }
  9614. else
  9615. {
  9616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9617. }
  9618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9619. isKnowKey = TRUE;
  9620. }
  9621. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9622. {
  9623. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9626. {
  9627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9628. }
  9629. else
  9630. {
  9631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9632. }
  9633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9634. isKnowKey = TRUE;
  9635. }
  9636. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9637. {
  9638. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9641. {
  9642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9643. }
  9644. else
  9645. {
  9646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9647. }
  9648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9649. isKnowKey = TRUE;
  9650. }
  9651. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9652. {
  9653. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9656. {
  9657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9658. }
  9659. else
  9660. {
  9661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9662. }
  9663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9664. isKnowKey = TRUE;
  9665. }
  9666. #if 0
  9667. //For OCTT Test Case
  9668. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9669. {
  9670. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9672. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9673. {
  9674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9675. }
  9676. else
  9677. {
  9678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9679. }
  9680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9681. isKnowKey = TRUE;
  9682. }
  9683. #endif
  9684. #if 1
  9685. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9686. {
  9687. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9689. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9690. {
  9691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9692. }
  9693. else
  9694. {
  9695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9696. }
  9697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9698. isKnowKey = TRUE;
  9699. }
  9700. #endif
  9701. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9702. {
  9703. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9705. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9706. {
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9708. }
  9709. else
  9710. {
  9711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9712. }
  9713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9714. isKnowKey = TRUE;
  9715. }
  9716. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9717. {
  9718. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9720. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9721. {
  9722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9723. }
  9724. else
  9725. {
  9726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9727. }
  9728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9729. isKnowKey = TRUE;
  9730. }
  9731. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9732. {
  9733. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9735. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9736. {
  9737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9738. }
  9739. else
  9740. {
  9741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9742. }
  9743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9744. isKnowKey = TRUE;
  9745. }
  9746. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9747. {
  9748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9750. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9751. {
  9752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9753. }
  9754. else
  9755. {
  9756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9757. }
  9758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9759. isKnowKey = TRUE;
  9760. }
  9761. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9762. {
  9763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9765. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9766. {
  9767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9768. }
  9769. else
  9770. {
  9771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9772. }
  9773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9774. isKnowKey = TRUE;
  9775. }
  9776. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9777. {
  9778. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9780. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9781. {
  9782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9783. }
  9784. else
  9785. {
  9786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9787. }
  9788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9789. isKnowKey = TRUE;
  9790. }
  9791. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9792. {
  9793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9795. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9796. {
  9797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9798. }
  9799. else
  9800. {
  9801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9802. }
  9803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9804. isKnowKey = TRUE;
  9805. }
  9806. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9807. {
  9808. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9810. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9811. {
  9812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9813. }
  9814. else
  9815. {
  9816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9817. }
  9818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9819. isKnowKey = TRUE;
  9820. }
  9821. //=========================================================
  9822. if(!isEmpty && !isKnowKey)
  9823. {
  9824. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9825. strcpy(unknownkey[UnknownKeynum], keyReq);
  9826. UnknownKeynum = UnknownKeynum + 1;
  9827. }
  9828. }
  9829. void processUnkownKey(void)
  9830. {
  9831. DEBUG_INFO("processUnkownKey\n");
  9832. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9833. for(int index=0; index < UnknownKeynum; index++)
  9834. {
  9835. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9836. {
  9837. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9838. }
  9839. }
  9840. }
  9841. int setKeyValue(char *key, char *value)
  9842. {
  9843. int isSuccess = NotSupported;
  9844. int check_ascii=0;
  9845. #ifdef Debug
  9846. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9847. #endif
  9848. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9849. {
  9850. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9852. {
  9853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9854. isSuccess = ConfigurationStatus_Accepted;
  9855. }
  9856. else
  9857. {
  9858. isSuccess = ConfigurationStatus_Rejected;
  9859. }
  9860. }
  9861. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9862. {
  9863. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9865. {
  9866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9867. isSuccess = ConfigurationStatus_Accepted;
  9868. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9869. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9870. }
  9871. else
  9872. {
  9873. isSuccess = ConfigurationStatus_Rejected;
  9874. }
  9875. }
  9876. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9877. {
  9878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9879. {
  9880. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9882. isSuccess = ConfigurationStatus_Accepted;
  9883. }
  9884. else
  9885. {
  9886. isSuccess = ConfigurationStatus_Rejected;
  9887. }
  9888. }
  9889. if(strcmp(key, "BlinkRepeat") == 0)
  9890. {
  9891. //Charger.BlinkRepeat = Integer.parseInt(value);
  9892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9893. {
  9894. check_ascii = value[0];
  9895. if( (check_ascii < 48) || (check_ascii > 57) )
  9896. {
  9897. isSuccess = ConfigurationStatus_Rejected;
  9898. }
  9899. else
  9900. {
  9901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9902. isSuccess = ConfigurationStatus_Accepted;
  9903. }
  9904. }
  9905. else
  9906. {
  9907. isSuccess = ConfigurationStatus_Rejected;
  9908. }
  9909. }
  9910. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9911. {
  9912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9913. {
  9914. check_ascii = value[0];
  9915. if( (check_ascii < 48) || (check_ascii > 57) )
  9916. {
  9917. isSuccess = ConfigurationStatus_Rejected;
  9918. }
  9919. else
  9920. {
  9921. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9923. isSuccess = ConfigurationStatus_Accepted;
  9924. }
  9925. }
  9926. else
  9927. {
  9928. isSuccess = ConfigurationStatus_Rejected;
  9929. }
  9930. }
  9931. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9932. {
  9933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9934. {
  9935. check_ascii = value[0];
  9936. if( (check_ascii < 48) || (check_ascii > 57) )
  9937. {
  9938. isSuccess = ConfigurationStatus_Rejected;
  9939. }
  9940. else
  9941. {
  9942. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9944. isSuccess = ConfigurationStatus_Accepted;
  9945. }
  9946. }
  9947. else
  9948. {
  9949. isSuccess = ConfigurationStatus_Rejected;
  9950. }
  9951. }
  9952. if(strcmp(key, "HeartbeatInterval") == 0)
  9953. {
  9954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9955. {
  9956. check_ascii = value[0];
  9957. if( (check_ascii < 48) || (check_ascii > 57) )
  9958. {
  9959. isSuccess = ConfigurationStatus_Rejected;
  9960. }
  9961. else
  9962. {
  9963. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9965. HeartBeatWaitTime = atoi(value);
  9966. isSuccess = ConfigurationStatus_Accepted;
  9967. }
  9968. }
  9969. else
  9970. {
  9971. isSuccess = ConfigurationStatus_Rejected;
  9972. }
  9973. }
  9974. if(strcmp(key, "LightIntensity") == 0)
  9975. {
  9976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9977. {
  9978. check_ascii = value[0];
  9979. if( (check_ascii < 48) || (check_ascii > 57) )
  9980. {
  9981. isSuccess = ConfigurationStatus_Rejected;
  9982. }
  9983. else
  9984. {
  9985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9986. isSuccess = ConfigurationStatus_Accepted;
  9987. }
  9988. }
  9989. else
  9990. {
  9991. isSuccess = ConfigurationStatus_Rejected;
  9992. }
  9993. }
  9994. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9995. {
  9996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9997. {
  9998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9999. isSuccess = ConfigurationStatus_Accepted;
  10000. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10001. }
  10002. else
  10003. {
  10004. isSuccess = ConfigurationStatus_Rejected;
  10005. }
  10006. }
  10007. if(strcmp(key, "LocalPreAuthorize") == 0)
  10008. {
  10009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10010. {
  10011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10012. isSuccess = ConfigurationStatus_Accepted;
  10013. }
  10014. else
  10015. {
  10016. isSuccess = ConfigurationStatus_Rejected;
  10017. }
  10018. }
  10019. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10020. {
  10021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10022. {
  10023. check_ascii = value[0];
  10024. if( (check_ascii < 48) || (check_ascii > 57) )
  10025. {
  10026. isSuccess = ConfigurationStatus_Rejected;
  10027. }
  10028. else
  10029. {
  10030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10031. isSuccess = ConfigurationStatus_Accepted;
  10032. }
  10033. }
  10034. else
  10035. {
  10036. isSuccess = ConfigurationStatus_Rejected;
  10037. }
  10038. }
  10039. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10040. {
  10041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10042. {
  10043. //int valueLength = strlen(value);
  10044. for(int i = 0; value[i]; i++){
  10045. value[i] = tolower(value[i]);
  10046. }
  10047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10048. isSuccess = ConfigurationStatus_Accepted;
  10049. }
  10050. else
  10051. {
  10052. isSuccess = ConfigurationStatus_Rejected;
  10053. }
  10054. }
  10055. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10056. {
  10057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10058. {
  10059. //int valueLength = strlen(value);
  10060. for(int i = 0; value[i]; i++){
  10061. value[i] = tolower(value[i]);
  10062. }
  10063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10064. isSuccess = ConfigurationStatus_Accepted;
  10065. }
  10066. else
  10067. {
  10068. isSuccess = ConfigurationStatus_Rejected;
  10069. }
  10070. }
  10071. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10072. {
  10073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10074. {
  10075. check_ascii = value[0];
  10076. if( (check_ascii < 48) || (check_ascii > 57) )
  10077. {
  10078. isSuccess = ConfigurationStatus_Rejected;
  10079. }
  10080. else
  10081. {
  10082. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10084. isSuccess = ConfigurationStatus_Accepted;
  10085. }
  10086. #ifdef Debug
  10087. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10088. #endif
  10089. }
  10090. else
  10091. {
  10092. isSuccess = ConfigurationStatus_Rejected;
  10093. #ifdef Debug
  10094. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10095. #endif
  10096. }
  10097. }
  10098. if(strcmp(key, "MinimumStatusDuration") == 0)
  10099. {
  10100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10101. {
  10102. check_ascii = value[0];
  10103. if( (check_ascii < 48) || (check_ascii > 57) )
  10104. {
  10105. isSuccess = ConfigurationStatus_Rejected;
  10106. }
  10107. else
  10108. {
  10109. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10111. isSuccess = ConfigurationStatus_Accepted;
  10112. }
  10113. }
  10114. else
  10115. {
  10116. isSuccess = ConfigurationStatus_Rejected;
  10117. }
  10118. }
  10119. if(strcmp(key, "ResetRetries") == 0)
  10120. {
  10121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10122. {
  10123. check_ascii = value[0];
  10124. if( (check_ascii < 48) || (check_ascii > 57) )
  10125. {
  10126. isSuccess = ConfigurationStatus_Rejected;
  10127. }
  10128. else
  10129. {
  10130. //Charger.ResetRetries = Integer.parseInt(value);
  10131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10132. isSuccess = ConfigurationStatus_Accepted;
  10133. }
  10134. }
  10135. else
  10136. {
  10137. isSuccess = ConfigurationStatus_Rejected;
  10138. }
  10139. }
  10140. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10141. {
  10142. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10143. {
  10144. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10145. //int valueLength = strlen(value);
  10146. for(int i = 0; value[i]; i++){
  10147. value[i] = tolower(value[i]);
  10148. }
  10149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10150. isSuccess = ConfigurationStatus_Accepted;
  10151. }
  10152. else
  10153. {
  10154. isSuccess = ConfigurationStatus_Rejected;
  10155. }
  10156. }
  10157. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10158. {
  10159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10160. {
  10161. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10163. isSuccess = ConfigurationStatus_Accepted;
  10164. }
  10165. else
  10166. {
  10167. isSuccess = ConfigurationStatus_Rejected;
  10168. }
  10169. }
  10170. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10171. {
  10172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10173. {
  10174. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10176. isSuccess = ConfigurationStatus_Accepted;
  10177. }
  10178. else
  10179. {
  10180. isSuccess = ConfigurationStatus_Rejected;
  10181. }
  10182. }
  10183. if(strcmp(key, "StopTxnAlignedData") == 0)
  10184. {
  10185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10186. {
  10187. //Charger.StopTxnAlignedData = value.toLowerCase();
  10188. //int valueLength = strlen(value);
  10189. for(int i = 0; value[i]; i++){
  10190. value[i] = tolower(value[i]);
  10191. }
  10192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10193. isSuccess = ConfigurationStatus_Accepted;
  10194. }
  10195. else
  10196. {
  10197. isSuccess = ConfigurationStatus_Rejected;
  10198. }
  10199. }
  10200. if(strcmp(key, "StopTxnSampledData") == 0)
  10201. {
  10202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10203. {
  10204. //Charger.StopTxnSampledData = value.toLowerCase();
  10205. //int valueLength = strlen(value);
  10206. for(int i = 0; value[i]; i++){
  10207. value[i] = tolower(value[i]);
  10208. }
  10209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10210. isSuccess = ConfigurationStatus_Accepted;
  10211. }
  10212. else
  10213. {
  10214. isSuccess = ConfigurationStatus_Rejected;
  10215. }
  10216. }
  10217. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10218. {
  10219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10220. {
  10221. check_ascii = value[0];
  10222. if( (check_ascii < 48) || (check_ascii > 57) )
  10223. {
  10224. isSuccess = ConfigurationStatus_Rejected;
  10225. }
  10226. else
  10227. {
  10228. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10230. TransactionMessageAttemptsValue = atoi(value);
  10231. isSuccess = ConfigurationStatus_Accepted;
  10232. }
  10233. }
  10234. else
  10235. {
  10236. isSuccess = ConfigurationStatus_Rejected;
  10237. }
  10238. }
  10239. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10240. {
  10241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10242. {
  10243. check_ascii = value[0];
  10244. if( (check_ascii < 48) || (check_ascii > 57) )
  10245. {
  10246. isSuccess = ConfigurationStatus_Rejected;
  10247. }
  10248. else
  10249. {
  10250. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10252. TransactionMessageRetryIntervalValue = atoi(value);
  10253. isSuccess = ConfigurationStatus_Accepted;
  10254. }
  10255. }
  10256. else
  10257. {
  10258. isSuccess = ConfigurationStatus_Rejected;
  10259. }
  10260. }
  10261. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10262. {
  10263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10264. {
  10265. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10267. isSuccess = ConfigurationStatus_Accepted;
  10268. }
  10269. else
  10270. {
  10271. isSuccess = ConfigurationStatus_Rejected;
  10272. }
  10273. }
  10274. if(strcmp(key, "WebSocketPingInterval") == 0)
  10275. {
  10276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10277. {
  10278. check_ascii = value[0];
  10279. if( (check_ascii < 48) || (check_ascii > 57) )
  10280. {
  10281. isSuccess = ConfigurationStatus_Rejected;
  10282. }
  10283. else
  10284. {
  10285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10286. isSuccess = ConfigurationStatus_Accepted;
  10287. }
  10288. }
  10289. else
  10290. {
  10291. isSuccess = ConfigurationStatus_Rejected;
  10292. }
  10293. }
  10294. #if 0
  10295. //For OCPP Test Case
  10296. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10297. {
  10298. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10299. {
  10300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10301. isSuccess = ConfigurationStatus_Accepted;
  10302. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10303. }
  10304. else
  10305. {
  10306. isSuccess = ConfigurationStatus_Rejected;
  10307. }
  10308. }
  10309. #endif
  10310. #if 1
  10311. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10312. {
  10313. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10314. {
  10315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10316. isSuccess = ConfigurationStatus_Accepted;
  10317. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10318. }
  10319. else
  10320. {
  10321. isSuccess = ConfigurationStatus_Rejected;
  10322. }
  10323. }
  10324. #endif
  10325. return isSuccess;
  10326. }
  10327. int updateSetting(char *key, char *value)
  10328. {
  10329. mtrace();
  10330. int isSuccess = FALSE;
  10331. char string[1000]={0}, buffer[1000]={0};
  10332. char strtemp[50]={0};
  10333. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10334. int pos, c = 0;
  10335. char *loc;
  10336. int pos1=0;
  10337. FILE *f = fopen("/var/www/settings1", "r");
  10338. if(f == NULL)
  10339. {
  10340. #ifdef Debug
  10341. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10342. #endif
  10343. return isSuccess;
  10344. }
  10345. fseek(f, 0, SEEK_END);
  10346. long fsize = ftell(f);
  10347. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10348. fread(string, 1, fsize, f);
  10349. fclose(f);
  10350. string[fsize] = 0;
  10351. loc = strstr(string, key);
  10352. if(loc != NULL)
  10353. {
  10354. DEBUG_INFO("key exist!\n");
  10355. pos = loc - string-1;
  10356. f = fopen("/var/www/settings1", "w");
  10357. strncpy(buffer, string, pos);
  10358. fprintf(f, "%s", buffer);
  10359. memset(sstr ,0, sizeof(sstr) );
  10360. c = 0;
  10361. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10362. {
  10363. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10364. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10365. c++;
  10366. }
  10367. sstr[c] = '\0';
  10368. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10369. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10370. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10371. memset(buffer ,0, sizeof(buffer) );
  10372. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10373. //printf("buffer=%s",buffer);
  10374. fprintf(f, "%s", buffer);
  10375. fclose(f);
  10376. }
  10377. else
  10378. {
  10379. printf("key not exist!\n");
  10380. f = fopen("/var/www/settings1", "w+");
  10381. fputs(string, f);
  10382. fseek(f, -1, SEEK_CUR);
  10383. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10384. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10385. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10386. fclose(f);
  10387. }
  10388. isSuccess = TRUE;
  10389. return isSuccess;
  10390. }
  10391. int TransactionMessageAttemptsGet(void)
  10392. {
  10393. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10394. }
  10395. int FirstHeartBeatResponse(void)
  10396. {
  10397. return FirstHeartBeat;
  10398. }
  10399. int TransactionMessageRetryIntervalGet(void)
  10400. {
  10401. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10402. }
  10403. #define SA struct sockaddr
  10404. #define MAXBUF 1024
  10405. //static int m_socket_data;
  10406. //static int sockfd;
  10407. int ReadHttpStatus(int sock){
  10408. //char c;
  10409. char buff[1024]="",*ptr=buff+1;
  10410. int bytes_received, status;
  10411. DEBUG_INFO("Begin Response ..\n");
  10412. while((bytes_received = recv(sock, ptr, 1, 0))){
  10413. if(bytes_received==-1){
  10414. perror("ReadHttpStatus");
  10415. exit(1);
  10416. }
  10417. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10418. ptr++;
  10419. }
  10420. *ptr=0;
  10421. ptr=buff+1;
  10422. sscanf(ptr,"%*s %d ", &status);
  10423. DEBUG_INFO("%s\n",ptr);
  10424. DEBUG_INFO("status=%d\n",status);
  10425. DEBUG_INFO("End Response ..\n");
  10426. return (bytes_received>0)?status:0;
  10427. }
  10428. //the only filed that it parsed is 'Content-Length'
  10429. int ParseHeader(int sock){
  10430. //char c;
  10431. char buff[1024]="",*ptr=buff+4;
  10432. int bytes_received;
  10433. DEBUG_INFO("Begin HEADER ..\n");
  10434. while((bytes_received = recv(sock, ptr, 1, 0))){
  10435. if(bytes_received==-1){
  10436. perror("Parse Header");
  10437. exit(1);
  10438. }
  10439. if(
  10440. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10441. (ptr[-1]=='\r') && (*ptr=='\n' )
  10442. ) break;
  10443. ptr++;
  10444. }
  10445. *ptr=0;
  10446. ptr=buff+4;
  10447. //printf("%s",ptr);
  10448. if(bytes_received){
  10449. ptr=strstr(ptr,"Content-Length:");
  10450. if(ptr){
  10451. sscanf(ptr,"%*s %d",&bytes_received);
  10452. }else
  10453. bytes_received=-1; //unknown size
  10454. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10455. }
  10456. DEBUG_INFO("End HEADER ..\n");
  10457. return bytes_received ;
  10458. }
  10459. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10460. {
  10461. char rmFileCmd[100]={0};
  10462. char FilePath[100]={0};
  10463. char ftpbuf[200];
  10464. int systemresult;
  10465. DEBUG_INFO("filename=%s\n",filename);
  10466. DEBUG_INFO("url=%s\n",url);
  10467. sprintf(FilePath,"../mnt/%s",filename);
  10468. if((access(FilePath,F_OK))!=-1)
  10469. {
  10470. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10471. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10472. system(rmFileCmd);
  10473. }
  10474. memset(ftpbuf, 0, sizeof(ftpbuf));
  10475. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10476. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10477. systemresult = system(ftpbuf);
  10478. DEBUG_INFO("systemresult=%d\n",systemresult);
  10479. if(systemresult != 0)
  10480. {
  10481. DEBUG_INFO("http DownLoad error!\n");
  10482. return FALSE;
  10483. }
  10484. return TRUE;
  10485. }
  10486. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10487. {
  10488. char rmFileCmd[100]={0};
  10489. char FilePath[100]={0};
  10490. char ftpbuf[200];
  10491. int systemresult;
  10492. //char temp[100];
  10493. #if 0
  10494. struct hostent* server;
  10495. char *IPbuffer;
  10496. server = gethostbyname(location);
  10497. // To convert an Internet network
  10498. // address into ASCII string
  10499. IPbuffer = inet_ntoa(*((struct in_addr*)
  10500. server->h_addr_list[0]));
  10501. #endif
  10502. sprintf(FilePath,"../mnt/%s",filename);
  10503. if((access(FilePath,F_OK))!=-1)
  10504. {
  10505. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10506. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10507. system(rmFileCmd);
  10508. }
  10509. memset(ftpbuf, 0, sizeof(ftpbuf));
  10510. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10511. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10512. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10513. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10514. systemresult = system(ftpbuf);
  10515. DEBUG_INFO("systemresult=%d\n",systemresult);
  10516. if(systemresult != 0)
  10517. {
  10518. printf("ftpget error!\n");
  10519. return FALSE;
  10520. }
  10521. return TRUE;
  10522. }
  10523. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10524. {
  10525. struct hostent* server;
  10526. char *IPbuffer;
  10527. char ftpbuf[200];
  10528. int systemresult;
  10529. // To retrieve host information
  10530. server = gethostbyname(location);
  10531. // To convert an Internet network
  10532. // address into ASCII string
  10533. IPbuffer = inet_ntoa(*((struct in_addr*)
  10534. server->h_addr_list[0]));
  10535. memset(ftpbuf, 0, sizeof(ftpbuf));
  10536. /* format : ftpput -u username -p passwd IP target source*/
  10537. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10538. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10539. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10540. systemresult = system(ftpbuf);
  10541. DEBUG_INFO("systemresult=%d\n",systemresult);
  10542. if(systemresult != 0)
  10543. {
  10544. DEBUG_INFO("ftpput error!\n");
  10545. return FALSE;
  10546. }
  10547. return TRUE;
  10548. }
  10549. int SettingChargingRecord(int target, int transactionId)
  10550. {
  10551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10552. {
  10553. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10554. {
  10555. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10556. {
  10557. addBuff(target, transactionId, 0);
  10558. return TRUE;
  10559. }
  10560. }
  10561. for (int index = 0; index < CCS_QUANTITY; index++)
  10562. {
  10563. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10564. {
  10565. addBuff(target, transactionId, 0);
  10566. return TRUE;
  10567. }
  10568. }
  10569. for (int index = 0; index < GB_QUANTITY; index++)
  10570. {
  10571. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10572. {
  10573. addBuff(target, transactionId, 0);
  10574. return TRUE;
  10575. }
  10576. }
  10577. }
  10578. else
  10579. {
  10580. for (int index = 0; index < AC_QUANTITY; index++)
  10581. {
  10582. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10583. {
  10584. addBuff(target, transactionId, 0);
  10585. return TRUE;
  10586. }
  10587. }
  10588. }
  10589. return FALSE;
  10590. }
  10591. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10592. {
  10593. int isSuccess = FALSE;
  10594. //char *query = NULL;
  10595. sqlite3_stmt *stmt;
  10596. int rc; // return code
  10597. char str[20];
  10598. sprintf(str,"%d",user_id);
  10599. 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 */
  10600. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10601. rc = sqlite3_step(stmt); /* 3 */
  10602. if (rc != SQLITE_DONE) {
  10603. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10604. goto out;
  10605. }
  10606. sqlite3_finalize(stmt);
  10607. // free(query);
  10608. out:
  10609. //----------------------
  10610. // close SQLite database
  10611. //----------------------
  10612. sqlite3_close(db);
  10613. printf("database closed.\n");
  10614. return isSuccess;
  10615. }
  10616. /**
  10617. * Place the contents of the specified file into a memory buffer
  10618. *
  10619. * @param[in] filename The path and name of the file to read
  10620. * @param[out] filebuffer A pointer to the contents in memory
  10621. * @return status 0 success, 1 on failure
  10622. */
  10623. int get_file_contents(const char* filename, char** outbuffer) {
  10624. FILE* file = NULL;
  10625. long filesize;
  10626. const int blocksize = 1;
  10627. size_t readsize;
  10628. char* filebuffer;
  10629. // Open the file
  10630. file = fopen(filename, "r");
  10631. if (NULL == file)
  10632. {
  10633. printf("'%s' not opened\n", filename);
  10634. exit(EXIT_FAILURE);
  10635. }
  10636. // Determine the file size
  10637. fseek(file, 0, SEEK_END);
  10638. filesize = ftell(file);
  10639. rewind (file);
  10640. // Allocate memory for the file contents
  10641. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10642. *outbuffer = filebuffer;
  10643. if (filebuffer == NULL)
  10644. {
  10645. fputs ("malloc out-of-memory", stderr);
  10646. exit(EXIT_FAILURE);
  10647. }
  10648. // Read in the file
  10649. readsize = fread(filebuffer, blocksize, filesize, file);
  10650. if (readsize != filesize)
  10651. {
  10652. fputs ("didn't read file completely",stderr);
  10653. exit(EXIT_FAILURE);
  10654. }
  10655. // Clean exit
  10656. fclose(file);
  10657. return EXIT_SUCCESS;
  10658. }
  10659. static int selectSqlCount = 0;
  10660. static int callback(void *data, int argc, char **argv, char **azColName){
  10661. int i;
  10662. printf("%s: ", (const char*)data);
  10663. selectSqlCount = argc;
  10664. for(i = 0; i<argc; i++){
  10665. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10666. }
  10667. printf("\n");
  10668. return 0;
  10669. }
  10670. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10671. //int i;
  10672. //printf("%s:\n", (const char*)data);
  10673. localversion = argv[5] ? atoi(argv[5]) : 0;
  10674. printf("localversion=%d\n", localversion);
  10675. return 0;
  10676. }
  10677. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10678. //int i;
  10679. //printf("%s:\n", (const char*)data);
  10680. //idTag
  10681. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10682. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10683. //parentIdTag
  10684. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10685. //expir_date
  10686. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10687. //status
  10688. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10689. //version
  10690. idTagQuery.listVersionInt = atoi(argv[5]);
  10691. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10692. return 0;
  10693. }
  10694. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10695. int i;
  10696. //printf("%s:\n", (const char*)data);
  10697. #if 1
  10698. for(i=0; i<argc; i++){
  10699. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10700. }
  10701. //printf("");
  10702. #endif
  10703. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10704. // printf("localversion=%d\n", localversion);
  10705. return 0;
  10706. }
  10707. /** sqlite3_exec的回调。
  10708. *
  10709. * 向控制台打印查询的结果。
  10710. *
  10711. * @param in data 传递给回调函数的数据。
  10712. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10713. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10714. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10715. * @return 状态码。
  10716. */
  10717. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10718. {
  10719. for (int i = 0; i < n_columns; i++)
  10720. {
  10721. DEBUG_INFO("%s/t", col_values[i]);
  10722. }
  10723. DEBUG_INFO("/n");
  10724. return 0;
  10725. }
  10726. void OCPP_getListVerion()
  10727. {
  10728. int rc = 0;
  10729. // const char* data = "Callback function called";
  10730. char sql[100];
  10731. char zErrMsg[100];
  10732. memset(sql, 0, 100);
  10733. memset(zErrMsg, 0, 100);
  10734. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10735. /* Execute SQL statement */
  10736. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10737. DEBUG_INFO("rc=%d\n",rc);
  10738. if( rc != SQLITE_OK ){
  10739. DEBUG_INFO("SQL error: %s", zErrMsg);
  10740. //sqlite3_free(zErrMsg);
  10741. }else{
  10742. DEBUG_INFO("Operation done successfully");
  10743. }
  10744. }
  10745. void OCPP_getIdTag(char *idTag)
  10746. {
  10747. int rc = 0;
  10748. // const char* data = "Callback function called";
  10749. char sql[100];
  10750. char zErrMsg[100];
  10751. memset(sql, 0, 100);
  10752. memset(zErrMsg, 0, 100);
  10753. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10754. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10755. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10756. /* Execute SQL statement */
  10757. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10758. if( rc != SQLITE_OK ){
  10759. DEBUG_INFO("SQL error: %s", zErrMsg);
  10760. //sqlite3_free(zErrMsg);
  10761. }else{
  10762. printf("Operation done successfully");
  10763. }
  10764. //return ver;
  10765. }
  10766. void OCPP_get_TableAuthlocalAllData(void)
  10767. {
  10768. int rc = 0;
  10769. // const char* data = "Callback function called";
  10770. char sql[100];
  10771. char zErrMsg[100];
  10772. memset(sql, 0, 100);
  10773. memset(zErrMsg, 0, 100);
  10774. sprintf(sql,"select * from ocpp_auth_local ");
  10775. /* Execute SQL statement */
  10776. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10777. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10778. if( rc != SQLITE_OK ){
  10779. DEBUG_INFO("SQL error: %s", zErrMsg);
  10780. //sqlite3_free(zErrMsg);
  10781. }else{
  10782. DEBUG_INFO("Operation done successfully");
  10783. }
  10784. //return ver;
  10785. }
  10786. int OCPP_cleanLocalList()
  10787. {
  10788. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10789. char *errMsg = 0;
  10790. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10791. if (SQLITE_OK != rc)
  10792. {
  10793. DEBUG_INFO("%s\n",errMsg);
  10794. return FALSE;
  10795. }
  10796. else
  10797. {
  10798. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10799. }
  10800. return TRUE;
  10801. }
  10802. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10803. {
  10804. int isSuccess = FALSE;
  10805. int ret = 0;
  10806. //const char* data = "Callback function called";
  10807. char sql[200];
  10808. char zErrMsg[100];
  10809. memset(sql, 0, 200);
  10810. memset(zErrMsg, 0, 100);
  10811. 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);
  10812. //* Execute SQL statement */
  10813. //zErrMsg = 0;
  10814. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10815. if( ret != SQLITE_OK ){
  10816. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10817. // free(zErrMsg);
  10818. // free(sql);
  10819. return isSuccess;
  10820. }
  10821. DEBUG_INFO("successfully Insert records created\n");
  10822. isSuccess = TRUE;
  10823. return isSuccess;
  10824. }
  10825. void OCPP_deleteIdTag(char *idTag)
  10826. {
  10827. //int ver = 0;
  10828. //int isSuccess = FALSE;
  10829. int rc = 0;
  10830. char sql[100];
  10831. char zErrMsg[100];
  10832. memset(sql, 0, 100);
  10833. memset(zErrMsg, 0, 100);
  10834. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10835. //* Execute SQL statement */
  10836. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10837. if( rc != SQLITE_OK ){
  10838. DEBUG_INFO("SQL error: %s", zErrMsg);
  10839. //sqlite3_free(zErrMsg);
  10840. }else{
  10841. DEBUG_INFO("Operation done successfully");
  10842. }
  10843. }
  10844. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10845. {
  10846. int isSuccess = FALSE;
  10847. int ret = 0;
  10848. const char* data = "Callback function called";
  10849. char sql[200];
  10850. char zErrMsg[100];
  10851. memset(sql, 0, 200);
  10852. memset(zErrMsg, 0, 100);
  10853. //* selectFromTable */
  10854. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10855. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10856. //* Execute SQL statement */
  10857. selectSqlCount = 0;
  10858. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10859. if( ret != SQLITE_OK ){
  10860. printf("Error SQL: %s\n", zErrMsg);
  10861. }
  10862. printf("successfully select operation done\n");
  10863. memset(sql, 0, 200);
  10864. memset(zErrMsg, 0, 100);
  10865. if(selectSqlCount == 0)
  10866. {
  10867. //Insert
  10868. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  10869. 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);
  10870. DEBUG_INFO("sql:%s\n", sql);
  10871. //* Execute SQL statement */
  10872. //zErrMsg = 0;
  10873. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10874. if( ret != SQLITE_OK ){
  10875. printf("SQL error: %s\n", zErrMsg);
  10876. return isSuccess;
  10877. }
  10878. DEBUG_INFO("successfully Insert records created\n");
  10879. isSuccess = TRUE;
  10880. }
  10881. else
  10882. {
  10883. //Update
  10884. //* Create merged SQL statement */
  10885. 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);
  10886. /* Execute SQL statement */
  10887. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10888. if( ret != SQLITE_OK ){
  10889. printf("SQL error: %s\n", zErrMsg);
  10890. //sqlite3_free(zErrMsg);
  10891. //sqlite3_free(sql);
  10892. return isSuccess;
  10893. }
  10894. DEBUG_INFO("Successfully operation done \n");
  10895. isSuccess = TRUE;
  10896. }
  10897. return isSuccess;
  10898. }
  10899. char *GetOcppServerURL()
  10900. {
  10901. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10902. memset(OcppHost, 0, sizeof(OcppHost));
  10903. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10904. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10905. {
  10906. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10907. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10908. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10909. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10910. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10911. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10912. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10913. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10914. goto End;
  10915. }
  10916. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10917. {
  10918. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10919. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10920. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10921. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10922. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10923. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10924. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10925. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10926. goto End;
  10927. }
  10928. else
  10929. {
  10930. strcpy(OcppHost,"");
  10931. }
  10932. End:
  10933. return OcppHost;
  10934. }
  10935. char *GetOcppPath()
  10936. {
  10937. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10938. {
  10939. if(OcppTempPath == NULL)
  10940. {
  10941. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10942. }
  10943. else
  10944. {
  10945. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10946. }
  10947. goto End;
  10948. }
  10949. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10950. {
  10951. if(OcppTempPath == NULL)
  10952. {
  10953. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10954. }
  10955. else
  10956. {
  10957. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10958. }
  10959. goto End;
  10960. }
  10961. else
  10962. {
  10963. strcpy(OcppHost,"");
  10964. }
  10965. End:
  10966. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10967. return OcppPath;
  10968. }
  10969. int GetOcppPort()
  10970. {
  10971. return OcppPort;
  10972. }
  10973. int GetOcppConnStatus(void)
  10974. {
  10975. return ShmOCPP16Data->OcppConnStatus;
  10976. }
  10977. void SetOcppConnStatus(uint8_t status)
  10978. {
  10979. ShmOCPP16Data->OcppConnStatus = status;
  10980. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10981. if(status == FALSE)
  10982. {
  10983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10984. {
  10985. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10986. }
  10987. else
  10988. {
  10989. SystemInitial = AC_QUANTITY;
  10990. }
  10991. }
  10992. }
  10993. int GetHeartBeatWithNOResponse(void)
  10994. {
  10995. return HeartBeatWithNOResponse;
  10996. }
  10997. void SetHeartBeatWithNOResponse(void)
  10998. {
  10999. HeartBeatWithNOResponse = 0;
  11000. }
  11001. int InternetDisconnect(void)
  11002. {
  11003. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  11004. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  11005. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  11006. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  11007. }
  11008. void GetChargingProfileRequest(int gunindex)
  11009. {
  11010. mtrace();
  11011. //int connectorIdInt, durationInt;
  11012. //char chargingRateUnitStr[4]={0};
  11013. int tempdurationInt = 0;
  11014. int tempchargingProfileId = 0;
  11015. int tempstackLevel = 0;
  11016. int temptransactionId = 0;
  11017. float tempminChargingRateFloat = 0.0;
  11018. char tempchargingProfilePurposeStr[24]={0};
  11019. char tempchargingProfileKindStr[12]={0};
  11020. char temprecurrencyKindStr[8]={0};
  11021. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  11022. char tempvalidToStr[28]={0};
  11023. int tempStartPeriodInt = 0;
  11024. float tempLimitInt = 0.0;//0.1;
  11025. int tempNumberPhasesInt=0;
  11026. char fname[200];
  11027. //char comfirmstr[20];
  11028. float MinChargingRate =0.0;
  11029. double diff_t;
  11030. struct tm tp;
  11031. FILE *fptr1;//, *fptr2;
  11032. int c = 0;
  11033. char * pch;
  11034. char *loc;
  11035. char sstr[200]={ 0 };
  11036. int n_chargingProfile = 0;
  11037. int n_SchedulePeriods = 0;
  11038. char SchedulePeriodList[10][200]={0};
  11039. char sLineWord[800]={0};
  11040. char word[1000]={0};
  11041. int confirmPeriods = 0;
  11042. struct StructProfile ChargePointMaxProfile;
  11043. struct StructProfile TxDefaultProfile;
  11044. struct StructProfile TxProfile;
  11045. struct StructProfile TxDefaultProfiletemp[2]={0};
  11046. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  11047. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  11048. struct StructChargingProfile TxProfile_TEMP={0};
  11049. int TxDefaultProfileFileIsNull=FALSE;
  11050. int ChargePointMaxProfileIsNull=FALSE;
  11051. int TxProfileIsNull=FALSE;
  11052. // int CompositeSceduleIndex = 0;
  11053. char ChargePointMaxProfileScheduleStr[30]={0};
  11054. char TxDefaultProfileScheduleStr[30]={0};
  11055. char TxProfileScheduleStr[30]={0};
  11056. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  11057. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  11058. memset(&TxProfile,0,sizeof(struct StructProfile));
  11059. DEBUG_INFO("GetChargingProfileRequest\n");
  11060. //*****************************ChargePointMaxProfile******************************************/
  11061. strcpy(fname, ChargePointMaxProfile_JSON);
  11062. ChargePointMaxProfileIsNull=TRUE;
  11063. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  11064. {
  11065. fptr1 = fopen(fname, "r");
  11066. int c;
  11067. c = fgetc(fptr1);
  11068. //DEBUG_INFO("c:%d\n",c);
  11069. rewind(fptr1);
  11070. if(c == EOF)
  11071. {
  11072. DEBUG_INFO("\n End of file reached.");
  11073. ChargePointMaxProfileIsNull=TRUE;
  11074. fclose(fptr1);
  11075. }
  11076. else
  11077. {
  11078. ChargePointMaxProfileIsNull=FALSE;
  11079. while(fscanf(fptr1, "%s", word) != EOF)
  11080. {
  11081. if(strcmp(word, "chargingProfileId") == 0)
  11082. {
  11083. n_chargingProfile = n_chargingProfile + 1;
  11084. }
  11085. }
  11086. rewind(fptr1);
  11087. //search Charging Profile Element
  11088. int i = 0;
  11089. int j = 0;
  11090. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11091. //***********chargingProfileId**************/
  11092. c = 0;
  11093. loc = strstr(sLineWord, "chargingProfileId");
  11094. //DEBUG_INFO("loc=%s\n",loc);
  11095. memset(sstr ,0, sizeof(sstr) );
  11096. if(loc != NULL)
  11097. {
  11098. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11099. {
  11100. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11101. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11102. c++;
  11103. }
  11104. sstr[c] = '\0';
  11105. DEBUG_INFO("chargingProfileId=%s\n",sstr);
  11106. tempchargingProfileId = atoi(sstr);
  11107. }
  11108. else
  11109. {
  11110. tempchargingProfileId = 0;
  11111. }
  11112. //***********stackLevel**************/
  11113. c = 0;
  11114. loc = strstr(sLineWord, "stackLevel");
  11115. //DEBUG_INFO("loc=%s\n",loc);
  11116. memset(sstr ,0, sizeof(sstr) );
  11117. if(loc != NULL)
  11118. {
  11119. while (loc[2+strlen("stackLevel")+c] != '\"')
  11120. {
  11121. sstr[c] = loc[2+strlen("stackLevel")+c];
  11122. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11123. c++;
  11124. }
  11125. sstr[c] = '\0';
  11126. DEBUG_INFO("stackLevel=%s\n",sstr);
  11127. tempstackLevel = atoi(sstr);
  11128. }
  11129. else
  11130. {
  11131. tempstackLevel = 0;
  11132. }
  11133. //***********chargingProfilePurpose **************/
  11134. c = 0;
  11135. loc = strstr(sLineWord, "chargingProfilePurpose");
  11136. //DEBUG_INFO("loc=%s\n",loc);
  11137. memset(sstr ,0, sizeof(sstr) );
  11138. if(loc != NULL)
  11139. {
  11140. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11141. {
  11142. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11143. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11144. c++;
  11145. }
  11146. sstr[c] = '\0';
  11147. DEBUG_INFO("chargingProfilePurpose =%s\n",sstr);
  11148. strcpy(tempchargingProfilePurposeStr,sstr);
  11149. }
  11150. else
  11151. {
  11152. strcpy(tempchargingProfilePurposeStr,"");
  11153. }
  11154. //***********chargingProfileKind **************/
  11155. c = 0;
  11156. loc = strstr(sLineWord, "chargingProfileKind");
  11157. //DEBUG_INFO("loc=%s\n",loc);
  11158. memset(sstr ,0, sizeof(sstr) );
  11159. if(loc != NULL)
  11160. {
  11161. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11162. {
  11163. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11164. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11165. c++;
  11166. }
  11167. sstr[c] = '\0';
  11168. DEBUG_INFO("chargingProfileKind =%s\n",sstr);
  11169. strcpy(tempchargingProfileKindStr,sstr);
  11170. }
  11171. else
  11172. {
  11173. strcpy(tempchargingProfileKindStr,"");
  11174. }
  11175. //***********recurrencyKind **************/
  11176. c = 0;
  11177. loc = strstr(sLineWord, "recurrencyKind");
  11178. //DEBUG_INFO("loc=%s\n",loc);
  11179. memset(sstr ,0, sizeof(sstr) );
  11180. if(loc != NULL)
  11181. {
  11182. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11183. {
  11184. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11185. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11186. c++;
  11187. }
  11188. sstr[c] = '\0';
  11189. DEBUG_INFO("recurrencyKind =%s\n",sstr);
  11190. strcpy(temprecurrencyKindStr,sstr);
  11191. }
  11192. else
  11193. {
  11194. strcpy(temprecurrencyKindStr,"");
  11195. }
  11196. //***********validFrom**************/
  11197. c = 0;
  11198. loc = strstr(sLineWord, "validFrom");
  11199. //DEBUG_INFO("loc=%s\n",loc);
  11200. memset(sstr ,0, sizeof(sstr) );
  11201. if(loc != NULL)
  11202. {
  11203. while (loc[3+strlen("validFrom")+c] != '\"')
  11204. {
  11205. sstr[c] = loc[3+strlen("validFrom")+c];
  11206. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11207. c++;
  11208. }
  11209. sstr[c] = '\0';
  11210. DEBUG_INFO("validFrom=%s\n",sstr);
  11211. strcpy(tempvalidFromStr,sstr);
  11212. }
  11213. else
  11214. {
  11215. strcpy(tempvalidFromStr,"");
  11216. }
  11217. //***********validTo **************/
  11218. c = 0;
  11219. loc = strstr(sLineWord, "validTo");
  11220. //DEBUG_INFO("loc=%s\n",loc);
  11221. memset(sstr ,0, sizeof(sstr) );
  11222. if(loc != NULL)
  11223. {
  11224. while (loc[3+strlen("validTo")+c] != '\"')
  11225. {
  11226. sstr[c] = loc[3+strlen("validTo")+c];
  11227. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11228. c++;
  11229. }
  11230. sstr[c] = '\0';
  11231. DEBUG_INFO("validTo =%s\n",sstr);
  11232. strcpy(tempvalidToStr,sstr);
  11233. }
  11234. else
  11235. {
  11236. strcpy(tempvalidToStr,"");
  11237. }
  11238. //***********validFrom**************/
  11239. c = 0;
  11240. loc = strstr(sLineWord, "validFrom");
  11241. if(loc != NULL)
  11242. {
  11243. memset(sstr ,0, sizeof(sstr) );
  11244. while (loc[3+strlen("validFrom")+c] != '\"')
  11245. {
  11246. sstr[c] = loc[3+strlen("validFrom")+c];
  11247. c++;
  11248. }
  11249. sstr[c] = '\0';
  11250. strcpy(tempvalidFromStr,sstr);
  11251. }
  11252. else
  11253. {
  11254. strcpy(tempvalidFromStr,"");
  11255. }
  11256. //***********duration**************/
  11257. c = 0;
  11258. loc = strstr(sLineWord, "duration");
  11259. if(loc != NULL)
  11260. {
  11261. memset(sstr ,0, sizeof(sstr) );
  11262. while (loc[2+strlen("duration")+c] != ',')
  11263. {
  11264. sstr[c] = loc[2+strlen("duration")+c];
  11265. c++;
  11266. }
  11267. sstr[c] = '\0';
  11268. tempdurationInt = atoi(sstr);
  11269. }
  11270. else
  11271. {
  11272. tempdurationInt = 0;
  11273. }
  11274. //**********startSchedule**********/
  11275. c = 0;
  11276. loc = strstr(sLineWord, "startSchedule");
  11277. memset(sstr ,0, sizeof(sstr) );
  11278. while (loc[3+strlen("startSchedule")+c] != '\"')
  11279. {
  11280. sstr[c] = loc[3+strlen("startSchedule")+c];
  11281. c++;
  11282. }
  11283. sstr[c] = '\0';
  11284. strcpy(tempstartScheduleStr, sstr);
  11285. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  11286. //**********chargingRateUnit**********/
  11287. c = 0;
  11288. loc = strstr(sLineWord, "chargingRateUnit");
  11289. memset(sstr ,0, sizeof(sstr) );
  11290. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11291. {
  11292. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11293. c++;
  11294. }
  11295. sstr[c] = '\0';
  11296. strcpy(tempchargingRateUnitStr, sstr);
  11297. //**********minChargingRate*******/
  11298. c = 0;
  11299. loc = strstr(sLineWord, "minChargingRate");
  11300. if(loc != NULL)
  11301. {
  11302. memset(sstr ,0, sizeof(sstr) );
  11303. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11304. {
  11305. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11306. c++;
  11307. }
  11308. sstr[c] = '\0';
  11309. tempminChargingRateFloat = atof(sstr);
  11310. }
  11311. else
  11312. {
  11313. tempminChargingRateFloat = 0.0;
  11314. }
  11315. //
  11316. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11317. tp.tm_isdst = -1;
  11318. time_t utc = mktime(&tp);
  11319. time_t t = time(NULL);
  11320. diff_t = difftime(t, utc);
  11321. DEBUG_INFO("diff_t=%f\n",diff_t);
  11322. DEBUG_INFO(" debug 5 -1\n");
  11323. //parsing strings to words
  11324. i = 0;
  11325. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11326. loc = loc+3+strlen("chargingSchedulePeriod");
  11327. pch = strtok(loc ,"{");
  11328. while (pch != NULL)
  11329. {
  11330. strcpy(SchedulePeriodList[i], pch);
  11331. pch = strtok (NULL, "{");
  11332. i = i + 1;
  11333. }
  11334. n_SchedulePeriods = i;
  11335. for(int i=0;i<n_SchedulePeriods;i++)
  11336. {
  11337. //*************startPeriod****************/
  11338. c = 0;
  11339. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11340. memset(sstr ,0, sizeof(sstr) );
  11341. while (loc[strlen("startPeriod")+2+c] != ',')
  11342. {
  11343. sstr[c] = loc[strlen("startPeriod")+2+c];
  11344. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11345. c++;
  11346. }
  11347. sstr[c] = '\0';
  11348. tempStartPeriodInt = atoi(sstr);
  11349. //*************limit****************/
  11350. c = 0;
  11351. loc = strstr(SchedulePeriodList[i], "limit");
  11352. memset(sstr ,0, sizeof(sstr) );
  11353. while (loc[strlen("limit")+2+c] != ',')
  11354. {
  11355. sstr[c] = loc[strlen("limit")+2+c];
  11356. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11357. c++;
  11358. }
  11359. sstr[c] = '\0';
  11360. tempLimitInt = atof(sstr);
  11361. //*************numberPhases****************/
  11362. c = 0;
  11363. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11364. memset(sstr ,0, sizeof(sstr) );
  11365. while (loc[strlen("numberPhases")+2+c] != '}')
  11366. {
  11367. sstr[c] = loc[strlen("numberPhases")+2+c];
  11368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11369. c++;
  11370. }
  11371. sstr[c] = '\0';
  11372. tempNumberPhasesInt = atoi(sstr);
  11373. if(j == 0)
  11374. {
  11375. ChargePointMaxProfile.Duration = tempdurationInt;
  11376. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  11377. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  11378. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11379. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11380. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11381. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  11382. ChargePointMaxProfile_TEMP.TransactionId = 0;
  11383. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11384. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11385. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11386. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11387. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11388. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11389. }
  11390. }
  11391. if(MinChargingRate < tempminChargingRateFloat)
  11392. {
  11393. MinChargingRate = tempminChargingRateFloat;
  11394. }
  11395. if(confirmPeriods < n_SchedulePeriods)
  11396. {
  11397. confirmPeriods = n_SchedulePeriods;
  11398. }
  11399. j = j + 1;
  11400. }
  11401. fclose(fptr1);
  11402. }
  11403. }// the end of access file ChargePointMaxProfile
  11404. //****************************TxDefaultProfile************************************************/
  11405. switch(gunindex + 1)
  11406. {
  11407. case 0:
  11408. break;
  11409. case 1:
  11410. strcpy(fname, TxDefaultProfile_1_JSON );
  11411. break;
  11412. case 2:
  11413. strcpy(fname, TxDefaultProfile_2_JSON );
  11414. break;
  11415. default:
  11416. strcpy(fname, TxDefaultProfile_1_JSON );
  11417. break;
  11418. }
  11419. TxDefaultProfileFileIsNull=TRUE;
  11420. if((access(fname,F_OK))!=-1)
  11421. {
  11422. fptr1 = fopen(fname, "r");
  11423. c = 0;
  11424. c = fgetc(fptr1);
  11425. //DEBUG_INFO("c:%d\n",c);
  11426. rewind(fptr1);
  11427. if(c == EOF)
  11428. {
  11429. DEBUG_INFO("\n End of file reached.");
  11430. TxDefaultProfileFileIsNull=TRUE;
  11431. fclose(fptr1);
  11432. }
  11433. else
  11434. {
  11435. TxDefaultProfileFileIsNull=FALSE;
  11436. while(fscanf(fptr1, "%s", word) != EOF)
  11437. {
  11438. if(strcmp(word, "chargingProfileId") == 0)
  11439. {
  11440. n_chargingProfile = n_chargingProfile + 1;
  11441. }
  11442. }
  11443. rewind(fptr1);
  11444. //search Charging Profile Element
  11445. int i = 0;
  11446. int j = 0;
  11447. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11448. #if 0
  11449. /***********connectorId****************/
  11450. c = 0;
  11451. loc = strstr(sLineWord, "connectorId");
  11452. memset(sstr ,0, sizeof(sstr) );
  11453. while (loc[strlen("connectorId")+2+c] != ',')
  11454. {
  11455. sstr[c] = loc[strlen("connectorId")+2+c];
  11456. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11457. c++;
  11458. }
  11459. sstr[c] = '\0';
  11460. tempconnectorIdInt = atoi(sstr);
  11461. #endif
  11462. //***********chargingProfileId**************/
  11463. c = 0;
  11464. loc = strstr(sLineWord, "chargingProfileId");
  11465. //DEBUG_INFO("loc=%s\n",loc);
  11466. memset(sstr ,0, sizeof(sstr) );
  11467. if(loc != NULL)
  11468. {
  11469. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11470. {
  11471. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11472. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11473. c++;
  11474. }
  11475. sstr[c] = '\0';
  11476. DEBUG_INFO("chargingProfileId=%s\n",sstr);
  11477. tempchargingProfileId = atoi(sstr);
  11478. }
  11479. else
  11480. {
  11481. tempchargingProfileId = 0;
  11482. }
  11483. //***********stackLevel**************/
  11484. c = 0;
  11485. loc = strstr(sLineWord, "stackLevel");
  11486. //DEBUG_INFO("loc=%s\n",loc);
  11487. memset(sstr ,0, sizeof(sstr) );
  11488. if(loc != NULL)
  11489. {
  11490. while (loc[2+strlen("stackLevel")+c] != '\"')
  11491. {
  11492. sstr[c] = loc[2+strlen("stackLevel")+c];
  11493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11494. c++;
  11495. }
  11496. sstr[c] = '\0';
  11497. DEBUG_INFO("stackLevel=%s\n",sstr);
  11498. tempstackLevel = atoi(sstr);
  11499. }
  11500. else
  11501. {
  11502. tempstackLevel = 0;
  11503. }
  11504. //***********chargingProfilePurpose **************/
  11505. c = 0;
  11506. loc = strstr(sLineWord, "chargingProfilePurpose");
  11507. //DEBUG_INFO("loc=%s\n",loc);
  11508. memset(sstr ,0, sizeof(sstr) );
  11509. if(loc != NULL)
  11510. {
  11511. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11512. {
  11513. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11514. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11515. c++;
  11516. }
  11517. sstr[c] = '\0';
  11518. DEBUG_INFO("chargingProfilePurpose =%s\n",sstr);
  11519. strcpy(tempchargingProfilePurposeStr,sstr);
  11520. }
  11521. else
  11522. {
  11523. strcpy(tempchargingProfilePurposeStr,"");
  11524. }
  11525. //***********chargingProfileKind **************/
  11526. c = 0;
  11527. loc = strstr(sLineWord, "chargingProfileKind");
  11528. //DEBUG_INFO("loc=%s\n",loc);
  11529. memset(sstr ,0, sizeof(sstr) );
  11530. if(loc != NULL)
  11531. {
  11532. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11533. {
  11534. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11535. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11536. c++;
  11537. }
  11538. sstr[c] = '\0';
  11539. DEBUG_INFO("chargingProfileKind =%s\n",sstr);
  11540. strcpy(tempchargingProfileKindStr,sstr);
  11541. }
  11542. else
  11543. {
  11544. strcpy(tempchargingProfileKindStr,"");
  11545. }
  11546. //***********recurrencyKind **************/
  11547. c = 0;
  11548. loc = strstr(sLineWord, "recurrencyKind");
  11549. //DEBUG_INFO("loc=%s\n",loc);
  11550. memset(sstr ,0, sizeof(sstr) );
  11551. if(loc != NULL)
  11552. {
  11553. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11554. {
  11555. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11556. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11557. c++;
  11558. }
  11559. sstr[c] = '\0';
  11560. DEBUG_INFO("recurrencyKind =%s\n",sstr);
  11561. strcpy(temprecurrencyKindStr,sstr);
  11562. }
  11563. else
  11564. {
  11565. strcpy(temprecurrencyKindStr,"");
  11566. }
  11567. //***********validFrom**************/
  11568. c = 0;
  11569. loc = strstr(sLineWord, "validFrom");
  11570. if(loc != NULL)
  11571. {
  11572. memset(sstr ,0, sizeof(sstr) );
  11573. while (loc[3+strlen("validFrom")+c] != '\"')
  11574. {
  11575. sstr[c] = loc[3+strlen("validFrom")+c];
  11576. c++;
  11577. }
  11578. sstr[c] = '\0';
  11579. strcpy(tempvalidFromStr,sstr);
  11580. }
  11581. else
  11582. {
  11583. strcpy(tempvalidFromStr,"");
  11584. }
  11585. //***********validFrom**************/
  11586. c = 0;
  11587. loc = strstr(sLineWord, "duration");
  11588. if(loc != NULL)
  11589. {
  11590. memset(sstr ,0, sizeof(sstr) );
  11591. while (loc[2+strlen("duration")+c] != ',')
  11592. {
  11593. sstr[c] = loc[2+strlen("duration")+c];
  11594. c++;
  11595. }
  11596. sstr[c] = '\0';
  11597. tempdurationInt = atoi(sstr);
  11598. }
  11599. else
  11600. {
  11601. tempdurationInt = 0;
  11602. }
  11603. //**********startSchedule**********/
  11604. c = 0;
  11605. loc = strstr(sLineWord, "startSchedule");
  11606. memset(sstr ,0, sizeof(sstr) );
  11607. while (loc[3+strlen("startSchedule")+c] != '\"')
  11608. {
  11609. sstr[c] = loc[3+strlen("startSchedule")+c];
  11610. c++;
  11611. }
  11612. sstr[c] = '\0';
  11613. strcpy(tempstartScheduleStr, sstr);
  11614. strcpy(TxDefaultProfileScheduleStr, sstr);
  11615. //**********chargingRateUnit**********/
  11616. c = 0;
  11617. loc = strstr(sLineWord, "chargingRateUnit");
  11618. memset(sstr ,0, sizeof(sstr) );
  11619. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11620. {
  11621. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11622. c++;
  11623. }
  11624. sstr[c] = '\0';
  11625. strcpy(tempchargingRateUnitStr, sstr);
  11626. //**********minChargingRate*******/
  11627. c = 0;
  11628. loc = strstr(sLineWord, "minChargingRate");
  11629. if(loc != NULL)
  11630. {
  11631. memset(sstr ,0, sizeof(sstr) );
  11632. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11633. {
  11634. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11635. c++;
  11636. }
  11637. sstr[c] = '\0';
  11638. tempminChargingRateFloat = atof(sstr);
  11639. }
  11640. else
  11641. {
  11642. tempminChargingRateFloat = 0.0;
  11643. }
  11644. //
  11645. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11646. tp.tm_isdst = -1;
  11647. time_t utc = mktime(&tp);
  11648. time_t t = time(NULL);
  11649. diff_t = difftime(t, utc);
  11650. DEBUG_INFO("diff_t=%f\n",diff_t);
  11651. //parsing strings to words
  11652. i = 0;
  11653. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11654. loc = loc+3+strlen("chargingSchedulePeriod");
  11655. pch = strtok(loc ,"{");
  11656. while (pch != NULL)
  11657. {
  11658. strcpy(SchedulePeriodList[i], pch);
  11659. pch = strtok (NULL, "{");
  11660. i = i + 1;
  11661. }
  11662. n_SchedulePeriods = i;
  11663. for(int i=0;i<n_SchedulePeriods;i++)
  11664. {
  11665. //*************startPeriod****************/
  11666. c = 0;
  11667. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11668. memset(sstr ,0, sizeof(sstr) );
  11669. while (loc[strlen("startPeriod")+2+c] != ',')
  11670. {
  11671. sstr[c] = loc[strlen("startPeriod")+2+c];
  11672. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11673. c++;
  11674. }
  11675. sstr[c] = '\0';
  11676. tempStartPeriodInt = atoi(sstr);
  11677. //*************limit****************/
  11678. c = 0;
  11679. loc = strstr(SchedulePeriodList[i], "limit");
  11680. memset(sstr ,0, sizeof(sstr) );
  11681. while (loc[strlen("limit")+2+c] != ',')
  11682. {
  11683. sstr[c] = loc[strlen("limit")+2+c];
  11684. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11685. c++;
  11686. }
  11687. sstr[c] = '\0';
  11688. tempLimitInt = atof(sstr);
  11689. //*************numberPhases****************/
  11690. c = 0;
  11691. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11692. memset(sstr ,0, sizeof(sstr) );
  11693. while (loc[strlen("numberPhases")+2+c] != '}')
  11694. {
  11695. sstr[c] = loc[strlen("numberPhases")+2+c];
  11696. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11697. c++;
  11698. }
  11699. sstr[c] = '\0';
  11700. tempNumberPhasesInt = atoi(sstr);
  11701. if(j == 0)
  11702. {
  11703. TxDefaultProfile.Duration = tempdurationInt;
  11704. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  11705. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  11706. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11707. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11708. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11709. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  11710. TxDefaultProfile_TEMP.TransactionId = 0;
  11711. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11712. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11713. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11714. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11715. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11716. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11717. }
  11718. else
  11719. {
  11720. //other stack level charging Profile
  11721. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  11722. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  11723. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  11724. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  11725. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  11726. }
  11727. }
  11728. if(MinChargingRate < tempminChargingRateFloat)
  11729. MinChargingRate = tempminChargingRateFloat;
  11730. if(confirmPeriods < n_SchedulePeriods)
  11731. confirmPeriods = n_SchedulePeriods;
  11732. j = j + 1;
  11733. }
  11734. fclose(fptr1);
  11735. //Stacking Charging Profiles
  11736. for(int l=0; l <(j-1) ;l++)
  11737. {
  11738. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  11739. {
  11740. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  11741. {
  11742. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  11743. {
  11744. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  11745. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  11746. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  11747. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11748. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11749. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11750. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11751. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11752. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11753. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11754. }
  11755. else
  11756. {
  11757. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11758. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11759. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11760. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11761. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11762. }
  11763. }
  11764. }
  11765. }
  11766. //end of Stacking Charging Profiles
  11767. }
  11768. }// the end of ACCESS TxDefaultProfile
  11769. //****************************TxProfile************************************************/
  11770. switch(gunindex + 1)
  11771. {
  11772. case 0:
  11773. break;
  11774. case 1:
  11775. strcpy(fname, TxProfile_1_JSON );
  11776. break;
  11777. case 2:
  11778. strcpy(fname, TxProfile_2_JSON );
  11779. break;
  11780. default:
  11781. strcpy(fname, TxProfile_1_JSON );
  11782. break;
  11783. }
  11784. TxProfileIsNull=TRUE;
  11785. if((access(fname,F_OK))!=-1)
  11786. {
  11787. fptr1 = fopen(fname, "r");
  11788. c = 0;
  11789. c = fgetc(fptr1);
  11790. //DEBUG_INFO("c:%d\n",c);
  11791. rewind(fptr1);
  11792. if(c == EOF)
  11793. {
  11794. DEBUG_INFO("\n End of file reached.");
  11795. TxProfileIsNull=TRUE;
  11796. fclose(fptr1);
  11797. }
  11798. else
  11799. {
  11800. TxProfileIsNull=FALSE;
  11801. while(fscanf(fptr1, "%s", word) != EOF)
  11802. {
  11803. if(strcmp(word, "chargingProfileId") == 0)
  11804. {
  11805. n_chargingProfile = n_chargingProfile + 1;
  11806. }
  11807. }
  11808. rewind(fptr1);
  11809. //search Charging Profile Element
  11810. int i= 0;
  11811. int j= 0;
  11812. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11813. #if 0
  11814. /***********connectorId****************/
  11815. c = 0;
  11816. loc = strstr(sLineWord, "connectorId");
  11817. memset(sstr ,0, sizeof(sstr) );
  11818. while (loc[strlen("connectorId")+2+c] != ',')
  11819. {
  11820. sstr[c] = loc[strlen("connectorId")+2+c];
  11821. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11822. c++;
  11823. }
  11824. sstr[c] = '\0';
  11825. tempconnectorIdInt = atoi(sstr);
  11826. #endif
  11827. //***********chargingProfileId**************/
  11828. c = 0;
  11829. loc = strstr(sLineWord, "chargingProfileId");
  11830. //DEBUG_INFO("loc=%s\n",loc);
  11831. memset(sstr ,0, sizeof(sstr) );
  11832. if(loc != NULL)
  11833. {
  11834. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11835. {
  11836. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11837. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11838. c++;
  11839. }
  11840. sstr[c] = '\0';
  11841. DEBUG_INFO("chargingProfileId=%s\n",sstr);
  11842. tempchargingProfileId = atoi(sstr);
  11843. }
  11844. else
  11845. {
  11846. tempchargingProfileId = 0;
  11847. }
  11848. //***********transactionId **************/
  11849. c = 0;
  11850. loc = strstr(sLineWord, "transactionId");
  11851. //DEBUG_INFO("loc=%s\n",loc);
  11852. memset(sstr ,0, sizeof(sstr) );
  11853. if(loc != NULL)
  11854. {
  11855. while (loc[2+strlen("transactionId")+c] != '\"')
  11856. {
  11857. sstr[c] = loc[2+strlen("transactionId")+c];
  11858. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11859. c++;
  11860. }
  11861. sstr[c] = '\0';
  11862. DEBUG_INFO("transactionId=%s\n",sstr);
  11863. temptransactionId = atoi(sstr);
  11864. }
  11865. else
  11866. {
  11867. temptransactionId = 0;
  11868. }
  11869. //***********stackLevel**************/
  11870. c = 0;
  11871. loc = strstr(sLineWord, "stackLevel");
  11872. //DEBUG_INFO("loc=%s\n",loc);
  11873. memset(sstr ,0, sizeof(sstr) );
  11874. if(loc != NULL)
  11875. {
  11876. while (loc[2+strlen("stackLevel")+c] != '\"')
  11877. {
  11878. sstr[c] = loc[2+strlen("stackLevel")+c];
  11879. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11880. c++;
  11881. }
  11882. sstr[c] = '\0';
  11883. DEBUG_INFO("stackLevel=%s\n",sstr);
  11884. tempstackLevel = atoi(sstr);
  11885. }
  11886. else
  11887. {
  11888. tempstackLevel = 0;
  11889. }
  11890. //***********chargingProfilePurpose **************/
  11891. c = 0;
  11892. loc = strstr(sLineWord, "chargingProfilePurpose");
  11893. //DEBUG_INFO("loc=%s\n",loc);
  11894. memset(sstr ,0, sizeof(sstr) );
  11895. if(loc != NULL)
  11896. {
  11897. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11898. {
  11899. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11900. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11901. c++;
  11902. }
  11903. sstr[c] = '\0';
  11904. DEBUG_INFO("chargingProfilePurpose =%s\n",sstr);
  11905. strcpy(tempchargingProfilePurposeStr,sstr);
  11906. }
  11907. else
  11908. {
  11909. strcpy(tempchargingProfilePurposeStr,"");
  11910. }
  11911. //***********chargingProfileKind **************/
  11912. c = 0;
  11913. loc = strstr(sLineWord, "chargingProfileKind");
  11914. //DEBUG_INFO("loc=%s\n",loc);
  11915. memset(sstr ,0, sizeof(sstr) );
  11916. if(loc != NULL)
  11917. {
  11918. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11919. {
  11920. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11921. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11922. c++;
  11923. }
  11924. sstr[c] = '\0';
  11925. DEBUG_INFO("chargingProfileKind =%s\n",sstr);
  11926. strcpy(tempchargingProfileKindStr,sstr);
  11927. }
  11928. else
  11929. {
  11930. strcpy(tempchargingProfileKindStr,"");
  11931. }
  11932. //***********recurrencyKind **************/
  11933. c = 0;
  11934. loc = strstr(sLineWord, "recurrencyKind");
  11935. //DEBUG_INFO("loc=%s\n",loc);
  11936. memset(sstr ,0, sizeof(sstr) );
  11937. if(loc != NULL)
  11938. {
  11939. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11940. {
  11941. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11943. c++;
  11944. }
  11945. sstr[c] = '\0';
  11946. DEBUG_INFO("recurrencyKind =%s\n",sstr);
  11947. strcpy(temprecurrencyKindStr,sstr);
  11948. }
  11949. else
  11950. {
  11951. strcpy(temprecurrencyKindStr,"");
  11952. }
  11953. //***********validFrom**************/
  11954. c = 0;
  11955. loc = strstr(sLineWord, "validFrom");
  11956. if(loc != NULL)
  11957. {
  11958. memset(sstr ,0, sizeof(sstr) );
  11959. while (loc[3+strlen("validFrom")+c] != '\"')
  11960. {
  11961. sstr[c] = loc[3+strlen("validFrom")+c];
  11962. c++;
  11963. }
  11964. sstr[c] = '\0';
  11965. strcpy(tempvalidFromStr,sstr);
  11966. }
  11967. else
  11968. {
  11969. strcpy(tempvalidFromStr,"");
  11970. }
  11971. //**********startSchedule**********/
  11972. c = 0;
  11973. loc = strstr(sLineWord, "startSchedule");
  11974. memset(sstr ,0, sizeof(sstr) );
  11975. while (loc[3+strlen("startSchedule")+c] != '\"')
  11976. {
  11977. sstr[c] = loc[3+strlen("startSchedule")+c];
  11978. c++;
  11979. }
  11980. sstr[c] = '\0';
  11981. strcpy(tempstartScheduleStr, sstr);
  11982. strcpy(TxProfileScheduleStr, sstr);
  11983. //**********chargingRateUnit**********/
  11984. c = 0;
  11985. loc = strstr(sLineWord, "chargingRateUnit");
  11986. memset(sstr ,0, sizeof(sstr) );
  11987. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11988. {
  11989. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11990. c++;
  11991. }
  11992. sstr[c] = '\0';
  11993. strcpy(tempchargingRateUnitStr, sstr);
  11994. //**********minChargingRate*******/
  11995. c = 0;
  11996. loc = strstr(sLineWord, "minChargingRate");
  11997. if(loc != NULL)
  11998. {
  11999. memset(sstr ,0, sizeof(sstr) );
  12000. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12001. {
  12002. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12003. c++;
  12004. }
  12005. sstr[c] = '\0';
  12006. tempminChargingRateFloat = atof(sstr);
  12007. }
  12008. else
  12009. {
  12010. tempminChargingRateFloat = 0.0;
  12011. }
  12012. //
  12013. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12014. tp.tm_isdst = -1;
  12015. time_t utc = mktime(&tp);
  12016. time_t t = time(NULL);
  12017. diff_t = difftime(t, utc);
  12018. DEBUG_INFO("diff_t=%f\n",diff_t);
  12019. //parsing strings to words
  12020. i = 0;
  12021. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12022. loc = loc+3+strlen("chargingSchedulePeriod");
  12023. pch = strtok(loc ,"{");
  12024. while (pch != NULL)
  12025. {
  12026. strcpy(SchedulePeriodList[i], pch);
  12027. pch = strtok (NULL, "{");
  12028. i = i + 1;
  12029. }
  12030. n_SchedulePeriods = i;
  12031. for(int i=0;i<n_SchedulePeriods;i++)
  12032. {
  12033. //*************startPeriod****************/
  12034. c = 0;
  12035. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12036. memset(sstr ,0, sizeof(sstr) );
  12037. while (loc[strlen("startPeriod")+2+c] != ',')
  12038. {
  12039. sstr[c] = loc[strlen("startPeriod")+2+c];
  12040. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12041. c++;
  12042. }
  12043. sstr[c] = '\0';
  12044. tempStartPeriodInt = atoi(sstr);
  12045. //*************limit****************/
  12046. c = 0;
  12047. loc = strstr(SchedulePeriodList[i], "limit");
  12048. memset(sstr ,0, sizeof(sstr) );
  12049. while (loc[strlen("limit")+2+c] != ',')
  12050. {
  12051. sstr[c] = loc[strlen("limit")+2+c];
  12052. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12053. c++;
  12054. }
  12055. sstr[c] = '\0';
  12056. tempLimitInt = atof(sstr);
  12057. //*************numberPhases****************/
  12058. c = 0;
  12059. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12060. memset(sstr ,0, sizeof(sstr) );
  12061. while (loc[strlen("numberPhases")+2+c] != '}')
  12062. {
  12063. sstr[c] = loc[strlen("numberPhases")+2+c];
  12064. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12065. c++;
  12066. }
  12067. sstr[c] = '\0';
  12068. tempNumberPhasesInt = atoi(sstr);
  12069. //TxProfile.Duration = durationInt;
  12070. TxProfile.TotalPeriod = n_SchedulePeriods;
  12071. TxProfile.Period[i].Limit = tempLimitInt;
  12072. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12073. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12074. }
  12075. if(MinChargingRate < tempminChargingRateFloat)
  12076. MinChargingRate = tempminChargingRateFloat;
  12077. if(confirmPeriods < n_SchedulePeriods)
  12078. confirmPeriods = n_SchedulePeriods;
  12079. if(j == 0)
  12080. {
  12081. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12082. TxProfile_TEMP.StackLevel = tempstackLevel;
  12083. TxProfile_TEMP.TransactionId = 0;
  12084. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12085. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12086. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12087. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12088. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12089. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12090. }
  12091. }
  12092. fclose(fptr1);
  12093. }
  12094. }// the end of ACCESS TxProfile
  12095. //CompositeSchedule
  12096. int period=0;
  12097. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  12098. {
  12099. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  12100. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  12101. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  12102. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  12103. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  12104. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  12105. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  12106. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  12107. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  12108. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  12109. for(int k=0; k < TxProfile.TotalPeriod;k++)
  12110. {
  12111. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  12112. {
  12113. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12114. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12115. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12116. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12117. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12118. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12119. period = period + 1;
  12120. }
  12121. else
  12122. {
  12123. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  12124. {
  12125. }
  12126. else
  12127. {
  12128. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12129. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12130. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12131. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12132. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12133. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12134. period = period + 1;
  12135. }
  12136. }
  12137. }
  12138. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12139. {
  12140. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  12141. {
  12142. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12143. {
  12144. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12145. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12146. }
  12147. else
  12148. {
  12149. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12150. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12151. }
  12152. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12153. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12154. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12155. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12156. period = period + 1;
  12157. }
  12158. }
  12159. }
  12160. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  12161. {
  12162. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12163. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12164. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12165. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12166. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12167. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12168. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12169. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12170. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12171. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12172. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12173. {
  12174. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12175. {
  12176. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12177. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12178. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12179. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12180. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12181. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12182. period = period + 1;
  12183. }
  12184. else
  12185. {
  12186. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12187. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12188. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12189. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12190. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12191. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12192. period = period + 1;
  12193. }
  12194. }
  12195. }
  12196. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  12197. {
  12198. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12199. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12200. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12201. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12202. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12203. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12204. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12205. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12206. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12207. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12208. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12209. {
  12210. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12211. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12213. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12214. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12215. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12216. period = period + 1;
  12217. }
  12218. }
  12219. confirmPeriods = period;
  12220. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  12221. #if 0
  12222. //* Define temporary variables */
  12223. struct tm *gtime;
  12224. time_t now;
  12225. char buf[28];
  12226. //* Read the current system time */
  12227. time(&now);
  12228. //* Convert the system time to GMT (now UTC) */
  12229. gtime = gmtime(&now);
  12230. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  12231. // make .conf
  12232. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  12233. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  12234. //DEBUG_INFO(" debug 11\n");
  12235. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  12236. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  12237. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  12238. #endif
  12239. }
  12240. #if 0
  12241. void Send(struct json_object *message)
  12242. {
  12243. printf("Send -1 \n");
  12244. printf("message=%s\n",json_object_to_json_string(message));
  12245. LWS_Send(json_object_to_json_string(message));
  12246. }
  12247. #endif
  12248. void LWS_Send(char * str)
  12249. {
  12250. #if 1
  12251. //=====================================================
  12252. // Check InternetConn 0: disconnected, 1: connected
  12253. //====================================================
  12254. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  12255. {
  12256. DEBUG_INFO("\n offline now !!!\n");
  12257. return;
  12258. }
  12259. #endif
  12260. pthread_mutex_lock(&lock);
  12261. memset(SendBuffer,0,SendBufLen);
  12262. sprintf((char *)SendBuffer, "%s", str);
  12263. pthread_mutex_unlock(&lock);
  12264. lws_callback_on_writable(wsi_client);
  12265. lws_service(context, 10000);//timeout_ms
  12266. //usleep(10000); // 等 ?? ?微 ?
  12267. //DEBUG_INFO("Send message end\n");
  12268. }