MessageHandler.c 451 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933
  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[2000]={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. //========================================
  122. // OCPP status/previous related variables
  123. //========================================
  124. static int GunStatusInterval = 10;
  125. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  126. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  127. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  128. static int GbPreviousSystemStatus[GB_QUANTITY];
  129. static int AcPreviousSystemStatus[AC_QUANTITY];
  130. int TransactionMessageAttemptsValue = 0;
  131. int TransactionMessageRetryIntervalValue = 0;
  132. static struct OCPPAuthLocalElemet
  133. {
  134. int listVersionInt;
  135. char idTagstr[20];
  136. char parentIdTag[20];
  137. char expiryDate[30];
  138. char idTagstatus[16];
  139. }idTagQuery;
  140. //=============================================
  141. // OCPP HeartBeat Response Not Receive Counts
  142. //============================================
  143. static int HeartBeatWithNOResponse = 0;
  144. extern struct lws *wsi_client;
  145. extern struct lws_context *context;
  146. #if 0
  147. extern unsigned char *SendBuffer;
  148. #endif
  149. extern unsigned char SendBuffer[4096];
  150. extern int SendBufLen;
  151. //extern map_t hashMap;
  152. //extern data_struct_t* mapItem; --- remove for temporally
  153. //extern data_struct_t mapItem[0];
  154. extern char *random_uuid( char buf[37] );
  155. extern void split(char **arr, char *str, const char *del);
  156. extern pthread_mutex_t mutex1;
  157. extern struct Charger_Info Charger;
  158. extern sqlite3 *db;
  159. int TransactionMessageAttemptsGet(void);
  160. int TransactionMessageRetryIntervalGet(void);
  161. int GetOcppConnStatus(void);
  162. void SetOcppConnStatus(uint8_t status);
  163. int updateSetting(char *key, char *value);
  164. int setKeyValue(char *key, char *value);
  165. void OCPP_get_TableAuthlocalAllData(void);
  166. void processUnkownKey(void);
  167. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  168. struct StructOCPPMeterValue
  169. {
  170. unsigned char TimeStamp[28];
  171. struct StructSampledValue SampledValue[10];
  172. };
  173. struct ClientTime
  174. {
  175. unsigned int Heartbeat;
  176. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  177. unsigned int StartTransaction;
  178. unsigned int StopTransaction;
  179. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  180. }clientTime;
  181. typedef union
  182. {
  183. //Operations Initiated by Central System
  184. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  185. struct
  186. {
  187. //CsMsgValue[0]
  188. unsigned char StatusNotificationReq :1; //bit 0,
  189. unsigned char StatusNotificationConf :1; //bit 0,
  190. unsigned char :6; //bit 2~7
  191. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  192. }CpinitiateMsg;
  193. CpinitiateMsg cpinitateMsg;
  194. //==========================================
  195. // Init all Enumeration & Mapping String
  196. //==========================================
  197. /*ChargePointErrorCode*/
  198. typedef enum {
  199. ConnectorLockFailure,
  200. EVCommunicationError,
  201. GroundFailure,
  202. HighTemperature,
  203. InternalError,
  204. LocalListConflict,
  205. NoError,
  206. OtherError,
  207. OverCurrentFailure,
  208. OverVoltage,
  209. PowerMeterFailure,
  210. PowerSwitchFailure,
  211. ReaderFailure,
  212. ResetFailure,
  213. UnderVoltage,
  214. WeakSignal
  215. } ChargePointErrorCode;
  216. #if 0
  217. static char *ChargePointErrorCodeStr[] = {
  218. MACROSTR(ConnectorLockFailure),
  219. MACROSTR(EVCommunicationError),
  220. MACROSTR(GroundFailure),
  221. MACROSTR(HighTemperature),
  222. MACROSTR(InternalError),
  223. MACROSTR(LocalListConflict),
  224. MACROSTR(NoError),
  225. MACROSTR(OtherError),
  226. MACROSTR(OverCurrentFailure),
  227. MACROSTR(OverVoltage),
  228. MACROSTR(PowerMeterFailure),
  229. MACROSTR(PowerSwitchFailure),
  230. MACROSTR(ReaderFailure),
  231. MACROSTR(ResetFailure),
  232. MACROSTR(UnderVoltage),
  233. MACROSTR(WeakSignal)
  234. };
  235. #endif
  236. /*ChargePointStatus*/
  237. typedef enum {
  238. Available =0,
  239. Preparing,
  240. Charging,
  241. SuspendedEVSE,
  242. SuspendedEV,
  243. Finishing,
  244. Reserved,
  245. Unavailable,
  246. Faulted
  247. } ChargePointStatus;
  248. static char * ChargePointStatusStr[] = {
  249. MACROSTR(Available),
  250. MACROSTR(Preparing),
  251. MACROSTR(Charging),
  252. MACROSTR(SuspendedEVSE),
  253. MACROSTR(SuspendedEV),
  254. MACROSTR(Finishing),
  255. MACROSTR(Reserved),
  256. MACROSTR(Unavailable),
  257. MACROSTR(Faulted)
  258. };
  259. /*AvailabilityType*/
  260. typedef enum {
  261. RegistrationStatus_Accepted,
  262. RegistrationStatus_Pending,
  263. RegistrationStatus_Rejected
  264. } RegistrationStatus;
  265. static char *RegistrationStatusStr[] = {
  266. MACROSTR(Accepted),
  267. MACROSTR(Pending),
  268. MACROSTR(Rejected)
  269. };
  270. /*AvailabilityType*/
  271. typedef enum {
  272. Inoperative,
  273. Operative
  274. } AvailabilityType;
  275. static char *AvailabilityTypeStr[] = {
  276. MACROSTR(Inoperative),
  277. MACROSTR(Operative)
  278. };
  279. /*AvailabilityStatus*/
  280. typedef enum {
  281. Accepted,
  282. Rejected,
  283. Scheduled
  284. } AvailabilityStatus;
  285. static char *AvailabilityStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected),
  288. MACROSTR(Scheduled)
  289. };
  290. /*ConfigurationStatus*/
  291. typedef enum {
  292. ConfigurationStatus_Accepted,
  293. ConfigurationStatus_Rejected,
  294. RebootRequired,
  295. NotSupported
  296. } ConfigurationStatus;
  297. static char *ConfigurationStatusStr[] = {
  298. MACROSTR(Accepted),
  299. MACROSTR(Rejected),
  300. MACROSTR(RebootRequired),
  301. MACROSTR(NotSupported)
  302. };
  303. /*ClearCacheStatus*/
  304. typedef enum {
  305. ClearCacheStatus_Accepted,
  306. ClearCacheStatus_Rejected
  307. } ClearCacheStatus;
  308. static char *ClearCacheStatusStr[] = {
  309. MACROSTR(Accepted),
  310. MACROSTR(Rejected)
  311. };
  312. /*ChargingProfilePurposeType*/
  313. typedef enum {
  314. ChargePointMaxProfile,
  315. TxDefaultProfile,
  316. TxProfile
  317. } ChargingProfilePurposeType;
  318. static char *ChargingProfilePurposeTypeStr[] = {
  319. MACROSTR(ChargePointMaxProfile),
  320. MACROSTR(TxDefaultProfile),
  321. MACROSTR(TxProfile)
  322. };
  323. /*ChargingProfileStatus*/
  324. typedef enum {
  325. ChargingProfileStatus_Accepted,
  326. ChargingProfileStatus_Rejected,
  327. ChargingProfileStatus_NotSupported
  328. } ChargingProfileStatus;
  329. static char *ChargingProfileStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Rejected),
  332. MACROSTR(NotSupported)
  333. };
  334. /*ClearChargingProfileStatus*/
  335. typedef enum {
  336. ClearChargingProfileStatus_Accepted,
  337. ClearChargingProfileStatus_Unknown
  338. } ClearChargingProfileStatus;
  339. static char *ClearChargingProfileStatusStr[] = {
  340. MACROSTR(Accepted),
  341. MACROSTR(Unknown)
  342. };
  343. /*GetCompositeScheduleStatus*/
  344. typedef enum {
  345. GetCompositeScheduleStatus_Accepted,
  346. GetCompositeScheduleStatus_Rejected
  347. } GetCompositeScheduleStatus;
  348. static char *GetCompositeScheduleStatusStr[] = {
  349. MACROSTR(Accepted),
  350. MACROSTR(Rejected)
  351. };
  352. /*ChargingRateUnitType*/
  353. typedef enum {
  354. ChargingRateUnitType_W,
  355. ChargingRateUnitType_A
  356. } ChargingRateUnitType;
  357. /*AuthorizationStatus*/
  358. typedef enum {
  359. AuthorizationStatus_Accepted ,
  360. AuthorizationStatus_Blocked ,
  361. AuthorizationStatus_Expired ,
  362. AuthorizationStatus_Invalid ,
  363. AuthorizationStatus_ConcurrentTx
  364. } AuthorizationStatus;
  365. /*UpdateType*/
  366. typedef enum {
  367. Differential ,
  368. Full
  369. } UpdateType;
  370. static char *UpdateTypeStr[] = {
  371. MACROSTR(Differential),
  372. MACROSTR(Full)
  373. };
  374. /*UpdateStatus*/
  375. typedef enum {
  376. UpdateStatus_Accepted ,
  377. UpdateStatus_Failed ,
  378. UpdateStatus_NotSupported ,
  379. UpdateStatus_VersionMismatch
  380. } UpdateStatus;
  381. static char *UpdateStatusStr[] = {
  382. MACROSTR(Accepted),
  383. MACROSTR(Failed),
  384. MACROSTR(NotSupported),
  385. MACROSTR(VersionMismatch)
  386. };
  387. /*RemoteStartStopStatus*/
  388. typedef enum {
  389. RemoteStartStopStatus_Accepted,
  390. RemoteStartStopStatus_Rejected
  391. } RemoteStartStopStatus;
  392. static char *RemoteStartStopStatusStr[] = {
  393. MACROSTR(Accepted),
  394. MACROSTR(Rejected)
  395. };
  396. /*ReservationStatus*/
  397. typedef enum {
  398. ReservationStatus_Accepted,
  399. ReservationStatus_Faulted,
  400. ReservationStatus_Occupied,
  401. ReservationStatus_Rejected,
  402. ReservationStatus_Unavailable
  403. } ReservationStatus;
  404. static char *ReservationStatusStr[] = {
  405. MACROSTR(Accepted),
  406. MACROSTR(Faulted),
  407. MACROSTR(Occupied),
  408. MACROSTR(Rejected),
  409. MACROSTR(Unavailable)
  410. };
  411. /*ResetType*/
  412. typedef enum {
  413. Hard,
  414. Soft
  415. } ResetType;
  416. static char *ResetTypeStr[] = {
  417. MACROSTR(Hard),
  418. MACROSTR(Soft)
  419. };
  420. /*ResetStatus*/
  421. typedef enum {
  422. ResetStatus_Accepted,
  423. ResetStatus_Rejected
  424. } ResetStatus;
  425. static char *ResetStatusStr[] = {
  426. MACROSTR(Accepted),
  427. MACROSTR(Rejected)
  428. };
  429. /*DiagnosticsStatus*/
  430. typedef enum {
  431. DiagnosticsStatus_Idle,
  432. DiagnosticsStatus_Uploaded,
  433. DiagnosticsStatus_UploadFailed,
  434. DiagnosticsStatus_Uploading
  435. } DiagnosticsStatus;
  436. static char * DiagnosticsStatusStr[] = {
  437. MACROSTR(Idle),
  438. MACROSTR(Uploaded),
  439. MACROSTR(UploadFailed),
  440. MACROSTR(Uploading)
  441. };
  442. /*FirmwareStatus*/
  443. typedef enum {
  444. FirmwareStatus_Downloaded,
  445. FirmwareStatus_DownloadFailed,
  446. FirmwareStatus_Downloading,
  447. FirmwareStatus_Idle,
  448. FirmwareStatus_InstallationFailed,
  449. FirmwareStatus_Installing,
  450. FirmwareStatus_Installed
  451. } FirmwareStatus;
  452. static char * FirmwareStatusStr[] = {
  453. MACROSTR(Downloaded),
  454. MACROSTR(DownloadFailed),
  455. MACROSTR(Downloading),
  456. MACROSTR(Idle),
  457. MACROSTR(InstallationFailed),
  458. MACROSTR(Installing),
  459. MACROSTR(Installed)
  460. };
  461. /*MessageTrigger*/
  462. typedef enum {
  463. BootNotification,
  464. DiagnosticsStatusNotification,
  465. FirmwareStatusNotification,
  466. Heartbeat,
  467. MeterValues,
  468. StatusNotification
  469. } MessageTrigger;
  470. static char * MessageTriggerStr[] = {
  471. MACROSTR(BootNotification),
  472. MACROSTR(DiagnosticsStatusNotification),
  473. MACROSTR(FirmwareStatusNotification),
  474. MACROSTR(Heartbeat),
  475. MACROSTR(MeterValues),
  476. MACROSTR(StatusNotification)
  477. };
  478. /*TriggerMessageStatus*/
  479. typedef enum {
  480. TriggerMessageStatus_Accepted ,
  481. TriggerMessageStatus_Rejected ,
  482. TriggerMessageStatus_NotImplemented
  483. } TriggerMessageStatus;
  484. static char * TriggerMessageStatusStr[] = {
  485. MACROSTR(Accepted),
  486. MACROSTR(Rejected),
  487. MACROSTR(NotImplemented)
  488. };
  489. /*UnlockStatus*/
  490. typedef enum {
  491. Unlocked,
  492. UnlockFailed,
  493. UnlockStatus_NotSupported
  494. } UnlockStatus;
  495. static char * UnlockStatusStr[] = {
  496. MACROSTR(Unlocked),
  497. MACROSTR(UnlockFailed),
  498. MACROSTR(NotSupported)
  499. };
  500. /*StopTransactionReason*/
  501. typedef enum {
  502. EmergencyStop,
  503. EVDisconnected,
  504. HardReset,
  505. Local,
  506. Other,
  507. PowerLoss,
  508. Reboot,
  509. Remote,
  510. SoftReset,
  511. UnlockCommand,
  512. DeAuthorized
  513. } StopTransactionReason;
  514. static char * StopTransactionReasonStr[] = {
  515. MACROSTR(EmergencyStop),
  516. MACROSTR(EVDisconnected),
  517. MACROSTR(HardReset),
  518. MACROSTR(Local),
  519. MACROSTR(Other),
  520. MACROSTR(PowerLoss),
  521. MACROSTR(Reboot),
  522. MACROSTR(Remote),
  523. MACROSTR(SoftReset),
  524. MACROSTR(UnlockCommand),
  525. MACROSTR(DeAuthorized)
  526. };
  527. /*CancelReservationStatus*/
  528. typedef enum {
  529. CancelReservationStatus_Accepted,
  530. CancelReservationStatus_Rejected
  531. } CancelReservationStatus;
  532. static char * CancelReservationStatusStr[] = {
  533. MACROSTR(Accepted),
  534. MACROSTR(Rejected)
  535. };
  536. /*ReadingContext*/
  537. typedef enum {
  538. ReadingContext_Interruption_Begin,
  539. ReadingContext_Interruption_End,
  540. ReadingContext_Other,
  541. ReadingContext_Sample_Clock,
  542. ReadingContext_Sample_Periodic ,
  543. ReadingContext_Transaction_Begin ,
  544. ReadingContext_Transaction_End,
  545. ReadingContext_Trigger
  546. } ReadingContext;
  547. static char * ReadingContextStr[] = {
  548. MACROSTR(Interruption.Begin),
  549. MACROSTR(Interruption.End),
  550. MACROSTR(Other),
  551. MACROSTR(Sample.Clock),
  552. MACROSTR(Sample.Periodic),
  553. MACROSTR(Transaction.Begin),
  554. MACROSTR(Transaction.End),
  555. MACROSTR(Trigger)
  556. };
  557. /*ValueFormat*/
  558. typedef enum {
  559. Raw,
  560. SignedData
  561. } ValueFormat;
  562. static char * ValueFormatStr[] = {
  563. MACROSTR(Raw),
  564. MACROSTR(SignedData)
  565. };
  566. /*Measurand*/
  567. typedef enum {
  568. Current_Export ,
  569. Current_Import,
  570. Current_Offered,
  571. Energy_Active_Export_Register,
  572. Energy_Active_Import_Register,
  573. Energy_Reactive_Export_Register,
  574. Energy_Reactive_Import_Register,
  575. Energy_Active_Export_Interval,
  576. Energy_Active_Import_Interval,
  577. Energy_Reactive_Export_Interval,
  578. Energy_Reactive_Import_Interval,
  579. Frequency,
  580. Power_Active_Export ,
  581. Power_Active_Import,
  582. Power_Factor,
  583. Power_Offered,
  584. Power_Reactive_Export,
  585. Power_Reactive_Import,
  586. RPM,
  587. SoC,
  588. Temperature ,
  589. Voltage
  590. } Measurand;
  591. static char * MeasurandStr[] = {
  592. MACROSTR(Current.Export),
  593. MACROSTR(Current.Import),
  594. MACROSTR(Current.Offered),
  595. MACROSTR(Energy.Active.Export.Register),
  596. MACROSTR(Energy.Active.Import.Register),
  597. MACROSTR(Energy.Reactive.Export.Register),
  598. MACROSTR(Energy.Reactive.Import.Register),
  599. MACROSTR(Energy.Active.Export.Interval),
  600. MACROSTR(Energy.Active.Import.Interval),
  601. MACROSTR(Energy.Reactive.Export.Interval),
  602. MACROSTR(Energy.Reactive.Import.Interval),
  603. MACROSTR(Frequency),
  604. MACROSTR(Power.Active.Export),
  605. MACROSTR(Power.Active.Import),
  606. MACROSTR(Power.Factor),
  607. MACROSTR(Power.Offered),
  608. MACROSTR(Power.Reactive.ExportMACROSTR),
  609. MACROSTR(Power.Reactive.Import),
  610. MACROSTR(RPM),
  611. MACROSTR(SoC),
  612. MACROSTR(Temperature),
  613. MACROSTR(Voltage)
  614. };
  615. /*Location*/
  616. typedef enum {
  617. Location_Body,
  618. Location_Cable,
  619. Location_EV,
  620. Location_Inlet ,
  621. Location_Outlet
  622. } Location;
  623. static char * LocationStr[] = {
  624. MACROSTR(Body),
  625. MACROSTR(Cable),
  626. MACROSTR(EV),
  627. MACROSTR(Inlet),
  628. MACROSTR(Outlet)
  629. };
  630. /*Phase*/
  631. typedef enum {
  632. L1,
  633. L2,
  634. L3,
  635. N,
  636. L1_N,
  637. L2_N,
  638. L3_N,
  639. L1_L2,
  640. L2_L3,
  641. L3_L1
  642. } Phase;
  643. static char * PhaseStr[] = {
  644. MACROSTR(L1),
  645. MACROSTR(L2),
  646. MACROSTR(L3),
  647. MACROSTR(N),
  648. MACROSTR(L1-N),
  649. MACROSTR(L2-N),
  650. MACROSTR(L3-N),
  651. MACROSTR(L1-L2),
  652. MACROSTR(L2-L3),
  653. MACROSTR(L3-L1)
  654. };
  655. /*UnitOfMeasure*/
  656. typedef enum {
  657. UnitOfMeasure_Wh,
  658. UnitOfMeasure_kWh ,
  659. UnitOfMeasure_varh ,
  660. UnitOfMeasure_kvarh ,
  661. UnitOfMeasure_W ,
  662. UnitOfMeasure_kW ,
  663. UnitOfMeasure_VA ,
  664. UnitOfMeasure_kVA ,
  665. UnitOfMeasure_var ,
  666. UnitOfMeasure_kvar ,
  667. UnitOfMeasure_A ,
  668. UnitOfMeasure_V ,
  669. UnitOfMeasure_Celsius ,
  670. UnitOfMeasure_Fahrenheit ,
  671. UnitOfMeasure_K ,
  672. UnitOfMeasure_Percent
  673. } UnitOfMeasure;
  674. static char * UnitOfMeasureStr[] = {
  675. MACROSTR(Wh),
  676. MACROSTR(kWh),
  677. MACROSTR(varh),
  678. MACROSTR(kvarh),
  679. MACROSTR(W),
  680. MACROSTR(kW),
  681. MACROSTR(VA),
  682. MACROSTR(kVA),
  683. MACROSTR(var),
  684. MACROSTR(kvar),
  685. MACROSTR(A),
  686. MACROSTR(V),
  687. MACROSTR(Celsius),
  688. MACROSTR(Fahrenheit),
  689. MACROSTR(K),
  690. MACROSTR(Percent)
  691. };
  692. /*Configuration enum*/
  693. enum CoreProfile {
  694. AllowOfflineTxForUnknownId=0,
  695. AuthorizationCacheEnabled,
  696. AuthorizeRemoteTxRequests,
  697. BlinkRepeat,
  698. ClockAlignedDataInterval,
  699. ConnectionTimeOut,
  700. GetConfigurationMaxKeys,
  701. HeartbeatInterval,
  702. LightIntensity,
  703. LocalAuthorizeOffline,
  704. LocalPreAuthorize,
  705. MaxEnergyOnInvalidId,
  706. MeterValuesAlignedData,
  707. MeterValuesAlignedDataMaxLength,
  708. MeterValuesSampledData,
  709. MeterValuesSampledDataMaxLength,
  710. MeterValueSampleInterval,
  711. MinimumStatusDuration,
  712. NumberOfConnectors,
  713. ResetRetries,
  714. ConnectorPhaseRotation,
  715. ConnectorPhaseRotationMaxLength,
  716. StopTransactionOnEVSideDisconnect,
  717. StopTransactionOnInvalidId,
  718. StopTxnAlignedData,
  719. StopTxnAlignedDataMaxLength,
  720. StopTxnSampledData,
  721. StopTxnSampledDataMaxLength,
  722. SupportedFeatureProfiles,
  723. SupportedFeatureProfilesMaxLength,
  724. TransactionMessageAttempts,
  725. TransactionMessageRetryInterval,
  726. UnlockConnectorOnEVSideDisconnect,
  727. WebSocketPingInterval,
  728. _CoreProfile_CNT
  729. };
  730. enum LocalAuthListManagementProfile{
  731. LocalAuthListEnabled=0,
  732. LocalAuthListMaxLength,
  733. SendLocalListMaxLength,
  734. _LocalAuthListManagementProfile_CNT
  735. };
  736. enum ReservationProfile{
  737. ReserveConnectorZeroSupported
  738. };
  739. enum SmartChargingProfile{
  740. ChargeProfileMaxStackLevel,
  741. ChargingScheduleAllowedChargingRateUnit,
  742. ChargingScheduleMaxPeriods,
  743. ConnectorSwitch3to1PhaseSupported,
  744. MaxChargingProfilesInstalled
  745. };
  746. enum ChargerSystemStatus{
  747. ChargerSystemStatus_Booting,
  748. ChargerSystemStatus_Idle,
  749. ChargerSystemStatus_Authorizing,
  750. ChargerSystemStatus_Preparing,
  751. ChargerSystemStatus_Charging,
  752. ChargerSystemStatus_Terminating,
  753. ChargerSystemStatus_Alarm,
  754. ChargerSystemStatus_Fault
  755. };
  756. enum GetConfigurationKey {
  757. GetConfiguration_AllowOfflineTxForUnknownId=0,
  758. GetConfiguration_AuthorizationCacheEnabled,
  759. GetConfiguration_AuthorizeRemoteTxRequests,
  760. GetConfiguration_BlinkRepeat,
  761. GetConfiguration_ClockAlignedDataInterval,
  762. GetConfiguration_ConnectionTimeOut,
  763. GetConfiguration_GetConfigurationMaxKeys,
  764. GetConfiguration_HeartbeatInterval,
  765. GetConfiguration_LightIntensity,
  766. GetConfiguration_LocalAuthorizeOffline,
  767. GetConfiguration_LocalPreAuthorize,
  768. GetConfiguration_MaxEnergyOnInvalidId,
  769. GetConfiguration_MeterValuesAlignedData,
  770. GetConfiguration_MeterValuesAlignedDataMaxLength,
  771. GetConfiguration_MeterValuesSampledData,
  772. GetConfiguration_MeterValuesSampledDataMaxLength,
  773. GetConfiguration_MeterValueSampleInterval,
  774. GetConfiguration_MinimumStatusDuration,
  775. GetConfiguration_NumberOfConnectors,
  776. GetConfiguration_ResetRetries,
  777. GetConfiguration_ConnectorPhaseRotation,
  778. GetConfiguration_ConnectorPhaseRotationMaxLength,
  779. GetConfiguration_StopTransactionOnEVSideDisconnect,
  780. GetConfiguration_StopTransactionOnInvalidId,
  781. GetConfiguration_StopTxnAlignedData,
  782. GetConfiguration_StopTxnAlignedDataMaxLength,
  783. GetConfiguration_StopTxnSampledData,
  784. GetConfiguration_StopTxnSampledDataMaxLength,
  785. GetConfiguration_SupportedFeatureProfiles,
  786. GetConfiguration_SupportedFeatureProfilesMaxLength,
  787. GetConfiguration_TransactionMessageAttempts,
  788. GetConfiguration_TransactionMessageRetryInterval,
  789. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  790. GetConfiguration_WebSocketPingInterval,
  791. GetConfiguration_LocalAuthListEnabled,
  792. GetConfiguration_LocalAuthListMaxLength,
  793. GetConfiguration_SendLocalListMaxLength,
  794. GetConfiguration_ReserveConnectorZeroSupported,
  795. GetConfiguration_ChargeProfileMaxStackLevel,
  796. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  797. GetConfiguration_ChargingScheduleMaxPeriods,
  798. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  799. GetConfiguration_MaxChargingProfilesInstalled,
  800. };
  801. //GetConfiguration Array
  802. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  803. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  804. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  805. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  806. //==========================================
  807. // Init all share memory
  808. //==========================================
  809. int InitShareMemory()
  810. {
  811. int result = PASS;
  812. int MeterSMId;
  813. //printf("1\n");
  814. //creat ShmSysConfigAndInfo
  815. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  816. {
  817. #ifdef SystemLogMessage
  818. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  819. #endif
  820. result = FAIL;
  821. }
  822. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  823. {
  824. #ifdef SystemLogMessage
  825. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  826. #endif
  827. result = FAIL;
  828. }
  829. else
  830. {}
  831. //printf("2\n");
  832. //creat ShmStatusCodeData
  833. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  834. {
  835. #ifdef SystemLogMessage
  836. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  837. #endif
  838. result = FAIL;
  839. }
  840. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  841. {
  842. #ifdef SystemLogMessage
  843. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  844. #endif
  845. result = FAIL;
  846. }
  847. else
  848. {}
  849. //printf("3\n");
  850. //creat ShmPsuData
  851. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmPsuData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmPsuData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmOCPP16Data
  868. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. /****************************** For Initial Settings************************************************/
  885. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  886. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  887. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  888. {
  889. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  890. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  891. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  892. }
  893. // Charger PRE_SYS_MODE
  894. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  895. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  896. clientTime.Heartbeat=time((time_t*)NULL);
  897. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  898. {
  899. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  900. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  901. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  902. }
  903. //HeartBeatWaitTime = 10;
  904. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  905. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  906. // allocate Configuration memory address
  907. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  908. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  909. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  910. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  912. {
  913. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  914. DEBUG_INFO("DC ...\n");
  915. }
  916. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  917. {
  918. SystemInitial = AC_QUANTITY;
  919. DEBUG_INFO("AC ...\n");
  920. }
  921. //Status Setting
  922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  923. {
  924. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  925. }
  926. for (int index = 0; index < CCS_QUANTITY; index++)
  927. {
  928. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  929. }
  930. for (int index = 0; index < GB_QUANTITY; index++)
  931. {
  932. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  933. }
  934. for (int index = 0; index < AC_QUANTITY; index++)
  935. {
  936. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  937. }
  938. //memset(unknownkey, 0, 10);
  939. return result;
  940. }
  941. int ProcessShareMemory()
  942. {
  943. if(InitShareMemory() == FAIL)
  944. {
  945. #ifdef SystemLogMessage
  946. DEBUG_ERROR("InitShareMemory NG\n");
  947. #endif
  948. if(ShmStatusCodeData!=NULL)
  949. {
  950. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  951. }
  952. sleep(5);
  953. return FAIL;
  954. }
  955. return PASS;
  956. }
  957. //---------------------------------------------
  958. // new:
  959. // enum SYSTEM_STATUS
  960. // {
  961. // SYS_MODE_BOOTING = 0,
  962. // SYS_MODE_IDLE = 1,
  963. // SYS_MODE_AUTHORIZING = 2,
  964. // SYS_MODE_PREPARING = 3,
  965. // SYS_MODE_CHARGING = 4,
  966. // SYS_MODE_TERMINATING = 5,
  967. // SYS_MODE_ALARM = 6,
  968. // SYS_MODE_FAULT = 7,
  969. // SYS_MODE_RESERVATION = 8,
  970. // SYS_MODE_BOOKING = 9,
  971. // SYS_MODE_MAINTAIN = 10,
  972. // SYS_MODE_DEBUG = 11,
  973. // SYS_MODE_REASSIGN_CHECK = 12,
  974. // SYS_MODE_REASSIGN = 13,
  975. // SYS_MODE_PRECHARGE = 14,
  976. // SYS_MODE_PREPARING_EV = 15,
  977. // SYS_MODE_PREPARING_EVSE = 16,
  978. // SYS_MODE_COMPLETE = 17
  979. // };
  980. //
  981. // old:
  982. // enum _SYSTEM_STATUS
  983. // {
  984. // S_BOOTING = 0,
  985. // S_IDLE, =1
  986. // S_AUTHORIZING, =2
  987. // S_REASSIGN_CHECK, =3
  988. // S_REASSIGN, =4
  989. // S_PRECHARGE, =5
  990. // S_PREPARING_FOR_EV, =6
  991. // S_PREPARING_FOR_EVSE, =7
  992. // S_CHARGING, =8
  993. // S_TERMINATING, =9
  994. // S_COMPLETE, =10
  995. // S_ALARM, =11
  996. // S_FAULT =12
  997. // };
  998. //
  999. //-----------------------------------------
  1000. void CheckSystemValue(void)
  1001. {
  1002. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1003. int IdleModeCnt = 0;
  1004. char filenmae[100]={0};
  1005. char str[100]={0};
  1006. //===============================
  1007. // send Heartbeat
  1008. //===============================
  1009. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1010. {
  1011. //parameter for test
  1012. sendHeartbeatRequest(0);
  1013. //==============================================
  1014. // Reset Waiting Time
  1015. //==============================================
  1016. clientTime.Heartbeat=time((time_t*)NULL);
  1017. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1018. }
  1019. //==============================================
  1020. // Update firmware request
  1021. //==============================================
  1022. if(isUpdateRequest == TRUE )
  1023. {
  1024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1025. {
  1026. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1027. {
  1028. //check SystemStatus
  1029. /*************************DC*******************************/
  1030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1031. {
  1032. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1033. {
  1034. IdleModeCnt = IdleModeCnt + 1;
  1035. }
  1036. }
  1037. for (int index = 0; index < CCS_QUANTITY; index++)
  1038. {
  1039. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1040. {
  1041. IdleModeCnt = IdleModeCnt + 1;
  1042. }
  1043. }
  1044. for (int index = 0; index < GB_QUANTITY; index++)
  1045. {
  1046. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1047. {
  1048. IdleModeCnt = IdleModeCnt + 1;
  1049. }
  1050. }
  1051. }
  1052. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1053. {
  1054. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1055. isUpdateRequest = FALSE;
  1056. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1057. }
  1058. }
  1059. else
  1060. {
  1061. /*************************AC*******************************/
  1062. for (int index = 0; index < AC_QUANTITY; index++)
  1063. {
  1064. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1065. {
  1066. IdleModeCnt = IdleModeCnt + 1;
  1067. }
  1068. }
  1069. if(IdleModeCnt == AC_QUANTITY)
  1070. {
  1071. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1072. isUpdateRequest = FALSE;
  1073. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1074. }
  1075. }
  1076. }
  1077. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1078. for(int gun_index=0;gun_index < gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1079. {
  1080. //===============================
  1081. // CSU Trigger Reset Conf
  1082. //===============================
  1083. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1084. {
  1085. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1086. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1087. {
  1088. server_sign = FALSE;
  1089. }
  1090. }
  1091. //===============================
  1092. // CSU Trigger Authorize Request
  1093. //===============================
  1094. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1095. {
  1096. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1097. {
  1098. sendAuthorizeRequest(0);
  1099. authorizeRetryTimes = authorizeRetryTimes + 1;
  1100. // authenrequest = TRUE
  1101. if(authorizeRetryTimes < 3)
  1102. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1103. }
  1104. }
  1105. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1106. {
  1107. authorizeRetryTimes = 0;
  1108. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1109. server_sign = FALSE;
  1110. }
  1111. //==============================================
  1112. // Charger start transaction
  1113. //==============================================
  1114. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1115. {
  1116. sendStartTransactionRequest(gun_index);
  1117. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1118. clientTime.StartTransaction = time((time_t*)NULL);
  1119. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1120. }
  1121. //==============================================
  1122. // Charger stop transaction
  1123. //==============================================
  1124. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1125. {
  1126. sendStopTransactionRequest(gun_index);
  1127. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1128. clientTime.StopTransaction = time((time_t*)NULL);
  1129. }
  1130. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1131. //==============================================
  1132. // Charger status report
  1133. //==============================================
  1134. /* Check Mode Change */
  1135. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1136. {
  1137. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1138. {
  1139. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1140. {
  1141. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1142. {
  1143. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1144. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1145. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1146. statusModeChage[gun_index] = TRUE;
  1147. }
  1148. }
  1149. }
  1150. for (int index = 0; index < CCS_QUANTITY; index++)
  1151. {
  1152. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1153. {
  1154. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1155. {
  1156. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1157. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1158. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1159. statusModeChage[gun_index] = TRUE;
  1160. }
  1161. }
  1162. }
  1163. for (int index = 0; index < GB_QUANTITY; index++)
  1164. {
  1165. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1166. {
  1167. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1168. {
  1169. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1170. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1171. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1172. statusModeChage[gun_index] = TRUE;
  1173. }
  1174. }
  1175. }
  1176. }
  1177. else //AC
  1178. {
  1179. for (int index = 0; index < AC_QUANTITY; index++)
  1180. {
  1181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1182. {
  1183. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1184. {
  1185. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1186. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1187. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1188. statusModeChage[gun_index] = TRUE;
  1189. }
  1190. }
  1191. }// END OF FOR
  1192. }// END OF ELSE
  1193. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1194. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1195. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1196. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1197. {
  1198. if(SystemInitial != 0)
  1199. SystemInitial = SystemInitial -1;
  1200. //GunStatusInterval= GunStatusInterval* gun_index;
  1201. sendStatusNotificationRequest(gun_index);
  1202. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1203. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1204. statusModeChage[gun_index] = FALSE;
  1205. //sleep(30); // sleep for 30 seconds
  1206. }
  1207. //==============================================
  1208. // Meter report
  1209. //==============================================
  1210. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1211. {
  1212. //check Transaction active
  1213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1214. {
  1215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1216. {
  1217. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1218. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1219. {
  1220. meterValueSend[gun_index] =1;
  1221. }
  1222. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1223. {
  1224. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1225. if((access(filenmae,F_OK))!=-1)
  1226. {
  1227. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1228. sprintf(str,"rm -f %s",filenmae);
  1229. system(str);
  1230. }
  1231. }
  1232. }// End for CHAdeMO
  1233. for (int index = 0; index < CCS_QUANTITY; index++)
  1234. {
  1235. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1236. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1237. {
  1238. meterValueSend[gun_index] =1;
  1239. }
  1240. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1241. {
  1242. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1243. if((access(filenmae,F_OK))!=-1)
  1244. {
  1245. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1246. sprintf(str,"rm -f %s",filenmae);
  1247. system(str);
  1248. }
  1249. }
  1250. } // End for CCS
  1251. for (int index = 0; index < GB_QUANTITY; index++)
  1252. {
  1253. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1254. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1255. {
  1256. meterValueSend[gun_index] =1;
  1257. }
  1258. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1259. {
  1260. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1261. if((access(filenmae,F_OK))!=-1)
  1262. {
  1263. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1264. sprintf(str,"rm -f %s",filenmae);
  1265. system(str);
  1266. }
  1267. }
  1268. }// End for GB
  1269. }
  1270. else
  1271. {
  1272. for (int index = 0; index < AC_QUANTITY; index++)
  1273. {
  1274. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1275. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1276. {
  1277. meterValueSend[gun_index] =1;
  1278. }
  1279. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1280. {
  1281. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1282. if((access(filenmae,F_OK))!=-1)
  1283. {
  1284. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1285. sprintf(str,"rm -f %s",filenmae);
  1286. system(str);
  1287. }
  1288. }
  1289. }//End for AC
  1290. }//END OF ELSE
  1291. // sleep(1);
  1292. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1293. if(meterValueSend[gun_index] == 1)
  1294. sendMeterValuesRequest(gun_index);
  1295. }
  1296. //==============================================
  1297. // Check Connector reserved
  1298. //==============================================
  1299. //===============================
  1300. // Check if Reserve is expired
  1301. //===============================
  1302. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1303. {
  1304. double diff_t;
  1305. struct tm tp;
  1306. // current time
  1307. time_t t = time(NULL);
  1308. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1309. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1310. tp.tm_isdst = -1;
  1311. time_t utc = mktime(&tp);
  1312. diff_t = difftime(utc, t);
  1313. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1314. if(diff_t <= 0)
  1315. {
  1316. DEBUG_INFO("reserve expired !!! \n");
  1317. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1318. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1319. }
  1320. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1321. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1322. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1323. {
  1324. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1325. }
  1326. else
  1327. {
  1328. //check Transaction active
  1329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1330. {
  1331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1332. {
  1333. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1334. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1335. {
  1336. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1337. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1338. {
  1339. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1340. }
  1341. }
  1342. }
  1343. for (int index = 0; index < CCS_QUANTITY; index++)
  1344. {
  1345. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1346. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1347. {
  1348. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1349. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1350. {
  1351. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1352. }
  1353. }
  1354. }
  1355. for (int index = 0; index < GB_QUANTITY; index++)
  1356. {
  1357. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1358. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1359. {
  1360. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1361. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1362. {
  1363. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1364. }
  1365. }
  1366. }
  1367. }
  1368. else //AC
  1369. {
  1370. for (int index = 0; index < AC_QUANTITY; index++)
  1371. {
  1372. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1373. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1374. {
  1375. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1376. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1377. {
  1378. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1379. }
  1380. }
  1381. }
  1382. }// END OF ELSE
  1383. }// END OF check Transaction active
  1384. }//END OF Check if Reserve is expired
  1385. //==========================================
  1386. // csu trigger FirmwareStatusNotificationReq
  1387. //==========================================
  1388. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1389. {
  1390. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1391. }
  1392. //==========================================
  1393. // csu trigger CancelReservationConf
  1394. //==========================================
  1395. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1396. {
  1397. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1398. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1399. }
  1400. //==========================================
  1401. // csu trigger ChangeAvailabilityConf
  1402. //==========================================
  1403. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1404. {
  1405. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1406. }
  1407. //==========================================
  1408. // csu trigger UnlockConnectorConf
  1409. //==========================================
  1410. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1411. {
  1412. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1413. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1414. }
  1415. //==========================================
  1416. // csu trigger ReserveNowConf
  1417. //==========================================
  1418. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1419. {
  1420. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1421. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1422. }
  1423. //==========================================
  1424. // csu trigger DataTransferReq
  1425. //==========================================
  1426. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1427. {
  1428. sendDataTransferRequest(gun_index);
  1429. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1430. }
  1431. }
  1432. }
  1433. //==========================================
  1434. // send request routine
  1435. //==========================================
  1436. int sendAuthorizeRequest(int gun_index)
  1437. {
  1438. mtrace();
  1439. int result = FAIL;
  1440. char message[100]={0};
  1441. char guid[37];
  1442. char tempdata[65]={0};
  1443. DEBUG_INFO("sendAuthorizeRequest \n");
  1444. //Local Authorize
  1445. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1446. {
  1447. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1448. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1449. {
  1450. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1451. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1452. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1453. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1454. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1455. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1456. authorizeRetryTimes = 0;
  1457. return result;
  1458. }
  1459. else
  1460. {
  1461. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1462. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1463. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1464. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1465. result = PASS;
  1466. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1467. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1468. authorizeRetryTimes = 0;
  1469. return result;
  1470. }
  1471. }
  1472. //initailize struct Authorize
  1473. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1474. //get data from shared memory
  1475. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1476. random_uuid(guid);
  1477. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1478. LWS_Send(message);
  1479. sprintf(tempdata, "Authorize,%d", gun_index);
  1480. if(hashmap_operation(0, guid, tempdata) == 1)
  1481. {
  1482. result = PASS;
  1483. DEBUG_ERROR("Authorize mapItem pass\n");
  1484. }
  1485. //#ifdef SystemLogMessage
  1486. //DEBUG_INFO(">>>>>Authorize request\n");
  1487. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1488. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1489. //#endif
  1490. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1491. return result;
  1492. }
  1493. int sendBootNotificationRequest(void)
  1494. {
  1495. mtrace();
  1496. int result = FAIL;
  1497. char message[500]={0}, payload[700]={0};
  1498. char guid[37]={0};
  1499. char tempdata[65]={0};
  1500. int IsGunCharging = FALSE;
  1501. //check Transaction active
  1502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1503. {
  1504. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1505. {
  1506. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1507. {
  1508. IsGunCharging = TRUE;
  1509. }
  1510. }
  1511. for (int index = 0; index < CCS_QUANTITY; index++)
  1512. {
  1513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1514. {
  1515. IsGunCharging = TRUE;
  1516. }
  1517. }
  1518. for (int index = 0; index < GB_QUANTITY; index++)
  1519. {
  1520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1521. {
  1522. IsGunCharging = TRUE;
  1523. }
  1524. }
  1525. }
  1526. else
  1527. {
  1528. for (int index = 0; index < AC_QUANTITY; index++)
  1529. {
  1530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1531. {
  1532. IsGunCharging = TRUE;
  1533. }
  1534. }
  1535. }
  1536. if(IsGunCharging == TRUE)
  1537. {
  1538. server_sign = TRUE;
  1539. return result;
  1540. }
  1541. // Fill BootNotification fields
  1542. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1543. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1544. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1545. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1546. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1547. ShmOCPP16Data->ChargeBoxId
  1548. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1549. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1550. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1551. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1552. ,ShmOCPP16Data->BootNotification.CpIccid
  1553. ,ShmOCPP16Data->BootNotification.CpImsi
  1554. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1555. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1556. random_uuid(guid);
  1557. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1558. LWS_Send(message);
  1559. sprintf(tempdata, "BootNotification,0");
  1560. 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*/)
  1561. {
  1562. result = PASS;
  1563. }
  1564. memset(queuedata, 0, sizeof(queuedata));
  1565. strcpy(queuedata,message);
  1566. //#ifdef SystemLogMessage
  1567. //DEBUG_INFO(">>>>>BootNotification request\n");
  1568. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1569. //#endif
  1570. return result;
  1571. }
  1572. int sendDataTransferRequest(int gun_index)
  1573. {
  1574. mtrace();
  1575. char message[1000]={0};
  1576. char guid[37]={0};
  1577. char tempdata[65]={0};
  1578. int result = FAIL;
  1579. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1580. random_uuid(guid);
  1581. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1582. MESSAGE_TYPE_CALL,
  1583. guid,
  1584. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1585. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1586. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1587. LWS_Send(message);
  1588. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1589. 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*/)
  1590. {
  1591. result = PASS;
  1592. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1593. }
  1594. //#ifdef SystemLogMessage
  1595. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1596. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1597. //#endif
  1598. return result;
  1599. }
  1600. int sendDiagnosticsStatusNotificationRequest(char *status)
  1601. {
  1602. mtrace();
  1603. int result = FAIL;
  1604. char message[110]={0};
  1605. char guid[37]={0};
  1606. char tempdata[65]={0};
  1607. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1608. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1609. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1610. random_uuid(guid);
  1611. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1612. LWS_Send(message);
  1613. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1614. if(hashmap_operation(0, guid, tempdata) == 1)
  1615. {
  1616. result = PASS;
  1617. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1618. }
  1619. //#ifdef SystemLogMessage
  1620. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1621. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1622. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1623. //#endif
  1624. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1625. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1626. //record status
  1627. if(strcmp(status,"Idle")==0)
  1628. {
  1629. DiagnosticsStatusNotificationStatus = 0;
  1630. }
  1631. else if(strcmp(status,"Uploaded")==0)
  1632. {
  1633. DiagnosticsStatusNotificationStatus = 1;
  1634. }
  1635. else if(strcmp(status,"UploadFailed")==0)
  1636. {
  1637. DiagnosticsStatusNotificationStatus = 2;
  1638. }
  1639. else if(strcmp(status,"Uploading")==0)
  1640. {
  1641. DiagnosticsStatusNotificationStatus = 3;
  1642. }
  1643. return result;
  1644. }
  1645. int sendFirmwareStatusNotificationRequest(char *status)
  1646. {
  1647. mtrace();
  1648. int result = FAIL;
  1649. char message[110]={0};
  1650. char guid[37]={0};
  1651. char tempdata[65]={0};
  1652. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1653. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1654. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1655. random_uuid(guid);
  1656. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1657. LWS_Send(message);
  1658. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1659. 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*/)
  1660. {
  1661. result = PASS;
  1662. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1663. }
  1664. //#ifdef SystemLogMessage
  1665. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1666. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1667. //#endif
  1668. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1669. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1670. //record status
  1671. if(strcmp(status,"Downloaded")==0)
  1672. {
  1673. FirmwareStatusNotificationStatus = 0;
  1674. }
  1675. else if(strcmp(status,"DownloadFailed")==0)
  1676. {
  1677. FirmwareStatusNotificationStatus = 1;
  1678. }
  1679. else if(strcmp(status,"Downloading")==0)
  1680. {
  1681. FirmwareStatusNotificationStatus = 2;
  1682. }
  1683. else if(strcmp(status,"Idle")==0)
  1684. {
  1685. FirmwareStatusNotificationStatus = 3;
  1686. }
  1687. else if(strcmp(status,"InstallationFailed")==0)
  1688. {
  1689. FirmwareStatusNotificationStatus = 4;
  1690. }
  1691. else if(strcmp(status,"Installing")==0)
  1692. {
  1693. FirmwareStatusNotificationStatus = 5;
  1694. }
  1695. else if(strcmp(status,"Installed")==0)
  1696. {
  1697. FirmwareStatusNotificationStatus = 6;
  1698. }
  1699. return result;
  1700. }
  1701. int sendHeartbeatRequest(int gun_index)
  1702. {
  1703. mtrace();
  1704. int result = FAIL;
  1705. char message[80]={0};
  1706. char guid[37]={0};
  1707. char tempdata[65]={0};
  1708. random_uuid(guid);
  1709. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1710. , MESSAGE_TYPE_CALL
  1711. , guid );
  1712. LWS_Send(message);
  1713. sprintf(tempdata, "Heartbeat,%d", 0);
  1714. 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*/)
  1715. {
  1716. result = PASS;
  1717. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1718. }
  1719. //#ifdef SystemLogMessage
  1720. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1721. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1722. //#endif
  1723. return result;
  1724. }
  1725. int sendStartTransactionRequest(int gun_index)
  1726. {
  1727. mtrace();
  1728. int result = FAIL;
  1729. char message[250]={0};
  1730. char guid[37]={0};
  1731. struct timeval tmnow;
  1732. struct tm *tm;
  1733. char buf[30];//, usec_buf[6];
  1734. char tempdata[65]={0};
  1735. DEBUG_INFO("sendStartTransactionRequest...");
  1736. gettimeofday(&tmnow, NULL);
  1737. time_t t;
  1738. t = time(NULL);
  1739. /*UTC time and date*/
  1740. tm = gmtime(&t);
  1741. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1742. #if 0 // remove temporally
  1743. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1744. strcat(buf,".");
  1745. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1746. strcat(buf,usec_buf);
  1747. #endif
  1748. //printf("Start Charging Time :%s",buf);
  1749. // set value
  1750. if(ShmOCPP16Data->OcppConnStatus == 1 )
  1751. {
  1752. //memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1753. }
  1754. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1755. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1756. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1758. {
  1759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1760. {
  1761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1762. {
  1763. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1764. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1765. }
  1766. }
  1767. for (int index = 0; index < CCS_QUANTITY; index++)
  1768. {
  1769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1770. {
  1771. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1772. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1773. }
  1774. }
  1775. for (int index = 0; index < GB_QUANTITY; index++)
  1776. {
  1777. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1778. {
  1779. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1780. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1781. }
  1782. }
  1783. }
  1784. else
  1785. {
  1786. for (int index = 0; index < AC_QUANTITY; index++)
  1787. {
  1788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1789. {
  1790. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1791. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1792. }
  1793. }
  1794. }//END OF ELSE
  1795. random_uuid(guid);
  1796. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1797. , MESSAGE_TYPE_CALL
  1798. , guid
  1799. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1800. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1801. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1802. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1803. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1804. LWS_Send(message);
  1805. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1806. 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*/)
  1807. {
  1808. result = PASS;
  1809. }
  1810. strcpy(queuedata, message);
  1811. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1812. //#ifdef SystemLogMessage
  1813. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1814. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1815. //#endif
  1816. return result;
  1817. }
  1818. int sendStatusNotificationRequest(int gun_index)
  1819. {
  1820. mtrace();
  1821. int result = FAIL;
  1822. char message[600]={0};
  1823. char guid[37];
  1824. int currentStatus = 0;
  1825. struct timeval tmnow;
  1826. struct tm *tm;
  1827. char buf[30];//, usec_buf[6];
  1828. char tempdata[65]={0};
  1829. gettimeofday(&tmnow, NULL);
  1830. time_t t;
  1831. t = time(NULL);
  1832. /*UTC time and date*/
  1833. tm = gmtime(&t);
  1834. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1835. #if 0 // remove temporally
  1836. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1837. strcat(buf,".");
  1838. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1839. strcat(buf,usec_buf);
  1840. #endif
  1841. printf("%s",buf);
  1842. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1843. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1844. // it's option
  1845. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1846. /*
  1847. enum _SYSTEM_STATUS
  1848. {
  1849. S_BOOTING = 0,
  1850. S_IDLE, = 1
  1851. S_AUTHORIZING, =2
  1852. S_REASSIGN_CHECK, =3
  1853. S_REASSIGN, =4
  1854. S_PRECHARGE, =5
  1855. S_PREPARING_FOR_EV, =6
  1856. S_PREPARING_FOR_EVSE, =7
  1857. S_CHARGING, =8
  1858. S_TERMINATING, =9
  1859. S_COMPLETE, =10
  1860. S_ALARM, =11
  1861. S_FAULT =12
  1862. }
  1863. */
  1864. //check Transaction active
  1865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1866. {
  1867. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1868. {
  1869. //printf("gun_index=%d\n",gun_index);
  1870. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1871. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1872. {
  1873. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1874. currentStatus = 0; //OCPP Status
  1875. }
  1876. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1877. {
  1878. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1879. currentStatus = 1; //OCPP Status
  1880. }
  1881. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1882. {
  1883. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1884. currentStatus = 2; //OCPP Status
  1885. }
  1886. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1887. {
  1888. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1889. currentStatus = 5; //OCPP Status
  1890. }
  1891. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1892. {
  1893. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1894. currentStatus = 4; //OCPP Status
  1895. }
  1896. 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))) //S_TERMINATING ---> Unavailable
  1897. {
  1898. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1899. currentStatus = 7; //OCPP Status: Unavailable
  1900. }
  1901. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1902. {
  1903. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1904. currentStatus = 8; //OCPP Status: Faulted
  1905. }
  1906. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1907. {
  1908. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1909. currentStatus = 6; //OCPP Status: Reserved
  1910. }
  1911. }//end of for CHAdeMO_QUANTITY
  1912. for (int index = 0; index < CCS_QUANTITY; index++)
  1913. {
  1914. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1915. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1916. {
  1917. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1918. currentStatus = 0; //OCPP Status
  1919. }
  1920. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1921. {
  1922. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1923. currentStatus = 1; //OCPP Status
  1924. }
  1925. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1926. {
  1927. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1928. currentStatus = 2; //OCPP Status
  1929. }
  1930. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1931. {
  1932. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1933. currentStatus = 5; //OCPP Status
  1934. }
  1935. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1936. {
  1937. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1938. currentStatus = 4; //OCPP Status
  1939. }
  1940. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1941. {
  1942. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1943. currentStatus = 7; //OCPP Status
  1944. }
  1945. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1946. {
  1947. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1948. currentStatus = 8; //OCPP Status
  1949. }
  1950. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1951. {
  1952. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1953. currentStatus = 6; //OCPP Status
  1954. }
  1955. }
  1956. for (int index = 0; index < GB_QUANTITY; index++)
  1957. {
  1958. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1959. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1960. {
  1961. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1962. currentStatus = 0; //OCPP Status
  1963. }
  1964. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1965. {
  1966. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1967. currentStatus = 1; //OCPP Status
  1968. }
  1969. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1970. {
  1971. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1972. currentStatus = 2; //OCPP Status
  1973. }
  1974. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1975. {
  1976. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1977. currentStatus = 5; //OCPP Status
  1978. }
  1979. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1980. {
  1981. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1982. currentStatus = 4; //OCPP Status
  1983. }
  1984. 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))) //S_TERMINATING ---> Unavailable
  1985. {
  1986. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1987. currentStatus = 7; //OCPP Status: Unavailable
  1988. }
  1989. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1990. {
  1991. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1992. currentStatus = 8; //OCPP Status: Faulted
  1993. }
  1994. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1995. {
  1996. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1997. currentStatus = 6; //OCPP Status: Faulted
  1998. }
  1999. }
  2000. }
  2001. else
  2002. {
  2003. for (int index = 0; index < AC_QUANTITY; index++)
  2004. {
  2005. //printf("gun_index=%d\n",gun_index);
  2006. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2007. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2008. {
  2009. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2010. currentStatus = 0; //OCPP Status
  2011. }
  2012. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2013. {
  2014. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2015. currentStatus = 1; //OCPP Status
  2016. }
  2017. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2018. {
  2019. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2020. currentStatus = 2; //OCPP Status
  2021. }
  2022. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2023. {
  2024. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2025. currentStatus = 5; //OCPP Status
  2026. }
  2027. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2028. {
  2029. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2030. currentStatus = 4; //OCPP Status
  2031. }
  2032. 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))) //S_TERMINATING ---> Unavailable
  2033. {
  2034. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2035. currentStatus = 7; //OCPP Status: Unavailable
  2036. }
  2037. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2038. {
  2039. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2040. currentStatus = 8; //OCPP Status: Faulted
  2041. }
  2042. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2043. {
  2044. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2045. currentStatus = 6; //OCPP Status: Reserved
  2046. }
  2047. }//end of for AC_QUANTITY
  2048. }//END OF ELSE
  2049. //it's option
  2050. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2051. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2052. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2053. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2054. random_uuid(guid);
  2055. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2056. , MESSAGE_TYPE_CALL
  2057. , guid
  2058. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2059. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2060. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2061. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2062. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2063. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2064. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2065. LWS_Send(message);
  2066. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2067. 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*/)
  2068. {
  2069. //DEBUG_ERROR("statusNotification mapitem pass");
  2070. result = PASS;
  2071. }
  2072. //#ifdef SystemLogMessage
  2073. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2074. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2075. //#endif
  2076. return result;
  2077. }
  2078. int sendStopTransactionRequest(int gun_index)
  2079. {
  2080. mtrace();
  2081. int result = FAIL;
  2082. char message[1500]={0};
  2083. char guid[37]={0};
  2084. char tempdata[65]={0};
  2085. int idx_sample=0;
  2086. DEBUG_ERROR("sendStopTransactionRequest \n");
  2087. //memset(&(ShmOCPP16Data->StopTransaction[gun_index].TransactionData), 0, sizeof(struct StructMeterValue));
  2088. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId/*ShmOCPP16Data->Authorize.IdTag*/);
  2089. //ENERGY_ACTIVE_IMPORT_REGISTER
  2090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2091. {
  2092. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2093. {
  2094. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2095. {
  2096. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2097. //Check Status
  2098. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2099. {
  2100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2101. }
  2102. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2103. }
  2104. }// END OF CHAdeMO_QUANTITY
  2105. for (int index = 0; index < CCS_QUANTITY; index++)
  2106. {
  2107. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2108. {
  2109. //for test
  2110. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2111. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2112. //Check Status
  2113. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2114. {
  2115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2116. }
  2117. else
  2118. {
  2119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2120. }
  2121. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2122. }
  2123. }// END OF CCS_QUANTITY
  2124. for (int index = 0; index < GB_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2127. {
  2128. // for test
  2129. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2130. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2131. //Check Status
  2132. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2133. {
  2134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2135. }
  2136. else
  2137. {
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2139. }
  2140. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2141. }
  2142. }// END OF GB_QUANTITY
  2143. }
  2144. else
  2145. {
  2146. for (int index = 0; index < AC_QUANTITY; index++)
  2147. {
  2148. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2149. {
  2150. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2151. //Check Status
  2152. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2153. {
  2154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2155. }
  2156. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2157. }
  2158. }// END OF AC_QUANTITY
  2159. }//END OF ELSE
  2160. //Stop Transaction Time
  2161. struct timeval tmnow;
  2162. struct tm *tm;
  2163. char buf[30];//, usec_buf[6];
  2164. gettimeofday(&tmnow, NULL);
  2165. time_t t;
  2166. t = time(NULL);
  2167. /*UTC time and date*/
  2168. tm = gmtime(&t);
  2169. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2170. #if 0 // remove temporally
  2171. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2172. strcat(buf,".");
  2173. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2174. strcat(buf,usec_buf);
  2175. #endif
  2176. printf("StopTransaction Time %s\n",buf);
  2177. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2179. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2180. random_uuid(guid);
  2181. sprintf(message,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":"
  2182. ,MESSAGE_TYPE_CALL
  2183. ,guid
  2184. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2185. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2186. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2187. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2188. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
  2189. /***********************************transactionData******************************************************/
  2190. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2191. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2192. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2193. {
  2194. //transactionData = json_object_new_object();
  2195. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  2197. sprintf(message + strlen(message), "[{\"timestamp\":\"%s\",\"sampledValue\":[", (const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp);
  2198. //=================================
  2199. // Transaction_Begin
  2200. //=================================
  2201. // Energy.Active.Export.Interval
  2202. idx_sample=0;
  2203. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2210. sprintf(message + strlen(message), "{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2211. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2212. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2213. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2214. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2215. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2216. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2217. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2218. );
  2219. //=================================
  2220. // Transaction_End
  2221. //=================================
  2222. //Current.Export
  2223. idx_sample=1;
  2224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2225. {
  2226. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2227. {
  2228. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2229. {
  2230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2231. }
  2232. }
  2233. for (int index = 0; index < CCS_QUANTITY; index++)
  2234. {
  2235. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2236. {
  2237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2238. }
  2239. }
  2240. for (int index = 0; index < GB_QUANTITY; index++)
  2241. {
  2242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2243. {
  2244. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2245. }
  2246. }
  2247. }
  2248. else
  2249. {
  2250. for (int index = 0; index < AC_QUANTITY; index++)
  2251. {
  2252. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2253. {
  2254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2255. }
  2256. }
  2257. }// END FOR AC ELSE
  2258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Current_Export/*Energy_Reactive_Export_Register*/]);
  2261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A/*UnitOfMeasure_kWh*/]);
  2264. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2265. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2266. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2267. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2268. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2269. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2270. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2271. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2272. );
  2273. //Energy.Active.Export.Interval
  2274. idx_sample=2;
  2275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2276. {
  2277. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2278. {
  2279. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2280. {
  2281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2282. }
  2283. }
  2284. for (int index = 0; index < CCS_QUANTITY; index++)
  2285. {
  2286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2287. {
  2288. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2289. }
  2290. }
  2291. for (int index = 0; index < GB_QUANTITY; index++)
  2292. {
  2293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2294. {
  2295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2296. }
  2297. }
  2298. }
  2299. else
  2300. {
  2301. for (int index = 0; index < AC_QUANTITY; index++)
  2302. {
  2303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2304. {
  2305. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2306. }
  2307. }
  2308. }// END FOR AC ELSE
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2315. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2316. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2317. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2318. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2319. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2320. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2321. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2322. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2323. );
  2324. //Power.Active.Export
  2325. idx_sample=3;
  2326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2327. {
  2328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2329. {
  2330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2331. {
  2332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2333. }
  2334. }
  2335. for (int index = 0; index < CCS_QUANTITY; index++)
  2336. {
  2337. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2338. {
  2339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2340. }
  2341. }
  2342. for (int index = 0; index < GB_QUANTITY; index++)
  2343. {
  2344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2345. {
  2346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2347. }
  2348. }
  2349. }
  2350. else
  2351. {
  2352. for (int index = 0; index < AC_QUANTITY; index++)
  2353. {
  2354. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2355. {
  2356. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2357. }
  2358. }
  2359. }// END FOR AC ELSE
  2360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2366. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2367. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2368. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2369. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2370. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2371. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2372. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2373. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2374. );
  2375. //Voltage
  2376. idx_sample=4;
  2377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2378. {
  2379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2380. {
  2381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2382. {
  2383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2384. }
  2385. }
  2386. for (int index = 0; index < CCS_QUANTITY; index++)
  2387. {
  2388. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2389. {
  2390. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2391. }
  2392. }
  2393. for (int index = 0; index < GB_QUANTITY; index++)
  2394. {
  2395. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2396. {
  2397. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2398. }
  2399. }
  2400. }
  2401. else
  2402. {
  2403. for (int index = 0; index < AC_QUANTITY; index++)
  2404. {
  2405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2406. {
  2407. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2408. }
  2409. }
  2410. }// END FOR AC ELSE
  2411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2417. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2418. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2419. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2420. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2421. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2422. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2423. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2424. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2425. );
  2426. //SoC
  2427. idx_sample=5;
  2428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2429. {
  2430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2431. {
  2432. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2433. {
  2434. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2435. }
  2436. }
  2437. for (int index = 0; index < CCS_QUANTITY; index++)
  2438. {
  2439. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2440. {
  2441. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2442. }
  2443. }
  2444. for (int index = 0; index < GB_QUANTITY; index++)
  2445. {
  2446. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2447. {
  2448. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2449. }
  2450. }
  2451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2457. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2458. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2459. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2460. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2461. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2462. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2463. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2464. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2465. );
  2466. } // END FOR DC CASE
  2467. sprintf(message + strlen(message)," ] } ] } ]");
  2468. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue);
  2469. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);
  2470. }
  2471. LWS_Send(message);
  2472. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2473. if(hashmap_operation(0, guid, tempdata) == 1)
  2474. {
  2475. result = PASS;
  2476. DEBUG_INFO("StopTransaction mapitem pass\n");
  2477. }
  2478. strcpy(queuedata, message);
  2479. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2480. //#ifdef SystemLogMessage
  2481. //DEBUG_INFO(">>>>>StopTransaction request\n");
  2482. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2483. //#endif
  2484. //for test
  2485. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2486. return result;
  2487. }
  2488. int sendMeterValuesRequest(int gun_index)
  2489. {
  2490. mtrace();
  2491. int result = FAIL;
  2492. char message[1500]={0};
  2493. char guid[37]={0};
  2494. int idx_sample=0;
  2495. //int length = 0;
  2496. char tempdata[65]={0};
  2497. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2498. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2499. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2500. {
  2501. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2502. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2503. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2504. return result;
  2505. }
  2506. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2507. {
  2508. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2509. }
  2510. //set value
  2511. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2512. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2513. random_uuid(guid);
  2514. sprintf(message,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":"
  2515. ,MESSAGE_TYPE_CALL
  2516. ,guid
  2517. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2518. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId);
  2519. //,comfirmpayload);
  2520. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2521. {
  2522. //allocate memory space
  2523. //ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2524. //UTC Date time
  2525. struct timeval tmnow;
  2526. struct tm *tm;
  2527. char buf[30];//, usec_buf[6];
  2528. gettimeofday(&tmnow, NULL);
  2529. time_t t;
  2530. t = time(NULL);
  2531. /*UTC time and date*/
  2532. tm = gmtime(&t);
  2533. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2534. #if 0 // remove temporally
  2535. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2536. strcat(buf,".");
  2537. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2538. strcat(buf,usec_buf);
  2539. #endif
  2540. // printf("%s",buf);
  2541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2542. //allocate memory space
  2543. //ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*6);
  2544. sprintf(message + strlen(message),"[{\"timestamp\":\"%s\",\"sampledValue\":[",(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp);
  2545. idx_sample=0;
  2546. //********************************(1)Current.Export************************************************/
  2547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2548. {
  2549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2552. {
  2553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2554. }
  2555. }
  2556. for (int index = 0; index < CCS_QUANTITY; index++)
  2557. {
  2558. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2559. {
  2560. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2561. }
  2562. }
  2563. for (int index = 0; index < GB_QUANTITY; index++)
  2564. {
  2565. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2566. {
  2567. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2568. }
  2569. }
  2570. }
  2571. else
  2572. {
  2573. for (int index = 0; index < AC_QUANTITY; index++)
  2574. {
  2575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2576. {
  2577. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2578. }
  2579. }
  2580. }// END FOR AC ELSE
  2581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Export]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2587. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2588. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2589. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2590. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2591. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2592. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2593. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2594. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2595. );
  2596. #if 0
  2597. idx_sample=1;
  2598. //****************************************************(2)Energy.Active.Export.Register*********************************************/
  2599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2600. {
  2601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2602. {
  2603. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2604. {
  2605. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2606. }
  2607. }
  2608. for (int index = 0; index < CCS_QUANTITY; index++)
  2609. {
  2610. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2611. {
  2612. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2613. }
  2614. }
  2615. for (int index = 0; index < GB_QUANTITY; index++)
  2616. {
  2617. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2618. {
  2619. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2621. }
  2622. }
  2623. }
  2624. else
  2625. {
  2626. for (int index = 0; index < AC_QUANTITY; index++)
  2627. {
  2628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2629. {
  2630. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2631. }
  2632. }
  2633. }// END FOR AC ELSE
  2634. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Register]);
  2637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2640. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2641. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2642. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2643. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2644. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2645. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2646. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2647. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2648. );
  2649. #endif
  2650. idx_sample=1;
  2651. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2653. {
  2654. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2655. {
  2656. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2657. {
  2658. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2659. }
  2660. }
  2661. for (int index = 0; index < CCS_QUANTITY; index++)
  2662. {
  2663. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2664. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2665. {
  2666. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2667. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2668. }
  2669. }
  2670. for (int index = 0; index < GB_QUANTITY; index++)
  2671. {
  2672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2673. {
  2674. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2675. }
  2676. }
  2677. }
  2678. else
  2679. {
  2680. for (int index = 0; index < AC_QUANTITY; index++)
  2681. {
  2682. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2683. {
  2684. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2685. }
  2686. }
  2687. }//END FOR AC ELSE
  2688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2691. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2692. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2693. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2694. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2695. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2696. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2697. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2698. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2699. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2700. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2701. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2702. );
  2703. idx_sample=2;
  2704. //********************************(4)Power.Active.Export************************************************/
  2705. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2706. {
  2707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2708. {
  2709. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2710. {
  2711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2712. }
  2713. }
  2714. for (int index = 0; index < CCS_QUANTITY; index++)
  2715. {
  2716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2717. {
  2718. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2719. }
  2720. }
  2721. for (int index = 0; index < GB_QUANTITY; index++)
  2722. {
  2723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2724. {
  2725. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2726. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2727. }
  2728. }
  2729. }
  2730. else
  2731. {
  2732. for (int index = 0; index < AC_QUANTITY; index++)
  2733. {
  2734. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2735. {
  2736. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2737. }
  2738. }
  2739. }// END FOR AC ELSE
  2740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Export]);
  2743. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2746. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2747. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2748. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2749. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2750. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2751. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2752. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2753. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2754. );
  2755. idx_sample=3;
  2756. //***********************************************(5)VOLTAGE******************************************************/
  2757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2758. {
  2759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2760. {
  2761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2762. {
  2763. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2764. }
  2765. }
  2766. for (int index = 0; index < CCS_QUANTITY; index++)
  2767. {
  2768. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2769. {
  2770. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2771. }
  2772. }
  2773. for (int index = 0; index < GB_QUANTITY; index++)
  2774. {
  2775. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2776. {
  2777. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2778. }
  2779. }
  2780. }
  2781. else
  2782. {
  2783. for (int index = 0; index < AC_QUANTITY; index++)
  2784. {
  2785. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2786. {
  2787. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2788. }
  2789. }
  2790. }//END FOR AC ELSE
  2791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2797. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2798. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2799. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2800. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2801. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2802. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2803. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2804. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2805. );
  2806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2807. {
  2808. idx_sample=4;
  2809. //sampledValue = NULL;
  2810. //***********************************************(6)SOC******************************************************/
  2811. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2812. {
  2813. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2814. {
  2815. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2816. }
  2817. }
  2818. for (int index = 0; index < CCS_QUANTITY; index++)
  2819. {
  2820. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2821. {
  2822. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2823. }
  2824. }
  2825. for (int index = 0; index < GB_QUANTITY; index++)
  2826. {
  2827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2828. {
  2829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2830. }
  2831. }
  2832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[SoC]);
  2835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2838. sprintf(message + strlen(message),",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2839. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2840. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2841. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2842. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2843. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2844. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2845. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2846. );
  2847. }
  2848. //}
  2849. sprintf(message + strlen(message)," ] } ] } ]");
  2850. //free(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue);
  2851. }
  2852. LWS_Send(message);
  2853. //memset(mapItem, 0, sizeof(data_struct_t));
  2854. // Put request guid to hash map
  2855. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2856. 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*/)
  2857. {
  2858. result = PASS;
  2859. DEBUG_INFO("MeterValues mapitem pass\n");
  2860. }
  2861. strcpy(queuedata, message);
  2862. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2863. //#ifdef SystemLogMessage
  2864. //DEBUG_INFO(">>>>>MeerValues request\n");
  2865. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2866. //#endif
  2867. return result;
  2868. }
  2869. //==========================================
  2870. // send confirm routine
  2871. //==========================================
  2872. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2873. {
  2874. mtrace();
  2875. int result = FAIL;
  2876. char message[100]={0};
  2877. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2878. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2879. LWS_Send(message);
  2880. result = TRUE;
  2881. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2882. return result;
  2883. }
  2884. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2885. {
  2886. mtrace();
  2887. int result = FAIL;
  2888. char message[100]={0};
  2889. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2890. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2891. LWS_Send(message);
  2892. result = TRUE;
  2893. return result;
  2894. }
  2895. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2896. {
  2897. mtrace();
  2898. int result = FAIL;
  2899. char message[100]={0};
  2900. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2901. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2902. LWS_Send(message);
  2903. result = TRUE;
  2904. return result;
  2905. }
  2906. int sendClearCacheConfirmation(char *uuid,char *payload)
  2907. {
  2908. mtrace();
  2909. int result = FAIL;
  2910. char message[500]={0};
  2911. // int count = 0;
  2912. // int gun_index = 0;
  2913. // char guid[37];
  2914. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2915. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2916. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2917. LWS_Send(message);
  2918. return result;
  2919. }
  2920. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2921. {
  2922. mtrace();
  2923. int result = FAIL;
  2924. char message[500]={0};
  2925. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2926. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2927. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2928. LWS_Send(message);
  2929. return result;
  2930. }
  2931. int sendDataTransferConfirmation(char *uuid,char *payload)
  2932. {
  2933. mtrace();
  2934. char statusStr[20]={0};
  2935. char dataStr[10]={0};
  2936. char sstr[20]={0};
  2937. int c = 0;
  2938. char *loc;
  2939. int result = FAIL;
  2940. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2941. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2942. /**********************status**************************/
  2943. loc = strstr(payload, "status");
  2944. memset(sstr ,0, sizeof(sstr) );
  2945. c = 0;
  2946. while (loc[3+strlen("status")+c] != '\"')
  2947. {
  2948. sstr[c] = loc[3+strlen("status")+c];
  2949. c++;
  2950. }
  2951. sstr[c] = '\0';
  2952. strcpy(statusStr, sstr);
  2953. /**********************data**************************/
  2954. loc = strstr(payload, "data");
  2955. memset(sstr ,0, sizeof(sstr) );
  2956. c = 0;
  2957. while (loc[3+strlen("data")+c] != '\"')
  2958. {
  2959. sstr[c] = loc[3+strlen("data")+c];
  2960. c++;
  2961. }
  2962. sstr[c] = '\0';
  2963. strcpy(dataStr, sstr);
  2964. return result;
  2965. }
  2966. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2967. {
  2968. mtrace();
  2969. int result = FAIL;
  2970. char message[1000]={0};
  2971. double diff_f = 0.0;
  2972. int diff_i = 0;
  2973. struct tm tp;
  2974. DEBUG_ERROR("handle sendGetCompositeScheduleConfirmation ...\n");
  2975. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2976. tp.tm_isdst = -1;
  2977. time_t utc = mktime(&tp);
  2978. time_t t = time(NULL);
  2979. diff_f = difftime(t, utc);
  2980. diff_i = (int)diff_f;
  2981. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2982. #if 0 //remove temporally
  2983. 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}"
  2984. ,MESSAGE_TYPE_CALLRESULT
  2985. ,uuid
  2986. ,payload
  2987. ,connectorIdInt
  2988. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2989. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2990. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2991. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2992. #endif
  2993. if(nPeriod == 0)
  2994. {
  2995. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2996. ,MESSAGE_TYPE_CALLRESULT
  2997. ,uuid
  2998. ,payload
  2999. ,connectorIdInt
  3000. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule);
  3001. }
  3002. else
  3003. {
  3004. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3005. ,MESSAGE_TYPE_CALLRESULT
  3006. ,uuid
  3007. ,payload
  3008. ,connectorIdInt
  3009. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3010. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3011. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3012. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3013. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3014. #if 1 // remove temporally
  3015. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3016. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3017. {
  3018. if (idx_sample == 0)
  3019. {
  3020. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3021. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  3022. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3023. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3024. }
  3025. else
  3026. {
  3027. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3028. , (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/)
  3029. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3030. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3031. }
  3032. }
  3033. #endif
  3034. sprintf(message + strlen(message), "]}}]");
  3035. }
  3036. LWS_Send(message);
  3037. result = TRUE;
  3038. return result;
  3039. }
  3040. int sendGetConfigurationConfirmation(char *uuid)
  3041. {
  3042. mtrace();
  3043. int result = FAIL;
  3044. int MaxKeySupported = 0;
  3045. int sentConfigurationNumber= 0;
  3046. int sentunConfigurationNumber= 0;
  3047. char message[4000]={0};
  3048. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3049. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3050. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3051. ,MESSAGE_TYPE_CALLRESULT
  3052. ,uuid );
  3053. //configuration key
  3054. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3055. {
  3056. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3057. {
  3058. if (sentConfigurationNumber == 0)
  3059. {
  3060. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3061. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3062. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3063. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3064. }
  3065. else
  3066. {
  3067. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3068. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3069. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3070. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3071. }
  3072. sentConfigurationNumber = sentConfigurationNumber + 1;
  3073. }
  3074. }
  3075. sprintf(message + strlen(message), "]");
  3076. if(UnknownKeynum != 0)
  3077. {
  3078. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3079. //unkown key
  3080. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3081. {
  3082. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3083. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3084. if(sentunConfigurationNumber == 0)
  3085. {
  3086. sprintf(message + strlen(message), "\"%s\""
  3087. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3088. }
  3089. else
  3090. {
  3091. sprintf(message + strlen(message), ",\"%s\""
  3092. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3093. }
  3094. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3095. }
  3096. sprintf(message + strlen(message), "]");
  3097. }
  3098. sprintf(message + strlen(message), "} ]");
  3099. LWS_Send(message);
  3100. #if 0
  3101. printf("error 1-0\n");
  3102. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3103. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3104. #endif
  3105. return result;
  3106. }
  3107. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3108. {
  3109. mtrace();
  3110. int result = FAIL;
  3111. char message[400]={0};
  3112. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3113. if(strcmp(payload,"")==0)
  3114. {
  3115. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3116. }
  3117. else
  3118. {
  3119. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3120. }
  3121. LWS_Send(message);
  3122. result = TRUE;
  3123. return result;
  3124. }
  3125. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3126. {
  3127. mtrace();
  3128. int result = FAIL;
  3129. char message[80]={0};
  3130. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3131. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3132. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3133. LWS_Send(message);
  3134. result = TRUE;
  3135. return result;
  3136. }
  3137. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3138. {
  3139. mtrace();
  3140. int result = FAIL;
  3141. char message[80]={0};
  3142. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3143. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3144. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3145. LWS_Send(message);
  3146. result = TRUE;
  3147. return result;
  3148. }
  3149. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3150. {
  3151. mtrace();
  3152. int result = FAIL;
  3153. char message[80]={0};
  3154. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3155. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3156. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3157. LWS_Send(message);
  3158. result = TRUE;
  3159. return result;
  3160. }
  3161. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3162. {
  3163. mtrace();
  3164. int result = FAIL;
  3165. char message[80]={0};
  3166. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3167. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3168. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3169. LWS_Send(message);
  3170. result = TRUE;
  3171. return result;
  3172. }
  3173. int sendResetConfirmation(char *uuid,char *payload)
  3174. {
  3175. mtrace();
  3176. int result = FAIL;
  3177. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3178. char message[80]={0};
  3179. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3180. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3181. LWS_Send(message);
  3182. result = TRUE;
  3183. return result;
  3184. }
  3185. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3186. {
  3187. mtrace();
  3188. int result = FAIL;
  3189. char message[500]={0};
  3190. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3191. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3192. LWS_Send(message);
  3193. result = TRUE;
  3194. return result;
  3195. }
  3196. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3197. {
  3198. mtrace();
  3199. int result = FAIL;
  3200. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3201. char message[80]={0};
  3202. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3203. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3204. LWS_Send(message);
  3205. result = TRUE;
  3206. return result;
  3207. }
  3208. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3209. {
  3210. mtrace();
  3211. int result = FAIL;
  3212. char message[80]={0};
  3213. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3214. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3215. LWS_Send(message);
  3216. result = TRUE;
  3217. return result;
  3218. }
  3219. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3220. {
  3221. mtrace();
  3222. int result = FAIL;
  3223. char message[80]={0};
  3224. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3225. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3226. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3227. LWS_Send(message);
  3228. result = TRUE;
  3229. return result;
  3230. }
  3231. int sendUpdateFirmwareConfirmation(char *uuid)
  3232. {
  3233. mtrace();
  3234. int result = FAIL;
  3235. char message[60]={0};
  3236. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3237. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3238. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3239. LWS_Send(message);
  3240. result = TRUE;
  3241. return result;
  3242. }
  3243. //==========================================
  3244. // send CallError routine
  3245. //==========================================
  3246. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3247. {
  3248. mtrace();
  3249. //int result = FAIL;
  3250. char message[220]={0};
  3251. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3252. #ifdef SystemLogMessage
  3253. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3254. uniqueId, action, errorCode, errorDescription);
  3255. #endif
  3256. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3257. LWS_Send(message);
  3258. //result = TRUE;
  3259. }
  3260. //==========================================
  3261. // Handle server request routine Start
  3262. //==========================================
  3263. #define GUN_NUM 1
  3264. int handleCancelReservationRequest(char *uuid, char *payload)
  3265. {
  3266. mtrace();
  3267. int result = FAIL;
  3268. int gunNO = 0;
  3269. int reservationIdInt =0;
  3270. char comfirmstr[20];
  3271. int c = 0;
  3272. char *loc;
  3273. char sstr[100]={0};
  3274. DEBUG_INFO("handle CancelReservationRequest\n");
  3275. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3276. c = 0;
  3277. loc = strstr(payload, "reservationId");
  3278. memset(sstr ,0, sizeof(sstr) );
  3279. while (loc[strlen("reservationId")+2+c] != '}')
  3280. {
  3281. sstr[c] = loc[strlen("reservationId")+2+c];
  3282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3283. c++;
  3284. }
  3285. sstr[c] = '\0';
  3286. reservationIdInt = atoi(sstr);
  3287. memset(comfirmstr, 0, sizeof comfirmstr);
  3288. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3289. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3290. //check Transaction active
  3291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3292. {
  3293. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3294. {
  3295. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3296. {
  3297. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3298. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3299. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3300. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3301. goto end;
  3302. }
  3303. }
  3304. for (int index = 0; index < CCS_QUANTITY; index++)
  3305. {
  3306. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3307. {
  3308. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3309. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3310. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3311. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3312. goto end;
  3313. }
  3314. }
  3315. for (int index = 0; index < GB_QUANTITY; index++)
  3316. {
  3317. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3318. {
  3319. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3320. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3321. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3322. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3323. goto end;
  3324. }
  3325. }
  3326. }
  3327. else
  3328. {
  3329. for (int index = 0; index < AC_QUANTITY; index++)
  3330. {
  3331. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3332. {
  3333. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3334. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3335. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3336. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3337. goto end;
  3338. }
  3339. }
  3340. }// END FOR AC ELSE
  3341. //The reservationId does NOT match the reservationId
  3342. sendCancelReservationConfirmation(uuid, comfirmstr);
  3343. end:
  3344. // Fill in ocpp packet uuid
  3345. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3346. return result;
  3347. }
  3348. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3349. {
  3350. mtrace();
  3351. int result = FAIL;
  3352. int gunIndex = 0;
  3353. char sstr[90]={0};
  3354. char typeStr[16]={0};
  3355. char comfirmstr[20];
  3356. int specificId = FALSE;
  3357. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3358. char *loc;
  3359. //int intervalInt = 0;
  3360. int c = 0;
  3361. /*** connectorId ****/
  3362. c = 0;
  3363. loc = strstr(payload, "connectorId");
  3364. memset(sstr ,0, sizeof(sstr) );
  3365. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3366. {
  3367. sstr[c] = loc[strlen("connectorId")+2+c];
  3368. c++;
  3369. }
  3370. sstr[c] = '\0';
  3371. gunIndex = atoi(sstr);
  3372. /***type ****/
  3373. loc = strstr(payload, "type");
  3374. memset(sstr ,0, sizeof(sstr) );
  3375. c = 0;
  3376. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3377. {
  3378. sstr[c] = loc[3+strlen("type")+c];
  3379. c++;
  3380. }
  3381. sstr[c] = '\0';
  3382. strcpy(typeStr, sstr);
  3383. if(gunIndex != 0)
  3384. {
  3385. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3386. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3387. }
  3388. else
  3389. {
  3390. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3391. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3392. }
  3393. memset(comfirmstr, 0, sizeof comfirmstr);
  3394. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3395. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3396. {
  3397. specificId = TRUE;
  3398. }
  3399. if(specificId == FALSE)
  3400. goto end;
  3401. if(gunIndex != 0)
  3402. {
  3403. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3404. }
  3405. else
  3406. {
  3407. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3408. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3409. }
  3410. /*
  3411. enum _SYSTEM_STATUS
  3412. {
  3413. S_BOOTING = 0,
  3414. S_IDLE, = 1
  3415. S_AUTHORIZING, =2
  3416. S_REASSIGN_CHECK, =3
  3417. S_REASSIGN, =4
  3418. S_PRECHARGE, =5
  3419. S_PREPARING_FOR_EV, =6
  3420. S_PREPARING_FOR_EVSE, =7
  3421. S_CHARGING, =8
  3422. S_TERMINATING, =9
  3423. S_COMPLETE, =10
  3424. S_ALARM, =11
  3425. S_FAULT =12
  3426. }
  3427. */
  3428. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3429. {
  3430. //check Transaction active
  3431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3432. {
  3433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3434. {
  3435. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3436. {
  3437. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3438. {
  3439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3440. }
  3441. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3442. {
  3443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3444. }
  3445. else
  3446. {
  3447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3448. }
  3449. goto end;
  3450. }
  3451. }//END FOR CHAdeMO_QUANTITY
  3452. for (int index = 0; index < CCS_QUANTITY; index++)
  3453. {
  3454. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3455. {
  3456. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3457. {
  3458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3459. }
  3460. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3461. {
  3462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3463. }
  3464. else
  3465. {
  3466. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3467. }
  3468. goto end;
  3469. }
  3470. }//END FOR CCS_QUANTITY
  3471. for (int index = 0; index < GB_QUANTITY; index++)
  3472. {
  3473. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3474. {
  3475. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3476. {
  3477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3478. }
  3479. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3480. {
  3481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3482. }
  3483. else
  3484. {
  3485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3486. }
  3487. goto end;
  3488. }
  3489. }// END FOR GB_QUANTITY
  3490. }
  3491. else
  3492. {
  3493. for (int index = 0; index < AC_QUANTITY; index++)
  3494. {
  3495. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3496. {
  3497. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3498. {
  3499. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3500. }
  3501. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3502. {
  3503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3504. }
  3505. else
  3506. {
  3507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3508. }
  3509. goto end;
  3510. }
  3511. }//END FOR AC_QUANTITY
  3512. }// END FOR AC ELSE
  3513. }//END FOR AvailabilityTypeStr[Inoperative]
  3514. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3515. {
  3516. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3517. //check Transaction active
  3518. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3519. {
  3520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3521. {
  3522. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3523. {
  3524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3525. goto end;
  3526. }
  3527. }//END FOR CHAdeMO_QUANTITY
  3528. for (int index = 0; index < CCS_QUANTITY; index++)
  3529. {
  3530. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3531. {
  3532. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3533. goto end;
  3534. }
  3535. }//END FOR CCS_QUANTITY
  3536. for (int index = 0; index < GB_QUANTITY; index++)
  3537. {
  3538. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3539. {
  3540. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3541. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3542. goto end;
  3543. }
  3544. }// END FOR GB_QUANTITY
  3545. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3546. }
  3547. else
  3548. {
  3549. for (int index = 0; index < AC_QUANTITY; index++)
  3550. {
  3551. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3552. {
  3553. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3554. goto end;
  3555. }
  3556. }//END FOR CHAdeMO_QUANTITY
  3557. }//END FOR AC ELSE
  3558. }//END FOR AvailabilityTypeStr[Operative]
  3559. end:
  3560. if(gunIndex != 0)
  3561. {
  3562. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3563. }
  3564. else
  3565. {
  3566. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3567. }
  3568. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3569. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3570. return result;
  3571. }
  3572. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3573. {
  3574. mtrace();
  3575. int result = FAIL;
  3576. char sstr[100]={0};
  3577. char keystr[40]={0};
  3578. char valuestr[16]={0};
  3579. char *loc;
  3580. int c = 0;
  3581. char comfirmstr[20];
  3582. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3583. /***key ****/
  3584. loc = strstr(payload, "key");
  3585. memset(sstr ,0, sizeof(sstr) );
  3586. c = 0;
  3587. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3588. {
  3589. sstr[c] = loc[3+strlen("key")+c];
  3590. c++;
  3591. }
  3592. sstr[c] = '\0';
  3593. strcpy(keystr, sstr);
  3594. /***value ****/
  3595. loc = strstr(payload, "value");
  3596. memset(sstr ,0, sizeof(sstr) );
  3597. c = 0;
  3598. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3599. {
  3600. sstr[c] = loc[3+strlen("value")+c];
  3601. c++;
  3602. }
  3603. sstr[c] = '\0';
  3604. strcpy(valuestr, sstr);
  3605. if((uuid==NULL) || (payload ==NULL) )
  3606. {
  3607. #ifdef Debug
  3608. DEBUG_INFO("payload is null\n");
  3609. #endif
  3610. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3611. }
  3612. else
  3613. {
  3614. int status = setKeyValue(keystr, valuestr);
  3615. switch(status)
  3616. {
  3617. case ConfigurationStatus_Accepted:
  3618. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3619. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3620. break;
  3621. case ConfigurationStatus_Rejected:
  3622. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3623. break;
  3624. case RebootRequired:
  3625. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3626. break;
  3627. case NotSupported:
  3628. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3629. break;
  3630. default:
  3631. break;
  3632. }
  3633. }
  3634. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3635. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3636. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3637. return result;
  3638. }
  3639. int handleClearCacheRequest(char *uuid, char *payload)
  3640. {
  3641. mtrace();
  3642. int result = FAIL;
  3643. char comfirmstr[20];
  3644. int fd;
  3645. char rmFileCmd[100]={0};
  3646. struct stat stats;
  3647. DEBUG_ERROR("handle ClearCacheRequest\n");
  3648. stat("../Storage/OCPP", &stats);
  3649. // Check for directory existence
  3650. if (S_ISDIR(stats.st_mode) == 1)
  3651. {
  3652. //DEBUG_ERROR("\n OCPP directory exist \n");
  3653. }
  3654. else
  3655. {
  3656. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3657. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3658. system(rmFileCmd);
  3659. }
  3660. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  3661. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3662. {
  3663. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3664. }
  3665. else
  3666. {
  3667. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3668. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3669. if(log == NULL)
  3670. {
  3671. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3672. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3673. goto end;
  3674. }
  3675. else
  3676. {
  3677. fclose(log);
  3678. }
  3679. }
  3680. fd = open(AuthorizationCache_JSON,O_RDWR);
  3681. if(fd < 0)
  3682. {
  3683. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3684. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3685. }
  3686. else
  3687. {
  3688. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3689. //* 清空?�件 */
  3690. ftruncate(fd,0);
  3691. //* ?�新设置?�件?�移??*/
  3692. lseek(fd,0,SEEK_SET);
  3693. close(fd);
  3694. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3695. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3696. }
  3697. end:
  3698. sendClearCacheConfirmation(uuid, comfirmstr);
  3699. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3700. return result;
  3701. }
  3702. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3703. {
  3704. mtrace();
  3705. int result = FAIL;
  3706. int resultRename;
  3707. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3708. char chargingProfilePurposeStr[26]={0};
  3709. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3710. char tempchargingProfilePurposeStr[26]={0};
  3711. char sstr[160]={0};//sstr[200]={ 0 };
  3712. char str[100]={0};
  3713. int c = 0;
  3714. //int i = 0;
  3715. //char * pch;
  3716. char *loc;
  3717. char fname[200];
  3718. char comfirmstr[20]={0};
  3719. char word[1000]={0};
  3720. int clearflag = FALSE;
  3721. int chargingProfileIdIsNULL = FALSE;
  3722. int connectorIsNULL = FALSE;
  3723. int chargingProfilePurposeIsNULL = FALSE;
  3724. int stackLevelIsNULL = FALSE;
  3725. FILE *fptr1, *fptr2;
  3726. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3727. int n_chargingProfile=0;
  3728. char sLineWord[1060]={0};
  3729. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3730. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3731. //***id ****/
  3732. c = 0;
  3733. loc = strstr(payload, "id");
  3734. memset(sstr ,0, sizeof(sstr) );
  3735. if(loc == NULL)
  3736. {
  3737. chargingProfileIdIsNULL = TRUE;
  3738. }
  3739. else
  3740. {
  3741. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3742. {
  3743. sstr[c] = loc[strlen("id")+2+c];
  3744. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3745. c++;
  3746. }
  3747. sstr[c] = '\0';
  3748. chargingProfileIdInt = atoi(sstr);
  3749. }
  3750. //***connectorId ****/
  3751. c=0;
  3752. loc = strstr(payload, "connectorId");
  3753. memset(sstr ,0, sizeof(sstr) );
  3754. if(loc == NULL)
  3755. {
  3756. connectorIsNULL = TRUE;
  3757. }
  3758. else
  3759. {
  3760. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3761. {
  3762. sstr[c] = loc[strlen("connectorId")+2+c];
  3763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3764. c++;
  3765. }
  3766. sstr[c] = '\0';
  3767. connectorIdInt = atoi(sstr);
  3768. }
  3769. //***chargingProfilePurpose ****/
  3770. loc = strstr(payload, "chargingProfilePurpose");
  3771. memset(sstr ,0, sizeof(sstr) );
  3772. c = 0;
  3773. if(loc == NULL)
  3774. {
  3775. chargingProfilePurposeIsNULL = TRUE;
  3776. }
  3777. else
  3778. {
  3779. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3780. {
  3781. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3782. c++;
  3783. }
  3784. sstr[c] = '\0';
  3785. strcpy(chargingProfilePurposeStr, sstr);
  3786. }
  3787. //***stackLevel ****/
  3788. c=0;
  3789. loc = strstr(payload, "stackLevel");
  3790. memset(sstr ,0, sizeof(sstr) );
  3791. if(loc == NULL)
  3792. {
  3793. stackLevelIsNULL = TRUE;
  3794. }
  3795. else
  3796. {
  3797. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3798. {
  3799. sstr[c] = loc[strlen("stackLevel")+2+c];
  3800. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3801. c++;
  3802. }
  3803. sstr[c] = '\0';
  3804. stackLevelInt = atoi(sstr);
  3805. }
  3806. if(connectorIsNULL == FALSE)
  3807. {
  3808. switch(connectorIdInt)
  3809. {
  3810. case 0:
  3811. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3812. {
  3813. strcpy(fname, ChargePointMaxProfile_JSON);
  3814. }
  3815. // else
  3816. // {
  3817. // strcpy(fname, TxDefaultProfile_0_JSON);
  3818. // }
  3819. break;
  3820. case 1:
  3821. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3822. {
  3823. strcpy(fname, TxDefaultProfile_1_JSON);
  3824. }
  3825. // else
  3826. // {
  3827. // strcpy(fname, TxProfile_1_JSON);
  3828. // }
  3829. break;
  3830. case 2:
  3831. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3832. {
  3833. strcpy(fname, TxDefaultProfile_2_JSON);
  3834. }
  3835. // else
  3836. // {
  3837. // strcpy(fname, TxProfile_2_JSON);
  3838. // }
  3839. break;
  3840. default:
  3841. strcpy(fname, ChargePointMaxProfile_JSON );
  3842. break;
  3843. }
  3844. }
  3845. else
  3846. {
  3847. strcpy(fname, ChargePointMaxProfile_JSON );
  3848. }
  3849. fptr1 = fopen(fname, "r");
  3850. if (!fptr1)
  3851. {
  3852. //file not exist
  3853. DEBUG_ERROR("Unable to open the input file!!\n");
  3854. fptr1 = fopen(fname, "w+");
  3855. }
  3856. fclose(fptr1);
  3857. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3858. {
  3859. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3860. goto end;
  3861. }
  3862. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3863. {
  3864. //clear the whole contents of a file in C
  3865. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3866. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3867. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3868. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3869. fclose(fopen(TxProfile_1_JSON, "w"));
  3870. fclose(fopen(TxProfile_2_JSON, "w"));
  3871. #if 0
  3872. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3873. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3874. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3875. #endif
  3876. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3877. }
  3878. else
  3879. {
  3880. fptr1 = fopen(fname, "r");
  3881. fptr2 = fopen(temp, "w+");
  3882. while(fscanf(fptr1, "%s", word) != EOF)
  3883. {
  3884. //DEBUG_INFO("word=%s\n",word);
  3885. if(strcmp(word, "chargingProfileId") == 0)
  3886. {
  3887. n_chargingProfile = n_chargingProfile + 1;
  3888. DEBUG_INFO("chargingProfileId Found\n");
  3889. }
  3890. }
  3891. rewind(fptr1);
  3892. //search Charging Profile Element
  3893. //int i= 0;
  3894. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3895. {
  3896. //*************************tempconnectorIdInt*********************************/
  3897. loc = strstr(sLineWord, "connectorId");
  3898. c = 0;
  3899. memset(sstr ,0, sizeof(sstr) );
  3900. while (loc[strlen("connectorId")+2+c] != ',')
  3901. {
  3902. sstr[c] = loc[strlen("connectorId")+2+c];
  3903. c++;
  3904. }
  3905. sstr[c] = '\0';
  3906. tempconnectorIdInt = atoi(sstr);
  3907. //chargingProfileId
  3908. c = 0;
  3909. loc = strstr(sLineWord, "chargingProfileId");
  3910. memset(sstr ,0, sizeof(sstr) );
  3911. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3912. {
  3913. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3914. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3915. c++;
  3916. }
  3917. sstr[c] = '\0';
  3918. tempchargingProfileIdInt = atoi(sstr);
  3919. //stackLevel
  3920. c = 0;
  3921. loc = strstr(sLineWord, "stackLevel");
  3922. memset(sstr ,0, sizeof(sstr) );
  3923. while (loc[strlen("stackLevel")+2+c] != ',')
  3924. {
  3925. sstr[c] = loc[strlen("stackLevel")+2+c];
  3926. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3927. c++;
  3928. }
  3929. sstr[c] = '\0';
  3930. tempstackLevelInt = atoi(sstr);
  3931. c = 0;
  3932. loc = strstr(sLineWord, "chargingProfilePurpose");
  3933. memset(sstr ,0, sizeof(sstr) );
  3934. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3935. {
  3936. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3937. c++;
  3938. }
  3939. sstr[c] = '\0';
  3940. strcpy(tempchargingProfilePurposeStr, sstr);
  3941. if(chargingProfileIdIsNULL == FALSE)
  3942. {
  3943. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3944. {
  3945. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3946. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3947. clearflag = TRUE;
  3948. continue;
  3949. }
  3950. else
  3951. {
  3952. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3953. //json_object_array_add(newHeatMap, jsonitem);
  3954. fprintf(fptr2, sLineWord);//writing data into file
  3955. }
  3956. }
  3957. else
  3958. {
  3959. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3960. {
  3961. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3962. {
  3963. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3964. clearflag = TRUE;
  3965. continue;
  3966. }
  3967. }
  3968. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3969. {
  3970. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3971. {
  3972. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3973. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3974. {
  3975. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3976. clearflag = TRUE;
  3977. continue;
  3978. }
  3979. }
  3980. }
  3981. else
  3982. {
  3983. //json_object_array_add(newHeatMap, jsonitem);
  3984. fprintf(fptr2, sLineWord);//writing data into file
  3985. }
  3986. }
  3987. memset(sLineWord, 0, sizeof sLineWord);
  3988. }
  3989. if(clearflag == FALSE)
  3990. {
  3991. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3992. goto end;
  3993. }
  3994. fclose(fptr1);
  3995. fclose(fptr2);
  3996. sprintf(str,"rm -f %s",fname);
  3997. system(str);
  3998. resultRename = rename(temp, fname);
  3999. if(resultRename == 0)
  4000. {
  4001. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4002. }
  4003. else
  4004. {
  4005. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4006. }
  4007. }
  4008. end:
  4009. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4010. return result;
  4011. }
  4012. int handleDataTransferRequest(char *uuid, char *payload)
  4013. {
  4014. mtrace();
  4015. int result = FAIL;
  4016. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4017. char tempvendorId[255]={0};
  4018. char tempmessageId[50]={0};
  4019. char tempdata[50]={0};
  4020. char sstr[160]={0};//sstr[200]={ 0 };
  4021. char message[80]={0};
  4022. int c = 0;
  4023. char *loc;
  4024. DEBUG_INFO("handle DataTransferRequest\n");
  4025. if((uuid != NULL) && (payload != NULL))
  4026. {
  4027. //===============================
  4028. // vendorId
  4029. //===============================
  4030. c = 0;
  4031. loc = strstr(payload, "vendorId");
  4032. while (loc[strlen("vendorId")+3+c] != '\"')
  4033. {
  4034. sstr[c] = loc[strlen("vendorId")+3+c];
  4035. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4036. c++;
  4037. }
  4038. sstr[c] = '\0';
  4039. strcpy(tempvendorId,sstr);
  4040. //===============================
  4041. // messageId
  4042. //===============================
  4043. memset(sstr ,0, sizeof(sstr) );
  4044. c = 0;
  4045. loc = strstr(payload, "messageId");
  4046. while (loc[strlen("messageId")+3+c] != '\"')
  4047. {
  4048. sstr[c] = loc[strlen("messageId")+3+c];
  4049. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4050. c++;
  4051. }
  4052. sstr[c] = '\0';
  4053. strcpy(tempmessageId,sstr);
  4054. //===============================
  4055. // data
  4056. //===============================
  4057. memset(sstr ,0, sizeof(sstr) );
  4058. c = 0;
  4059. loc = strstr(payload, "data");
  4060. printf("loc=%s\n",loc);
  4061. while (loc[strlen("data")+3+c] != '\"')
  4062. {
  4063. sstr[c] = loc[strlen("data")+3+c];
  4064. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4065. c++;
  4066. }
  4067. sstr[c] = '\0';
  4068. strcpy(tempdata,sstr);
  4069. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4070. }
  4071. else
  4072. {
  4073. char guid[37]={0};
  4074. random_uuid(guid);
  4075. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4076. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4077. }
  4078. LWS_Send(message);
  4079. return result;
  4080. }
  4081. #if 0
  4082. long long diff_tm(struct tm *a, struct tm *b) {
  4083. return a->tm_sec - b->tm_sec
  4084. + 60LL * (a->tm_min - b->tm_min)
  4085. + 3600LL * (a->tm_hour - b->tm_hour)
  4086. + 86400LL * (a->tm_yday - b->tm_yday)
  4087. + (a->tm_year - 70) * 31536000LL
  4088. - (a->tm_year - 69) / 4 * 86400LL
  4089. + (a->tm_year - 1) / 100 * 86400LL
  4090. - (a->tm_year + 299) / 400 * 86400LL
  4091. - (b->tm_year - 70) * 31536000LL
  4092. + (b->tm_year - 69) / 4 * 86400LL
  4093. - (b->tm_year - 1) / 100 * 86400LL
  4094. + (b->tm_year + 299) /400 * 86400LL;
  4095. }
  4096. #endif
  4097. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4098. {
  4099. mtrace();
  4100. int result = FAIL;
  4101. int connectorIdInt, durationInt;
  4102. char chargingRateUnitStr[4]={0};
  4103. //int tempconnectorIdInt,
  4104. int tempdurationInt;
  4105. float tempminChargingRateFloat = 0.0;
  4106. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4107. int tempStartPeriodInt=0;
  4108. float tempLimitInt=0.0;//0.1;
  4109. int tempNumberPhasesInt=0;
  4110. char fname[200];
  4111. char comfirmstr[20];
  4112. //float totallimit =0.0;
  4113. float MinChargingRate =0.0;
  4114. double diff_t;
  4115. struct tm tp;
  4116. //int clearflag = FALSE;
  4117. FILE *fptr1;//, *fptr2;
  4118. //char temp[] = "../Storage/OCPP/temp.json";
  4119. int c = 0;
  4120. //int i = 0;
  4121. char * pch;
  4122. char *loc;
  4123. char sstr[200]={ 0 };
  4124. int n_chargingProfile = 0;
  4125. int n_SchedulePeriods = 0;
  4126. char SchedulePeriodList[10][200]={0};
  4127. char sLineWord[800]={0};
  4128. //int n_periods = 0;
  4129. char word[1000]={0};
  4130. int confirmPeriods = 0;
  4131. struct StructProfile ChargePointMaxProfile;
  4132. struct StructProfile TxDefaultProfile;
  4133. struct StructProfile TxProfile;
  4134. struct StructProfile TxDefaultProfiletemp[2]={0};
  4135. int TxDefaultProfileFileIsNull=FALSE;
  4136. int ChargePointMaxProfileIsNull=FALSE;
  4137. int TxProfileIsNull=FALSE;
  4138. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4139. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4140. memset(&TxProfile,0,sizeof(struct StructProfile));
  4141. c=0;
  4142. loc = strstr(payload, "connectorId");
  4143. memset(sstr ,0, sizeof(sstr) );
  4144. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4145. {
  4146. sstr[c] = loc[strlen("connectorId")+2+c];
  4147. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4148. c++;
  4149. }
  4150. sstr[c] = '\0';
  4151. connectorIdInt = atoi(sstr);
  4152. c=0;
  4153. loc = strstr(payload, "duration");
  4154. memset(sstr ,0, sizeof(sstr) );
  4155. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4156. {
  4157. sstr[c] = loc[strlen("duration")+2+c];
  4158. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4159. c++;
  4160. }
  4161. sstr[c] = '\0';
  4162. durationInt = atoi(sstr);
  4163. c = 0;
  4164. loc = strstr(payload, "chargingRateUnit");
  4165. memset(sstr ,0, sizeof(sstr) );
  4166. if(loc == NULL)
  4167. {
  4168. }
  4169. else
  4170. {
  4171. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4172. {
  4173. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4174. c++;
  4175. }
  4176. sstr[c] = '\0';
  4177. strcpy(chargingRateUnitStr, sstr);
  4178. }
  4179. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4180. if(connectorIdInt==0) // connectorId is 0
  4181. {
  4182. //******************************ChargePointMaxProfile*****************************************************/
  4183. strcpy(fname, ChargePointMaxProfile_JSON );
  4184. char word[30]={0};
  4185. char sLineWord[1060]={0};
  4186. int n_chargingProfile=0;
  4187. ChargePointMaxProfileIsNull=TRUE;
  4188. if((access(fname,F_OK))!=-1)
  4189. {
  4190. fptr1 = fopen(fname, "r");
  4191. int c;
  4192. c = fgetc(fptr1);
  4193. //DEBUG_INFO("c:%d\n",c);
  4194. rewind(fptr1);
  4195. if(c == EOF)
  4196. {
  4197. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4198. ChargePointMaxProfileIsNull=TRUE;
  4199. fclose(fptr1);
  4200. }
  4201. else
  4202. {
  4203. ChargePointMaxProfileIsNull=FALSE;
  4204. while(fscanf(fptr1, "%s", word) != EOF)
  4205. {
  4206. if(strcmp(word, "chargingProfileId") == 0)
  4207. {
  4208. n_chargingProfile = n_chargingProfile + 1;
  4209. printf("Found\n");
  4210. }
  4211. }
  4212. rewind(fptr1);
  4213. //search Charging Profile Element
  4214. int i= 0;
  4215. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4216. #if 0
  4217. /***********connectorId****************/
  4218. c = 0;
  4219. loc = strstr(sLineWord, "connectorId");
  4220. // printf("loc=%s\n",loc);
  4221. memset(sstr ,0, sizeof(sstr) );
  4222. while (loc[strlen("connectorId")+2+c] != ',')
  4223. {
  4224. sstr[c] = loc[strlen("connectorId")+2+c];
  4225. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4226. c++;
  4227. }
  4228. sstr[c] = '\0';
  4229. tempconnectorIdInt = atoi(sstr);
  4230. #endif
  4231. //***********validFrom**************/
  4232. c = 0;
  4233. loc = strstr(sLineWord, "validFrom");
  4234. //DEBUG_INFO("loc=%s\n",loc);
  4235. memset(sstr ,0, sizeof(sstr) );
  4236. if(loc != NULL)
  4237. {
  4238. while (loc[3+strlen("validFrom")+c] != '\"')
  4239. {
  4240. sstr[c] = loc[3+strlen("validFrom")+c];
  4241. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4242. c++;
  4243. }
  4244. sstr[c] = '\0';
  4245. DEBUG_INFO("validFrom=%s\n",sstr);
  4246. strcpy(tempvalidFromStr,sstr);
  4247. }
  4248. else
  4249. {
  4250. strcpy(tempvalidFromStr,"");
  4251. }
  4252. //**********startSchedule**********/
  4253. c = 0;
  4254. loc = strstr(sLineWord, "startSchedule");
  4255. //DEBUG_INFO("loc=%s\n",loc);
  4256. memset(sstr ,0, sizeof(sstr) );
  4257. while (loc[3+strlen("startSchedule")+c] != '\"')
  4258. {
  4259. sstr[c] = loc[3+strlen("startSchedule")+c];
  4260. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4261. c++;
  4262. }
  4263. sstr[c] = '\0';
  4264. strcpy(tempstartScheduleStr, sstr);
  4265. //**********startSchedule**********/
  4266. c = 0;
  4267. loc = strstr(sLineWord, "chargingRateUnit");
  4268. memset(sstr ,0, sizeof(sstr) );
  4269. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4270. {
  4271. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4272. c++;
  4273. }
  4274. sstr[c] = '\0';
  4275. strcpy(tempchargingRateUnitStr, sstr);
  4276. //**********minChargingRate*******/
  4277. c = 0;
  4278. loc = strstr(sLineWord, "minChargingRate");
  4279. //printf("loc=%s\n",loc);
  4280. if(loc != NULL)
  4281. {
  4282. memset(sstr ,0, sizeof(sstr) );
  4283. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4284. {
  4285. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4287. c++;
  4288. }
  4289. sstr[c] = '\0';
  4290. tempminChargingRateFloat = atof(sstr);
  4291. }
  4292. else
  4293. {
  4294. tempminChargingRateFloat = 0.0;
  4295. }
  4296. //
  4297. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4298. tp.tm_isdst = -1;
  4299. time_t utc = mktime(&tp);
  4300. // current time
  4301. time_t t = time(NULL);
  4302. diff_t = difftime(t, utc);
  4303. //parsing strings to words
  4304. i = 0;
  4305. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4306. loc = loc+3+strlen("chargingSchedulePeriod");
  4307. pch = strtok(loc ,"{");
  4308. while (pch != NULL)
  4309. {
  4310. strcpy(SchedulePeriodList[i], pch);
  4311. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4312. //printf ("%s\n",pch);
  4313. pch = strtok (NULL, "{");
  4314. i = i + 1;
  4315. }
  4316. n_SchedulePeriods = i;
  4317. for(int i=0;i<n_SchedulePeriods;i++)
  4318. {
  4319. //*************startPeriod****************/
  4320. c = 0;
  4321. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4322. memset(sstr ,0, sizeof(sstr) );
  4323. while (loc[strlen("startPeriod")+2+c] != ',')
  4324. {
  4325. sstr[c] = loc[strlen("startPeriod")+2+c];
  4326. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4327. c++;
  4328. }
  4329. sstr[c] = '\0';
  4330. tempStartPeriodInt = atoi(sstr);
  4331. //*************limit****************/
  4332. c = 0;
  4333. loc = strstr(SchedulePeriodList[i], "limit");
  4334. memset(sstr ,0, sizeof(sstr) );
  4335. while (loc[strlen("limit")+2+c] != ',')
  4336. {
  4337. sstr[c] = loc[strlen("limit")+2+c];
  4338. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4339. c++;
  4340. }
  4341. sstr[c] = '\0';
  4342. tempLimitInt = atof(sstr);
  4343. //*************numberPhases****************/
  4344. c = 0;
  4345. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4346. memset(sstr ,0, sizeof(sstr) );
  4347. while (loc[strlen("numberPhases")+2+c] != ',')
  4348. {
  4349. sstr[c] = loc[strlen("numberPhases")+2+c];
  4350. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4351. c++;
  4352. }
  4353. sstr[c] = '\0';
  4354. tempNumberPhasesInt = atoi(sstr);
  4355. ChargePointMaxProfile.Duration = durationInt;
  4356. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4357. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4358. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4359. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4360. }
  4361. if(MinChargingRate < tempminChargingRateFloat)
  4362. MinChargingRate = tempminChargingRateFloat;
  4363. }
  4364. }// End of file ChargingProfile
  4365. } //THE END OF ACCESS ChargePointMaxProfile
  4366. //******************************TxDefaultProfile***********************************************/
  4367. strcpy(fname, TxDefaultProfile_0_JSON);
  4368. memset(word, 0, 30);
  4369. memset(sLineWord, 0, 1060);
  4370. //char word[30]={0};
  4371. //char sLineWord[1060]={0};
  4372. n_chargingProfile=0;
  4373. TxDefaultProfileFileIsNull=TRUE;
  4374. if((access(fname,F_OK))!=-1)
  4375. {
  4376. fptr1 = fopen(fname, "r");
  4377. c = 0;
  4378. c = fgetc(fptr1);
  4379. //DEBUG_INFO("c:%d\n",c);
  4380. rewind(fptr1);
  4381. if(c == EOF)
  4382. {
  4383. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4384. TxDefaultProfileFileIsNull=TRUE;
  4385. fclose(fptr1);
  4386. }
  4387. else
  4388. {
  4389. TxDefaultProfileFileIsNull=FALSE;
  4390. while(fscanf(fptr1, "%s", word) != EOF)
  4391. {
  4392. if(strcmp(word, "chargingProfileId") == 0)
  4393. {
  4394. n_chargingProfile = n_chargingProfile + 1;
  4395. printf("Found\n");
  4396. }
  4397. }
  4398. rewind(fptr1);
  4399. //search Charging Profile Element
  4400. int i= 0;
  4401. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4402. #if 0
  4403. /***********connectorId****************/
  4404. c = 0;
  4405. loc = strstr(sLineWord, "connectorId");
  4406. // printf("loc=%s\n",loc);
  4407. memset(sstr ,0, sizeof(sstr) );
  4408. while (loc[strlen("connectorId")+2+c] != ',')
  4409. {
  4410. sstr[c] = loc[strlen("connectorId")+2+c];
  4411. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4412. c++;
  4413. }
  4414. sstr[c] = '\0';
  4415. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4416. tempconnectorIdInt = atoi(sstr);
  4417. #endif
  4418. //***********validFrom**************/
  4419. c = 0;
  4420. loc = strstr(sLineWord, "validFrom");
  4421. //DEBUG_INFO("loc=%s\n",loc);
  4422. memset(sstr ,0, sizeof(sstr) );
  4423. if(loc != NULL)
  4424. {
  4425. while (loc[3+strlen("validFrom")+c] != '\"')
  4426. {
  4427. sstr[c] = loc[3+strlen("validFrom")+c];
  4428. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4429. c++;
  4430. }
  4431. sstr[c] = '\0';
  4432. DEBUG_INFO("validFrom=%s\n",sstr);
  4433. strcpy(tempvalidFromStr,sstr);
  4434. }
  4435. else
  4436. {
  4437. strcpy(tempvalidFromStr,"");
  4438. }
  4439. //**********startSchedule**********/
  4440. c = 0;
  4441. loc = strstr(sLineWord, "startSchedule");
  4442. //DEBUG_INFO("loc=%s\n",loc);
  4443. memset(sstr ,0, sizeof(sstr) );
  4444. while (loc[3+strlen("startSchedule")+c] != '\"')
  4445. {
  4446. sstr[c] = loc[3+strlen("startSchedule")+c];
  4447. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4448. c++;
  4449. }
  4450. sstr[c] = '\0';
  4451. strcpy(tempstartScheduleStr, sstr);
  4452. DEBUG_INFO(" debug 3-1\n");
  4453. //**********startSchedule**********/
  4454. c = 0;
  4455. loc = strstr(sLineWord, "chargingRateUnit");
  4456. memset(sstr ,0, sizeof(sstr) );
  4457. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4458. {
  4459. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4460. c++;
  4461. }
  4462. sstr[c] = '\0';
  4463. strcpy(tempchargingRateUnitStr, sstr);
  4464. //**********minChargingRate*******/
  4465. c = 0;
  4466. loc = strstr(sLineWord, "minChargingRate");
  4467. //printf("loc=%s\n",loc);
  4468. if(loc != NULL)
  4469. {
  4470. memset(sstr ,0, sizeof(sstr) );
  4471. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4472. {
  4473. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4474. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4475. c++;
  4476. }
  4477. sstr[c] = '\0';
  4478. tempminChargingRateFloat = atof(sstr);
  4479. }
  4480. else
  4481. {
  4482. tempminChargingRateFloat = 0.0;
  4483. }
  4484. //
  4485. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4486. tp.tm_isdst = -1;
  4487. time_t utc = mktime(&tp);
  4488. // current time
  4489. time_t t = time(NULL);
  4490. diff_t = difftime(t, utc);
  4491. //parsing strings to words
  4492. i = 0;
  4493. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4494. loc = loc+3+strlen("chargingSchedulePeriod");
  4495. pch = strtok(loc ,"{");
  4496. while (pch != NULL)
  4497. {
  4498. strcpy(SchedulePeriodList[i], pch);
  4499. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4500. //printf ("%s\n",pch);
  4501. pch = strtok (NULL, "{");
  4502. i = i + 1;
  4503. }
  4504. n_SchedulePeriods = i;
  4505. for(int i=0;i<n_SchedulePeriods;i++)
  4506. {
  4507. //*************startPeriod****************/
  4508. c = 0;
  4509. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4510. memset(sstr ,0, sizeof(sstr) );
  4511. while (loc[strlen("startPeriod")+2+c] != ',')
  4512. {
  4513. sstr[c] = loc[strlen("startPeriod")+2+c];
  4514. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4515. c++;
  4516. }
  4517. sstr[c] = '\0';
  4518. tempStartPeriodInt = atoi(sstr);
  4519. //*************limit****************/
  4520. c = 0;
  4521. loc = strstr(SchedulePeriodList[i], "limit");
  4522. memset(sstr ,0, sizeof(sstr) );
  4523. while (loc[strlen("limit")+2+c] != ',')
  4524. {
  4525. sstr[c] = loc[strlen("limit")+2+c];
  4526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4527. c++;
  4528. }
  4529. sstr[c] = '\0';
  4530. tempLimitInt = atof(sstr);
  4531. //*************numberPhases****************/
  4532. c = 0;
  4533. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4534. memset(sstr ,0, sizeof(sstr) );
  4535. while (loc[strlen("numberPhases")+2+c] != ',')
  4536. {
  4537. sstr[c] = loc[strlen("numberPhases")+2+c];
  4538. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4539. c++;
  4540. }
  4541. sstr[c] = '\0';
  4542. tempNumberPhasesInt = atoi(sstr);
  4543. TxDefaultProfile.Duration = durationInt;
  4544. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4545. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4546. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4547. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4548. }
  4549. if(MinChargingRate < tempminChargingRateFloat)
  4550. MinChargingRate = tempminChargingRateFloat;
  4551. }
  4552. }
  4553. }// the end of ACCESS TxDefaultProfile
  4554. // Composite Schedule
  4555. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4556. {
  4557. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4558. {
  4559. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4560. {
  4561. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4562. }
  4563. else
  4564. {
  4565. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4566. }
  4567. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4568. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4569. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4570. }
  4571. }
  4572. //* Define temporary variables */
  4573. struct tm *gtime;
  4574. time_t now;
  4575. char buf[28];
  4576. /* Read the current system time */
  4577. time(&now);
  4578. /* Convert the system time to GMT (now UTC) */
  4579. gtime = gmtime(&now);
  4580. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4581. // make .conf
  4582. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  4583. //MaxChargingProfilesInstalled is 10
  4584. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4585. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4586. //nPeriod = 1;
  4587. if(chargingRateUnitStr[0] != 0)
  4588. {
  4589. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4590. }
  4591. else
  4592. {
  4593. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  4594. }
  4595. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4596. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4597. confirmPeriods = 1;
  4598. }
  4599. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4600. {
  4601. //*****************************ChargePointMaxProfile******************************************/
  4602. strcpy(fname, ChargePointMaxProfile_JSON);
  4603. ChargePointMaxProfileIsNull=TRUE;
  4604. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4605. {
  4606. fptr1 = fopen(fname, "r");
  4607. int c;
  4608. c = fgetc(fptr1);
  4609. //DEBUG_INFO("c:%d\n",c);
  4610. rewind(fptr1);
  4611. if(c == EOF)
  4612. {
  4613. DEBUG_INFO("\n End of file reached.");
  4614. ChargePointMaxProfileIsNull=TRUE;
  4615. fclose(fptr1);
  4616. }
  4617. else
  4618. {
  4619. ChargePointMaxProfileIsNull=FALSE;
  4620. while(fscanf(fptr1, "%s", word) != EOF)
  4621. {
  4622. if(strcmp(word, "chargingProfileId") == 0)
  4623. {
  4624. n_chargingProfile = n_chargingProfile + 1;
  4625. }
  4626. }
  4627. rewind(fptr1);
  4628. //search Charging Profile Element
  4629. int i = 0;
  4630. int j = 0;
  4631. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4632. #if 0
  4633. /***********connectorId****************/
  4634. c = 0;
  4635. loc = strstr(sLineWord, "connectorId");
  4636. memset(sstr ,0, sizeof(sstr) );
  4637. while (loc[strlen("connectorId")+2+c] != ',')
  4638. {
  4639. sstr[c] = loc[strlen("connectorId")+2+c];
  4640. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4641. c++;
  4642. }
  4643. sstr[c] = '\0';
  4644. tempconnectorIdInt = atoi(sstr);
  4645. #endif
  4646. //***********validFrom**************/
  4647. c = 0;
  4648. loc = strstr(sLineWord, "validFrom");
  4649. if(loc != NULL)
  4650. {
  4651. memset(sstr ,0, sizeof(sstr) );
  4652. while (loc[3+strlen("validFrom")+c] != '\"')
  4653. {
  4654. sstr[c] = loc[3+strlen("validFrom")+c];
  4655. c++;
  4656. }
  4657. sstr[c] = '\0';
  4658. strcpy(tempvalidFromStr,sstr);
  4659. }
  4660. else
  4661. {
  4662. strcpy(tempvalidFromStr,"");
  4663. }
  4664. //***********validFrom**************/
  4665. c = 0;
  4666. loc = strstr(sLineWord, "duration");
  4667. if(loc != NULL)
  4668. {
  4669. memset(sstr ,0, sizeof(sstr) );
  4670. while (loc[2+strlen("duration")+c] != ',')
  4671. {
  4672. sstr[c] = loc[2+strlen("duration")+c];
  4673. c++;
  4674. }
  4675. sstr[c] = '\0';
  4676. tempdurationInt = atoi(sstr);
  4677. }
  4678. else
  4679. {
  4680. tempdurationInt = 0;
  4681. }
  4682. //**********startSchedule**********/
  4683. c = 0;
  4684. loc = strstr(sLineWord, "startSchedule");
  4685. memset(sstr ,0, sizeof(sstr) );
  4686. while (loc[3+strlen("startSchedule")+c] != '\"')
  4687. {
  4688. sstr[c] = loc[3+strlen("startSchedule")+c];
  4689. c++;
  4690. }
  4691. sstr[c] = '\0';
  4692. strcpy(tempstartScheduleStr, sstr);
  4693. //**********startSchedule**********/
  4694. c = 0;
  4695. loc = strstr(sLineWord, "chargingRateUnit");
  4696. memset(sstr ,0, sizeof(sstr) );
  4697. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4698. {
  4699. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4700. c++;
  4701. }
  4702. sstr[c] = '\0';
  4703. strcpy(tempchargingRateUnitStr, sstr);
  4704. //**********minChargingRate*******/
  4705. c = 0;
  4706. loc = strstr(sLineWord, "minChargingRate");
  4707. if(loc != NULL)
  4708. {
  4709. memset(sstr ,0, sizeof(sstr) );
  4710. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4711. {
  4712. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4713. c++;
  4714. }
  4715. sstr[c] = '\0';
  4716. tempminChargingRateFloat = atof(sstr);
  4717. }
  4718. else
  4719. {
  4720. tempminChargingRateFloat = 0.0;
  4721. }
  4722. //
  4723. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4724. tp.tm_isdst = -1;
  4725. time_t utc = mktime(&tp);
  4726. time_t t = time(NULL);
  4727. diff_t = difftime(t, utc);
  4728. DEBUG_INFO("diff_t=%f\n",diff_t);
  4729. DEBUG_INFO(" debug 5 -1\n");
  4730. //parsing strings to words
  4731. i = 0;
  4732. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4733. loc = loc+3+strlen("chargingSchedulePeriod");
  4734. pch = strtok(loc ,"{");
  4735. while (pch != NULL)
  4736. {
  4737. strcpy(SchedulePeriodList[i], pch);
  4738. pch = strtok (NULL, "{");
  4739. i = i + 1;
  4740. }
  4741. n_SchedulePeriods = i;
  4742. for(int i=0;i<n_SchedulePeriods;i++)
  4743. {
  4744. //*************startPeriod****************/
  4745. c = 0;
  4746. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4747. memset(sstr ,0, sizeof(sstr) );
  4748. while (loc[strlen("startPeriod")+2+c] != ',')
  4749. {
  4750. sstr[c] = loc[strlen("startPeriod")+2+c];
  4751. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4752. c++;
  4753. }
  4754. sstr[c] = '\0';
  4755. tempStartPeriodInt = atoi(sstr);
  4756. //*************limit****************/
  4757. c = 0;
  4758. loc = strstr(SchedulePeriodList[i], "limit");
  4759. memset(sstr ,0, sizeof(sstr) );
  4760. while (loc[strlen("limit")+2+c] != ',')
  4761. {
  4762. sstr[c] = loc[strlen("limit")+2+c];
  4763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4764. c++;
  4765. }
  4766. sstr[c] = '\0';
  4767. tempLimitInt = atof(sstr);
  4768. //*************numberPhases****************/
  4769. c = 0;
  4770. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4771. memset(sstr ,0, sizeof(sstr) );
  4772. while (loc[strlen("numberPhases")+2+c] != '}')
  4773. {
  4774. sstr[c] = loc[strlen("numberPhases")+2+c];
  4775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4776. c++;
  4777. }
  4778. sstr[c] = '\0';
  4779. tempNumberPhasesInt = atoi(sstr);
  4780. if(j == 0)
  4781. {
  4782. ChargePointMaxProfile.Duration = tempdurationInt;
  4783. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4784. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4785. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4786. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4787. }
  4788. }
  4789. if(MinChargingRate < tempminChargingRateFloat)
  4790. {
  4791. MinChargingRate = tempminChargingRateFloat;
  4792. }
  4793. if(confirmPeriods < n_SchedulePeriods)
  4794. {
  4795. confirmPeriods = n_SchedulePeriods;
  4796. }
  4797. j = j + 1;
  4798. }
  4799. fclose(fptr1);
  4800. }
  4801. }// the end of access file ChargePointMaxProfile
  4802. //****************************TxDefaultProfile************************************************/
  4803. switch(connectorIdInt)
  4804. {
  4805. case 0:
  4806. break;
  4807. case 1:
  4808. strcpy(fname, TxDefaultProfile_1_JSON );
  4809. break;
  4810. case 2:
  4811. strcpy(fname, TxDefaultProfile_2_JSON );
  4812. break;
  4813. default:
  4814. strcpy(fname, TxDefaultProfile_1_JSON );
  4815. break;
  4816. }
  4817. TxDefaultProfileFileIsNull=TRUE;
  4818. if((access(fname,F_OK))!=-1)
  4819. {
  4820. fptr1 = fopen(fname, "r");
  4821. c = 0;
  4822. c = fgetc(fptr1);
  4823. //DEBUG_INFO("c:%d\n",c);
  4824. rewind(fptr1);
  4825. if(c == EOF)
  4826. {
  4827. DEBUG_INFO("\n End of file reached.");
  4828. TxDefaultProfileFileIsNull=TRUE;
  4829. fclose(fptr1);
  4830. }
  4831. else
  4832. {
  4833. TxDefaultProfileFileIsNull=FALSE;
  4834. while(fscanf(fptr1, "%s", word) != EOF)
  4835. {
  4836. if(strcmp(word, "chargingProfileId") == 0)
  4837. {
  4838. n_chargingProfile = n_chargingProfile + 1;
  4839. }
  4840. }
  4841. rewind(fptr1);
  4842. //search Charging Profile Element
  4843. int i = 0;
  4844. int j = 0;
  4845. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4846. #if 0
  4847. /***********connectorId****************/
  4848. c = 0;
  4849. loc = strstr(sLineWord, "connectorId");
  4850. memset(sstr ,0, sizeof(sstr) );
  4851. while (loc[strlen("connectorId")+2+c] != ',')
  4852. {
  4853. sstr[c] = loc[strlen("connectorId")+2+c];
  4854. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4855. c++;
  4856. }
  4857. sstr[c] = '\0';
  4858. tempconnectorIdInt = atoi(sstr);
  4859. #endif
  4860. //***********validFrom**************/
  4861. c = 0;
  4862. loc = strstr(sLineWord, "validFrom");
  4863. if(loc != NULL)
  4864. {
  4865. memset(sstr ,0, sizeof(sstr) );
  4866. while (loc[3+strlen("validFrom")+c] != '\"')
  4867. {
  4868. sstr[c] = loc[3+strlen("validFrom")+c];
  4869. c++;
  4870. }
  4871. sstr[c] = '\0';
  4872. strcpy(tempvalidFromStr,sstr);
  4873. }
  4874. else
  4875. {
  4876. strcpy(tempvalidFromStr,"");
  4877. }
  4878. //***********validFrom**************/
  4879. c = 0;
  4880. loc = strstr(sLineWord, "duration");
  4881. if(loc != NULL)
  4882. {
  4883. memset(sstr ,0, sizeof(sstr) );
  4884. while (loc[2+strlen("duration")+c] != ',')
  4885. {
  4886. sstr[c] = loc[2+strlen("duration")+c];
  4887. c++;
  4888. }
  4889. sstr[c] = '\0';
  4890. tempdurationInt = atoi(sstr);
  4891. }
  4892. else
  4893. {
  4894. tempdurationInt = 0;
  4895. }
  4896. //**********startSchedule**********/
  4897. c = 0;
  4898. loc = strstr(sLineWord, "startSchedule");
  4899. memset(sstr ,0, sizeof(sstr) );
  4900. while (loc[3+strlen("startSchedule")+c] != '\"')
  4901. {
  4902. sstr[c] = loc[3+strlen("startSchedule")+c];
  4903. c++;
  4904. }
  4905. sstr[c] = '\0';
  4906. strcpy(tempstartScheduleStr, sstr);
  4907. //**********startSchedule**********/
  4908. c = 0;
  4909. loc = strstr(sLineWord, "chargingRateUnit");
  4910. memset(sstr ,0, sizeof(sstr) );
  4911. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4912. {
  4913. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4914. c++;
  4915. }
  4916. sstr[c] = '\0';
  4917. strcpy(tempchargingRateUnitStr, sstr);
  4918. //**********minChargingRate*******/
  4919. c = 0;
  4920. loc = strstr(sLineWord, "minChargingRate");
  4921. if(loc != NULL)
  4922. {
  4923. memset(sstr ,0, sizeof(sstr) );
  4924. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4925. {
  4926. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4927. c++;
  4928. }
  4929. sstr[c] = '\0';
  4930. tempminChargingRateFloat = atof(sstr);
  4931. }
  4932. else
  4933. {
  4934. tempminChargingRateFloat = 0.0;
  4935. }
  4936. //
  4937. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4938. tp.tm_isdst = -1;
  4939. time_t utc = mktime(&tp);
  4940. time_t t = time(NULL);
  4941. diff_t = difftime(t, utc);
  4942. DEBUG_INFO("diff_t=%f\n",diff_t);
  4943. DEBUG_INFO(" debug 5 -1\n");
  4944. //parsing strings to words
  4945. i = 0;
  4946. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4947. loc = loc+3+strlen("chargingSchedulePeriod");
  4948. pch = strtok(loc ,"{");
  4949. while (pch != NULL)
  4950. {
  4951. strcpy(SchedulePeriodList[i], pch);
  4952. pch = strtok (NULL, "{");
  4953. i = i + 1;
  4954. }
  4955. n_SchedulePeriods = i;
  4956. for(int i=0;i<n_SchedulePeriods;i++)
  4957. {
  4958. //*************startPeriod****************/
  4959. c = 0;
  4960. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4961. memset(sstr ,0, sizeof(sstr) );
  4962. while (loc[strlen("startPeriod")+2+c] != ',')
  4963. {
  4964. sstr[c] = loc[strlen("startPeriod")+2+c];
  4965. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4966. c++;
  4967. }
  4968. sstr[c] = '\0';
  4969. tempStartPeriodInt = atoi(sstr);
  4970. //*************limit****************/
  4971. c = 0;
  4972. loc = strstr(SchedulePeriodList[i], "limit");
  4973. memset(sstr ,0, sizeof(sstr) );
  4974. while (loc[strlen("limit")+2+c] != ',')
  4975. {
  4976. sstr[c] = loc[strlen("limit")+2+c];
  4977. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4978. c++;
  4979. }
  4980. sstr[c] = '\0';
  4981. tempLimitInt = atof(sstr);
  4982. //*************numberPhases****************/
  4983. c = 0;
  4984. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4985. memset(sstr ,0, sizeof(sstr) );
  4986. while (loc[strlen("numberPhases")+2+c] != '}')
  4987. {
  4988. sstr[c] = loc[strlen("numberPhases")+2+c];
  4989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4990. c++;
  4991. }
  4992. sstr[c] = '\0';
  4993. tempNumberPhasesInt = atoi(sstr);
  4994. if(j == 0)
  4995. {
  4996. TxDefaultProfile.Duration = tempdurationInt;
  4997. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4998. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4999. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5000. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5001. }
  5002. else
  5003. {
  5004. //other stack level charging Profile
  5005. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5006. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5007. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5008. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5009. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5010. }
  5011. }
  5012. if(MinChargingRate < tempminChargingRateFloat)
  5013. MinChargingRate = tempminChargingRateFloat;
  5014. if(confirmPeriods < n_SchedulePeriods)
  5015. confirmPeriods = n_SchedulePeriods;
  5016. j = j + 1;
  5017. }
  5018. fclose(fptr1);
  5019. //Stacking Charging Profiles
  5020. for(int l=0; l <(j-1) ;l++)
  5021. {
  5022. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5023. {
  5024. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5025. {
  5026. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5027. {
  5028. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5029. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5030. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5031. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5032. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5033. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5034. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5035. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5036. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5037. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5038. }
  5039. else
  5040. {
  5041. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5042. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5043. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5044. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5045. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5046. }
  5047. }
  5048. }
  5049. }
  5050. //end of Stacking Charging Profiles
  5051. }
  5052. }// the end of ACCESS TxDefaultProfile
  5053. //****************************TxProfile************************************************/
  5054. switch(connectorIdInt)
  5055. {
  5056. case 0:
  5057. break;
  5058. case 1:
  5059. strcpy(fname, TxProfile_1_JSON );
  5060. break;
  5061. case 2:
  5062. strcpy(fname, TxProfile_2_JSON );
  5063. break;
  5064. default:
  5065. strcpy(fname, TxProfile_1_JSON );
  5066. break;
  5067. }
  5068. TxProfileIsNull=TRUE;
  5069. if((access(fname,F_OK))!=-1)
  5070. {
  5071. fptr1 = fopen(fname, "r");
  5072. c = 0;
  5073. c = fgetc(fptr1);
  5074. //DEBUG_INFO("c:%d\n",c);
  5075. rewind(fptr1);
  5076. if(c == EOF)
  5077. {
  5078. DEBUG_INFO("\n End of file reached.");
  5079. TxProfileIsNull=TRUE;
  5080. fclose(fptr1);
  5081. }
  5082. else
  5083. {
  5084. TxProfileIsNull=FALSE;
  5085. while(fscanf(fptr1, "%s", word) != EOF)
  5086. {
  5087. if(strcmp(word, "chargingProfileId") == 0)
  5088. {
  5089. n_chargingProfile = n_chargingProfile + 1;
  5090. }
  5091. }
  5092. rewind(fptr1);
  5093. //search Charging Profile Element
  5094. int i= 0;
  5095. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5096. #if 0
  5097. /***********connectorId****************/
  5098. c = 0;
  5099. loc = strstr(sLineWord, "connectorId");
  5100. memset(sstr ,0, sizeof(sstr) );
  5101. while (loc[strlen("connectorId")+2+c] != ',')
  5102. {
  5103. sstr[c] = loc[strlen("connectorId")+2+c];
  5104. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5105. c++;
  5106. }
  5107. sstr[c] = '\0';
  5108. tempconnectorIdInt = atoi(sstr);
  5109. #endif
  5110. //***********validFrom**************/
  5111. c = 0;
  5112. loc = strstr(sLineWord, "validFrom");
  5113. if(loc != NULL)
  5114. {
  5115. memset(sstr ,0, sizeof(sstr) );
  5116. while (loc[3+strlen("validFrom")+c] != '\"')
  5117. {
  5118. sstr[c] = loc[3+strlen("validFrom")+c];
  5119. c++;
  5120. }
  5121. sstr[c] = '\0';
  5122. strcpy(tempvalidFromStr,sstr);
  5123. }
  5124. else
  5125. {
  5126. strcpy(tempvalidFromStr,"");
  5127. }
  5128. //**********startSchedule**********/
  5129. c = 0;
  5130. loc = strstr(sLineWord, "startSchedule");
  5131. memset(sstr ,0, sizeof(sstr) );
  5132. while (loc[3+strlen("startSchedule")+c] != '\"')
  5133. {
  5134. sstr[c] = loc[3+strlen("startSchedule")+c];
  5135. c++;
  5136. }
  5137. sstr[c] = '\0';
  5138. strcpy(tempstartScheduleStr, sstr);
  5139. //**********startSchedule**********/
  5140. c = 0;
  5141. loc = strstr(sLineWord, "chargingRateUnit");
  5142. memset(sstr ,0, sizeof(sstr) );
  5143. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5144. {
  5145. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5146. c++;
  5147. }
  5148. sstr[c] = '\0';
  5149. strcpy(tempchargingRateUnitStr, sstr);
  5150. //**********minChargingRate*******/
  5151. c = 0;
  5152. loc = strstr(sLineWord, "minChargingRate");
  5153. if(loc != NULL)
  5154. {
  5155. memset(sstr ,0, sizeof(sstr) );
  5156. while (loc[3+strlen("minChargingRate")+c] != '\"')
  5157. {
  5158. sstr[c] = loc[3+strlen("minChargingRate")+c];
  5159. c++;
  5160. }
  5161. sstr[c] = '\0';
  5162. tempminChargingRateFloat = atof(sstr);
  5163. }
  5164. else
  5165. {
  5166. tempminChargingRateFloat = 0.0;
  5167. }
  5168. //
  5169. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5170. tp.tm_isdst = -1;
  5171. time_t utc = mktime(&tp);
  5172. time_t t = time(NULL);
  5173. diff_t = difftime(t, utc);
  5174. DEBUG_INFO("diff_t=%f\n",diff_t);
  5175. //parsing strings to words
  5176. i = 0;
  5177. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5178. loc = loc+3+strlen("chargingSchedulePeriod");
  5179. pch = strtok(loc ,"{");
  5180. while (pch != NULL)
  5181. {
  5182. strcpy(SchedulePeriodList[i], pch);
  5183. pch = strtok (NULL, "{");
  5184. i = i + 1;
  5185. }
  5186. n_SchedulePeriods = i;
  5187. for(int i=0;i<n_SchedulePeriods;i++)
  5188. {
  5189. //*************startPeriod****************/
  5190. c = 0;
  5191. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5192. memset(sstr ,0, sizeof(sstr) );
  5193. while (loc[strlen("startPeriod")+2+c] != ',')
  5194. {
  5195. sstr[c] = loc[strlen("startPeriod")+2+c];
  5196. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5197. c++;
  5198. }
  5199. sstr[c] = '\0';
  5200. tempStartPeriodInt = atoi(sstr);
  5201. //*************limit****************/
  5202. c = 0;
  5203. loc = strstr(SchedulePeriodList[i], "limit");
  5204. memset(sstr ,0, sizeof(sstr) );
  5205. while (loc[strlen("limit")+2+c] != ',')
  5206. {
  5207. sstr[c] = loc[strlen("limit")+2+c];
  5208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5209. c++;
  5210. }
  5211. sstr[c] = '\0';
  5212. tempLimitInt = atof(sstr);
  5213. //*************numberPhases****************/
  5214. c = 0;
  5215. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5216. memset(sstr ,0, sizeof(sstr) );
  5217. while (loc[strlen("numberPhases")+2+c] != '}')
  5218. {
  5219. sstr[c] = loc[strlen("numberPhases")+2+c];
  5220. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5221. c++;
  5222. }
  5223. sstr[c] = '\0';
  5224. tempNumberPhasesInt = atoi(sstr);
  5225. TxProfile.Duration = durationInt;
  5226. TxProfile.TotalPeriod = n_SchedulePeriods;
  5227. TxProfile.Period[i].Limit = tempLimitInt;
  5228. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5229. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5230. }
  5231. if(MinChargingRate < tempminChargingRateFloat)
  5232. MinChargingRate = tempminChargingRateFloat;
  5233. if(confirmPeriods < n_SchedulePeriods)
  5234. confirmPeriods = n_SchedulePeriods;
  5235. }
  5236. fclose(fptr1);
  5237. }
  5238. }// the end of ACCESS TxProfile
  5239. //CompositeSchedule
  5240. int period=0;
  5241. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5242. {
  5243. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5244. {
  5245. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5246. {
  5247. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5248. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5249. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5250. period = period + 1;
  5251. }
  5252. else
  5253. {
  5254. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5255. {
  5256. }
  5257. else
  5258. {
  5259. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5260. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5261. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5262. period = period + 1;
  5263. }
  5264. }
  5265. }
  5266. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5267. {
  5268. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5269. {
  5270. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5271. {
  5272. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5273. }
  5274. else
  5275. {
  5276. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5277. }
  5278. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5279. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5280. period = period + 1;
  5281. }
  5282. }
  5283. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5284. {
  5285. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5286. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5287. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5288. period = period + 1;
  5289. }
  5290. }
  5291. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5292. {
  5293. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5294. {
  5295. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5296. {
  5297. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5298. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5299. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5300. period = period + 1;
  5301. }
  5302. else
  5303. {
  5304. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5305. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5306. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5307. period = period + 1;
  5308. }
  5309. }
  5310. }
  5311. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5312. {
  5313. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5314. {
  5315. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5316. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5317. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5318. period = period + 1;
  5319. }
  5320. }
  5321. confirmPeriods = period;
  5322. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5323. //* Define temporary variables */
  5324. struct tm *gtime;
  5325. time_t now;
  5326. char buf[28];
  5327. //* Read the current system time */
  5328. time(&now);
  5329. //* Convert the system time to GMT (now UTC) */
  5330. gtime = gmtime(&now);
  5331. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5332. // make .conf
  5333. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  5334. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  5335. //DEBUG_INFO(" debug 11\n");
  5336. // if(chargingRateUnitStr[0] != 0)
  5337. // {
  5338. // strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  5339. // }
  5340. // else
  5341. {
  5342. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5343. }
  5344. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5345. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5346. }
  5347. else
  5348. {
  5349. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5350. }
  5351. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5352. return result;
  5353. }
  5354. int handleGetConfigurationRequest(char *uuid, char *payload)
  5355. {
  5356. mtrace();
  5357. int result = FAIL;
  5358. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5359. //struct json_object *jsonitem;
  5360. int MaxKeySupported = 0;
  5361. int n_keys = 0;
  5362. char requestKey[43][50]={0};
  5363. char search[]="[";
  5364. char sstr[500]={ 0 };
  5365. //int pos;
  5366. int l, c = 0;
  5367. int i = 0;
  5368. char *delim = "\",\"";
  5369. char * pch;
  5370. char *loc = strstr(payload, search);
  5371. //********************* Parsing String ***********************************/
  5372. if(loc == NULL) {
  5373. DEBUG_INFO("no key match in Configuration \n");
  5374. }
  5375. else {
  5376. //pos = loc - payload;
  5377. l = strlen(loc)-4;
  5378. while (c < l)
  5379. {
  5380. sstr[c] = loc[c+2];
  5381. c++;
  5382. }
  5383. sstr[c] = '\0';
  5384. //parsing strings to words
  5385. pch = strtok(sstr,delim);
  5386. if(pch == NULL)
  5387. {
  5388. strcpy(requestKey[0], sstr);
  5389. }
  5390. else
  5391. {
  5392. while (pch != NULL)
  5393. {
  5394. strcpy(requestKey[i], pch);
  5395. pch = strtok (NULL, delim);
  5396. i = i + 1;
  5397. }
  5398. n_keys = i;
  5399. }
  5400. }
  5401. UnknownKeynum = 0;
  5402. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5403. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5404. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5405. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5406. if(n_keys != 0)
  5407. {
  5408. for(int i=0;i<n_keys;i++)
  5409. {
  5410. getKeyValue(requestKey[i]);
  5411. //json_object_put(jsonitem);
  5412. }
  5413. }
  5414. else
  5415. {
  5416. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5417. getKeyValue("");
  5418. }
  5419. processUnkownKey();
  5420. sendGetConfigurationConfirmation(uuid);
  5421. return result;
  5422. }
  5423. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5424. {
  5425. mtrace();
  5426. int result = FAIL;
  5427. //void *ret; //
  5428. char fnamePlusPath[50]="";
  5429. char fname[16]="";
  5430. pthread_t t; // pthread 變數
  5431. time_t rawtime;
  5432. struct tm * timeinfo;
  5433. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5434. system("exec /root/logPackTools 'log' 6");
  5435. //char buffer [128];
  5436. time (&rawtime);
  5437. //printf("%ld\n", rawtime);
  5438. timeinfo = localtime (&rawtime);
  5439. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5440. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5441. if((access(fnamePlusPath,F_OK))!=-1)
  5442. {
  5443. DEBUG_INFO("fnamePlusPath exist.\n");
  5444. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5445. }
  5446. else
  5447. {
  5448. DEBUG_INFO("fnamePlusPath not exist!\n");
  5449. }
  5450. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5451. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5452. pthread_join(t, NULL/*&ret*/);
  5453. return result;
  5454. }
  5455. void* GetDiagnosticsProcess(void* data)
  5456. {
  5457. mtrace();
  5458. int retriesInt=0, retryIntervalInt=0;
  5459. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5460. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5461. 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};
  5462. int port=0;
  5463. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5464. char fname[16]="";
  5465. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5466. int c = 0;
  5467. char *loc;
  5468. int isSuccess = FALSE;
  5469. char ftpbuf[200]={0};
  5470. //char temp[100]={0};
  5471. char * pch;
  5472. // [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"}]
  5473. char *str = (char*) data; // ?��?輸入資�?
  5474. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5475. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5476. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5477. //****************location*******************/
  5478. c = 0;
  5479. memset(sstr ,0, sizeof(sstr) );
  5480. loc = strstr(str, "location");
  5481. while (loc[3+strlen("location")+c] != '\"')
  5482. {
  5483. sstr[c] = loc[3+strlen("location")+c];
  5484. c++;
  5485. }
  5486. sstr[c] = '\0';
  5487. strcpy(locationstr,sstr);
  5488. if(strcmp(locationstr,"")==0)
  5489. {
  5490. DEBUG_INFO("location is <Empty>!\n");
  5491. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5492. goto end;
  5493. }
  5494. //****************retries*******************/
  5495. c = 0;
  5496. loc = strstr(str, "retries");
  5497. if(loc == NULL)
  5498. {
  5499. retriesIsNULL = TRUE;
  5500. }
  5501. else
  5502. {
  5503. while (loc[strlen("retries")+2+c] != ',')
  5504. {
  5505. sstr[c] = loc[strlen("retries")+2+c];
  5506. c++;
  5507. }
  5508. sstr[c] = '\0';
  5509. retriesInt = atoi(sstr);
  5510. }
  5511. if(retriesIsNULL == TRUE)
  5512. {
  5513. retriesInt = 0;
  5514. }
  5515. //****************retryInterval*******************/
  5516. c = 0;
  5517. loc = strstr(str, "retryInterval");
  5518. if(loc == NULL)
  5519. {
  5520. retryIntervalIsNULL = TRUE;
  5521. }
  5522. else
  5523. {
  5524. while (loc[strlen("retryInterval")+2+c] != ',')
  5525. {
  5526. sstr[c] = loc[strlen("retryInterval")+2+c];
  5527. c++;
  5528. }
  5529. sstr[c] = '\0';
  5530. retryIntervalInt = atoi(sstr);
  5531. }
  5532. //****************startTime*******************/
  5533. c = 0;
  5534. memset(sstr ,0, sizeof(sstr) );
  5535. loc = strstr(str, "startTime");
  5536. if(loc == NULL)
  5537. {
  5538. startTimeIsNULL = TRUE;
  5539. }
  5540. else
  5541. {
  5542. while (loc[3+strlen("startTime")+c] != '\"')
  5543. {
  5544. sstr[c] = loc[3+strlen("startTime")+c];
  5545. c++;
  5546. }
  5547. sstr[c] = '\0';
  5548. strcpy(startTimestr,sstr);
  5549. }
  5550. //****************stopTime*******************/
  5551. c = 0;
  5552. memset(sstr ,0, sizeof(sstr) );
  5553. loc = strstr(str, "stopTime");
  5554. if(loc == NULL)
  5555. {
  5556. stopTimeIsNULL = TRUE;
  5557. }
  5558. else
  5559. {
  5560. while (loc[3+strlen("stopTime")+c] != '\"')
  5561. {
  5562. sstr[c] = loc[3+strlen("stopTime")+c];
  5563. c++;
  5564. }
  5565. sstr[c] = '\0';
  5566. strcpy(stopTimestr,sstr);
  5567. }
  5568. memset(protocol, 0, sizeof(protocol));
  5569. memset(user, 0, sizeof(user) );
  5570. memset(password, 0, sizeof(password));
  5571. memset(host, 0, sizeof(host));
  5572. memset(path, 0, sizeof(path));
  5573. memset(ftppath, 0, sizeof(ftppath));
  5574. memset(host1, 0, sizeof(host1));
  5575. memset(path1, 0, sizeof(path1));
  5576. /*location: ftp://user:password@host:port/path*/
  5577. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5578. // protocol, user, password, host, &port, path);
  5579. #if 0 // remove for temporally
  5580. //zip files in /Storage
  5581. system("exec /root/logPackTools 'log' 6");
  5582. #endif
  5583. // system("exec /root/Module_WebService 'log' 6");
  5584. time_t rawtime;
  5585. struct tm * timeinfo;
  5586. //char buffer [128];
  5587. time (&rawtime);
  5588. //printf("%ld\n", rawtime);
  5589. timeinfo = localtime (&rawtime);
  5590. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5591. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5592. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5593. if((access(fnamePlusPath,F_OK))!=-1)
  5594. {
  5595. DEBUG_INFO("fnamePlusPath exist.\n");
  5596. }
  5597. else
  5598. {
  5599. DEBUG_INFO("fnamePlusPath not exist!\n");
  5600. goto end;
  5601. }
  5602. pch=strchr(locationstr,'@');
  5603. if(pch==NULL)
  5604. {
  5605. sscanf(locationstr,
  5606. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5607. protocol, host, &port, path);
  5608. strcpy(user,"anonymous");
  5609. strcpy(password,"");
  5610. }
  5611. else
  5612. {
  5613. DEBUG_INFO("pch=%s\n", pch);
  5614. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5615. protocol, user, password, host, &port, path);
  5616. }
  5617. if(strcmp(protocol,"ftp")!=0)
  5618. {
  5619. DEBUG_INFO("protocol is not ftp!\n");
  5620. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5621. goto end;
  5622. }
  5623. sscanf(host,"%[^/]%s",host1, path1);
  5624. sprintf(ftppath,"%s", path1);
  5625. DEBUG_INFO("protocol =%s\n",protocol);
  5626. DEBUG_INFO("user =%s\n",user);
  5627. DEBUG_INFO("password =%s\n",password);
  5628. DEBUG_INFO("host1 =%s\n",host1);
  5629. DEBUG_INFO("port =%d\n",port);
  5630. DEBUG_INFO("path1 =%s\n",path1);
  5631. DEBUG_INFO("ftppath=%s\n",ftppath);
  5632. int ftppathlen=strlen(ftppath);
  5633. int i=1;
  5634. char filenametemp[50];
  5635. while(i < ftppathlen)
  5636. {
  5637. int len=ftppathlen-i;
  5638. if(ftppath[len]== 47) // '/' ascll code: 47
  5639. {
  5640. DEBUG_INFO("find '/' all right\n");
  5641. break;
  5642. }
  5643. i=i+1;
  5644. }
  5645. memset(filenametemp, 0, sizeof(filenametemp));
  5646. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5647. filenametemp[i+1] = 0;
  5648. //httpDownLoadFile(host, ftppath, fname);
  5649. memset(ftpbuf, 0, sizeof(ftpbuf));
  5650. if(port == 0)
  5651. port = 21;
  5652. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5653. do{
  5654. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5655. sleep(retryIntervalInt);
  5656. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5657. if(!isSuccess)
  5658. {
  5659. //BulldogUtil.sleepMs(interval*1000);
  5660. DEBUG_INFO("Diagnostics fail.\n");
  5661. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5662. }
  5663. else
  5664. {
  5665. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5666. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5667. //isUpdateRequest = TRUE;
  5668. }
  5669. end:
  5670. // json_object_put(obj);
  5671. DiagnosticsStatusNotificationStatus = 0; //Idle
  5672. pthread_exit(NULL/*(void *) fname*/); // ?��?子執行�?
  5673. }
  5674. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5675. {
  5676. mtrace();
  5677. int result = FAIL;
  5678. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5679. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5680. {
  5681. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5682. localversion = -1;
  5683. }
  5684. else
  5685. {
  5686. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5687. OCPP_getListVerion();
  5688. }
  5689. //from db.OCPP_getListVerion
  5690. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5691. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5692. sendGetLocalListVersionConfirmation(uuid,"");
  5693. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5694. return result;
  5695. }
  5696. int handleRemoteStartRequest(char *uuid, char *payload)
  5697. {
  5698. mtrace();
  5699. int result = FAIL;
  5700. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5701. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5702. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5703. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5704. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5705. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5706. int chargingSchedulePeriodCount = 0;
  5707. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5708. int c = 0;
  5709. char *loc;
  5710. char comfirmstr[20]={0};
  5711. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5712. if(server_pending == TRUE)
  5713. {
  5714. return 0;
  5715. }
  5716. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5717. //**********connectorId****************/
  5718. c = 0;
  5719. memset(sstr ,0, sizeof(sstr) );
  5720. loc = strstr(payload, "connectorId");
  5721. if(loc == NULL)
  5722. {
  5723. connectorIdIsNULL = TRUE;
  5724. }
  5725. else
  5726. {
  5727. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5728. {
  5729. sstr[c] = loc[strlen("connectorId")+2+c];
  5730. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5731. c++;
  5732. }
  5733. sstr[c] = '\0';
  5734. connectorIdInt = atoi(sstr);
  5735. }
  5736. if(connectorIdIsNULL == TRUE) // need to discussion
  5737. {
  5738. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5739. goto end;
  5740. }
  5741. //****************idTag*******************/
  5742. c = 0;
  5743. memset(sstr ,0, sizeof(sstr) );
  5744. loc = strstr(payload, "idTag");
  5745. while (loc[3+strlen("idTag")+c] != '\"')
  5746. {
  5747. sstr[c] = loc[3+strlen("idTag")+c];
  5748. c++;
  5749. }
  5750. sstr[c] = '\0';
  5751. strcpy(idTagstr,sstr);
  5752. //****************chargingProfile*******************/
  5753. c = 0;
  5754. memset(sstr ,0, sizeof(sstr) );
  5755. loc = strstr(payload, "chargingProfile");
  5756. if(loc == NULL)
  5757. {
  5758. chargingProfileIsNULL = TRUE;
  5759. }
  5760. else
  5761. {
  5762. //****************chargingProfileId*******************/
  5763. c=0;
  5764. loc = strstr(payload, "chargingProfileId");
  5765. memset(sstr ,0, sizeof(sstr) );
  5766. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5767. {
  5768. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5769. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5770. c++;
  5771. }
  5772. sstr[c] = '\0';
  5773. chargingProfileIdInt = atoi(sstr);
  5774. //****************transactionId*******************/
  5775. loc = strstr(payload, "transactionId");
  5776. if(loc == NULL)
  5777. {
  5778. transactionIdIsNULL = TRUE;
  5779. }
  5780. else
  5781. {
  5782. c=0;
  5783. memset(sstr ,0, sizeof(sstr) );
  5784. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5785. {
  5786. sstr[c] = loc[strlen("transactionId")+2+c];
  5787. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5788. c++;
  5789. }
  5790. sstr[c] = '\0';
  5791. transactionIdInt = atoi(sstr);
  5792. }
  5793. //****************stackLevel*******************/
  5794. c=0;
  5795. loc = strstr(payload, "stackLevel");
  5796. memset(sstr ,0, sizeof(sstr) );
  5797. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5798. {
  5799. sstr[c] = loc[strlen("stackLevel")+2+c];
  5800. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5801. c++;
  5802. }
  5803. sstr[c] = '\0';
  5804. stackLevelInt = atoi(sstr);
  5805. //****************chargingProfilePurpose*******************/
  5806. c = 0;
  5807. memset(sstr ,0, sizeof(sstr) );
  5808. loc = strstr(payload, "chargingProfilePurpose");
  5809. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5810. {
  5811. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5812. c++;
  5813. }
  5814. sstr[c] = '\0';
  5815. strcpy(chargingProfilePurposestr,sstr);
  5816. //****************chargingProfileKind*******************/
  5817. c = 0;
  5818. memset(sstr ,0, sizeof(sstr) );
  5819. loc = strstr(payload, "chargingProfileKind");
  5820. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5821. {
  5822. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5823. c++;
  5824. }
  5825. sstr[c] = '\0';
  5826. strcpy(chargingProfileKindstr,sstr);
  5827. //****************recurrencyKind*******************/
  5828. loc = strstr(payload, "recurrencyKind");
  5829. if(loc == NULL)
  5830. {
  5831. recurrencyKindIsNULL = TRUE;
  5832. }
  5833. else
  5834. {
  5835. c = 0;
  5836. memset(sstr ,0, sizeof(sstr) );
  5837. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5838. {
  5839. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5840. c++;
  5841. }
  5842. sstr[c] = '\0';
  5843. strcpy(recurrencyKindstr,sstr);
  5844. }
  5845. //****************validFrom*******************/
  5846. loc = strstr(payload, "validFrom");
  5847. if(loc == NULL)
  5848. {
  5849. validFromIsNULL = TRUE;
  5850. }
  5851. else
  5852. {
  5853. c = 0;
  5854. memset(sstr ,0, sizeof(sstr) );
  5855. while (loc[3+strlen("validFrom")+c] != '\"')
  5856. {
  5857. sstr[c] = loc[3+strlen("validFrom")+c];
  5858. c++;
  5859. }
  5860. sstr[c] = '\0';
  5861. strcpy(validFromstr,sstr);
  5862. }
  5863. //****************validTo*******************/
  5864. loc = strstr(payload, "validTo");
  5865. if(loc == NULL)
  5866. {
  5867. validToIsNULL = TRUE;
  5868. }
  5869. else
  5870. {
  5871. c = 0;
  5872. memset(sstr ,0, sizeof(sstr) );
  5873. while (loc[3+strlen("validTo")+c] != '\"')
  5874. {
  5875. sstr[c] = loc[3+strlen("validTo")+c];
  5876. c++;
  5877. }
  5878. sstr[c] = '\0';
  5879. strcpy(validTostr,sstr);
  5880. }
  5881. //****************chargingSchedule*******************/
  5882. loc = strstr(payload, "chargingSchedule");
  5883. if(loc != NULL)
  5884. {
  5885. //****************duration*******************/
  5886. loc = strstr(payload, "duration");
  5887. if(loc == NULL)
  5888. {
  5889. durationIsNULL = TRUE;
  5890. }
  5891. else
  5892. {
  5893. c=0;
  5894. memset(sstr ,0, sizeof(sstr) );
  5895. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5896. {
  5897. sstr[c] = loc[strlen("duration")+2+c];
  5898. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5899. c++;
  5900. }
  5901. sstr[c] = '\0';
  5902. durationInt = atoi(sstr);
  5903. }
  5904. //****************startSchedule******************/
  5905. loc = strstr(payload, "startSchedule");
  5906. if(loc == NULL)
  5907. {
  5908. startScheduleIsNULL = TRUE;
  5909. }
  5910. else
  5911. {
  5912. c = 0;
  5913. memset(sstr ,0, sizeof(sstr) );
  5914. while (loc[3+strlen("startSchedule")+c] != '\"')
  5915. {
  5916. sstr[c] = loc[3+strlen("startSchedule")+c];
  5917. c++;
  5918. }
  5919. sstr[c] = '\0';
  5920. strcpy(startSchedulestr,sstr);
  5921. }
  5922. //****************chargingRateUnit*******************/
  5923. c = 0;
  5924. memset(sstr ,0, sizeof(sstr) );
  5925. loc = strstr(payload, "chargingRateUnit");
  5926. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5927. {
  5928. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5929. c++;
  5930. }
  5931. sstr[c] = '\0';
  5932. strcpy(chargingRateUnitstr,sstr);
  5933. //****************minChargingRate*******************/
  5934. loc = strstr(payload, "minChargingRate");
  5935. if(loc == NULL)
  5936. {
  5937. minChargingRateIsNULL = TRUE;
  5938. }
  5939. else
  5940. {
  5941. c=0;
  5942. memset(sstr ,0, sizeof(sstr) );
  5943. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5944. {
  5945. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5946. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5947. c++;
  5948. }
  5949. sstr[c] = '\0';
  5950. minChargingRateflaot = atof(sstr);
  5951. }
  5952. //****************chargingSchedulePeriod count*******************/
  5953. int what_len = strlen("startPeriod");
  5954. char *where = payload;
  5955. while ((where = strstr(where, "startPeriod"))) {
  5956. where += what_len;
  5957. chargingSchedulePeriodCount++;
  5958. }
  5959. where = payload;
  5960. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5961. {
  5962. //****************startPeriod*******************/
  5963. c=0;
  5964. loc = strstr(where, "startPeriod");
  5965. memset(sstr ,0, sizeof(sstr) );
  5966. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5967. {
  5968. sstr[c] = loc[strlen("startPeriod")+2+c];
  5969. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5970. c++;
  5971. }
  5972. sstr[c] = '\0';
  5973. startPeriodInt[periodNums] = atoi(sstr);
  5974. //****************limit*******************/
  5975. c=0;
  5976. loc = strstr(where, "limit");
  5977. memset(sstr ,0, sizeof(sstr) );
  5978. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5979. {
  5980. sstr[c] = loc[strlen("limit")+2+c];
  5981. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5982. c++;
  5983. }
  5984. sstr[c] = '\0';
  5985. limitflaot[periodNums] = atof(sstr);
  5986. //****************numberPhases*******************/
  5987. loc = strstr(where, "numberPhases");
  5988. if(loc == NULL)
  5989. {
  5990. numberPhasesIsNULL = TRUE;
  5991. }
  5992. else
  5993. {
  5994. c=0;
  5995. memset(sstr ,0, sizeof(sstr) );
  5996. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5997. {
  5998. sstr[c] = loc[strlen("numberPhases")+2+c];
  5999. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6000. c++;
  6001. }
  6002. sstr[c] = '\0';
  6003. numberPhasesInt[periodNums] = atoi(sstr);
  6004. }
  6005. where = loc;
  6006. }
  6007. }
  6008. }
  6009. /*
  6010. enum _SYSTEM_STATUS
  6011. {
  6012. S_BOOTING = 0,
  6013. S_IDLE, = 1
  6014. S_AUTHORIZING, =2
  6015. S_REASSIGN_CHECK, =3
  6016. S_REASSIGN, =4
  6017. S_PRECHARGE, =5
  6018. S_PREPARING_FOR_EV, =6
  6019. S_PREPARING_FOR_EVSE, =7
  6020. S_CHARGING, =8
  6021. S_TERMINATING, =9
  6022. S_COMPLETE, =10
  6023. S_ALARM, =11
  6024. S_FAULT =12
  6025. }
  6026. */
  6027. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6028. {
  6029. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6030. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6031. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6032. //check Transaction active
  6033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6034. {
  6035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6036. {
  6037. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6038. {
  6039. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6040. {
  6041. //Reserved
  6042. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6043. }
  6044. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6045. {
  6046. //Reserved
  6047. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6048. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6049. goto end;
  6050. }
  6051. else
  6052. {
  6053. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6054. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6055. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6056. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6057. {
  6058. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6059. goto end;
  6060. }
  6061. }//END FOR ELSE
  6062. }
  6063. }// END FOR CHAdeMO_QUANTITY
  6064. for (int index = 0; index < CCS_QUANTITY; index++)
  6065. {
  6066. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6067. {
  6068. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6069. {
  6070. //Reserved
  6071. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6072. }
  6073. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6074. {
  6075. //Reserved
  6076. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6077. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6078. goto end;
  6079. }
  6080. else
  6081. {
  6082. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6083. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6084. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6085. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6086. {
  6087. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6088. goto end;
  6089. }
  6090. }// END FOR ELSE
  6091. }
  6092. }// END FOR CCS_QUANTITY
  6093. for (int index = 0; index < GB_QUANTITY; index++)
  6094. {
  6095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6096. {
  6097. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6098. {
  6099. //Reserved
  6100. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6101. }
  6102. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6103. {
  6104. //Reserved
  6105. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6106. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6107. goto end;
  6108. }
  6109. else
  6110. {
  6111. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6112. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6113. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6114. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6115. {
  6116. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6117. goto end;
  6118. }
  6119. }// END FOR ELSE
  6120. }
  6121. } // END FOR GB_QUANTITY
  6122. }
  6123. else
  6124. {
  6125. for (int index = 0; index < AC_QUANTITY; index++)
  6126. {
  6127. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6128. {
  6129. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6130. {
  6131. //Reserved
  6132. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6133. }
  6134. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6135. {
  6136. //Reserved
  6137. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6138. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6139. goto end;
  6140. }
  6141. else
  6142. {
  6143. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6144. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6145. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6146. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6147. {
  6148. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6149. goto end;
  6150. }
  6151. }//END FOR ELSE
  6152. }
  6153. }// END FOR AC_QUANTITY
  6154. }
  6155. if(chargingProfileIsNULL == FALSE)
  6156. {
  6157. //ChargingProfile
  6158. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6159. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6160. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6161. if(recurrencyKindIsNULL == FALSE) //OPTION
  6162. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6163. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6164. if(transactionIdIsNULL == FALSE) // OPTION
  6165. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6166. if(validFromIsNULL == FALSE) // OPTION
  6167. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6168. if(validToIsNULL == FALSE) //OPTION
  6169. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6170. //ChargingSchedule
  6171. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6172. if(durationIsNULL == FALSE) //OPTION
  6173. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6174. if(minChargingRateIsNULL == FALSE) //OPTION
  6175. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6176. if(startScheduleIsNULL == FALSE) //OPTION
  6177. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6178. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6179. {
  6180. //ChargingSchedulePeriod
  6181. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6182. if(numberPhasesIsNULL == FALSE)
  6183. {
  6184. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6185. }
  6186. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6187. }
  6188. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6189. {
  6190. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6191. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6192. }
  6193. else
  6194. {
  6195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6196. }
  6197. }
  6198. else
  6199. {
  6200. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6201. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6202. }
  6203. }
  6204. else
  6205. {
  6206. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6207. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6208. }
  6209. end:
  6210. if(connectorIdIsNULL == FALSE)
  6211. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6212. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6213. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6214. //OCPP send RemoteStartConfirmation by first.
  6215. sendRemoteStartConfirmation(uuid, comfirmstr);
  6216. return result;
  6217. }
  6218. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6219. {
  6220. mtrace();
  6221. int result = FAIL;
  6222. int match = FALSE;
  6223. int GunNO = 0;
  6224. int transactionIdInt=0;
  6225. int transactionIdIsNULL= FALSE;
  6226. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6227. int c = 0;
  6228. char *loc;
  6229. char comfirmstr[20];
  6230. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6231. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6232. if(server_pending == TRUE)
  6233. {
  6234. return 0;
  6235. }
  6236. c=0;
  6237. loc = strstr(payload, "transactionId");
  6238. if(loc == NULL)
  6239. {
  6240. transactionIdIsNULL= TRUE;
  6241. }
  6242. else
  6243. {
  6244. memset(sstr ,0, sizeof(sstr) );
  6245. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6246. {
  6247. sstr[c] = loc[strlen("transactionId")+2+c];
  6248. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6249. c++;
  6250. }
  6251. sstr[c] = '\0';
  6252. transactionIdInt = atoi(sstr);
  6253. }
  6254. if(transactionIdIsNULL == FALSE)
  6255. {
  6256. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6257. {
  6258. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6259. {
  6260. //check Transaction active
  6261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6262. {
  6263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6264. {
  6265. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6266. {
  6267. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6268. {
  6269. match = TRUE;
  6270. GunNO = gun_index;
  6271. }
  6272. }
  6273. }// END FOR CHAdeMO_QUANTITY
  6274. for (int index = 0; index < CCS_QUANTITY; index++)
  6275. {
  6276. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6277. {
  6278. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6279. {
  6280. match = TRUE;
  6281. GunNO = gun_index;
  6282. }
  6283. }
  6284. }// END FOR CCS_QUANTITY
  6285. for (int index = 0; index < GB_QUANTITY; index++)
  6286. {
  6287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6288. {
  6289. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6290. {
  6291. match = TRUE;
  6292. GunNO = gun_index;
  6293. }
  6294. }
  6295. }// END FOR GB_QUANTITY
  6296. }
  6297. else
  6298. {
  6299. for (int index = 0; index < AC_QUANTITY; index++)
  6300. {
  6301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6302. {
  6303. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6304. {
  6305. match = TRUE;
  6306. GunNO = gun_index;
  6307. }
  6308. }
  6309. }// END FOR CHAdeMO_QUANTITY
  6310. }// END FOR AC ELSE
  6311. }// CHECK IF ResponseTransactionId == transactionIdInt
  6312. }//END FOR
  6313. if( match == TRUE)
  6314. {
  6315. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6316. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6317. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6318. }
  6319. else
  6320. {
  6321. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6322. }
  6323. }
  6324. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6325. return result;
  6326. }
  6327. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6328. {
  6329. mtrace();
  6330. int result = FAIL;
  6331. int connectorIdInt=0, reservationIdInt=0;
  6332. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6333. char comfirmstr[20]={0};
  6334. char sstr[180]={ 0 };
  6335. int c = 0;
  6336. char *loc;
  6337. //char *ptr;
  6338. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6339. //***(1)connectorId ****/
  6340. c=0;
  6341. loc = strstr(payload, "connectorId");
  6342. memset(sstr ,0, sizeof(sstr) );
  6343. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6344. {
  6345. sstr[c] = loc[strlen("connectorId")+2+c];
  6346. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6347. c++;
  6348. }
  6349. sstr[c] = '\0';
  6350. connectorIdInt = atoi(sstr);
  6351. //***(2)expiryDate ****/
  6352. loc = strstr(payload, "expiryDate");
  6353. memset(sstr ,0, sizeof(sstr) );
  6354. c = 0;
  6355. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6356. {
  6357. sstr[c] = loc[3+strlen("expiryDate")+c];
  6358. c++;
  6359. }
  6360. sstr[c] = '\0';
  6361. strcpy(expiryDatestr, sstr);
  6362. //***(3)idTag ****/
  6363. loc = strstr(payload, "idTag");
  6364. memset(sstr ,0, sizeof(sstr) );
  6365. c = 0;
  6366. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6367. {
  6368. sstr[c] = loc[3+strlen("idTag")+c];
  6369. c++;
  6370. }
  6371. sstr[c] = '\0';
  6372. strcpy(idTagstr, sstr);
  6373. //***(4)parentIdTag ****/
  6374. loc = strstr(payload, "parentIdTag");
  6375. memset(sstr ,0, sizeof(sstr) );
  6376. c = 0;
  6377. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6378. {
  6379. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6380. c++;
  6381. }
  6382. sstr[c] = '\0';
  6383. strcpy(parentIdTagstr, sstr);
  6384. //***(5)reservationId ****/
  6385. c=0;
  6386. loc = strstr(payload, "reservationId");
  6387. memset(sstr ,0, sizeof(sstr) );
  6388. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6389. {
  6390. sstr[c] = loc[strlen("reservationId")+2+c];
  6391. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6392. c++;
  6393. }
  6394. sstr[c] = '\0';
  6395. reservationIdInt = atoi(sstr);
  6396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6397. /*
  6398. enum _SYSTEM_STATUS
  6399. {
  6400. S_BOOTING = 0,
  6401. S_IDLE, = 1
  6402. S_AUTHORIZING, =2
  6403. S_REASSIGN_CHECK, =3
  6404. S_REASSIGN, =4
  6405. S_PRECHARGE, =5
  6406. S_PREPARING_FOR_EV, =6
  6407. S_PREPARING_FOR_EVSE, =7
  6408. S_CHARGING, =8
  6409. S_TERMINATING, =9
  6410. S_COMPLETE, =10
  6411. S_ALARM, =11
  6412. S_FAULT =12
  6413. }
  6414. */
  6415. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6416. {
  6417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6418. goto end;
  6419. }
  6420. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6421. {
  6422. //check Transaction active
  6423. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6424. {
  6425. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6428. {
  6429. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6430. {
  6431. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6432. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6433. {
  6434. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6435. {
  6436. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6438. }
  6439. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6440. {
  6441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6442. }
  6443. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6444. {
  6445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6446. }
  6447. else
  6448. {
  6449. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6450. }
  6451. }
  6452. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6453. {
  6454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6455. }
  6456. }
  6457. else
  6458. {
  6459. //replace reservation
  6460. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6462. }
  6463. }
  6464. } // END FOR CHAdeMO_QUANTITY
  6465. for (int index = 0; index < CCS_QUANTITY; index++)
  6466. {
  6467. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6468. {
  6469. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6470. {
  6471. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6472. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6473. {
  6474. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6475. {
  6476. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6478. }
  6479. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6480. {
  6481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6482. }
  6483. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6484. {
  6485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6486. }
  6487. else
  6488. {
  6489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6490. }
  6491. }
  6492. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6493. {
  6494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6495. }
  6496. }
  6497. else
  6498. {
  6499. //replace reservation
  6500. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6501. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6502. }
  6503. }
  6504. } // END FOR CCS_QUANTITY
  6505. for (int index = 0; index < GB_QUANTITY; index++)
  6506. {
  6507. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6508. {
  6509. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6510. {
  6511. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6512. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6513. {
  6514. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6515. {
  6516. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6518. }
  6519. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6520. {
  6521. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6522. }
  6523. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6524. {
  6525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6526. }
  6527. else
  6528. {
  6529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6530. }
  6531. }
  6532. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6533. {
  6534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6535. }
  6536. }
  6537. else
  6538. {
  6539. //replace reservation
  6540. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6542. }
  6543. }
  6544. }// END FOR GB_QUANTITY
  6545. }
  6546. else
  6547. {
  6548. for (int index = 0; index < AC_QUANTITY; index++)
  6549. {
  6550. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6551. {
  6552. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6553. {
  6554. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6555. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6556. {
  6557. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6558. {
  6559. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6561. }
  6562. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6563. {
  6564. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6565. }
  6566. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6567. {
  6568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6569. }
  6570. else
  6571. {
  6572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6573. }
  6574. }
  6575. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6576. {
  6577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6578. }
  6579. }
  6580. else
  6581. {
  6582. //replace reservation
  6583. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6585. }
  6586. }
  6587. } // END FOR AC_QUANTITY
  6588. }//END FOR AC ELSE
  6589. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6590. }
  6591. else if(connectorIdInt == 0)
  6592. {
  6593. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6594. {
  6595. //check Transaction active
  6596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6597. {
  6598. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6599. {
  6600. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6601. {
  6602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6603. goto end;
  6604. }
  6605. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6606. {
  6607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6608. goto end;
  6609. }
  6610. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6611. {
  6612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6613. goto end;
  6614. }
  6615. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6616. {
  6617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6618. goto end;
  6619. }
  6620. }
  6621. }// END FOR CHAdeMO_QUANTITY
  6622. for (int index = 0; index < CCS_QUANTITY; index++)
  6623. {
  6624. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6625. {
  6626. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6627. {
  6628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6629. }
  6630. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6631. {
  6632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6633. }
  6634. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6635. {
  6636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6637. }
  6638. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6639. {
  6640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6641. }
  6642. }
  6643. } // END FOR CCS_QUANTITY
  6644. for (int index = 0; index < GB_QUANTITY; index++)
  6645. {
  6646. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6647. {
  6648. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6649. {
  6650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6651. }
  6652. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6653. {
  6654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6655. }
  6656. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6657. {
  6658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6659. }
  6660. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6661. {
  6662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6663. }
  6664. }
  6665. } // END FOR GB_QUANTITY
  6666. }
  6667. else
  6668. {
  6669. for (int index = 0; index < AC_QUANTITY; index++)
  6670. {
  6671. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6672. {
  6673. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6674. {
  6675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6676. goto end;
  6677. }
  6678. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6679. {
  6680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6681. goto end;
  6682. }
  6683. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6684. {
  6685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6686. goto end;
  6687. }
  6688. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6689. {
  6690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6691. goto end;
  6692. }
  6693. }
  6694. }// END FOR AC_QUANTITY
  6695. }
  6696. //The connectorId is 0
  6697. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6699. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6700. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6701. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6702. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6703. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6704. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6705. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6706. result = TRUE;
  6707. return result;
  6708. }
  6709. else
  6710. {
  6711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6712. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6713. }
  6714. if(strcmp(comfirmstr,"Accepted") == 0)
  6715. {
  6716. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6717. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6718. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6719. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6720. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6721. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6722. result = TRUE;
  6723. return result;
  6724. }
  6725. end:
  6726. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6727. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6728. return result;
  6729. }
  6730. int handleResetRequest(char *uuid, char *payload)
  6731. {
  6732. mtrace();
  6733. int result = FAIL;
  6734. char sstr[10]={0};
  6735. char typestr[10]={0};
  6736. char comfirmstr[20]={0};
  6737. int c = 0;
  6738. char *loc;
  6739. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6740. DEBUG_INFO("handleResetRequest ...\n");
  6741. loc = strstr(payload, "type");
  6742. memset(sstr ,0, sizeof(sstr) );
  6743. c = 0;
  6744. while (loc[3+strlen("type")+c] != '\"')
  6745. {
  6746. sstr[c] = loc[3+strlen("type")+c];
  6747. c++;
  6748. }
  6749. sstr[c] = '\0';
  6750. strcpy(typestr,sstr);
  6751. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6752. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6753. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6754. {
  6755. //check Transaction active
  6756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6757. {
  6758. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6759. {
  6760. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6761. {
  6762. //0: unplug, 1: Plug-in
  6763. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6764. }
  6765. }
  6766. for (int index = 0; index < CCS_QUANTITY; index++)
  6767. {
  6768. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6769. {
  6770. //0: unplug, 1: Plug-in
  6771. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6772. }
  6773. }
  6774. for (int index = 0; index < GB_QUANTITY; index++)
  6775. {
  6776. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6777. {
  6778. //0: unplug, 1: Plug-in
  6779. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6780. }
  6781. }
  6782. }
  6783. else
  6784. {
  6785. for (int index = 0; index < AC_QUANTITY; index++)
  6786. {
  6787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6788. {
  6789. //0: unplug, 1: Plug-in
  6790. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6791. }
  6792. }
  6793. }// END FOR AC ELSE
  6794. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6795. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6796. result = TRUE;
  6797. return result;
  6798. }
  6799. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6800. {
  6801. //check Transaction active
  6802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6803. {
  6804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6805. {
  6806. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6807. {
  6808. //0: unplug, 1: Plug-in
  6809. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6810. }
  6811. }
  6812. for (int index = 0; index < CCS_QUANTITY; index++)
  6813. {
  6814. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6815. {
  6816. //0: unplug, 1: Plug-in
  6817. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6818. }
  6819. }
  6820. for (int index = 0; index < GB_QUANTITY; index++)
  6821. {
  6822. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6823. {
  6824. //0: unplug, 1: Plug-in
  6825. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6826. }
  6827. }
  6828. }
  6829. else
  6830. {
  6831. for (int index = 0; index < AC_QUANTITY; index++)
  6832. {
  6833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6834. {
  6835. //0: unplug, 1: Plug-in
  6836. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6837. }
  6838. }
  6839. }// END FOR AC ELSE
  6840. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6841. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6842. result = TRUE;
  6843. return result;
  6844. }
  6845. else
  6846. {
  6847. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6848. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6849. goto errorend;
  6850. }
  6851. errorend:
  6852. sendResetConfirmation(uuid, comfirmstr);
  6853. return result;
  6854. }
  6855. int handleSendLocalListRequest(char *uuid, char *payload)
  6856. {
  6857. mtrace();
  6858. int result = FAIL;
  6859. int listVersionInt;
  6860. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6861. char listsearch[]="listVersion";
  6862. char updateTypesearch[]="updateType";
  6863. char localAuthorizationListsearch[]="localAuthorizationList";
  6864. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6865. char CardList[500][160]={0};
  6866. char updateTypestr[15]={0};
  6867. char idTagstr[20]={0};
  6868. char parentIdTag[20]={0};
  6869. char expiryDate[30]={0};
  6870. char idTagstatus[16]={0};
  6871. int c = 0;
  6872. int i = 0;
  6873. char *delim1 = "}";
  6874. char * pch;
  6875. char *loc;
  6876. //char *ptr;
  6877. char comfirmstr[20];
  6878. //int n_localAuthorizations = 0;
  6879. int checkState_Faulted = FALSE;
  6880. DEBUG_INFO("handleSendLocalListRequest\n");
  6881. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6882. {
  6883. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6884. goto end;
  6885. }
  6886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6887. {
  6888. //check Charge Point state
  6889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6890. {
  6891. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6892. {
  6893. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6894. }
  6895. }
  6896. for (int index = 0; index < CCS_QUANTITY; index++)
  6897. {
  6898. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6899. {
  6900. checkState_Faulted = TRUE; //OCPP Status
  6901. }
  6902. }
  6903. for (int index = 0; index < GB_QUANTITY; index++)
  6904. {
  6905. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6906. {
  6907. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6908. }
  6909. }
  6910. }
  6911. else
  6912. {
  6913. //check Charge Point state
  6914. for (int index = 0; index < AC_QUANTITY; index++)
  6915. {
  6916. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6917. {
  6918. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6919. }
  6920. }
  6921. }// END FOR AC ELSE
  6922. if(checkState_Faulted == TRUE)
  6923. {
  6924. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6925. goto end;
  6926. }
  6927. //listVersion
  6928. c = 0;
  6929. loc = strstr(payload, listsearch);
  6930. while (loc[strlen("listVersion")+2+c] != ',')
  6931. {
  6932. sstr[c] = loc[strlen("listVersion")+2+c];
  6933. c++;
  6934. }
  6935. sstr[c] = '\0';
  6936. listVersionInt = atoi(sstr);
  6937. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6938. //updateType
  6939. loc = strstr(payload, updateTypesearch);
  6940. c = 0;
  6941. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6942. {
  6943. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6944. c++;
  6945. }
  6946. sstr[c] = '\0';
  6947. strcpy(updateTypestr, sstr);
  6948. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6949. //localAuthorizationList
  6950. memset(sstr ,0, sizeof(sstr) );
  6951. loc = strstr(payload, localAuthorizationListsearch);
  6952. if(loc != NULL) // localAuthorizationList is not NULL
  6953. {
  6954. //Check UpdateType
  6955. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6956. {
  6957. //Local list full update
  6958. printf("Local list full update.\n");
  6959. OCPP_cleanLocalList();
  6960. }
  6961. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6962. {
  6963. //Local list different update
  6964. printf("Local list different update.\n");
  6965. OCPP_getListVerion();
  6966. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6967. {
  6968. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6969. goto end;
  6970. }
  6971. }
  6972. else
  6973. {
  6974. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6975. goto end;
  6976. }
  6977. c = 0;
  6978. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6979. {
  6980. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6981. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6982. c++;
  6983. }
  6984. sstr[c] = '\0';
  6985. //parsing strings to words
  6986. i = 0;
  6987. pch = strtok(sstr,delim1);
  6988. while (pch != NULL)
  6989. {
  6990. strcpy(CardList[i], pch);
  6991. pch = strtok (NULL, delim1);
  6992. i = i + 1;
  6993. }
  6994. //local Authorizations List Numbers
  6995. //n_localAuthorizations = i;
  6996. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6997. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  6998. c= 0;
  6999. while(c < i)
  7000. {
  7001. //Search "IdToken"
  7002. memset(sstr ,0, sizeof(sstr) );
  7003. loc = strstr(CardList[c], "idTag");
  7004. int j = 0;
  7005. while (loc[3+strlen("idTag")+j] != '\"')
  7006. {
  7007. sstr[j] = loc[3+strlen("idTag")+j];
  7008. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7009. j++;
  7010. }
  7011. sstr[j] = '\0';
  7012. strcpy(idTagstr, sstr);
  7013. //Search "expiryDate"
  7014. memset(sstr ,0, sizeof(sstr) );
  7015. loc = strstr(CardList[c], "expiryDate");
  7016. j = 0;
  7017. while (loc[3+strlen("expiryDate")+j] != '\"')
  7018. {
  7019. sstr[j] = loc[3+strlen("expiryDate")+j];
  7020. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7021. j++;
  7022. }
  7023. sstr[j] = '\0';
  7024. strcpy(expiryDate, sstr);
  7025. //Search "parentIdTag"
  7026. memset(sstr ,0, sizeof(sstr) );
  7027. loc = strstr(CardList[c], "parentIdTag");
  7028. j = 0;
  7029. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7030. {
  7031. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7032. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7033. j++;
  7034. }
  7035. sstr[j] = '\0';
  7036. strcpy(parentIdTag, sstr);
  7037. //Search "status"
  7038. memset(sstr ,0, sizeof(sstr) );
  7039. loc = strstr(CardList[c], "status");
  7040. j = 0;
  7041. while (loc[3+strlen("status")+j] != '\"')
  7042. {
  7043. sstr[j] = loc[3+strlen("status")+j];
  7044. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7045. j++;
  7046. }
  7047. sstr[j] = '\0';
  7048. strcpy(idTagstatus, sstr);
  7049. OCPP_getIdTag(idTagstr);
  7050. //OCPP_getIdTag("test"); For Test
  7051. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7052. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7053. {
  7054. //Local list full update
  7055. DEBUG_INFO("Local list full update.\n");
  7056. // update list
  7057. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7058. OCPP_get_TableAuthlocalAllData();
  7059. }
  7060. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7061. {
  7062. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7063. {
  7064. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7065. }
  7066. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7067. {
  7068. OCPP_deleteIdTag(idTagstr);
  7069. }
  7070. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7071. {
  7072. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7073. }
  7074. }
  7075. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7076. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7077. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7078. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7079. c++;
  7080. }
  7081. }
  7082. else
  7083. {
  7084. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7085. {
  7086. //Local list different update
  7087. DEBUG_INFO("Local list different update.\n");
  7088. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7089. goto end;
  7090. }
  7091. }
  7092. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7093. end:
  7094. sendSendLocalListConfirmation(uuid, comfirmstr);
  7095. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7096. #if 0
  7097. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7098. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7099. #endif
  7100. return result;
  7101. }
  7102. /*
  7103. enum _SYSTEM_STATUS
  7104. {
  7105. S_BOOTING = 0,
  7106. S_IDLE, =1
  7107. S_AUTHORIZING, =2
  7108. S_REASSIGN_CHECK, =3
  7109. S_REASSIGN, =4
  7110. S_PRECHARGE, =5
  7111. S_PREPARING_FOR_EV, =6
  7112. S_PREPARING_FOR_EVSE, =7
  7113. S_CHARGING, =8
  7114. S_TERMINATING, =9
  7115. S_COMPLETE, =10
  7116. S_ALARM, =11
  7117. S_FAULT =12
  7118. };
  7119. */
  7120. #define MAX 200
  7121. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7122. {
  7123. mtrace();
  7124. int result = FAIL;
  7125. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7126. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7127. char chargingProfilePurposeStr[30]={0};
  7128. char chargingProfileKindStr[16]={0};
  7129. char recurrencyKindStr[10]={0};
  7130. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7131. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7132. int chargingSchedulePeriodCount = 0;
  7133. //int updateflag = FALSE;
  7134. char comfirmstr[20]={0};
  7135. int meet= FALSE;
  7136. char sstr[10]={0};
  7137. int c = 0;
  7138. char *loc;
  7139. FILE *fptr1;//, *fptr2;
  7140. //int lno=0;//, linectr = 0;
  7141. //int modifyflag = FALSE;
  7142. char filename[MAX]={0};
  7143. char tempfile[] = "../Storage/OCPP/temp.json";
  7144. int resultRename=0;
  7145. char rmFileCmd[50]={0};
  7146. char tempchargingProfilePurposeStr[30]={0};
  7147. //[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}}}]
  7148. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7149. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7150. //*********************connectorId***************************/
  7151. loc = strstr(payload, "connectorId");
  7152. c = 0;
  7153. memset(sstr ,0, sizeof(sstr) );
  7154. while (loc[strlen("connectorId")+2+c] != ',')
  7155. {
  7156. sstr[c] = loc[strlen("connectorId")+2+c];
  7157. c++;
  7158. }
  7159. sstr[c] = '\0';
  7160. connectorIdInt = atoi(sstr);
  7161. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7162. {
  7163. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7164. }
  7165. else
  7166. {
  7167. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7168. }
  7169. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7170. //*********************chargingProfileId***************************/
  7171. loc = strstr(payload, "chargingProfileId");
  7172. c = 0;
  7173. memset(sstr ,0, sizeof(sstr) );
  7174. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7175. {
  7176. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7177. c++;
  7178. }
  7179. sstr[c] = '\0';
  7180. chargingProfileIdInt = atoi(sstr);
  7181. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7182. {
  7183. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7184. }
  7185. else
  7186. {
  7187. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7188. }
  7189. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7190. //*********************transactionId***************************/
  7191. loc = strstr(payload, "transactionId");
  7192. if(loc != NULL)
  7193. {
  7194. c = 0;
  7195. memset(sstr ,0, sizeof(sstr) );
  7196. while (loc[strlen("transactionId")+2+c] != ',')
  7197. {
  7198. sstr[c] = loc[strlen("transactionId")+2+c];
  7199. c++;
  7200. }
  7201. sstr[c] = '\0';
  7202. transactionIdInt = atoi(sstr);
  7203. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7204. {
  7205. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7206. }
  7207. else
  7208. {
  7209. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7210. }
  7211. }
  7212. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7213. //*********************stackLevel***************************/
  7214. loc = strstr(payload, "stackLevel");
  7215. c = 0;
  7216. memset(sstr ,0, sizeof(sstr) );
  7217. while (loc[strlen("stackLevel")+2+c] != ',')
  7218. {
  7219. sstr[c] = loc[strlen("stackLevel")+2+c];
  7220. c++;
  7221. }
  7222. sstr[c] = '\0';
  7223. stackLevelInt = atoi(sstr);
  7224. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7225. {
  7226. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7227. }
  7228. else
  7229. {
  7230. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7231. }
  7232. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7233. //*********************chargingProfilePurpose***************************/
  7234. loc = strstr(payload, "chargingProfilePurpose");
  7235. c = 0;
  7236. memset(sstr ,0, sizeof(sstr) );
  7237. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7238. {
  7239. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7240. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7241. c++;
  7242. }
  7243. sstr[c] = '\0';
  7244. strcpy(chargingProfilePurposeStr,sstr);
  7245. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7246. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7247. {
  7248. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7249. }
  7250. else
  7251. {
  7252. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7253. }
  7254. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7255. //*********************chargingProfileKind***************************/
  7256. loc = strstr(payload, "chargingProfileKind");
  7257. c = 0;
  7258. memset(sstr ,0, sizeof(sstr) );
  7259. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7260. {
  7261. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7262. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7263. c++;
  7264. }
  7265. sstr[c] = '\0';
  7266. strcpy(chargingProfileKindStr,sstr);
  7267. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7268. {
  7269. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7270. }
  7271. else
  7272. {
  7273. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7274. }
  7275. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7276. //*********************recurrencyKind***************************/
  7277. loc = strstr(payload, "recurrencyKind");
  7278. if(loc != NULL)
  7279. {
  7280. c = 0;
  7281. memset(sstr ,0, sizeof(sstr) );
  7282. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7283. {
  7284. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7286. c++;
  7287. }
  7288. sstr[c] = '\0';
  7289. strcpy(recurrencyKindStr,sstr);
  7290. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7291. {
  7292. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7293. }
  7294. else
  7295. {
  7296. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7297. }
  7298. }
  7299. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7300. //*********************validFrom***************************/
  7301. loc = strstr(payload, "validFrom");
  7302. if(loc != NULL)
  7303. {
  7304. c = 0;
  7305. memset(sstr ,0, sizeof(sstr) );
  7306. while (loc[3+strlen("validFrom")+c] != '\"')
  7307. {
  7308. sstr[c] = loc[3+strlen("validFrom")+c];
  7309. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7310. c++;
  7311. }
  7312. sstr[c] = '\0';
  7313. strcpy(validFromStr,sstr);
  7314. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7315. {
  7316. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7317. }
  7318. else
  7319. {
  7320. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7321. }
  7322. }
  7323. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7324. //*********************validTo***************************/
  7325. loc = strstr(payload, "validTo");
  7326. if(loc != NULL)
  7327. {
  7328. c = 0;
  7329. memset(sstr ,0, sizeof(sstr) );
  7330. while (loc[3+strlen("validTo")+c] != '\"')
  7331. {
  7332. sstr[c] = loc[3+strlen("validTo")+c];
  7333. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7334. c++;
  7335. }
  7336. sstr[c] = '\0';
  7337. strcpy(validToStr,sstr);
  7338. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7339. {
  7340. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7341. }
  7342. else
  7343. {
  7344. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7345. }
  7346. }
  7347. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7348. //*********************duration***************************/
  7349. loc = strstr(payload, "duration");
  7350. if(loc != NULL)
  7351. {
  7352. c = 0;
  7353. memset(sstr ,0, sizeof(sstr) );
  7354. while (loc[strlen("duration")+2+c] != ',')
  7355. {
  7356. sstr[c] = loc[strlen("duration")+2+c];
  7357. c++;
  7358. }
  7359. sstr[c] = '\0';
  7360. durationInt = atoi(sstr);
  7361. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7362. {
  7363. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7364. }
  7365. else
  7366. {
  7367. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7368. }
  7369. }
  7370. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7371. //*********************startSchedule***************************/
  7372. loc = strstr(payload, "startSchedule");
  7373. if(loc != NULL)
  7374. {
  7375. c = 0;
  7376. memset(sstr ,0, sizeof(sstr) );
  7377. while (loc[3+strlen("startSchedule")+c] != '\"')
  7378. {
  7379. sstr[c] = loc[3+strlen("startSchedule")+c];
  7380. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7381. c++;
  7382. }
  7383. sstr[c] = '\0';
  7384. strcpy(startScheduleStr,sstr);
  7385. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7386. {
  7387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7388. }
  7389. else
  7390. {
  7391. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7392. }
  7393. }
  7394. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7395. //*********************chargingRateUnit***************************/
  7396. loc = strstr(payload, "chargingRateUnit");
  7397. if(loc != NULL)
  7398. {
  7399. c = 0;
  7400. memset(sstr ,0, sizeof(sstr) );
  7401. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7402. {
  7403. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7404. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7405. c++;
  7406. }
  7407. sstr[c] = '\0';
  7408. strcpy(chargingRateUnitStr,sstr);
  7409. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7410. {
  7411. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7412. }
  7413. else
  7414. {
  7415. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7416. }
  7417. }
  7418. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7419. //****************chargingSchedulePeriod count start*******************/
  7420. int what_len = strlen("startPeriod");
  7421. char *where = payload;
  7422. if (what_len)
  7423. while ((where = strstr(where, "startPeriod"))) {
  7424. where += what_len;
  7425. chargingSchedulePeriodCount++;
  7426. }
  7427. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7428. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7429. where = payload;
  7430. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7431. {
  7432. //****************startPeriod*******************/
  7433. c=0;
  7434. loc = strstr(where, "startPeriod");
  7435. memset(sstr ,0, sizeof(sstr) );
  7436. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7437. {
  7438. sstr[c] = loc[strlen("startPeriod")+2+c];
  7439. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7440. c++;
  7441. }
  7442. sstr[c] = '\0';
  7443. startPeriodInt[periodNums] = atoi(sstr);
  7444. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7445. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7446. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7447. {
  7448. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7449. }
  7450. else
  7451. {
  7452. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7453. }
  7454. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7455. //****************limit*******************/
  7456. c=0;
  7457. loc = strstr(where, "limit");
  7458. memset(sstr ,0, sizeof(sstr) );
  7459. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7460. {
  7461. sstr[c] = loc[strlen("limit")+2+c];
  7462. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7463. c++;
  7464. }
  7465. sstr[c] = '\0';
  7466. limitflaot[periodNums] = atof(sstr);
  7467. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7468. {
  7469. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7470. }
  7471. else
  7472. {
  7473. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7474. }
  7475. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7476. //****************numberPhases*******************/
  7477. loc = strstr(where, "numberPhases");
  7478. if(loc != NULL)
  7479. {
  7480. c=0;
  7481. memset(sstr ,0, sizeof(sstr) );
  7482. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7483. {
  7484. sstr[c] = loc[strlen("numberPhases")+2+c];
  7485. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7486. c++;
  7487. }
  7488. sstr[c] = '\0';
  7489. numberPhasesInt[periodNums] = atoi(sstr);
  7490. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7491. {
  7492. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7493. }
  7494. else
  7495. {
  7496. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7497. }
  7498. }
  7499. where = loc;
  7500. }
  7501. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7502. //****************chargingSchedulePeriod count end*******************/
  7503. //*********************minChargingRate***************************/
  7504. loc = strstr(payload, "minChargingRate");
  7505. if(loc != NULL)
  7506. {
  7507. c = 0;
  7508. memset(sstr ,0, sizeof(sstr) );
  7509. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7510. {
  7511. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7512. c++;
  7513. }
  7514. sstr[c] = '\0';
  7515. minChargingRateFloat = atof(sstr);
  7516. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7517. {
  7518. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7519. }
  7520. else
  7521. {
  7522. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7523. }
  7524. }
  7525. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7526. DEBUG_INFO("-------------------------------------------------------------\n");
  7527. DEBUG_INFO(" Input the file name to be opened : ");
  7528. //fgets(fname, MAX, stdin);
  7529. //fname[strlen(fname) - 1] = '\0';
  7530. #if 0
  7531. switch(connectorIdInt)
  7532. {
  7533. case 0:
  7534. strcpy(filename, ChargingProfile_0_JSON );
  7535. break;
  7536. case 1:
  7537. strcpy(filename, ChargingProfile_1_JSON );
  7538. break;
  7539. case 2:
  7540. strcpy(filename, ChargingProfile_2_JSON );
  7541. break;
  7542. default:
  7543. strcpy(filename, ChargingProfile_0_JSON );
  7544. break;
  7545. }
  7546. fptr1 = fopen(filename, "r");
  7547. if (!fptr1)
  7548. {
  7549. //file not exist
  7550. DEBUG_INFO("Unable to open the input file!!\n");
  7551. fptr1 = fopen(filename, "w+");
  7552. }
  7553. fclose(fptr1);
  7554. #endif
  7555. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7556. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7557. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7558. {
  7559. //printf("set chargingProfile 1-2\n");
  7560. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7561. if(connectorIdInt != 0)
  7562. {
  7563. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7564. goto end;
  7565. }
  7566. strcpy(filename, ChargePointMaxProfile_JSON );
  7567. fptr1 = fopen(filename, "r");
  7568. if (!fptr1)
  7569. {
  7570. //file not exist
  7571. DEBUG_INFO("Unable to open the input file!!\n");
  7572. fptr1 = fopen(filename, "w+");
  7573. }
  7574. fclose(fptr1);
  7575. }
  7576. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7577. {
  7578. //printf("set chargingProfile 1-3\n");
  7579. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7580. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7581. {
  7582. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7583. goto end;
  7584. }
  7585. switch(connectorIdInt)
  7586. {
  7587. case 0:
  7588. strcpy(filename, TxDefaultProfile_0_JSON );
  7589. break;
  7590. case 1:
  7591. strcpy(filename, TxDefaultProfile_1_JSON );
  7592. break;
  7593. case 2:
  7594. strcpy(filename, TxDefaultProfile_2_JSON );
  7595. break;
  7596. default:
  7597. strcpy(filename, TxDefaultProfile_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. }
  7609. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7610. {
  7611. //printf("set chargingProfile 1-4\n");
  7612. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7613. //check Transaction active
  7614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7615. {
  7616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7617. {
  7618. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7619. {
  7620. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7621. {
  7622. meet = TRUE;
  7623. break;
  7624. }
  7625. }
  7626. }
  7627. }
  7628. for (int index = 0; index < CCS_QUANTITY; index++)
  7629. {
  7630. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7631. {
  7632. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7633. {
  7634. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7635. {
  7636. meet = TRUE;
  7637. break;
  7638. }
  7639. }
  7640. }
  7641. }
  7642. for (int index = 0; index < GB_QUANTITY; index++)
  7643. {
  7644. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7645. {
  7646. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7647. {
  7648. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7649. {
  7650. meet = TRUE;
  7651. break;
  7652. }
  7653. }
  7654. }
  7655. }
  7656. if(meet == FALSE)
  7657. {
  7658. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7659. goto end;
  7660. }
  7661. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7662. {
  7663. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7664. goto end;
  7665. }
  7666. switch(connectorIdInt)
  7667. {
  7668. case 0:
  7669. break;
  7670. case 1:
  7671. strcpy(filename, TxProfile_1_JSON);
  7672. break;
  7673. case 2:
  7674. strcpy(filename, TxProfile_2_JSON);
  7675. break;
  7676. default:
  7677. strcpy(filename, TxProfile_1_JSON);
  7678. break;
  7679. }
  7680. fptr1 = fopen(filename, "r");
  7681. if (!fptr1)
  7682. {
  7683. //file not exist
  7684. DEBUG_INFO("Unable to open the input file!!\n");
  7685. fptr1 = fopen(filename, "w+");
  7686. }
  7687. fclose(fptr1);
  7688. }
  7689. //**********************************Write to File********************************************************/
  7690. FILE *infile;
  7691. FILE *outfile;
  7692. // open file for writing
  7693. infile = fopen (filename, "r");
  7694. outfile = fopen (tempfile, "w");
  7695. int d =0;
  7696. d = fgetc(infile);
  7697. DEBUG_INFO("d:%d\n",d);
  7698. rewind(infile);
  7699. //*检测到文件结束标识返回1,否则返回0。*/
  7700. if(d == EOF)
  7701. {
  7702. DEBUG_INFO("ChargingProfile content is NULL\n");
  7703. fprintf(outfile,"[%s]\n",payload);
  7704. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7705. fclose(infile);
  7706. fclose(outfile);
  7707. sprintf(rmFileCmd,"rm -f %s",filename);
  7708. system(rmFileCmd);
  7709. resultRename = rename(tempfile, filename);
  7710. if(resultRename == 0)
  7711. {
  7712. DEBUG_INFO("File chargingProfile renamed successfully");
  7713. }
  7714. else
  7715. {
  7716. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7717. }
  7718. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7719. //system(rmFileCmd);
  7720. }
  7721. else
  7722. {
  7723. char buf[1000]={0};
  7724. while (fgets(buf, sizeof(buf), infile) != NULL)
  7725. {
  7726. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7727. //*************************tempconnectorIdInt*********************************/
  7728. loc = strstr(buf, "connectorId");
  7729. c = 0;
  7730. memset(sstr ,0, sizeof(sstr) );
  7731. while (loc[strlen("connectorId")+2+c] != ',')
  7732. {
  7733. sstr[c] = loc[strlen("connectorId")+2+c];
  7734. c++;
  7735. }
  7736. sstr[c] = '\0';
  7737. tempconnectorIdInt = atoi(sstr);
  7738. //*************************tempchargingProfileIdInt*********************************/
  7739. loc = strstr(buf, "chargingProfileId");
  7740. c = 0;
  7741. memset(sstr ,0, sizeof(sstr) );
  7742. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7743. {
  7744. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7745. c++;
  7746. }
  7747. sstr[c] = '\0';
  7748. tempchargingProfileIdInt = atoi(sstr);
  7749. //*************************tempstackLevelInt*********************************/
  7750. loc = strstr(buf, "stackLevel");
  7751. c = 0;
  7752. memset(sstr ,0, sizeof(sstr) );
  7753. while (loc[strlen("stackLevel")+2+c] != ',')
  7754. {
  7755. sstr[c] = loc[strlen("stackLevel")+2+c];
  7756. c++;
  7757. }
  7758. sstr[c] = '\0';
  7759. tempstackLevelInt = atoi(sstr);
  7760. //*************************tempchargingProfilePurposeStr*********************************/
  7761. loc = strstr(payload, "chargingProfilePurpose");
  7762. c = 0;
  7763. memset(sstr ,0, sizeof(sstr) );
  7764. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7765. {
  7766. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7767. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7768. c++;
  7769. }
  7770. sstr[c] = '\0';
  7771. strcpy(tempchargingProfilePurposeStr,sstr);
  7772. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7773. {
  7774. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7775. {
  7776. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7777. fprintf(outfile,"[%s]\n",payload);
  7778. }
  7779. else
  7780. {
  7781. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7782. if(tempstackLevelInt < stackLevelInt)
  7783. {
  7784. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7785. fprintf(outfile,"[%s]\n",payload);
  7786. fprintf(outfile,"[%s]\n",buf);
  7787. }
  7788. else
  7789. {
  7790. fprintf(outfile,"[%s]\n",buf);
  7791. fprintf(outfile,"[%s]\n",payload);
  7792. }
  7793. }
  7794. DEBUG_INFO("update set chargingProfile to file\n");
  7795. }
  7796. else
  7797. {
  7798. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7799. {
  7800. fprintf(outfile,"[%s]\n",payload);
  7801. fprintf(outfile,"[%s]\n",buf);
  7802. }
  7803. else if(tempstackLevelInt < stackLevelInt)
  7804. {
  7805. fprintf(outfile,"[%s]\n",payload);
  7806. fprintf(outfile,"[%s]\n",buf);
  7807. }
  7808. else
  7809. {
  7810. fprintf(outfile,"[%s]\n",buf);
  7811. fprintf(outfile,"[%s]\n",payload);
  7812. }
  7813. fprintf(outfile,"[%s]\n",buf);
  7814. DEBUG_INFO("add set chargingProfile to file\n");
  7815. }
  7816. } // end of while loop
  7817. fclose(infile);
  7818. fclose(outfile);
  7819. sprintf(rmFileCmd,"rm -f %s",filename);
  7820. system(rmFileCmd);
  7821. resultRename = rename(tempfile, filename);
  7822. if(resultRename == 0)
  7823. {
  7824. DEBUG_INFO("File chargingProfile renamed successfully");
  7825. }
  7826. else
  7827. {
  7828. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7829. }
  7830. result = TRUE;
  7831. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7832. }
  7833. end:
  7834. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7835. return result;
  7836. return result;
  7837. }
  7838. int handleTriggerMessageRequest(char *uuid, char *payload)
  7839. {
  7840. mtrace();
  7841. int result = FAIL;
  7842. int connectorIdIsNULL = FALSE;
  7843. int connectorIdInt =0;
  7844. char sstr[40]={0};
  7845. char requestedMessagestr[40]={0};
  7846. char comfirmstr[20]={0};
  7847. int c = 0;
  7848. char *loc;
  7849. DEBUG_INFO("handleTriggerMessageRequest\n");
  7850. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7851. c = 0;
  7852. loc = strstr(payload, "requestedMessage");
  7853. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7854. {
  7855. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7856. c++;
  7857. }
  7858. sstr[c] = '\0';
  7859. strcpy(requestedMessagestr, sstr);
  7860. c = 0;
  7861. loc = strstr(payload, "connectorId");
  7862. if(loc == NULL)
  7863. {
  7864. connectorIdIsNULL = TRUE;
  7865. }
  7866. else
  7867. {
  7868. memset(sstr ,0, sizeof(sstr) );
  7869. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7870. {
  7871. sstr[c] = loc[strlen("connectorId")+2+c];
  7872. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7873. c++;
  7874. }
  7875. sstr[c] = '\0';
  7876. connectorIdInt = atoi(sstr);
  7877. }
  7878. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7879. {
  7880. //connectorIdInt = json_object_get_int(connectorId);
  7881. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7882. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7883. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7884. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7885. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7886. }
  7887. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7888. {
  7889. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7890. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7891. return TRUE;
  7892. }
  7893. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7894. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7895. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7896. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7897. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7898. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7899. {
  7900. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7901. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7902. return TRUE;
  7903. }
  7904. else
  7905. {
  7906. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7907. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7908. }
  7909. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7910. {
  7911. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7912. {
  7913. FirmwareStatusNotificationStatus = 3;
  7914. }
  7915. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7916. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7917. }
  7918. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7919. {
  7920. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7921. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7922. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7923. }
  7924. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7925. {
  7926. sendBootNotificationRequest();
  7927. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7928. }
  7929. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7930. {
  7931. sendHeartbeatRequest(connectorIdInt);
  7932. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7933. }
  7934. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7935. {
  7936. if(connectorIdIsNULL == FALSE)
  7937. {
  7938. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7939. {
  7940. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7941. sendMeterValuesRequest(connectorIdInt -1);
  7942. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7943. }
  7944. }
  7945. else
  7946. {
  7947. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7948. {
  7949. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7950. sendMeterValuesRequest(idx);
  7951. }
  7952. }
  7953. }
  7954. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7955. {
  7956. if(connectorIdIsNULL == FALSE)
  7957. {
  7958. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7959. {
  7960. sendStatusNotificationRequest(connectorIdInt -1);
  7961. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7962. }
  7963. }
  7964. else
  7965. {
  7966. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7967. sendStatusNotificationRequest(idx);
  7968. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7969. }
  7970. }
  7971. return result;
  7972. }
  7973. int handleUnlockConnectorRequest(char *uuid, char *payload)
  7974. {
  7975. mtrace();
  7976. int result = FAIL;
  7977. char sstr[6]={0};
  7978. int connectorIdInt =0;
  7979. char comfirmstr[20]={0};
  7980. int c = 0;
  7981. char *loc;
  7982. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  7983. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  7984. c = 0;
  7985. loc = strstr(payload, "connectorId");
  7986. memset(sstr ,0, sizeof(sstr) );
  7987. while (loc[strlen("connectorId")+2+c] != '}')
  7988. {
  7989. sstr[c] = loc[strlen("connectorId")+2+c];
  7990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7991. c++;
  7992. }
  7993. sstr[c] = '\0';
  7994. connectorIdInt = atoi(sstr);
  7995. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  7996. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  7997. {
  7998. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  7999. goto end;
  8000. }
  8001. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8002. {
  8003. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8004. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8005. goto end;
  8006. }
  8007. else
  8008. {
  8009. //check Transaction active
  8010. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8011. {
  8012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8013. {
  8014. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8015. {
  8016. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8017. }
  8018. }
  8019. for (int index = 0; index < CCS_QUANTITY; index++)
  8020. {
  8021. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8022. {
  8023. //stop Transaction
  8024. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8025. }
  8026. }
  8027. for (int index = 0; index < GB_QUANTITY; index++)
  8028. {
  8029. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8030. {
  8031. //stop Transaction
  8032. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8033. }
  8034. }
  8035. }
  8036. else
  8037. {
  8038. for (int index = 0; index < AC_QUANTITY; index++)
  8039. {
  8040. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8041. {
  8042. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8043. }
  8044. }
  8045. }// END FOR AC ELSE
  8046. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8047. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8048. result = TRUE;
  8049. return result;
  8050. }
  8051. end:
  8052. //json_object_put(obj); --- remove temporally
  8053. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8054. return result;
  8055. }
  8056. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8057. {
  8058. mtrace();
  8059. int result = FAIL;
  8060. pthread_t t;
  8061. sendUpdateFirmwareConfirmation(uuid);
  8062. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8063. ////pthread_join(t, NULL); //
  8064. pthread_detach(t);
  8065. //sendUpdateFirmwareConfirmation(uuid);
  8066. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8067. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8068. return result;
  8069. }
  8070. void *UpdateFirmwareProcess(void *data)
  8071. {
  8072. mtrace();
  8073. int retriesInt =0, retryIntervalInt=0;
  8074. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8075. int port=0;
  8076. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8077. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8078. //char comfirmstr[20];
  8079. int isSuccess = 0;
  8080. char ftpbuf[200];
  8081. char temp[100];
  8082. char * pch;
  8083. int retriesISNULL=FALSE;
  8084. int retryInterval=FALSE;
  8085. int c = 0;
  8086. //int i = 0;
  8087. char *loc;
  8088. char sstr[300]={ 0 };
  8089. char *str = (char*) data; // ?��?輸入資�?
  8090. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8091. //***************location **************/
  8092. loc = strstr(str, "location");
  8093. memset(sstr ,0, sizeof(sstr) );
  8094. c = 0;
  8095. while (loc[3+strlen("location")+c] != '\"')
  8096. {
  8097. sstr[c] = loc[3+strlen("location")+c];
  8098. c++;
  8099. }
  8100. sstr[c] = '\0';
  8101. strcpy(locationstr, sstr);
  8102. //***************retries**************/
  8103. c = 0;
  8104. loc = strstr(str, "retries");
  8105. if(loc == NULL)
  8106. {
  8107. retriesISNULL=TRUE;
  8108. }
  8109. else
  8110. {
  8111. memset(sstr ,0, sizeof(sstr) );
  8112. while (loc[strlen("retries")+2+c] != ',')
  8113. {
  8114. sstr[c] = loc[strlen("retries")+2+c];
  8115. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8116. c++;
  8117. }
  8118. sstr[c] = '\0';
  8119. }
  8120. if(retriesISNULL == FALSE)
  8121. {
  8122. retriesInt = atoi(sstr);
  8123. }
  8124. //***************retrieveDate **************/
  8125. loc = strstr(str, "retrieveDate");
  8126. memset(sstr ,0, sizeof(sstr) );
  8127. c = 0;
  8128. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8129. {
  8130. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8131. c++;
  8132. }
  8133. sstr[c] = '\0';
  8134. strcpy(retrieveDatestr, sstr);
  8135. //***************retryInterval **************/
  8136. c = 0;
  8137. loc = strstr(str, "retryInterval");
  8138. memset(sstr ,0, sizeof(sstr) );
  8139. if(loc == NULL)
  8140. {
  8141. retryInterval=TRUE;
  8142. }
  8143. else
  8144. {
  8145. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8146. {
  8147. sstr[c] = loc[strlen("retryInterval")+2+c];
  8148. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8149. c++;
  8150. }
  8151. sstr[c] = '\0';
  8152. }
  8153. if(retryInterval==FALSE)
  8154. {
  8155. retryIntervalInt = atoi(sstr);
  8156. }
  8157. memset(ftppath, 0, sizeof(ftppath));
  8158. memset(path, 0, sizeof(path));
  8159. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8160. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8161. if(strncmp(locationstr,"http", 4) == 0)
  8162. {
  8163. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8164. protocol, host, path);
  8165. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8166. // protocol, user, password, host, path);
  8167. sprintf(ftppath,"/%s", path);
  8168. DEBUG_INFO("protocol =%s\n",protocol);
  8169. DEBUG_INFO("host =%s\n",host);
  8170. DEBUG_INFO("path =%s\n",path);
  8171. DEBUG_INFO("ftppath=%s\n",ftppath);
  8172. int ftppathlen=strlen(ftppath);
  8173. int i=1;
  8174. char filenametemp[50];
  8175. while(i < ftppathlen)
  8176. {
  8177. int len=ftppathlen-i;
  8178. if(ftppath[len]== 47) // '/' ascll code: 47
  8179. {
  8180. DEBUG_INFO("compare '/' all right\n");
  8181. break;
  8182. }
  8183. i=i+1;
  8184. }
  8185. memset(filenametemp, 0, sizeof(filenametemp));
  8186. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8187. filenametemp[i+1] = 0;
  8188. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8189. do{
  8190. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8191. sleep(retryIntervalInt);
  8192. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8193. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8194. if(!isSuccess)
  8195. {
  8196. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8197. }
  8198. else
  8199. {
  8200. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8201. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8202. isUpdateRequest = TRUE;
  8203. }
  8204. }
  8205. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8206. {
  8207. memset(ftpbuf, 0, sizeof(ftpbuf));
  8208. memset(temp, 0, sizeof(temp));
  8209. DEBUG_INFO("locationstr=%s\n",locationstr);
  8210. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8211. int ftppathlen=strlen(ftpbuf);
  8212. int i=1;
  8213. char filenametemp[50];
  8214. while(i < ftppathlen)
  8215. {
  8216. int len=ftppathlen-i;
  8217. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8218. {
  8219. DEBUG_INFO(" compare '/' all right\n");
  8220. break;
  8221. }
  8222. i=i+1;
  8223. }
  8224. memset(filenametemp, 0, sizeof(filenametemp));
  8225. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8226. filenametemp[i+1] = 0;
  8227. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8228. pch=strchr(temp,'@');
  8229. if(pch==NULL)
  8230. {
  8231. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8232. protocol, host, &port, path);
  8233. strcpy(user,"anonymous");
  8234. strcpy(password,"");
  8235. }
  8236. else
  8237. {
  8238. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8239. protocol, user, password, host, &port, path);
  8240. }
  8241. sscanf(host,"%[^/]%s",host1, path1);
  8242. sprintf(ftppath,"%s", path1);
  8243. DEBUG_INFO("protocol =%s\n",protocol);
  8244. DEBUG_INFO("user =%s\n",user);
  8245. DEBUG_INFO("password =%s\n",password);
  8246. DEBUG_INFO("host1 =%s\n",host1);
  8247. DEBUG_INFO("port =%d\n",port);
  8248. DEBUG_INFO("path1 =%s\n",path1);
  8249. DEBUG_INFO("ftppath=%s\n",ftppath);
  8250. //ftpFile(host, user, password, port, ftppath, fname);
  8251. //download firmware pthred
  8252. if(port == 0)
  8253. {
  8254. port = 21;
  8255. }
  8256. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8257. do{
  8258. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8259. sleep(retryIntervalInt);
  8260. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8261. if(!isSuccess)
  8262. {
  8263. //BulldogUtil.sleepMs(interval*1000);
  8264. DEBUG_INFO("Update firmware request and download file fail.\n");
  8265. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8266. }
  8267. else
  8268. {
  8269. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8270. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8271. isUpdateRequest = TRUE;
  8272. }
  8273. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8274. }
  8275. else
  8276. {
  8277. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8278. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8279. }
  8280. pthread_exit(NULL);
  8281. }
  8282. //==========================================
  8283. // Handle server response routine
  8284. //==========================================
  8285. void handleAuthorizeResponse(char *payload, int gun_index)
  8286. {
  8287. mtrace();
  8288. char expiryDatestr[30]={0};
  8289. char parentIdTagstr[20]={0};
  8290. char statusstr[20]={0};
  8291. char expiryDatestrtemp[30]={0};
  8292. char parentIdTagstrtemp[20]={0};
  8293. char IdTagstrtemp[20]={0};
  8294. char statusstrtemp[20]={0};
  8295. int expiryDateISNULL=FALSE;
  8296. int parentIdTagISNULL=FALSE;
  8297. char sstr[160]={ 0 };
  8298. char* filename = AuthorizationCache_JSON;
  8299. char tempfile[] = "../Storage/OCPP/temp.json";
  8300. int c = 0;
  8301. char *loc;
  8302. int resultRename=0;
  8303. int responseIdTagInfoAsZero= 0;
  8304. char rmFileCmd[50]={0};
  8305. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8306. //***********expiryDate*************/
  8307. loc = strstr(payload, "expiryDate");
  8308. memset(sstr ,0, sizeof(sstr) );
  8309. c = 0;
  8310. if(loc == NULL)
  8311. {
  8312. expiryDateISNULL = TRUE;
  8313. }
  8314. else
  8315. {
  8316. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8317. {
  8318. sstr[c] = loc[3+strlen("expiryDate")+c];
  8319. c++;
  8320. }
  8321. sstr[c] = '\0';
  8322. strcpy(expiryDatestr, sstr);
  8323. }
  8324. //***********parentIdTag*************/
  8325. loc = strstr(payload, "parentIdTag");
  8326. memset(sstr ,0, sizeof(sstr) );
  8327. c = 0;
  8328. if(loc == NULL)
  8329. {
  8330. parentIdTagISNULL = TRUE;
  8331. }
  8332. else
  8333. {
  8334. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8335. {
  8336. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8337. c++;
  8338. }
  8339. sstr[c] = '\0';
  8340. strcpy(parentIdTagstr, sstr);
  8341. }
  8342. //***********status*************/
  8343. loc = strstr(payload, "status");
  8344. memset(sstr ,0, sizeof(sstr) );
  8345. c = 0;
  8346. while (loc[3+strlen("status")+c] != '\"')
  8347. {
  8348. sstr[c] = loc[3+strlen("status")+c];
  8349. c++;
  8350. }
  8351. sstr[c] = '\0';
  8352. strcpy(statusstr, sstr);
  8353. //#ifdef SystemLogMessage
  8354. // if(expiryDateISNULL == FALSE)
  8355. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8356. // if(parentIdTagISNULL == FALSE)
  8357. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8358. // DEBUG_INFO("status: %s\n", statusstr);
  8359. //#endif
  8360. if(expiryDateISNULL == FALSE)
  8361. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8362. if(parentIdTagISNULL == FALSE)
  8363. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8364. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8365. //Update idTag information to authorization cache if supproted
  8366. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8367. {
  8368. if((access(filename,F_OK))!=-1)
  8369. {
  8370. DEBUG_INFO("AuthorizationCache exist.\n");
  8371. }
  8372. else
  8373. {
  8374. DEBUG_INFO("AuthorizationCache not exist\n");
  8375. FILE *log = fopen(filename, "w+");
  8376. if(log == NULL)
  8377. {
  8378. DEBUG_INFO("log is NULL\n");
  8379. goto out;
  8380. }
  8381. else
  8382. {
  8383. fclose(log);
  8384. }
  8385. }
  8386. FILE *infile;
  8387. FILE *outfile;
  8388. // open file for writing
  8389. infile = fopen (filename, "r");
  8390. outfile = fopen (tempfile, "w");
  8391. //*检测到文件结束标识返回1,否则返回0。*/
  8392. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8393. int c;
  8394. c = fgetc(infile);
  8395. //DEBUG_INFO("c:%d\n",c);
  8396. rewind(infile);
  8397. if(c == EOF)
  8398. {
  8399. DEBUG_INFO("Orignal File is NULL\n");
  8400. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8401. {
  8402. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8403. }
  8404. else
  8405. {
  8406. strcpy(expiryDatestrtemp, "");
  8407. }
  8408. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8409. {
  8410. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8411. }
  8412. else
  8413. {
  8414. //write Authorize IdTag
  8415. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8416. }
  8417. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8418. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8419. fclose(infile);
  8420. fclose(outfile);
  8421. sprintf(rmFileCmd,"rm -f %s",filename);
  8422. system(rmFileCmd);
  8423. resultRename = rename(tempfile, filename);
  8424. if(resultRename == 0)
  8425. {
  8426. DEBUG_INFO("File renamed successfully");
  8427. }
  8428. else
  8429. {
  8430. DEBUG_INFO("Error: unable to rename the file");
  8431. }
  8432. }
  8433. else
  8434. {
  8435. char buf[160]={0};
  8436. //DEBUG_INFO("Orignal File is not NULL\n");
  8437. while (fgets(buf, sizeof(buf), infile) != NULL)
  8438. {
  8439. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8440. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8441. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8442. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8443. memset(statusstr, 0, sizeof(statusstrtemp));
  8444. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8445. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8446. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8447. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8448. //------------------IdTag-----------------------
  8449. loc = strstr(buf, "idTag");
  8450. memset(sstr ,0, sizeof(sstr) );
  8451. c = 0;
  8452. while (loc[3+strlen("idTag")+c] != '\"')
  8453. {
  8454. sstr[c] = loc[3+strlen("idTag")+c];
  8455. c++;
  8456. }
  8457. sstr[c] = '\0';
  8458. strcpy(IdTagstrtemp,sstr);
  8459. //*********************expiryDate***************/
  8460. loc = strstr(buf, "expiryDate");
  8461. memset(sstr ,0, sizeof(sstr) );
  8462. c = 0;
  8463. while (loc[3+strlen("expiryDate")+c] != '\"')
  8464. {
  8465. sstr[c] = loc[3+strlen("expiryDate")+c];
  8466. c++;
  8467. }
  8468. sstr[c] = '\0';
  8469. strcpy(expiryDatestr,sstr);
  8470. //*********************parentIdTag***************/
  8471. loc = strstr(buf, "parentIdTag");
  8472. memset(sstr ,0, sizeof(sstr) );
  8473. c = 0;
  8474. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8475. {
  8476. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8477. c++;
  8478. }
  8479. sstr[c] = '\0';
  8480. strcpy(parentIdTagstr,sstr);
  8481. //*********************status***************/
  8482. loc = strstr(buf, "status");
  8483. memset(sstr ,0, sizeof(sstr) );
  8484. c = 0;
  8485. while (loc[3+strlen("status")+c] != '\"')
  8486. {
  8487. sstr[c] = loc[3+strlen("status")+c];
  8488. c++;
  8489. }
  8490. sstr[c] = '\0';
  8491. strcpy(statusstr,sstr);
  8492. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8493. {
  8494. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8495. responseIdTagInfoAsZero = 1;
  8496. }
  8497. else
  8498. {
  8499. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8500. }
  8501. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8502. {
  8503. //modify item
  8504. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8505. {
  8506. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8507. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8508. }
  8509. else
  8510. {
  8511. strcpy(expiryDatestrtemp, "");
  8512. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8513. }
  8514. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8515. {
  8516. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8517. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8518. }
  8519. else
  8520. {
  8521. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8522. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8523. }
  8524. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8525. }
  8526. else
  8527. {
  8528. //wrie original item
  8529. strcpy(expiryDatestrtemp, expiryDatestr);
  8530. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8531. strcpy(statusstrtemp, statusstr);
  8532. }
  8533. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8534. }
  8535. fclose(infile);
  8536. fclose(outfile);
  8537. sprintf(rmFileCmd,"rm -f %s",filename);
  8538. system(rmFileCmd);
  8539. resultRename = rename(tempfile, filename);
  8540. if(resultRename == 0)
  8541. {
  8542. DEBUG_INFO("File renamed successfully");
  8543. }
  8544. else
  8545. {
  8546. DEBUG_INFO("Error: unable to rename the file");
  8547. }
  8548. }
  8549. }
  8550. out:
  8551. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8552. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8553. authorizeRetryTimes = 0;
  8554. }
  8555. void handleBootNotificationResponse(char *payload, int gun_index)
  8556. {
  8557. mtrace();
  8558. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8559. char statusStr[12]={0};
  8560. char currentTimeStr[30]={0};
  8561. char *loc;
  8562. int intervalInt = 0;
  8563. int c = 0;
  8564. //double diff_t;
  8565. struct tm tp;
  8566. char buf[28]={0};
  8567. char timebuf[50]={0};
  8568. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8569. //*** interval ****/
  8570. c = 0;
  8571. loc = strstr(payload, "interval");
  8572. //printf("loc=%s\n",loc);
  8573. memset(sstr ,0, sizeof(sstr) );
  8574. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8575. {
  8576. sstr[c] = loc[strlen("interval")+2+c];
  8577. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8578. c++;
  8579. }
  8580. sstr[c] = '\0';
  8581. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8582. intervalInt = atoi(sstr);
  8583. //***status ****/
  8584. loc = strstr(payload, "status");
  8585. memset(sstr ,0, sizeof(sstr) );
  8586. c = 0;
  8587. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8588. {
  8589. sstr[c] = loc[3+strlen("status")+c];
  8590. c++;
  8591. }
  8592. sstr[c] = '\0';
  8593. strcpy(statusStr, sstr);
  8594. //***currentTime ****/
  8595. loc = strstr(payload, "currentTime");
  8596. //printf("loc=%s\n",loc);
  8597. memset(sstr ,0, sizeof(sstr) );
  8598. c = 0;
  8599. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8600. {
  8601. sstr[c] = loc[3+strlen("currentTime")+c];
  8602. c++;
  8603. }
  8604. sstr[c] = '\0';
  8605. strcpy(currentTimeStr, sstr);
  8606. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8607. HeartBeatWaitTime = BootNotificationInterval;
  8608. //#ifdef SystemLogMessage
  8609. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8610. // DEBUG_INFO("interval: %d\n", intervalInt);
  8611. // DEBUG_INFO("status: %s\n", statusStr);
  8612. //#endif
  8613. //write back to ShmOCPP16Data->BootNotification
  8614. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8615. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8616. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8617. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8618. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8619. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8620. {
  8621. server_sign = TRUE;
  8622. server_pending =FALSE;
  8623. }
  8624. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8625. {
  8626. server_pending = TRUE;
  8627. }
  8628. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8629. tp.tm_isdst = -1;
  8630. //time_t utc = mktime(&tp);
  8631. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8632. memset(timebuf, 0, sizeof timebuf);
  8633. sprintf(timebuf,"date -s '%s'",buf);
  8634. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8635. system(timebuf);
  8636. //==============================================
  8637. // RTC sync
  8638. //==============================================
  8639. system("/sbin/hwclock -w --systohc");
  8640. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8641. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8642. }
  8643. void handleDataTransferResponse(char *payload, int gun_index)
  8644. {
  8645. char sstr[160]={0};//sstr[200]={ 0 };
  8646. int c = 0;
  8647. char *loc;
  8648. DEBUG_INFO("handleDataTransferResponse ...\n");
  8649. loc = strstr(payload, "status");
  8650. printf("loc=%s\n",loc);
  8651. c = 0;
  8652. while (loc[3+strlen("status")+c] != '\"')
  8653. {
  8654. sstr[c] = loc[3+strlen("status")+c];
  8655. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8656. c++;
  8657. }
  8658. sstr[c] = '\0';
  8659. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8660. //#ifdef SystemLogMessage
  8661. //DEBUG_INFO("data: %s\n", payload);
  8662. //#endif
  8663. }
  8664. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8665. {
  8666. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8667. //struct json_object *obj;
  8668. // obj = json_tokener_parse(payload);
  8669. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8670. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8671. //No fields are defined.
  8672. }
  8673. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8674. {
  8675. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8676. //struct json_object *obj;
  8677. // obj = json_tokener_parse(payload);
  8678. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8679. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8680. //No fields are defined.
  8681. }
  8682. void handleHeartbeatResponse(char *payload, int gun_index)
  8683. {
  8684. mtrace();
  8685. //double diff_t;
  8686. struct tm tp;
  8687. char buf[28]={0};
  8688. char timebuf[50]={0};
  8689. char sstr[30]={ 0 };
  8690. int c = 0;
  8691. char *loc;
  8692. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8693. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8694. c = 0;
  8695. loc = strstr(payload, "currentTime");
  8696. memset(sstr ,0, sizeof(sstr) );
  8697. while (loc[3+strlen("currentTime")+c] != '\"')
  8698. {
  8699. sstr[c] = loc[3+strlen("currentTime")+c];
  8700. c++;
  8701. }
  8702. sstr[c] = '\0';
  8703. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8704. // #ifdef SystemLogMessage
  8705. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8706. // #endif
  8707. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8708. tp.tm_isdst = -1;
  8709. //time_t utc = mktime(&tp);
  8710. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8711. memset(timebuf, 0, sizeof timebuf);
  8712. sprintf(timebuf,"date -s '%s'",buf);
  8713. system(timebuf);
  8714. //==============================================
  8715. // RTC sync
  8716. //==============================================
  8717. system("/sbin/hwclock -w --systohc");
  8718. if(FirstHeartBeat == 0)
  8719. {
  8720. FirstHeartBeat = 1;
  8721. }
  8722. HeartBeatWithNOResponse = 0;
  8723. }
  8724. void handleMeterValuesResponse(char *payload, int gun_index)
  8725. {
  8726. mtrace();
  8727. //struct json_object *obj;
  8728. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8729. //No fields are defined.
  8730. }
  8731. void handleStartTransactionResponse(char *payload, int gun_index)
  8732. {
  8733. mtrace();
  8734. char sstr[30]={ 0 };
  8735. int c = 0;
  8736. char *loc;
  8737. int transactionIdInt = 0;
  8738. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8739. DEBUG_INFO("handleStartTransactionResponse\n");
  8740. //****************expiryDate********************/
  8741. loc = strstr(payload, "expiryDate");
  8742. if(loc == NULL)
  8743. {
  8744. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8745. }
  8746. else
  8747. {
  8748. c = 0;
  8749. memset(sstr ,0, sizeof(sstr) );
  8750. while (loc[3+strlen("expiryDate")+c] != '\"')
  8751. {
  8752. sstr[c] = loc[3+strlen("expiryDate")+c];
  8753. c++;
  8754. }
  8755. sstr[c] = '\0';
  8756. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8757. }
  8758. //****************parentIdTag********************/
  8759. loc = strstr(payload, "parentIdTag");
  8760. if(loc == NULL)
  8761. {
  8762. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8763. }
  8764. else
  8765. {
  8766. c = 0;
  8767. memset(sstr ,0, sizeof(sstr) );
  8768. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8769. {
  8770. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8771. c++;
  8772. }
  8773. sstr[c] = '\0';
  8774. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8775. }
  8776. //****************status********************/
  8777. loc = strstr(payload, "status");
  8778. if(loc == NULL)
  8779. {
  8780. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8781. }
  8782. else
  8783. {
  8784. c = 0;
  8785. memset(sstr ,0, sizeof(sstr) );
  8786. while (loc[3+strlen("status")+c] != '\"')
  8787. {
  8788. sstr[c] = loc[3+strlen("status")+c];
  8789. c++;
  8790. }
  8791. sstr[c] = '\0';
  8792. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8793. }
  8794. //****************transactionId********************/
  8795. c=0;
  8796. loc = strstr(payload, "transactionId");
  8797. memset(sstr ,0, sizeof(sstr) );
  8798. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8799. {
  8800. sstr[c] = loc[strlen("transactionId")+2+c];
  8801. c++;
  8802. }
  8803. sstr[c] = '\0';
  8804. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8805. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8806. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8807. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8808. #ifdef SystemLogMessage
  8809. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8810. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8811. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8812. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8813. #endif
  8814. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8815. {
  8816. //add Charging Record
  8817. SettingChargingRecord(gun_index, transactionIdInt);
  8818. }
  8819. }
  8820. void handleStatusNotificationResponse(char *payload, int gun_index)
  8821. {
  8822. mtrace();
  8823. printf("handleStatusNotificationResponse\n");
  8824. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8825. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8826. }
  8827. void handleStopTransactionnResponse(char *payload, int gun_index)
  8828. {
  8829. mtrace();
  8830. char sstr[30]={ 0 };
  8831. int c = 0;
  8832. char *loc;
  8833. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8834. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8835. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8836. loc = strstr(payload, "idTagInfo");
  8837. //***********************idTagInfo************************/
  8838. if(loc != NULL)
  8839. {
  8840. //***********************expiryDate************************/
  8841. loc = strstr(payload, "expiryDate");
  8842. if(loc != NULL)
  8843. {
  8844. memset(sstr ,0, sizeof(sstr) );
  8845. c = 0;
  8846. while (loc[3+strlen("expiryDate")+c] != '\"')
  8847. {
  8848. sstr[c] = loc[3+strlen("expiryDate")+c];
  8849. c++;
  8850. }
  8851. sstr[c] = '\0';
  8852. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8853. }
  8854. //***********************parentIdTag************************/
  8855. loc = strstr(payload, "parentIdTag");
  8856. if(loc != NULL)
  8857. {
  8858. memset(sstr ,0, sizeof(sstr) );
  8859. c = 0;
  8860. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8861. {
  8862. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8863. c++;
  8864. }
  8865. sstr[c] = '\0';
  8866. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8867. }
  8868. //***********************status************************/
  8869. loc = strstr(payload, "status");
  8870. memset(sstr ,0, sizeof(sstr) );
  8871. c = 0;
  8872. while (loc[3+strlen("status")+c] != '\"')
  8873. {
  8874. sstr[c] = loc[3+strlen("status")+c];
  8875. c++;
  8876. }
  8877. sstr[c] = '\0';
  8878. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8879. }
  8880. #ifdef SystemLogMessage
  8881. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8882. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8883. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8884. #endif
  8885. }
  8886. //==========================================
  8887. // Handle Error routine
  8888. //==========================================
  8889. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8890. {
  8891. mtrace();
  8892. #ifdef SystemLogMessage
  8893. DEBUG_INFO("errorCode: %s\n", errorCode);
  8894. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8895. DEBUG_INFO("errorDetails: %s\n", payload);
  8896. #endif
  8897. }
  8898. //===============================================
  8899. // Common routine
  8900. //===============================================
  8901. int initialConfigurationTable(void)
  8902. {
  8903. printf("initialConfigurationTable \n");
  8904. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8905. /*Core Profile*/
  8906. //AllowOfflineTxForUnknownId
  8907. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8908. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8911. //AuthorizationCacheEnabled
  8912. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8915. //AuthorizeRemoteTxRequests
  8916. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8919. //BlinkRepeat
  8920. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8923. //ClockAlignedDataInterval
  8924. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8927. //ConnectionTimeOut
  8928. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8931. //GetConfigurationMaxKeys
  8932. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8935. // HeartbeatInterval
  8936. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8939. // LightIntensity
  8940. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8943. // LocalAuthorizeOffline
  8944. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8947. // LocalPreAuthorize
  8948. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8951. // MaxEnergyOnInvalidId
  8952. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8955. // MeterValuesAlignedData
  8956. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  8957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  8958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8959. // MeterValuesAlignedDataMaxLength
  8960. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  8961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  8962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  8963. // MeterValuesSampledData
  8964. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  8965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  8966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8967. // MeterValuesSampledDataMaxLength
  8968. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  8969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  8970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  8971. // MeterValueSampleInterval
  8972. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  8973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  8974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  8975. // MinimumStatusDuration
  8976. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  8977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  8978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  8979. // NumberOfConnectors
  8980. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  8981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  8982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  8983. // ResetRetries
  8984. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  8985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  8986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  8987. // ConnectorPhaseRotation
  8988. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  8990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  8991. // ConnectorPhaseRotationMaxLength
  8992. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  8993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  8994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  8995. // StopTransactionOnEVSideDisconnect
  8996. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  8997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  8999. // StopTransactionOnInvalidId
  9000. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9003. // StopTxnAlignedData
  9004. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9007. // StopTxnAlignedDataMaxLength
  9008. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9011. // StopTxnSampledData
  9012. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9015. // StopTxnSampledDataMaxLength
  9016. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9019. // SupportedFeatureProfiles
  9020. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9023. // SupportedFeatureProfilesMaxLength
  9024. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9027. // TransactionMessageAttempts
  9028. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9031. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9032. // TransactionMessageRetryInterval
  9033. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9036. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9037. // UnlockConnectorOnEVSideDisconnect
  9038. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9041. // WebSocketPingInterval
  9042. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9045. //* Local Auth List Management Profile*/
  9046. #if 0
  9047. //For OCTT Test Case
  9048. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9051. #endif
  9052. #if 1
  9053. //LocalAuthListEnabled
  9054. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9057. #endif
  9058. //LocalAuthListMaxLength
  9059. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9062. //SendLocalListMaxLength
  9063. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9066. //ReserveConnectorZeroSupported
  9067. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9070. //* Smart Charging Profile */
  9071. //ChargeProfileMaxStackLevel
  9072. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9075. // ChargingScheduleAllowedChargingRateUnit
  9076. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9079. // ChargingScheduleMaxPeriods
  9080. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9083. // ConnectorSwitch3to1PhaseSupported
  9084. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9087. // MaxChargingProfilesInstalled
  9088. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9091. return 0;
  9092. }
  9093. void getKeyValue(char *keyReq)
  9094. {
  9095. int isEmpty = FALSE;
  9096. int isKnowKey = FALSE;
  9097. //int unKnowIndex = 0;
  9098. DEBUG_INFO("getKeyValue \n");
  9099. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9100. isEmpty = TRUE;
  9101. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9102. {
  9103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9106. {
  9107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9108. }
  9109. else
  9110. {
  9111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9112. }
  9113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9114. isKnowKey = TRUE;
  9115. }
  9116. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9117. {
  9118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9121. {
  9122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9123. }
  9124. else
  9125. {
  9126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9127. }
  9128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9129. isKnowKey = TRUE;
  9130. }
  9131. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9132. {
  9133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9136. {
  9137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9138. }
  9139. else
  9140. {
  9141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9142. }
  9143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9144. isKnowKey = TRUE;
  9145. }
  9146. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9147. {
  9148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9151. {
  9152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9153. }
  9154. else
  9155. {
  9156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9157. }
  9158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9159. isKnowKey = TRUE;
  9160. }
  9161. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9162. {
  9163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9166. {
  9167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9168. }
  9169. else
  9170. {
  9171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9172. }
  9173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9174. isKnowKey = TRUE;
  9175. }
  9176. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9177. {
  9178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9181. {
  9182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9183. }
  9184. else
  9185. {
  9186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9187. }
  9188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9189. isKnowKey = TRUE;
  9190. }
  9191. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9192. {
  9193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9196. {
  9197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9198. }
  9199. else
  9200. {
  9201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9202. }
  9203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9204. isKnowKey = TRUE;
  9205. }
  9206. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9207. {
  9208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9211. {
  9212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9213. }
  9214. else
  9215. {
  9216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9217. }
  9218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9219. isKnowKey = TRUE;
  9220. }
  9221. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9222. {
  9223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9226. {
  9227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9228. }
  9229. else
  9230. {
  9231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9232. }
  9233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9234. isKnowKey = TRUE;
  9235. }
  9236. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9237. {
  9238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9241. {
  9242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9243. }
  9244. else
  9245. {
  9246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9247. }
  9248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9249. isKnowKey = TRUE;
  9250. }
  9251. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9252. {
  9253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9256. {
  9257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9258. }
  9259. else
  9260. {
  9261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9262. }
  9263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9264. isKnowKey = TRUE;
  9265. }
  9266. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9267. {
  9268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9271. {
  9272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9273. }
  9274. else
  9275. {
  9276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9277. }
  9278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9279. isKnowKey = TRUE;
  9280. }
  9281. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9282. {
  9283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9286. {
  9287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9288. }
  9289. else
  9290. {
  9291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9292. }
  9293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9294. isKnowKey = TRUE;
  9295. }
  9296. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9297. {
  9298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9301. {
  9302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9303. }
  9304. else
  9305. {
  9306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9307. }
  9308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9309. isKnowKey = TRUE;
  9310. }
  9311. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9312. {
  9313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9316. {
  9317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9318. }
  9319. else
  9320. {
  9321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9322. }
  9323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9324. isKnowKey = TRUE;
  9325. }
  9326. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9327. {
  9328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9331. {
  9332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9333. }
  9334. else
  9335. {
  9336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9337. }
  9338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9339. isKnowKey = TRUE;
  9340. }
  9341. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9342. {
  9343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9346. {
  9347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9348. }
  9349. else
  9350. {
  9351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9352. }
  9353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9354. isKnowKey = TRUE;
  9355. }
  9356. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9357. {
  9358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9361. {
  9362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9363. }
  9364. else
  9365. {
  9366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9367. }
  9368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9369. isKnowKey = TRUE;
  9370. }
  9371. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9372. {
  9373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9376. {
  9377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9378. }
  9379. else
  9380. {
  9381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9382. }
  9383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9384. isKnowKey = TRUE;
  9385. }
  9386. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9387. {
  9388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9391. {
  9392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9393. }
  9394. else
  9395. {
  9396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9397. }
  9398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9399. isKnowKey = TRUE;
  9400. }
  9401. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9402. {
  9403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9406. {
  9407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9408. }
  9409. else
  9410. {
  9411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9412. }
  9413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9414. isKnowKey = TRUE;
  9415. }
  9416. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9417. {
  9418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9421. {
  9422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9423. }
  9424. else
  9425. {
  9426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9427. }
  9428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9429. isKnowKey = TRUE;
  9430. }
  9431. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9432. {
  9433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9436. {
  9437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9438. }
  9439. else
  9440. {
  9441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9442. }
  9443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9444. isKnowKey = TRUE;
  9445. }
  9446. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9447. {
  9448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9451. {
  9452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9453. }
  9454. else
  9455. {
  9456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9457. }
  9458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9459. isKnowKey = TRUE;
  9460. }
  9461. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9462. {
  9463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9466. {
  9467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9468. }
  9469. else
  9470. {
  9471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9472. }
  9473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9474. isKnowKey = TRUE;
  9475. }
  9476. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9477. {
  9478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9481. {
  9482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9483. }
  9484. else
  9485. {
  9486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9487. }
  9488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9489. isKnowKey = TRUE;
  9490. }
  9491. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9492. {
  9493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9496. {
  9497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9498. }
  9499. else
  9500. {
  9501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9502. }
  9503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9504. isKnowKey = TRUE;
  9505. }
  9506. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9507. {
  9508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9511. {
  9512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9513. }
  9514. else
  9515. {
  9516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9517. }
  9518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9519. isKnowKey = TRUE;
  9520. }
  9521. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9522. {
  9523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9526. {
  9527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9528. }
  9529. else
  9530. {
  9531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9532. }
  9533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9534. isKnowKey = TRUE;
  9535. }
  9536. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9537. {
  9538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9541. {
  9542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9543. }
  9544. else
  9545. {
  9546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9547. }
  9548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9549. isKnowKey = TRUE;
  9550. }
  9551. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9552. {
  9553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9556. {
  9557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9558. }
  9559. else
  9560. {
  9561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9562. }
  9563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9564. isKnowKey = TRUE;
  9565. }
  9566. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9567. {
  9568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9571. {
  9572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9573. }
  9574. else
  9575. {
  9576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9577. }
  9578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9579. isKnowKey = TRUE;
  9580. }
  9581. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9582. {
  9583. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9586. {
  9587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9588. }
  9589. else
  9590. {
  9591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9592. }
  9593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9594. isKnowKey = TRUE;
  9595. }
  9596. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9597. {
  9598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9601. {
  9602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9603. }
  9604. else
  9605. {
  9606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9607. }
  9608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9609. isKnowKey = TRUE;
  9610. }
  9611. #if 0
  9612. //For OCTT Test Case
  9613. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9614. {
  9615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9617. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9618. {
  9619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9620. }
  9621. else
  9622. {
  9623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9624. }
  9625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9626. isKnowKey = TRUE;
  9627. }
  9628. #endif
  9629. #if 1
  9630. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9631. {
  9632. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9634. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9635. {
  9636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9637. }
  9638. else
  9639. {
  9640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9641. }
  9642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9643. isKnowKey = TRUE;
  9644. }
  9645. #endif
  9646. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9647. {
  9648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9650. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9651. {
  9652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9653. }
  9654. else
  9655. {
  9656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9657. }
  9658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9659. isKnowKey = TRUE;
  9660. }
  9661. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9662. {
  9663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9665. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9666. {
  9667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9668. }
  9669. else
  9670. {
  9671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9672. }
  9673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9674. isKnowKey = TRUE;
  9675. }
  9676. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9677. {
  9678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9680. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9681. {
  9682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9683. }
  9684. else
  9685. {
  9686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9687. }
  9688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9689. isKnowKey = TRUE;
  9690. }
  9691. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9692. {
  9693. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9695. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9696. {
  9697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9698. }
  9699. else
  9700. {
  9701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9702. }
  9703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9704. isKnowKey = TRUE;
  9705. }
  9706. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9707. {
  9708. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9710. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9711. {
  9712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9713. }
  9714. else
  9715. {
  9716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9717. }
  9718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9719. isKnowKey = TRUE;
  9720. }
  9721. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9722. {
  9723. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9725. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9726. {
  9727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9728. }
  9729. else
  9730. {
  9731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9732. }
  9733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9734. isKnowKey = TRUE;
  9735. }
  9736. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9737. {
  9738. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9740. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9741. {
  9742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9743. }
  9744. else
  9745. {
  9746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9747. }
  9748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9749. isKnowKey = TRUE;
  9750. }
  9751. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9752. {
  9753. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9755. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9756. {
  9757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9758. }
  9759. else
  9760. {
  9761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9762. }
  9763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9764. isKnowKey = TRUE;
  9765. }
  9766. //=========================================================
  9767. if(!isEmpty && !isKnowKey)
  9768. {
  9769. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9770. strcpy(unknownkey[UnknownKeynum], keyReq);
  9771. UnknownKeynum = UnknownKeynum + 1;
  9772. }
  9773. }
  9774. void processUnkownKey(void)
  9775. {
  9776. DEBUG_INFO("processUnkownKey\n");
  9777. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9778. for(int index=0; index < UnknownKeynum; index++)
  9779. {
  9780. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9781. {
  9782. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9783. }
  9784. }
  9785. }
  9786. int setKeyValue(char *key, char *value)
  9787. {
  9788. int isSuccess = NotSupported;
  9789. int check_ascii=0;
  9790. #ifdef Debug
  9791. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9792. #endif
  9793. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9794. {
  9795. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9797. {
  9798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9799. isSuccess = ConfigurationStatus_Accepted;
  9800. }
  9801. else
  9802. {
  9803. isSuccess = ConfigurationStatus_Rejected;
  9804. }
  9805. }
  9806. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9807. {
  9808. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9809. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9810. {
  9811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9812. isSuccess = ConfigurationStatus_Accepted;
  9813. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9814. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9815. }
  9816. else
  9817. {
  9818. isSuccess = ConfigurationStatus_Rejected;
  9819. }
  9820. }
  9821. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9822. {
  9823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9824. {
  9825. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9827. isSuccess = ConfigurationStatus_Accepted;
  9828. }
  9829. else
  9830. {
  9831. isSuccess = ConfigurationStatus_Rejected;
  9832. }
  9833. }
  9834. if(strcmp(key, "BlinkRepeat") == 0)
  9835. {
  9836. //Charger.BlinkRepeat = Integer.parseInt(value);
  9837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9838. {
  9839. check_ascii = value[0];
  9840. if( (check_ascii < 48) || (check_ascii > 57) )
  9841. {
  9842. isSuccess = ConfigurationStatus_Rejected;
  9843. }
  9844. else
  9845. {
  9846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9847. isSuccess = ConfigurationStatus_Accepted;
  9848. }
  9849. }
  9850. else
  9851. {
  9852. isSuccess = ConfigurationStatus_Rejected;
  9853. }
  9854. }
  9855. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9856. {
  9857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9858. {
  9859. check_ascii = value[0];
  9860. if( (check_ascii < 48) || (check_ascii > 57) )
  9861. {
  9862. isSuccess = ConfigurationStatus_Rejected;
  9863. }
  9864. else
  9865. {
  9866. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9868. isSuccess = ConfigurationStatus_Accepted;
  9869. }
  9870. }
  9871. else
  9872. {
  9873. isSuccess = ConfigurationStatus_Rejected;
  9874. }
  9875. }
  9876. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9877. {
  9878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9879. {
  9880. check_ascii = value[0];
  9881. if( (check_ascii < 48) || (check_ascii > 57) )
  9882. {
  9883. isSuccess = ConfigurationStatus_Rejected;
  9884. }
  9885. else
  9886. {
  9887. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9889. isSuccess = ConfigurationStatus_Accepted;
  9890. }
  9891. }
  9892. else
  9893. {
  9894. isSuccess = ConfigurationStatus_Rejected;
  9895. }
  9896. }
  9897. if(strcmp(key, "HeartbeatInterval") == 0)
  9898. {
  9899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9900. {
  9901. check_ascii = value[0];
  9902. if( (check_ascii < 48) || (check_ascii > 57) )
  9903. {
  9904. isSuccess = ConfigurationStatus_Rejected;
  9905. }
  9906. else
  9907. {
  9908. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9910. HeartBeatWaitTime = atoi(value);
  9911. isSuccess = ConfigurationStatus_Accepted;
  9912. }
  9913. }
  9914. else
  9915. {
  9916. isSuccess = ConfigurationStatus_Rejected;
  9917. }
  9918. }
  9919. if(strcmp(key, "LightIntensity") == 0)
  9920. {
  9921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9922. {
  9923. check_ascii = value[0];
  9924. if( (check_ascii < 48) || (check_ascii > 57) )
  9925. {
  9926. isSuccess = ConfigurationStatus_Rejected;
  9927. }
  9928. else
  9929. {
  9930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9931. isSuccess = ConfigurationStatus_Accepted;
  9932. }
  9933. }
  9934. else
  9935. {
  9936. isSuccess = ConfigurationStatus_Rejected;
  9937. }
  9938. }
  9939. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9940. {
  9941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9942. {
  9943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9944. isSuccess = ConfigurationStatus_Accepted;
  9945. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9946. }
  9947. else
  9948. {
  9949. isSuccess = ConfigurationStatus_Rejected;
  9950. }
  9951. }
  9952. if(strcmp(key, "LocalPreAuthorize") == 0)
  9953. {
  9954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9955. {
  9956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9957. isSuccess = ConfigurationStatus_Accepted;
  9958. }
  9959. else
  9960. {
  9961. isSuccess = ConfigurationStatus_Rejected;
  9962. }
  9963. }
  9964. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  9965. {
  9966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9967. {
  9968. check_ascii = value[0];
  9969. if( (check_ascii < 48) || (check_ascii > 57) )
  9970. {
  9971. isSuccess = ConfigurationStatus_Rejected;
  9972. }
  9973. else
  9974. {
  9975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  9976. isSuccess = ConfigurationStatus_Accepted;
  9977. }
  9978. }
  9979. else
  9980. {
  9981. isSuccess = ConfigurationStatus_Rejected;
  9982. }
  9983. }
  9984. if(strcmp(key, "MeterValuesAlignedData") == 0)
  9985. {
  9986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9987. {
  9988. //int valueLength = strlen(value);
  9989. for(int i = 0; value[i]; i++){
  9990. value[i] = tolower(value[i]);
  9991. }
  9992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  9993. isSuccess = ConfigurationStatus_Accepted;
  9994. }
  9995. else
  9996. {
  9997. isSuccess = ConfigurationStatus_Rejected;
  9998. }
  9999. }
  10000. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10001. {
  10002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10003. {
  10004. //int valueLength = strlen(value);
  10005. for(int i = 0; value[i]; i++){
  10006. value[i] = tolower(value[i]);
  10007. }
  10008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10009. isSuccess = ConfigurationStatus_Accepted;
  10010. }
  10011. else
  10012. {
  10013. isSuccess = ConfigurationStatus_Rejected;
  10014. }
  10015. }
  10016. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10017. {
  10018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10019. {
  10020. check_ascii = value[0];
  10021. if( (check_ascii < 48) || (check_ascii > 57) )
  10022. {
  10023. isSuccess = ConfigurationStatus_Rejected;
  10024. }
  10025. else
  10026. {
  10027. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10029. isSuccess = ConfigurationStatus_Accepted;
  10030. }
  10031. #ifdef Debug
  10032. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10033. #endif
  10034. }
  10035. else
  10036. {
  10037. isSuccess = ConfigurationStatus_Rejected;
  10038. #ifdef Debug
  10039. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10040. #endif
  10041. }
  10042. }
  10043. if(strcmp(key, "MinimumStatusDuration") == 0)
  10044. {
  10045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10046. {
  10047. check_ascii = value[0];
  10048. if( (check_ascii < 48) || (check_ascii > 57) )
  10049. {
  10050. isSuccess = ConfigurationStatus_Rejected;
  10051. }
  10052. else
  10053. {
  10054. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10056. isSuccess = ConfigurationStatus_Accepted;
  10057. }
  10058. }
  10059. else
  10060. {
  10061. isSuccess = ConfigurationStatus_Rejected;
  10062. }
  10063. }
  10064. if(strcmp(key, "ResetRetries") == 0)
  10065. {
  10066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10067. {
  10068. check_ascii = value[0];
  10069. if( (check_ascii < 48) || (check_ascii > 57) )
  10070. {
  10071. isSuccess = ConfigurationStatus_Rejected;
  10072. }
  10073. else
  10074. {
  10075. //Charger.ResetRetries = Integer.parseInt(value);
  10076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10077. isSuccess = ConfigurationStatus_Accepted;
  10078. }
  10079. }
  10080. else
  10081. {
  10082. isSuccess = ConfigurationStatus_Rejected;
  10083. }
  10084. }
  10085. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10086. {
  10087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10088. {
  10089. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10090. //int valueLength = strlen(value);
  10091. for(int i = 0; value[i]; i++){
  10092. value[i] = tolower(value[i]);
  10093. }
  10094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10095. isSuccess = ConfigurationStatus_Accepted;
  10096. }
  10097. else
  10098. {
  10099. isSuccess = ConfigurationStatus_Rejected;
  10100. }
  10101. }
  10102. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10103. {
  10104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10105. {
  10106. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10108. isSuccess = ConfigurationStatus_Accepted;
  10109. }
  10110. else
  10111. {
  10112. isSuccess = ConfigurationStatus_Rejected;
  10113. }
  10114. }
  10115. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10116. {
  10117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10118. {
  10119. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10121. isSuccess = ConfigurationStatus_Accepted;
  10122. }
  10123. else
  10124. {
  10125. isSuccess = ConfigurationStatus_Rejected;
  10126. }
  10127. }
  10128. if(strcmp(key, "StopTxnAlignedData") == 0)
  10129. {
  10130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10131. {
  10132. //Charger.StopTxnAlignedData = value.toLowerCase();
  10133. //int valueLength = strlen(value);
  10134. for(int i = 0; value[i]; i++){
  10135. value[i] = tolower(value[i]);
  10136. }
  10137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10138. isSuccess = ConfigurationStatus_Accepted;
  10139. }
  10140. else
  10141. {
  10142. isSuccess = ConfigurationStatus_Rejected;
  10143. }
  10144. }
  10145. if(strcmp(key, "StopTxnSampledData") == 0)
  10146. {
  10147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10148. {
  10149. //Charger.StopTxnSampledData = value.toLowerCase();
  10150. //int valueLength = strlen(value);
  10151. for(int i = 0; value[i]; i++){
  10152. value[i] = tolower(value[i]);
  10153. }
  10154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10155. isSuccess = ConfigurationStatus_Accepted;
  10156. }
  10157. else
  10158. {
  10159. isSuccess = ConfigurationStatus_Rejected;
  10160. }
  10161. }
  10162. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10163. {
  10164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10165. {
  10166. check_ascii = value[0];
  10167. if( (check_ascii < 48) || (check_ascii > 57) )
  10168. {
  10169. isSuccess = ConfigurationStatus_Rejected;
  10170. }
  10171. else
  10172. {
  10173. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10175. TransactionMessageAttemptsValue = atoi(value);
  10176. isSuccess = ConfigurationStatus_Accepted;
  10177. }
  10178. }
  10179. else
  10180. {
  10181. isSuccess = ConfigurationStatus_Rejected;
  10182. }
  10183. }
  10184. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10185. {
  10186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10187. {
  10188. check_ascii = value[0];
  10189. if( (check_ascii < 48) || (check_ascii > 57) )
  10190. {
  10191. isSuccess = ConfigurationStatus_Rejected;
  10192. }
  10193. else
  10194. {
  10195. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10197. TransactionMessageRetryIntervalValue = atoi(value);
  10198. isSuccess = ConfigurationStatus_Accepted;
  10199. }
  10200. }
  10201. else
  10202. {
  10203. isSuccess = ConfigurationStatus_Rejected;
  10204. }
  10205. }
  10206. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10207. {
  10208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10209. {
  10210. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10212. isSuccess = ConfigurationStatus_Accepted;
  10213. }
  10214. else
  10215. {
  10216. isSuccess = ConfigurationStatus_Rejected;
  10217. }
  10218. }
  10219. if(strcmp(key, "WebSocketPingInterval") == 0)
  10220. {
  10221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10222. {
  10223. check_ascii = value[0];
  10224. if( (check_ascii < 48) || (check_ascii > 57) )
  10225. {
  10226. isSuccess = ConfigurationStatus_Rejected;
  10227. }
  10228. else
  10229. {
  10230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10231. isSuccess = ConfigurationStatus_Accepted;
  10232. }
  10233. }
  10234. else
  10235. {
  10236. isSuccess = ConfigurationStatus_Rejected;
  10237. }
  10238. }
  10239. #if 0
  10240. //For OCPP Test Case
  10241. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10242. {
  10243. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10244. {
  10245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10246. isSuccess = ConfigurationStatus_Accepted;
  10247. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10248. }
  10249. else
  10250. {
  10251. isSuccess = ConfigurationStatus_Rejected;
  10252. }
  10253. }
  10254. #endif
  10255. #if 1
  10256. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10257. {
  10258. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10259. {
  10260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10261. isSuccess = ConfigurationStatus_Accepted;
  10262. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10263. }
  10264. else
  10265. {
  10266. isSuccess = ConfigurationStatus_Rejected;
  10267. }
  10268. }
  10269. #endif
  10270. return isSuccess;
  10271. }
  10272. int updateSetting(char *key, char *value)
  10273. {
  10274. mtrace();
  10275. int isSuccess = FALSE;
  10276. char string[1000]={0}, buffer[1000]={0};
  10277. char strtemp[50]={0};
  10278. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10279. int pos, c = 0;
  10280. char *loc;
  10281. int pos1=0;
  10282. FILE *f = fopen("/var/www/settings1", "r");
  10283. if(f == NULL)
  10284. {
  10285. #ifdef Debug
  10286. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10287. #endif
  10288. return isSuccess;
  10289. }
  10290. fseek(f, 0, SEEK_END);
  10291. long fsize = ftell(f);
  10292. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10293. fread(string, 1, fsize, f);
  10294. fclose(f);
  10295. string[fsize] = 0;
  10296. loc = strstr(string, key);
  10297. if(loc != NULL)
  10298. {
  10299. DEBUG_INFO("key exist!\n");
  10300. pos = loc - string-1;
  10301. f = fopen("/var/www/settings1", "w");
  10302. strncpy(buffer, string, pos);
  10303. fprintf(f, "%s", buffer);
  10304. memset(sstr ,0, sizeof(sstr) );
  10305. c = 0;
  10306. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10307. {
  10308. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10309. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10310. c++;
  10311. }
  10312. sstr[c] = '\0';
  10313. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10314. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10315. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10316. memset(buffer ,0, sizeof(buffer) );
  10317. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10318. //printf("buffer=%s",buffer);
  10319. fprintf(f, "%s", buffer);
  10320. fclose(f);
  10321. }
  10322. else
  10323. {
  10324. printf("key not exist!\n");
  10325. f = fopen("/var/www/settings1", "w+");
  10326. fputs(string, f);
  10327. fseek(f, -1, SEEK_CUR);
  10328. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10329. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10330. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10331. fclose(f);
  10332. }
  10333. isSuccess = TRUE;
  10334. return isSuccess;
  10335. }
  10336. int TransactionMessageAttemptsGet(void)
  10337. {
  10338. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10339. }
  10340. int FirstHeartBeatResponse(void)
  10341. {
  10342. return FirstHeartBeat;
  10343. }
  10344. int TransactionMessageRetryIntervalGet(void)
  10345. {
  10346. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10347. }
  10348. #define SA struct sockaddr
  10349. #define MAXBUF 1024
  10350. //static int m_socket_data;
  10351. //static int sockfd;
  10352. int ReadHttpStatus(int sock){
  10353. //char c;
  10354. char buff[1024]="",*ptr=buff+1;
  10355. int bytes_received, status;
  10356. DEBUG_INFO("Begin Response ..\n");
  10357. while((bytes_received = recv(sock, ptr, 1, 0))){
  10358. if(bytes_received==-1){
  10359. perror("ReadHttpStatus");
  10360. exit(1);
  10361. }
  10362. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10363. ptr++;
  10364. }
  10365. *ptr=0;
  10366. ptr=buff+1;
  10367. sscanf(ptr,"%*s %d ", &status);
  10368. DEBUG_INFO("%s\n",ptr);
  10369. DEBUG_INFO("status=%d\n",status);
  10370. DEBUG_INFO("End Response ..\n");
  10371. return (bytes_received>0)?status:0;
  10372. }
  10373. //the only filed that it parsed is 'Content-Length'
  10374. int ParseHeader(int sock){
  10375. //char c;
  10376. char buff[1024]="",*ptr=buff+4;
  10377. int bytes_received;
  10378. DEBUG_INFO("Begin HEADER ..\n");
  10379. while((bytes_received = recv(sock, ptr, 1, 0))){
  10380. if(bytes_received==-1){
  10381. perror("Parse Header");
  10382. exit(1);
  10383. }
  10384. if(
  10385. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10386. (ptr[-1]=='\r') && (*ptr=='\n' )
  10387. ) break;
  10388. ptr++;
  10389. }
  10390. *ptr=0;
  10391. ptr=buff+4;
  10392. //printf("%s",ptr);
  10393. if(bytes_received){
  10394. ptr=strstr(ptr,"Content-Length:");
  10395. if(ptr){
  10396. sscanf(ptr,"%*s %d",&bytes_received);
  10397. }else
  10398. bytes_received=-1; //unknown size
  10399. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10400. }
  10401. DEBUG_INFO("End HEADER ..\n");
  10402. return bytes_received ;
  10403. }
  10404. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10405. {
  10406. char rmFileCmd[100]={0};
  10407. char FilePath[100]={0};
  10408. char ftpbuf[200];
  10409. int systemresult;
  10410. DEBUG_INFO("filename=%s\n",filename);
  10411. DEBUG_INFO("url=%s\n",url);
  10412. sprintf(FilePath,"../mnt/%s",filename);
  10413. if((access(FilePath,F_OK))!=-1)
  10414. {
  10415. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10416. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10417. system(rmFileCmd);
  10418. }
  10419. memset(ftpbuf, 0, sizeof(ftpbuf));
  10420. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10421. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10422. systemresult = system(ftpbuf);
  10423. DEBUG_INFO("systemresult=%d\n",systemresult);
  10424. if(systemresult != 0)
  10425. {
  10426. DEBUG_INFO("http DownLoad error!\n");
  10427. return FALSE;
  10428. }
  10429. return TRUE;
  10430. }
  10431. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10432. {
  10433. char rmFileCmd[100]={0};
  10434. char FilePath[100]={0};
  10435. char ftpbuf[200];
  10436. int systemresult;
  10437. //char temp[100];
  10438. #if 0
  10439. struct hostent* server;
  10440. char *IPbuffer;
  10441. server = gethostbyname(location);
  10442. // To convert an Internet network
  10443. // address into ASCII string
  10444. IPbuffer = inet_ntoa(*((struct in_addr*)
  10445. server->h_addr_list[0]));
  10446. #endif
  10447. sprintf(FilePath,"../mnt/%s",filename);
  10448. if((access(FilePath,F_OK))!=-1)
  10449. {
  10450. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10451. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10452. system(rmFileCmd);
  10453. }
  10454. memset(ftpbuf, 0, sizeof(ftpbuf));
  10455. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10456. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10457. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10458. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10459. systemresult = system(ftpbuf);
  10460. DEBUG_INFO("systemresult=%d\n",systemresult);
  10461. if(systemresult != 0)
  10462. {
  10463. printf("ftpget error!\n");
  10464. return FALSE;
  10465. }
  10466. return TRUE;
  10467. }
  10468. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10469. {
  10470. struct hostent* server;
  10471. char *IPbuffer;
  10472. char ftpbuf[200];
  10473. int systemresult;
  10474. // To retrieve host information
  10475. server = gethostbyname(location);
  10476. // To convert an Internet network
  10477. // address into ASCII string
  10478. IPbuffer = inet_ntoa(*((struct in_addr*)
  10479. server->h_addr_list[0]));
  10480. memset(ftpbuf, 0, sizeof(ftpbuf));
  10481. /* format : ftpput -u username -p passwd IP target source*/
  10482. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10483. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10484. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10485. systemresult = system(ftpbuf);
  10486. DEBUG_INFO("systemresult=%d\n",systemresult);
  10487. if(systemresult != 0)
  10488. {
  10489. DEBUG_INFO("ftpput error!\n");
  10490. return FALSE;
  10491. }
  10492. return TRUE;
  10493. }
  10494. int SettingChargingRecord(int target, int transactionId)
  10495. {
  10496. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10497. {
  10498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10499. {
  10500. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10501. {
  10502. addBuff(target, transactionId, 0);
  10503. return TRUE;
  10504. }
  10505. }
  10506. for (int index = 0; index < CCS_QUANTITY; index++)
  10507. {
  10508. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10509. {
  10510. addBuff(target, transactionId, 0);
  10511. return TRUE;
  10512. }
  10513. }
  10514. for (int index = 0; index < GB_QUANTITY; index++)
  10515. {
  10516. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10517. {
  10518. addBuff(target, transactionId, 0);
  10519. return TRUE;
  10520. }
  10521. }
  10522. }
  10523. else
  10524. {
  10525. for (int index = 0; index < AC_QUANTITY; index++)
  10526. {
  10527. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10528. {
  10529. addBuff(target, transactionId, 0);
  10530. return TRUE;
  10531. }
  10532. }
  10533. }
  10534. return FALSE;
  10535. }
  10536. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10537. {
  10538. int isSuccess = FALSE;
  10539. //char *query = NULL;
  10540. sqlite3_stmt *stmt;
  10541. int rc; // return code
  10542. char str[20];
  10543. sprintf(str,"%d",user_id);
  10544. 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 */
  10545. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10546. rc = sqlite3_step(stmt); /* 3 */
  10547. if (rc != SQLITE_DONE) {
  10548. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10549. goto out;
  10550. }
  10551. sqlite3_finalize(stmt);
  10552. // free(query);
  10553. out:
  10554. //----------------------
  10555. // close SQLite database
  10556. //----------------------
  10557. sqlite3_close(db);
  10558. printf("database closed.\n");
  10559. return isSuccess;
  10560. }
  10561. /**
  10562. * Place the contents of the specified file into a memory buffer
  10563. *
  10564. * @param[in] filename The path and name of the file to read
  10565. * @param[out] filebuffer A pointer to the contents in memory
  10566. * @return status 0 success, 1 on failure
  10567. */
  10568. int get_file_contents(const char* filename, char** outbuffer) {
  10569. FILE* file = NULL;
  10570. long filesize;
  10571. const int blocksize = 1;
  10572. size_t readsize;
  10573. char* filebuffer;
  10574. // Open the file
  10575. file = fopen(filename, "r");
  10576. if (NULL == file)
  10577. {
  10578. printf("'%s' not opened\n", filename);
  10579. exit(EXIT_FAILURE);
  10580. }
  10581. // Determine the file size
  10582. fseek(file, 0, SEEK_END);
  10583. filesize = ftell(file);
  10584. rewind (file);
  10585. // Allocate memory for the file contents
  10586. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10587. *outbuffer = filebuffer;
  10588. if (filebuffer == NULL)
  10589. {
  10590. fputs ("malloc out-of-memory", stderr);
  10591. exit(EXIT_FAILURE);
  10592. }
  10593. // Read in the file
  10594. readsize = fread(filebuffer, blocksize, filesize, file);
  10595. if (readsize != filesize)
  10596. {
  10597. fputs ("didn't read file completely",stderr);
  10598. exit(EXIT_FAILURE);
  10599. }
  10600. // Clean exit
  10601. fclose(file);
  10602. return EXIT_SUCCESS;
  10603. }
  10604. static int selectSqlCount = 0;
  10605. static int callback(void *data, int argc, char **argv, char **azColName){
  10606. int i;
  10607. printf("%s: ", (const char*)data);
  10608. selectSqlCount = argc;
  10609. for(i = 0; i<argc; i++){
  10610. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10611. }
  10612. printf("\n");
  10613. return 0;
  10614. }
  10615. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10616. //int i;
  10617. //printf("%s:\n", (const char*)data);
  10618. localversion = argv[5] ? atoi(argv[5]) : 0;
  10619. printf("localversion=%d\n", localversion);
  10620. return 0;
  10621. }
  10622. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10623. //int i;
  10624. //printf("%s:\n", (const char*)data);
  10625. //idTag
  10626. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10627. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10628. //parentIdTag
  10629. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10630. //expir_date
  10631. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10632. //status
  10633. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10634. //version
  10635. idTagQuery.listVersionInt = atoi(argv[5]);
  10636. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10637. return 0;
  10638. }
  10639. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10640. int i;
  10641. //printf("%s:\n", (const char*)data);
  10642. #if 1
  10643. for(i=0; i<argc; i++){
  10644. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10645. }
  10646. //printf("");
  10647. #endif
  10648. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10649. // printf("localversion=%d\n", localversion);
  10650. return 0;
  10651. }
  10652. /** sqlite3_exec的回调。
  10653. *
  10654. * 向控制台打印查询的结果。
  10655. *
  10656. * @param in data 传递给回调函数的数据。
  10657. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10658. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10659. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10660. * @return 状态码。
  10661. */
  10662. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10663. {
  10664. for (int i = 0; i < n_columns; i++)
  10665. {
  10666. DEBUG_INFO("%s/t", col_values[i]);
  10667. }
  10668. DEBUG_INFO("/n");
  10669. return 0;
  10670. }
  10671. void OCPP_getListVerion()
  10672. {
  10673. int rc = 0;
  10674. // const char* data = "Callback function called";
  10675. char sql[100];
  10676. char zErrMsg[100];
  10677. memset(sql, 0, 100);
  10678. memset(zErrMsg, 0, 100);
  10679. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10680. /* Execute SQL statement */
  10681. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10682. DEBUG_INFO("rc=%d\n",rc);
  10683. if( rc != SQLITE_OK ){
  10684. DEBUG_INFO("SQL error: %s", zErrMsg);
  10685. //sqlite3_free(zErrMsg);
  10686. }else{
  10687. DEBUG_INFO("Operation done successfully");
  10688. }
  10689. }
  10690. void OCPP_getIdTag(char *idTag)
  10691. {
  10692. int rc = 0;
  10693. // const char* data = "Callback function called";
  10694. char sql[100];
  10695. char zErrMsg[100];
  10696. memset(sql, 0, 100);
  10697. memset(zErrMsg, 0, 100);
  10698. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10699. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10700. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10701. /* Execute SQL statement */
  10702. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10703. if( rc != SQLITE_OK ){
  10704. DEBUG_INFO("SQL error: %s", zErrMsg);
  10705. //sqlite3_free(zErrMsg);
  10706. }else{
  10707. printf("Operation done successfully");
  10708. }
  10709. //return ver;
  10710. }
  10711. void OCPP_get_TableAuthlocalAllData(void)
  10712. {
  10713. int rc = 0;
  10714. // const char* data = "Callback function called";
  10715. char sql[100];
  10716. char zErrMsg[100];
  10717. memset(sql, 0, 100);
  10718. memset(zErrMsg, 0, 100);
  10719. sprintf(sql,"select * from ocpp_auth_local ");
  10720. /* Execute SQL statement */
  10721. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10722. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10723. if( rc != SQLITE_OK ){
  10724. DEBUG_INFO("SQL error: %s", zErrMsg);
  10725. //sqlite3_free(zErrMsg);
  10726. }else{
  10727. DEBUG_INFO("Operation done successfully");
  10728. }
  10729. //return ver;
  10730. }
  10731. int OCPP_cleanLocalList()
  10732. {
  10733. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10734. char *errMsg = 0;
  10735. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10736. if (SQLITE_OK != rc)
  10737. {
  10738. DEBUG_INFO("%s\n",errMsg);
  10739. return FALSE;
  10740. }
  10741. else
  10742. {
  10743. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10744. }
  10745. return TRUE;
  10746. }
  10747. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10748. {
  10749. int isSuccess = FALSE;
  10750. int ret = 0;
  10751. //const char* data = "Callback function called";
  10752. char sql[200];
  10753. char zErrMsg[100];
  10754. memset(sql, 0, 200);
  10755. memset(zErrMsg, 0, 100);
  10756. 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);
  10757. //* Execute SQL statement */
  10758. //zErrMsg = 0;
  10759. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10760. if( ret != SQLITE_OK ){
  10761. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10762. // free(zErrMsg);
  10763. // free(sql);
  10764. return isSuccess;
  10765. }
  10766. DEBUG_INFO("successfully Insert records created\n");
  10767. isSuccess = TRUE;
  10768. return isSuccess;
  10769. }
  10770. void OCPP_deleteIdTag(char *idTag)
  10771. {
  10772. //int ver = 0;
  10773. //int isSuccess = FALSE;
  10774. int rc = 0;
  10775. char sql[100];
  10776. char zErrMsg[100];
  10777. memset(sql, 0, 100);
  10778. memset(zErrMsg, 0, 100);
  10779. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10780. //* Execute SQL statement */
  10781. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10782. if( rc != SQLITE_OK ){
  10783. DEBUG_INFO("SQL error: %s", zErrMsg);
  10784. //sqlite3_free(zErrMsg);
  10785. }else{
  10786. DEBUG_INFO("Operation done successfully");
  10787. }
  10788. }
  10789. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10790. {
  10791. int isSuccess = FALSE;
  10792. int ret = 0;
  10793. const char* data = "Callback function called";
  10794. char sql[200];
  10795. char zErrMsg[100];
  10796. memset(sql, 0, 200);
  10797. memset(zErrMsg, 0, 100);
  10798. //* selectFromTable */
  10799. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10800. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10801. //* Execute SQL statement */
  10802. selectSqlCount = 0;
  10803. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10804. if( ret != SQLITE_OK ){
  10805. printf("Error SQL: %s\n", zErrMsg);
  10806. }
  10807. printf("successfully select operation done\n");
  10808. memset(sql, 0, 200);
  10809. memset(zErrMsg, 0, 100);
  10810. if(selectSqlCount == 0)
  10811. {
  10812. //Insert
  10813. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10814. 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);
  10815. DEBUG_INFO("sql:%s\n", sql);
  10816. //* Execute SQL statement */
  10817. //zErrMsg = 0;
  10818. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10819. if( ret != SQLITE_OK ){
  10820. printf("SQL error: %s\n", zErrMsg);
  10821. return isSuccess;
  10822. }
  10823. DEBUG_INFO("successfully Insert records created\n");
  10824. isSuccess = TRUE;
  10825. }
  10826. else
  10827. {
  10828. //Update
  10829. //* Create merged SQL statement */
  10830. 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);
  10831. /* Execute SQL statement */
  10832. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10833. if( ret != SQLITE_OK ){
  10834. printf("SQL error: %s\n", zErrMsg);
  10835. //sqlite3_free(zErrMsg);
  10836. //sqlite3_free(sql);
  10837. return isSuccess;
  10838. }
  10839. DEBUG_INFO("Successfully operation done \n");
  10840. isSuccess = TRUE;
  10841. }
  10842. return isSuccess;
  10843. }
  10844. char *GetOcppServerURL()
  10845. {
  10846. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10847. memset(OcppHost, 0, sizeof(OcppHost));
  10848. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10849. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10850. {
  10851. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10852. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10853. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10854. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10855. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10856. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10857. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10858. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10859. goto End;
  10860. }
  10861. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10862. {
  10863. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10864. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10865. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10866. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10867. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10868. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10869. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10870. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10871. goto End;
  10872. }
  10873. else
  10874. {
  10875. strcpy(OcppHost,"");
  10876. }
  10877. End:
  10878. return OcppHost;
  10879. }
  10880. char *GetOcppPath()
  10881. {
  10882. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10883. {
  10884. if(OcppTempPath == NULL)
  10885. {
  10886. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10887. }
  10888. else
  10889. {
  10890. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10891. }
  10892. goto End;
  10893. }
  10894. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10895. {
  10896. if(OcppTempPath == NULL)
  10897. {
  10898. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10899. }
  10900. else
  10901. {
  10902. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10903. }
  10904. goto End;
  10905. }
  10906. else
  10907. {
  10908. strcpy(OcppHost,"");
  10909. }
  10910. End:
  10911. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10912. return OcppPath;
  10913. }
  10914. int GetOcppPort()
  10915. {
  10916. return OcppPort;
  10917. }
  10918. int GetOcppConnStatus(void)
  10919. {
  10920. return ShmOCPP16Data->OcppConnStatus;
  10921. }
  10922. void SetOcppConnStatus(uint8_t status)
  10923. {
  10924. ShmOCPP16Data->OcppConnStatus = status;
  10925. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10926. if(status == FALSE)
  10927. {
  10928. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10929. {
  10930. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10931. }
  10932. else
  10933. {
  10934. SystemInitial = AC_QUANTITY;
  10935. }
  10936. }
  10937. }
  10938. int GetHeartBeatWithNOResponse(void)
  10939. {
  10940. return HeartBeatWithNOResponse;
  10941. }
  10942. void SetHeartBeatWithNOResponse(void)
  10943. {
  10944. HeartBeatWithNOResponse = 0;
  10945. }
  10946. int InternetDisconnect(void)
  10947. {
  10948. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  10949. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  10950. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  10951. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  10952. }
  10953. #if 0
  10954. void Send(struct json_object *message)
  10955. {
  10956. printf("Send -1 \n");
  10957. printf("message=%s\n",json_object_to_json_string(message));
  10958. LWS_Send(json_object_to_json_string(message));
  10959. }
  10960. #endif
  10961. void LWS_Send(char * str)
  10962. {
  10963. #if 1
  10964. //=====================================================
  10965. // Check InternetConn 0: disconnected, 1: connected
  10966. //====================================================
  10967. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  10968. {
  10969. DEBUG_INFO("\n offline now !!!\n");
  10970. return;
  10971. }
  10972. #endif
  10973. pthread_mutex_lock(&lock);
  10974. memset(SendBuffer,0,SendBufLen);
  10975. sprintf((char *)SendBuffer, "%s", str);
  10976. pthread_mutex_unlock(&lock);
  10977. lws_callback_on_writable(wsi_client);
  10978. lws_service(context, 10000);//timeout_ms
  10979. //usleep(10000); // 等�??��?微�?
  10980. //DEBUG_INFO("Send message end\n");
  10981. }