MessageHandler.c 676 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "define.h"
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <stdlib.h>
  24. /*for sendfile()*/
  25. #include <sys/sendfile.h>
  26. /*for O_RDONLY*/
  27. #include <fcntl.h>
  28. #include "sqlite3.h"
  29. #include <arpa/inet.h>
  30. #include <time.h>
  31. #include <assert.h>
  32. #include <pthread.h>
  33. #include <mcheck.h>
  34. #include "MessageHandler.h"
  35. #include "SystemLogMessage.h"
  36. #include "hashmap.h"
  37. #include "ShareMemory.h"
  38. #include "TransactionQueue.h"
  39. #define PASS 1
  40. #define FAIL -1
  41. #define FALSE 0
  42. #define TRUE 1 // Option 1
  43. //ChargePointMaxProfile
  44. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  45. //TxDefaultProfile
  46. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  47. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  48. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  49. //TxProfile
  50. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  51. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  52. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  53. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  54. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  55. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  56. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  57. //===================================
  58. // Define CP State constant
  59. //===================================
  60. #define CP_STATE_UNKNOWN 0
  61. #define CP_STATE_A 1
  62. #define CP_STATE_B 2
  63. #define CP_STATE_C 3
  64. #define CP_STATE_D 4
  65. #define CP_STATE_E 5
  66. #define CP_STATE_F 6
  67. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  68. struct StatusCodeData *ShmStatusCodeData;
  69. struct PsuData *ShmPsuData ;
  70. struct OCPP16Data *ShmOCPP16Data;
  71. // define Macro
  72. #define SystemLogMessage
  73. // OCPP Message Type
  74. #define MESSAGE_TYPE_CALL 2
  75. #define MESSAGE_TYPE_CALLRESULT 3
  76. #define MESSAGE_TYPE_CALLERROR 4
  77. //
  78. //#define server_cycle_Status 120
  79. #define MACROSTR(k) #k
  80. //ConfigurationMaxKeys
  81. #define GetConfigurationMaxKeysNUM 43
  82. //char guid[37];
  83. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  84. char queuedata[2600]={0};
  85. //=================================
  86. // StatusNotification cycle
  87. //=================================
  88. static int server_cycle_Status = 120;
  89. //===============================
  90. // Configuration: unknownkey
  91. //===============================
  92. static char unknownkey[10][20]={0};
  93. static int UnknownKeynum = 0;
  94. //===============================
  95. // Gun Total Numbers
  96. //===============================
  97. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  98. static int gunTotalNumber=0;
  99. static unsigned char gunType[4]={0};
  100. //===============================
  101. // Local List Version
  102. //===============================
  103. static int localversion=0;
  104. static char idTagAuthorization[32]={0};
  105. //===============================
  106. // OCPP Path
  107. //===============================
  108. extern char OcppPath[160];
  109. extern char OcppProtocol[10];
  110. extern char OcppHost[50];
  111. extern char OcppTempPath[50];
  112. extern char StartTransactionIdTagTemp[20];
  113. static int OcppPort=0;
  114. //===============================
  115. // OCPP sign variable
  116. //===============================
  117. static int server_sign = FALSE;
  118. int server_pending = FALSE;
  119. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  120. static int BootNotificationInterval = 0;
  121. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  122. //===============================
  123. // OCPP auth variable
  124. //===============================
  125. static int authorizeRetryTimes = 0; //number of Retry times
  126. //===============================
  127. // OCPP StartTransaction transactionId variables
  128. //===============================
  129. //static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  130. //===============================
  131. // OCPP other variables
  132. //===============================
  133. //int isUpdateRequest = FALSE;
  134. static int HeartBeatWaitTime = 10;
  135. static int FirstHeartBeat = 0;
  136. static int FirmwareStatusNotificationStatus = 3; // Idle
  137. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  138. static char CurrentChargingProfileScheduleStr[30]={0};
  139. //========================================
  140. // OCPP status/previous related variables
  141. //========================================
  142. static int GunStatusInterval = 10;
  143. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  144. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  145. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  146. static int GbPreviousSystemStatus[GB_QUANTITY];
  147. static int AcPreviousSystemStatus[AC_QUANTITY];
  148. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  149. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  150. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  151. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  152. static int TransactionMessageAttemptsValue = 0;
  153. static int TransactionMessageRetryIntervalValue = 0;
  154. static int TempMeterValueInterval = 0;
  155. static struct OCPPAuthLocalElemet
  156. {
  157. int listVersionInt;
  158. char idTagstr[20];
  159. char parentIdTag[20];
  160. char expiryDate[30];
  161. char idTagstatus[16];
  162. }idTagQuery;
  163. //=============================================
  164. // OCPP HeartBeat Response Not Receive Counts
  165. //============================================
  166. static int HeartBeatWithNOResponse = 0;
  167. static int HeartBeatCountPerHour = 0;
  168. extern struct lws *wsi_client;
  169. extern struct lws_context *context;
  170. extern unsigned char SendBuffer[4096];
  171. extern int SendBufLen;
  172. extern char *random_uuid( char buf[37] );
  173. extern void split(char **arr, char *str, const char *del);
  174. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  175. extern int GetTransactionQueueNum(void);
  176. extern pthread_mutex_t mutex1;
  177. extern struct Charger_Info Charger;
  178. extern sqlite3 *db;
  179. int TransactionMessageAttemptsGet(void);
  180. int TransactionMessageRetryIntervalGet(void);
  181. int GetOcppConnStatus(void);
  182. void SetOcppConnStatus(uint8_t status);
  183. int updateSetting(char *key, char *value);
  184. int setKeyValue(char *key, char *value);
  185. void OCPP_get_TableAuthlocalAllData(void);
  186. void processUnkownKey(void);
  187. struct StructOCPPMeterValue
  188. {
  189. unsigned char TimeStamp[28];
  190. struct StructSampledValue SampledValue[10];
  191. };
  192. struct ClientTime
  193. {
  194. unsigned int Heartbeat;
  195. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  196. unsigned int StartTransaction;
  197. unsigned int StopTransaction;
  198. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  199. }clientTime;
  200. typedef union
  201. {
  202. //Operations Initiated by Central System
  203. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  204. struct
  205. {
  206. //CsMsgValue[0]
  207. unsigned char StatusNotificationReq :1; //bit 0,
  208. unsigned char StatusNotificationConf :1; //bit 0,
  209. unsigned char :6; //bit 2~7
  210. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  211. }CpinitiateMsg;
  212. CpinitiateMsg cpinitateMsg;
  213. //==========================================
  214. // Init all Enumeration & Mapping String
  215. //==========================================
  216. /*ChargePointErrorCode*/
  217. typedef enum {
  218. ConnectorLockFailure,
  219. EVCommunicationError,
  220. GroundFailure,
  221. HighTemperature,
  222. InternalError,
  223. LocalListConflict,
  224. NoError,
  225. OtherError,
  226. OverCurrentFailure,
  227. OverVoltage,
  228. PowerMeterFailure,
  229. PowerSwitchFailure,
  230. ReaderFailure,
  231. ResetFailure,
  232. UnderVoltage,
  233. WeakSignal
  234. } ChargePointErrorCode;
  235. #if 0
  236. static char *ChargePointErrorCodeStr[] = {
  237. MACROSTR(ConnectorLockFailure),
  238. MACROSTR(EVCommunicationError),
  239. MACROSTR(GroundFailure),
  240. MACROSTR(HighTemperature),
  241. MACROSTR(InternalError),
  242. MACROSTR(LocalListConflict),
  243. MACROSTR(NoError),
  244. MACROSTR(OtherError),
  245. MACROSTR(OverCurrentFailure),
  246. MACROSTR(OverVoltage),
  247. MACROSTR(PowerMeterFailure),
  248. MACROSTR(PowerSwitchFailure),
  249. MACROSTR(ReaderFailure),
  250. MACROSTR(ResetFailure),
  251. MACROSTR(UnderVoltage),
  252. MACROSTR(WeakSignal)
  253. };
  254. #endif
  255. /*ChargePointStatus*/
  256. typedef enum {
  257. Available =0,
  258. Preparing,
  259. Charging,
  260. SuspendedEVSE,
  261. SuspendedEV,
  262. Finishing,
  263. Reserved,
  264. Unavailable,
  265. Faulted
  266. } ChargePointStatus;
  267. static char * ChargePointStatusStr[] = {
  268. MACROSTR(Available),
  269. MACROSTR(Preparing),
  270. MACROSTR(Charging),
  271. MACROSTR(SuspendedEVSE),
  272. MACROSTR(SuspendedEV),
  273. MACROSTR(Finishing),
  274. MACROSTR(Reserved),
  275. MACROSTR(Unavailable),
  276. MACROSTR(Faulted)
  277. };
  278. /*AvailabilityType*/
  279. typedef enum {
  280. RegistrationStatus_Accepted,
  281. RegistrationStatus_Pending,
  282. RegistrationStatus_Rejected
  283. } RegistrationStatus;
  284. static char *RegistrationStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Pending),
  287. MACROSTR(Rejected)
  288. };
  289. /*AvailabilityType*/
  290. typedef enum {
  291. Inoperative,
  292. Operative
  293. } AvailabilityType;
  294. static char *AvailabilityTypeStr[] = {
  295. MACROSTR(Inoperative),
  296. MACROSTR(Operative)
  297. };
  298. /*AvailabilityStatus*/
  299. typedef enum {
  300. Accepted,
  301. Rejected,
  302. Scheduled
  303. } AvailabilityStatus;
  304. static char *AvailabilityStatusStr[] = {
  305. MACROSTR(Accepted),
  306. MACROSTR(Rejected),
  307. MACROSTR(Scheduled)
  308. };
  309. /*ConfigurationStatus*/
  310. typedef enum {
  311. ConfigurationStatus_Accepted,
  312. ConfigurationStatus_Rejected,
  313. RebootRequired,
  314. NotSupported
  315. } ConfigurationStatus;
  316. static char *ConfigurationStatusStr[] = {
  317. MACROSTR(Accepted),
  318. MACROSTR(Rejected),
  319. MACROSTR(RebootRequired),
  320. MACROSTR(NotSupported)
  321. };
  322. /*ClearCacheStatus*/
  323. typedef enum {
  324. ClearCacheStatus_Accepted,
  325. ClearCacheStatus_Rejected
  326. } ClearCacheStatus;
  327. static char *ClearCacheStatusStr[] = {
  328. MACROSTR(Accepted),
  329. MACROSTR(Rejected)
  330. };
  331. /*ChargingProfilePurposeType*/
  332. typedef enum {
  333. ChargePointMaxProfile,
  334. TxDefaultProfile,
  335. TxProfile
  336. } ChargingProfilePurposeType;
  337. static char *ChargingProfilePurposeTypeStr[] = {
  338. MACROSTR(ChargePointMaxProfile),
  339. MACROSTR(TxDefaultProfile),
  340. MACROSTR(TxProfile)
  341. };
  342. /*ChargingProfileStatus*/
  343. typedef enum {
  344. ChargingProfileStatus_Accepted,
  345. ChargingProfileStatus_Rejected,
  346. ChargingProfileStatus_NotSupported
  347. } ChargingProfileStatus;
  348. static char *ChargingProfileStatusStr[] = {
  349. MACROSTR(Accepted),
  350. MACROSTR(Rejected),
  351. MACROSTR(NotSupported)
  352. };
  353. /*ClearChargingProfileStatus*/
  354. typedef enum {
  355. ClearChargingProfileStatus_Accepted,
  356. ClearChargingProfileStatus_Unknown
  357. } ClearChargingProfileStatus;
  358. static char *ClearChargingProfileStatusStr[] = {
  359. MACROSTR(Accepted),
  360. MACROSTR(Unknown)
  361. };
  362. /*GetCompositeScheduleStatus*/
  363. typedef enum {
  364. GetCompositeScheduleStatus_Accepted,
  365. GetCompositeScheduleStatus_Rejected
  366. } GetCompositeScheduleStatus;
  367. static char *GetCompositeScheduleStatusStr[] = {
  368. MACROSTR(Accepted),
  369. MACROSTR(Rejected)
  370. };
  371. /*ChargingRateUnitType*/
  372. typedef enum {
  373. ChargingRateUnitType_W,
  374. ChargingRateUnitType_A
  375. } ChargingRateUnitType;
  376. /*AuthorizationStatus*/
  377. typedef enum {
  378. AuthorizationStatus_Accepted ,
  379. AuthorizationStatus_Blocked ,
  380. AuthorizationStatus_Expired ,
  381. AuthorizationStatus_Invalid ,
  382. AuthorizationStatus_ConcurrentTx
  383. } AuthorizationStatus;
  384. /*UpdateType*/
  385. typedef enum {
  386. Differential ,
  387. Full
  388. } UpdateType;
  389. static char *UpdateTypeStr[] = {
  390. MACROSTR(Differential),
  391. MACROSTR(Full)
  392. };
  393. /*UpdateStatus*/
  394. typedef enum {
  395. UpdateStatus_Accepted ,
  396. UpdateStatus_Failed ,
  397. UpdateStatus_NotSupported ,
  398. UpdateStatus_VersionMismatch
  399. } UpdateStatus;
  400. static char *UpdateStatusStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Failed),
  403. MACROSTR(NotSupported),
  404. MACROSTR(VersionMismatch)
  405. };
  406. /*RemoteStartStopStatus*/
  407. typedef enum {
  408. RemoteStartStopStatus_Accepted,
  409. RemoteStartStopStatus_Rejected
  410. } RemoteStartStopStatus;
  411. static char *RemoteStartStopStatusStr[] = {
  412. MACROSTR(Accepted),
  413. MACROSTR(Rejected)
  414. };
  415. /*ReservationStatus*/
  416. typedef enum {
  417. ReservationStatus_Accepted,
  418. ReservationStatus_Faulted,
  419. ReservationStatus_Occupied,
  420. ReservationStatus_Rejected,
  421. ReservationStatus_Unavailable
  422. } ReservationStatus;
  423. static char *ReservationStatusStr[] = {
  424. MACROSTR(Accepted),
  425. MACROSTR(Faulted),
  426. MACROSTR(Occupied),
  427. MACROSTR(Rejected),
  428. MACROSTR(Unavailable)
  429. };
  430. /*ResetType*/
  431. typedef enum {
  432. Hard,
  433. Soft
  434. } ResetType;
  435. static char *ResetTypeStr[] = {
  436. MACROSTR(Hard),
  437. MACROSTR(Soft)
  438. };
  439. /*ResetStatus*/
  440. typedef enum {
  441. ResetStatus_Accepted,
  442. ResetStatus_Rejected
  443. } ResetStatus;
  444. static char *ResetStatusStr[] = {
  445. MACROSTR(Accepted),
  446. MACROSTR(Rejected)
  447. };
  448. /*DiagnosticsStatus*/
  449. typedef enum {
  450. DiagnosticsStatus_Idle,
  451. DiagnosticsStatus_Uploaded,
  452. DiagnosticsStatus_UploadFailed,
  453. DiagnosticsStatus_Uploading
  454. } DiagnosticsStatus;
  455. static char * DiagnosticsStatusStr[] = {
  456. MACROSTR(Idle),
  457. MACROSTR(Uploaded),
  458. MACROSTR(UploadFailed),
  459. MACROSTR(Uploading)
  460. };
  461. /*FirmwareStatus*/
  462. typedef enum {
  463. FirmwareStatus_Downloaded,
  464. FirmwareStatus_DownloadFailed,
  465. FirmwareStatus_Downloading,
  466. FirmwareStatus_Idle,
  467. FirmwareStatus_InstallationFailed,
  468. FirmwareStatus_Installing,
  469. FirmwareStatus_Installed
  470. } FirmwareStatus;
  471. static char * FirmwareStatusStr[] = {
  472. MACROSTR(Downloaded),
  473. MACROSTR(DownloadFailed),
  474. MACROSTR(Downloading),
  475. MACROSTR(Idle),
  476. MACROSTR(InstallationFailed),
  477. MACROSTR(Installing),
  478. MACROSTR(Installed)
  479. };
  480. /*MessageTrigger*/
  481. typedef enum {
  482. BootNotification,
  483. DiagnosticsStatusNotification,
  484. FirmwareStatusNotification,
  485. Heartbeat,
  486. MeterValues,
  487. StatusNotification
  488. } MessageTrigger;
  489. static char * MessageTriggerStr[] = {
  490. MACROSTR(BootNotification),
  491. MACROSTR(DiagnosticsStatusNotification),
  492. MACROSTR(FirmwareStatusNotification),
  493. MACROSTR(Heartbeat),
  494. MACROSTR(MeterValues),
  495. MACROSTR(StatusNotification)
  496. };
  497. /*TriggerMessageStatus*/
  498. typedef enum {
  499. TriggerMessageStatus_Accepted ,
  500. TriggerMessageStatus_Rejected ,
  501. TriggerMessageStatus_NotImplemented
  502. } TriggerMessageStatus;
  503. static char * TriggerMessageStatusStr[] = {
  504. MACROSTR(Accepted),
  505. MACROSTR(Rejected),
  506. MACROSTR(NotImplemented)
  507. };
  508. /*UnlockStatus*/
  509. typedef enum {
  510. Unlocked,
  511. UnlockFailed,
  512. UnlockStatus_NotSupported
  513. } UnlockStatus;
  514. static char * UnlockStatusStr[] = {
  515. MACROSTR(Unlocked),
  516. MACROSTR(UnlockFailed),
  517. MACROSTR(NotSupported)
  518. };
  519. /*StopTransactionReason*/
  520. typedef enum {
  521. EmergencyStop,
  522. EVDisconnected,
  523. HardReset,
  524. Local,
  525. Other,
  526. PowerLoss,
  527. Reboot,
  528. Remote,
  529. SoftReset,
  530. UnlockCommand,
  531. DeAuthorized
  532. } StopTransactionReason;
  533. #if 0
  534. static char * StopTransactionReasonStr[] = {
  535. MACROSTR(EmergencyStop),
  536. MACROSTR(EVDisconnected),
  537. MACROSTR(HardReset),
  538. MACROSTR(Local),
  539. MACROSTR(Other),
  540. MACROSTR(PowerLoss),
  541. MACROSTR(Reboot),
  542. MACROSTR(Remote),
  543. MACROSTR(SoftReset),
  544. MACROSTR(UnlockCommand),
  545. MACROSTR(DeAuthorized)
  546. };
  547. #endif
  548. /*CancelReservationStatus*/
  549. typedef enum {
  550. CancelReservationStatus_Accepted,
  551. CancelReservationStatus_Rejected
  552. } CancelReservationStatus;
  553. static char * CancelReservationStatusStr[] = {
  554. MACROSTR(Accepted),
  555. MACROSTR(Rejected)
  556. };
  557. /*ReadingContext*/
  558. typedef enum {
  559. ReadingContext_Interruption_Begin,
  560. ReadingContext_Interruption_End,
  561. ReadingContext_Other,
  562. ReadingContext_Sample_Clock,
  563. ReadingContext_Sample_Periodic ,
  564. ReadingContext_Transaction_Begin ,
  565. ReadingContext_Transaction_End,
  566. ReadingContext_Trigger
  567. } ReadingContext;
  568. static char * ReadingContextStr[] = {
  569. MACROSTR(Interruption.Begin),
  570. MACROSTR(Interruption.End),
  571. MACROSTR(Other),
  572. MACROSTR(Sample.Clock),
  573. MACROSTR(Sample.Periodic),
  574. MACROSTR(Transaction.Begin),
  575. MACROSTR(Transaction.End),
  576. MACROSTR(Trigger)
  577. };
  578. /*ValueFormat*/
  579. typedef enum {
  580. Raw,
  581. SignedData
  582. } ValueFormat;
  583. static char * ValueFormatStr[] = {
  584. MACROSTR(Raw),
  585. MACROSTR(SignedData)
  586. };
  587. /*Measurand*/
  588. typedef enum {
  589. Current_Export ,
  590. Current_Import,
  591. Current_Offered,
  592. Energy_Active_Export_Register,
  593. Energy_Active_Import_Register,
  594. Energy_Reactive_Export_Register,
  595. Energy_Reactive_Import_Register,
  596. Energy_Active_Export_Interval,
  597. Energy_Active_Import_Interval,
  598. Energy_Reactive_Export_Interval,
  599. Energy_Reactive_Import_Interval,
  600. Frequency,
  601. Power_Active_Export ,
  602. Power_Active_Import,
  603. Power_Factor,
  604. Power_Offered,
  605. Power_Reactive_Export,
  606. Power_Reactive_Import,
  607. RPM,
  608. SoC,
  609. Temperature ,
  610. Voltage
  611. } Measurand;
  612. static char * MeasurandStr[] = {
  613. MACROSTR(Current.Export),
  614. MACROSTR(Current.Import),
  615. MACROSTR(Current.Offered),
  616. MACROSTR(Energy.Active.Export.Register),
  617. MACROSTR(Energy.Active.Import.Register),
  618. MACROSTR(Energy.Reactive.Export.Register),
  619. MACROSTR(Energy.Reactive.Import.Register),
  620. MACROSTR(Energy.Active.Export.Interval),
  621. MACROSTR(Energy.Active.Import.Interval),
  622. MACROSTR(Energy.Reactive.Export.Interval),
  623. MACROSTR(Energy.Reactive.Import.Interval),
  624. MACROSTR(Frequency),
  625. MACROSTR(Power.Active.Export),
  626. MACROSTR(Power.Active.Import),
  627. MACROSTR(Power.Factor),
  628. MACROSTR(Power.Offered),
  629. MACROSTR(Power.Reactive.ExportMACROSTR),
  630. MACROSTR(Power.Reactive.Import),
  631. MACROSTR(RPM),
  632. MACROSTR(SoC),
  633. MACROSTR(Temperature),
  634. MACROSTR(Voltage)
  635. };
  636. /*Location*/
  637. typedef enum {
  638. Location_Body,
  639. Location_Cable,
  640. Location_EV,
  641. Location_Inlet ,
  642. Location_Outlet
  643. } Location;
  644. static char * LocationStr[] = {
  645. MACROSTR(Body),
  646. MACROSTR(Cable),
  647. MACROSTR(EV),
  648. MACROSTR(Inlet),
  649. MACROSTR(Outlet)
  650. };
  651. /*Phase*/
  652. typedef enum {
  653. L1,
  654. L2,
  655. L3,
  656. N,
  657. L1_N,
  658. L2_N,
  659. L3_N,
  660. L1_L2,
  661. L2_L3,
  662. L3_L1
  663. } Phase;
  664. static char * PhaseStr[] = {
  665. MACROSTR(L1),
  666. MACROSTR(L2),
  667. MACROSTR(L3),
  668. MACROSTR(N),
  669. MACROSTR(L1-N),
  670. MACROSTR(L2-N),
  671. MACROSTR(L3-N),
  672. MACROSTR(L1-L2),
  673. MACROSTR(L2-L3),
  674. MACROSTR(L3-L1)
  675. };
  676. /*UnitOfMeasure*/
  677. typedef enum {
  678. UnitOfMeasure_Wh,
  679. UnitOfMeasure_kWh ,
  680. UnitOfMeasure_varh ,
  681. UnitOfMeasure_kvarh ,
  682. UnitOfMeasure_W ,
  683. UnitOfMeasure_kW ,
  684. UnitOfMeasure_VA ,
  685. UnitOfMeasure_kVA ,
  686. UnitOfMeasure_var ,
  687. UnitOfMeasure_kvar ,
  688. UnitOfMeasure_A ,
  689. UnitOfMeasure_V ,
  690. UnitOfMeasure_Celsius ,
  691. UnitOfMeasure_Fahrenheit ,
  692. UnitOfMeasure_K ,
  693. UnitOfMeasure_Percent
  694. } UnitOfMeasure;
  695. static char * UnitOfMeasureStr[] = {
  696. MACROSTR(Wh),
  697. MACROSTR(kWh),
  698. MACROSTR(varh),
  699. MACROSTR(kvarh),
  700. MACROSTR(W),
  701. MACROSTR(kW),
  702. MACROSTR(VA),
  703. MACROSTR(kVA),
  704. MACROSTR(var),
  705. MACROSTR(kvar),
  706. MACROSTR(A),
  707. MACROSTR(V),
  708. MACROSTR(Celsius),
  709. MACROSTR(Fahrenheit),
  710. MACROSTR(K),
  711. MACROSTR(Percent)
  712. };
  713. #if 0
  714. /*Configuration enum*/
  715. enum CoreProfile {
  716. AllowOfflineTxForUnknownId=0,
  717. AuthorizationCacheEnabled,
  718. AuthorizeRemoteTxRequests,
  719. BlinkRepeat,
  720. ClockAlignedDataInterval,
  721. ConnectionTimeOut,
  722. GetConfigurationMaxKeys,
  723. HeartbeatInterval,
  724. LightIntensity,
  725. LocalAuthorizeOffline,
  726. LocalPreAuthorize,
  727. MaxEnergyOnInvalidId,
  728. MeterValuesAlignedData,
  729. MeterValuesAlignedDataMaxLength,
  730. MeterValuesSampledData,
  731. MeterValuesSampledDataMaxLength,
  732. MeterValueSampleInterval,
  733. MinimumStatusDuration,
  734. NumberOfConnectors,
  735. ResetRetries,
  736. ConnectorPhaseRotation,
  737. ConnectorPhaseRotationMaxLength,
  738. StopTransactionOnEVSideDisconnect,
  739. StopTransactionOnInvalidId,
  740. StopTxnAlignedData,
  741. StopTxnAlignedDataMaxLength,
  742. StopTxnSampledData,
  743. StopTxnSampledDataMaxLength,
  744. SupportedFeatureProfiles,
  745. SupportedFeatureProfilesMaxLength,
  746. TransactionMessageAttempts,
  747. TransactionMessageRetryInterval,
  748. UnlockConnectorOnEVSideDisconnect,
  749. WebSocketPingInterval,
  750. _CoreProfile_CNT
  751. };
  752. #endif
  753. enum LocalAuthListManagementProfile{
  754. LocalAuthListEnabled=0,
  755. LocalAuthListMaxLength,
  756. SendLocalListMaxLength,
  757. _LocalAuthListManagementProfile_CNT
  758. };
  759. enum ReservationProfile{
  760. ReserveConnectorZeroSupported
  761. };
  762. enum SmartChargingProfile{
  763. ChargeProfileMaxStackLevel,
  764. ChargingScheduleAllowedChargingRateUnit,
  765. ChargingScheduleMaxPeriods,
  766. ConnectorSwitch3to1PhaseSupported,
  767. MaxChargingProfilesInstalled
  768. };
  769. enum ChargerSystemStatus{
  770. ChargerSystemStatus_Booting,
  771. ChargerSystemStatus_Idle,
  772. ChargerSystemStatus_Authorizing,
  773. ChargerSystemStatus_Preparing,
  774. ChargerSystemStatus_Charging,
  775. ChargerSystemStatus_Terminating,
  776. ChargerSystemStatus_Alarm,
  777. ChargerSystemStatus_Fault
  778. };
  779. enum GetConfigurationKey {
  780. GetConfiguration_AllowOfflineTxForUnknownId=0,
  781. GetConfiguration_AuthorizationCacheEnabled,
  782. GetConfiguration_AuthorizeRemoteTxRequests,
  783. GetConfiguration_BlinkRepeat,
  784. GetConfiguration_ClockAlignedDataInterval,
  785. GetConfiguration_ConnectionTimeOut,
  786. GetConfiguration_GetConfigurationMaxKeys,
  787. GetConfiguration_HeartbeatInterval,
  788. GetConfiguration_LightIntensity,
  789. GetConfiguration_LocalAuthorizeOffline,
  790. GetConfiguration_LocalPreAuthorize,
  791. GetConfiguration_MaxEnergyOnInvalidId,
  792. GetConfiguration_MeterValuesAlignedData,
  793. GetConfiguration_MeterValuesAlignedDataMaxLength,
  794. GetConfiguration_MeterValuesSampledData,
  795. GetConfiguration_MeterValuesSampledDataMaxLength,
  796. GetConfiguration_MeterValueSampleInterval,
  797. GetConfiguration_MinimumStatusDuration,
  798. GetConfiguration_NumberOfConnectors,
  799. GetConfiguration_ResetRetries,
  800. GetConfiguration_ConnectorPhaseRotation,
  801. GetConfiguration_ConnectorPhaseRotationMaxLength,
  802. GetConfiguration_StopTransactionOnEVSideDisconnect,
  803. GetConfiguration_StopTransactionOnInvalidId,
  804. GetConfiguration_StopTxnAlignedData,
  805. GetConfiguration_StopTxnAlignedDataMaxLength,
  806. GetConfiguration_StopTxnSampledData,
  807. GetConfiguration_StopTxnSampledDataMaxLength,
  808. GetConfiguration_SupportedFeatureProfiles,
  809. GetConfiguration_SupportedFeatureProfilesMaxLength,
  810. GetConfiguration_TransactionMessageAttempts,
  811. GetConfiguration_TransactionMessageRetryInterval,
  812. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  813. GetConfiguration_WebSocketPingInterval,
  814. GetConfiguration_LocalAuthListEnabled,
  815. GetConfiguration_LocalAuthListMaxLength,
  816. GetConfiguration_SendLocalListMaxLength,
  817. GetConfiguration_ReserveConnectorZeroSupported,
  818. GetConfiguration_ChargeProfileMaxStackLevel,
  819. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  820. GetConfiguration_ChargingScheduleMaxPeriods,
  821. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  822. GetConfiguration_MaxChargingProfilesInstalled,
  823. };
  824. //GetConfiguration Array
  825. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  826. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  827. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  828. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  829. //==========================================
  830. // Init all share memory
  831. //==========================================
  832. int InitShareMemory()
  833. {
  834. int result = PASS;
  835. int MeterSMId;
  836. //creat ShmSysConfigAndInfo
  837. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  838. {
  839. #ifdef SystemLogMessage
  840. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  841. #endif
  842. result = FAIL;
  843. }
  844. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  845. {
  846. #ifdef SystemLogMessage
  847. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  848. #endif
  849. result = FAIL;
  850. }
  851. else
  852. {}
  853. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  854. {
  855. #ifdef SystemLogMessage
  856. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  857. #endif
  858. result = FAIL;
  859. }
  860. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  861. {
  862. #ifdef SystemLogMessage
  863. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  864. #endif
  865. result = FAIL;
  866. }
  867. else
  868. {}
  869. //creat ShmPsuData
  870. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  871. {
  872. #ifdef SystemLogMessage
  873. DEBUG_ERROR("shmget ShmPsuData NG\n");
  874. #endif
  875. result = FAIL;
  876. }
  877. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  878. {
  879. #ifdef SystemLogMessage
  880. DEBUG_ERROR("shmat ShmPsuData NG\n");
  881. #endif
  882. result = FAIL;
  883. }
  884. else
  885. {}
  886. //creat ShmOCPP16Data
  887. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  888. {
  889. #ifdef SystemLogMessage
  890. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  891. #endif
  892. result = FAIL;
  893. }
  894. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  895. {
  896. #ifdef SystemLogMessage
  897. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  898. #endif
  899. result = FAIL;
  900. }
  901. else
  902. {}
  903. /****************************** For Initial Settings************************************************/
  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. //offline MeterValue Interval
  912. TempMeterValueInterval = 0;
  913. return result;
  914. }
  915. int ProcessShareMemory()
  916. {
  917. if(InitShareMemory() == FAIL)
  918. {
  919. #ifdef SystemLogMessage
  920. DEBUG_ERROR("InitShareMemory NG\n");
  921. #endif
  922. if(ShmStatusCodeData!=NULL)
  923. {
  924. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  925. }
  926. sleep(5);
  927. return FAIL;
  928. }
  929. return PASS;
  930. }
  931. //---------------------common routine---------------------------//
  932. char * stringtrim( char * s )
  933. {
  934. char * p1 = s;
  935. char * p2 = s;
  936. while(*p1 != '\0')
  937. {
  938. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  939. {
  940. if(*p1 != ',')
  941. {
  942. p1 ++;
  943. }
  944. else
  945. {
  946. break;
  947. }
  948. }
  949. if(*p1 != ',')
  950. {
  951. * p2 ++ = *p1 ++;
  952. //printf("p2=%s\n",p2);
  953. }
  954. else
  955. {
  956. break;
  957. }
  958. }
  959. *p2 = '\0';
  960. return (s);
  961. }
  962. char * stringtrimspace( char * s )
  963. {
  964. char * p1 = s;
  965. char * p2 = s;
  966. while(*p1 != '\0')
  967. {
  968. while(*p1 == ' ') //while(*p1 == ' ' || *p1 == '\t' || *p1 == '\n' || *p1 == '\r')
  969. {
  970. p1 ++;
  971. }
  972. * p2 ++ = *p1 ++;
  973. //printf("p2=%s\n",p2);
  974. }
  975. *p2 = '\0';
  976. return (s);
  977. }
  978. int isOFFline(void)
  979. {
  980. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  981. {
  982. if(TempMeterValueInterval >= 2 )
  983. {
  984. TempMeterValueInterval = 0;
  985. return TRUE;
  986. }
  987. else
  988. {
  989. TempMeterValueInterval = TempMeterValueInterval+ 1;
  990. return FALSE;
  991. }
  992. }
  993. else
  994. {
  995. return FALSE;
  996. }
  997. }
  998. //---------------------------------------------
  999. // new:
  1000. // enum SYSTEM_STATUS
  1001. // {
  1002. // SYS_MODE_BOOTING = 0,
  1003. // SYS_MODE_IDLE = 1,
  1004. // SYS_MODE_AUTHORIZING = 2,
  1005. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1006. // SYS_MODE_REASSIGN = 4,
  1007. // SYS_MODE_PREPARING = 5,
  1008. // SYS_MODE_PREPARE_FOR_EV = 6,
  1009. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1010. // SYS_MODE_CHARGING = 8,
  1011. // SYS_MODE_TERMINATING = 9,
  1012. // SYS_MODE_COMPLETE = 10,
  1013. // SYS_MODE_ALARM = 11,
  1014. // SYS_MODE_FAULT = 12,
  1015. // SYS_MODE_RESERVATION = 13,
  1016. // SYS_MODE_BOOKING = 14,
  1017. // SYS_MODE_MAINTAIN = 15,
  1018. // SYS_MODE_DEBUG = 16,
  1019. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1020. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1021. // SYS_MODE_UPDATE = 19
  1022. // };
  1023. //
  1024. //
  1025. //-----------------------------------------
  1026. void CheckSystemValue(void)
  1027. {
  1028. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1029. //int IdleModeCnt = 0;
  1030. char filenmae[100]={0};
  1031. char str[100]={0};
  1032. //===============================
  1033. // send Heartbeat
  1034. //===============================
  1035. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1036. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1037. {
  1038. clientTime.Heartbeat=time((time_t*)NULL);
  1039. if(server_sign == TRUE)
  1040. {
  1041. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1042. }
  1043. else
  1044. {
  1045. HeartBeatWaitTime = 10;
  1046. }
  1047. }
  1048. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1049. {
  1050. DEBUG_INFO("Heartbeat !!!\n");
  1051. //parameter for test
  1052. sendHeartbeatRequest(0);
  1053. //==============================================
  1054. // Reset Waiting Time
  1055. //==============================================
  1056. clientTime.Heartbeat=time((time_t*)NULL);
  1057. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1058. }
  1059. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1060. {
  1061. //===============================
  1062. // CSU Trigger Reset Conf
  1063. //===============================
  1064. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1065. {
  1066. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1067. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1068. {
  1069. server_sign = FALSE;
  1070. }
  1071. }
  1072. //===============================
  1073. // CSU Trigger Authorize Request
  1074. //===============================
  1075. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1076. {
  1077. sendAuthorizeRequest(0);
  1078. authorizeRetryTimes = authorizeRetryTimes + 1;
  1079. if(authorizeRetryTimes < 3)
  1080. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1081. }
  1082. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1083. {
  1084. authorizeRetryTimes = 0;
  1085. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1086. server_sign = FALSE;
  1087. }
  1088. else if((server_sign == FALSE) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  1089. {
  1090. sendAuthorizeRequest(0);
  1091. }
  1092. //===============================
  1093. // CSU Trigger Smart Charging Profilw
  1094. //===============================
  1095. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1096. {
  1097. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1098. GetChargingProfileRequest(gun_index);
  1099. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1100. }
  1101. //==============================================
  1102. // Charger start transaction
  1103. //==============================================
  1104. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1105. {
  1106. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1107. sendStartTransactionRequest(gun_index);
  1108. clientTime.StartTransaction = time((time_t*)NULL);
  1109. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1110. }
  1111. //==============================================
  1112. // Charger stop transaction
  1113. //==============================================
  1114. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1115. {
  1116. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1117. sendStopTransactionRequest(gun_index);
  1118. clientTime.StopTransaction = time((time_t*)NULL);
  1119. }
  1120. //==============================================
  1121. // Charger status report
  1122. //==============================================
  1123. //--- Check Mode Change ---//
  1124. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1125. if(gunType[gun_index] == 'J')
  1126. {
  1127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1128. {
  1129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1130. {
  1131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1132. {
  1133. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1134. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1135. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1136. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1137. statusModeChage[gun_index] = TRUE;
  1138. }
  1139. #if 1 // for TempStopTransaction
  1140. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1141. {
  1142. checkTempStopTransaction(gun_index);
  1143. }
  1144. #endif
  1145. }
  1146. }
  1147. }
  1148. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//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. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. #if 1 // for TempStopTransaction
  1163. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1164. {
  1165. checkTempStopTransaction(gun_index);
  1166. }
  1167. #endif
  1168. }
  1169. }
  1170. }
  1171. else if(gunType[gun_index] == 'G')
  1172. {
  1173. for (int index = 0; index < GB_QUANTITY; index++)
  1174. {
  1175. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1176. {
  1177. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1178. {
  1179. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1180. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1181. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1182. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1183. statusModeChage[gun_index] = TRUE;
  1184. }
  1185. #if 1 // for TempStopTransaction
  1186. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1187. {
  1188. checkTempStopTransaction(gun_index);
  1189. }
  1190. #endif
  1191. }
  1192. }
  1193. }
  1194. else
  1195. {
  1196. for (int index = 0; index < AC_QUANTITY; index++)
  1197. {
  1198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1199. {
  1200. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1201. {
  1202. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1203. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1204. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1205. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1206. statusModeChage[gun_index] = TRUE;
  1207. }
  1208. #if 1 // for TempStopTransaction
  1209. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1210. {
  1211. checkTempStopTransaction(gun_index);
  1212. }
  1213. #endif
  1214. }
  1215. }// END
  1216. }
  1217. if(((SystemInitial > 0)&& (server_sign == TRUE))||
  1218. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1219. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1220. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1221. {
  1222. if(SystemInitial > 0)
  1223. SystemInitial = SystemInitial -1;
  1224. sendStatusNotificationRequest(gun_index);
  1225. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1226. statusModeChage[gun_index] = FALSE;
  1227. DEBUG_INFO("SystemInitial=%d !!!\n",SystemInitial);
  1228. //DEBUG_INFO("difftime(time((time_t*)NULL), clientTime.Heartbeat)=%d !!!\n",difftime(time((time_t*)NULL), clientTime.Heartbeat));
  1229. //DEBUG_INFO("HeartBeatWaitTime=%d !!!\n",HeartBeatWaitTime);
  1230. //DEBUG_INFO("ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval=%d !!!\n",ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  1231. }
  1232. //==============================================
  1233. // Meter report
  1234. //==============================================
  1235. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) || ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1236. {
  1237. DEBUG_INFO("Sent Meter Value\n");
  1238. //check Transaction active
  1239. if(gunType[gun_index] == 'J')
  1240. {
  1241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1242. {
  1243. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1244. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1245. {
  1246. meterValueSend[gun_index] =1;
  1247. }
  1248. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1249. {
  1250. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1251. if((access(filenmae,F_OK))!=-1)
  1252. {
  1253. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1254. sprintf(str,"rm -f %s",filenmae);
  1255. system(str);
  1256. }
  1257. }
  1258. }// End for CHAdeMO
  1259. }
  1260. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1261. {
  1262. for (int index = 0; index < CCS_QUANTITY; index++)
  1263. {
  1264. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1265. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1266. {
  1267. meterValueSend[gun_index] =1;
  1268. }
  1269. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1270. {
  1271. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1272. if((access(filenmae,F_OK))!=-1)
  1273. {
  1274. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1275. sprintf(str,"rm -f %s",filenmae);
  1276. system(str);
  1277. }
  1278. }
  1279. } // End for CCS
  1280. }
  1281. else if(gunType[gun_index] == 'G')
  1282. {
  1283. for (int index = 0; index < GB_QUANTITY; index++)
  1284. {
  1285. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1286. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1287. {
  1288. meterValueSend[gun_index] =1;
  1289. }
  1290. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1291. {
  1292. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1293. if((access(filenmae,F_OK))!=-1)
  1294. {
  1295. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1296. sprintf(str,"rm -f %s",filenmae);
  1297. system(str);
  1298. }
  1299. }
  1300. }// End for GB
  1301. }
  1302. else
  1303. {
  1304. for (int index = 0; index < AC_QUANTITY; index++)
  1305. {
  1306. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1307. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1308. {
  1309. meterValueSend[gun_index] =1;
  1310. }
  1311. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1312. {
  1313. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1314. if((access(filenmae,F_OK))!=-1)
  1315. {
  1316. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1317. sprintf(str,"rm -f %s",filenmae);
  1318. system(str);
  1319. }
  1320. }
  1321. }//End for AC
  1322. }
  1323. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1324. if(meterValueSend[gun_index] == 1)
  1325. {
  1326. sendMeterValuesRequest(gun_index);
  1327. #if 1 // for TempStopTransaction
  1328. storeTempStopTransaction(gun_index);
  1329. #endif
  1330. }
  1331. }
  1332. //==============================================
  1333. // Check Connector reserved
  1334. //==============================================
  1335. //===============================
  1336. // Check if Reserve is expired
  1337. //===============================
  1338. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1339. {
  1340. double diff_t;
  1341. struct tm tp;
  1342. // current time
  1343. time_t t = time(NULL);
  1344. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1345. tp.tm_isdst = -1;
  1346. time_t utc = mktime(&tp);
  1347. diff_t = difftime(utc, t);
  1348. if(diff_t <= 0)
  1349. {
  1350. DEBUG_INFO("reserve expired !!! \n");
  1351. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1352. }
  1353. }//END OF Check if Reserve is expired
  1354. //==========================================
  1355. // csu trigger FirmwareStatusNotificationReq
  1356. //==========================================
  1357. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1358. {
  1359. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1360. }
  1361. //==========================================
  1362. // csu trigger CancelReservationConf
  1363. //==========================================
  1364. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1365. {
  1366. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1367. }
  1368. //==========================================
  1369. // csu trigger ChangeAvailabilityConf
  1370. //==========================================
  1371. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1372. {
  1373. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1374. }
  1375. //==========================================
  1376. // csu trigger UnlockConnectorConf
  1377. //==========================================
  1378. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1379. {
  1380. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1381. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1382. }
  1383. //==========================================
  1384. // csu trigger ReserveNowConf
  1385. //==========================================
  1386. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1387. {
  1388. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1389. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1390. }
  1391. //==========================================
  1392. // csu trigger DataTransferReq
  1393. //==========================================
  1394. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1395. {
  1396. sendDataTransferRequest(gun_index);
  1397. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1398. }
  1399. }
  1400. }
  1401. //==========================================
  1402. // send request routine
  1403. //==========================================
  1404. int sendAuthorizeRequest(int gun_index)
  1405. {
  1406. mtrace();
  1407. int result = FAIL;
  1408. char message[100]={0};
  1409. char guid[37];
  1410. char tempdata[65]={0};
  1411. DEBUG_INFO("sendAuthorizeRequest \n");
  1412. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1413. //Local Authorize
  1414. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1415. {
  1416. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1417. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1418. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1419. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1420. result = PASS;
  1421. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1422. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1423. authorizeRetryTimes = 0;
  1424. return result;
  1425. }
  1426. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  1427. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1428. {
  1429. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1430. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1431. {
  1432. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1433. {
  1434. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1435. }
  1436. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1437. {
  1438. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1439. }
  1440. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1441. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1442. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1443. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1444. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1445. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1446. authorizeRetryTimes = 0;
  1447. return result;
  1448. }
  1449. else
  1450. {
  1451. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1452. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1453. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1454. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1455. result = PASS;
  1456. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1457. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1458. authorizeRetryTimes = 0;
  1459. return result;
  1460. }
  1461. }
  1462. //initailize struct Authorize
  1463. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1464. //get data from shared memory
  1465. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1466. random_uuid(guid);
  1467. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1468. LWS_Send(message);
  1469. sprintf(tempdata, "Authorize,%d", gun_index);
  1470. if(hashmap_operation(0, guid, tempdata) == 1)
  1471. {
  1472. result = PASS;
  1473. DEBUG_ERROR("Authorize mapItem pass\n");
  1474. }
  1475. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1476. return result;
  1477. }
  1478. int sendBootNotificationRequest(void)
  1479. {
  1480. mtrace();
  1481. int result = FAIL;
  1482. char message[500]={0}, payload[700]={0};
  1483. char guid[37]={0};
  1484. char tempdata[65]={0};
  1485. int IsGunCharging = FALSE;
  1486. //check Transaction active
  1487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1488. {
  1489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1490. {
  1491. IsGunCharging = TRUE;
  1492. }
  1493. }
  1494. for (int index = 0; index < CCS_QUANTITY; index++)
  1495. {
  1496. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1497. {
  1498. IsGunCharging = TRUE;
  1499. }
  1500. }
  1501. for (int index = 0; index < GB_QUANTITY; index++)
  1502. {
  1503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1504. {
  1505. IsGunCharging = TRUE;
  1506. }
  1507. }
  1508. for (int index = 0; index < AC_QUANTITY; index++)
  1509. {
  1510. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1511. {
  1512. IsGunCharging = TRUE;
  1513. }
  1514. }
  1515. if(IsGunCharging == TRUE)
  1516. {
  1517. server_sign = TRUE;
  1518. return result;
  1519. }
  1520. // Fill BootNotification fields
  1521. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1522. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1523. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1524. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1525. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1526. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1527. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1528. #if 0
  1529. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1530. ShmOCPP16Data->ChargeBoxId
  1531. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1532. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1533. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1534. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1535. ,ShmOCPP16Data->BootNotification.CpIccid
  1536. ,ShmOCPP16Data->BootNotification.CpImsi
  1537. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1538. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1539. #endif
  1540. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1541. ShmOCPP16Data->ChargeBoxId
  1542. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1543. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1544. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1545. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1546. ,ShmOCPP16Data->BootNotification.CpIccid
  1547. ,ShmOCPP16Data->BootNotification.CpImsi);
  1548. random_uuid(guid);
  1549. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1550. LWS_Send(message);
  1551. sprintf(tempdata, "BootNotification,0");
  1552. 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*/)
  1553. {
  1554. result = PASS;
  1555. }
  1556. memset(queuedata, 0, sizeof(queuedata));
  1557. strcpy(queuedata,message);
  1558. return result;
  1559. }
  1560. int sendDataTransferRequest(int gun_index)
  1561. {
  1562. mtrace();
  1563. char message[1000]={0};
  1564. char guid[37]={0};
  1565. char tempdata[65]={0};
  1566. int result = FAIL;
  1567. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1568. random_uuid(guid);
  1569. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1570. MESSAGE_TYPE_CALL,
  1571. guid,
  1572. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1573. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1574. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1575. LWS_Send(message);
  1576. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1577. 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*/)
  1578. {
  1579. result = PASS;
  1580. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1581. }
  1582. return result;
  1583. }
  1584. int sendDiagnosticsStatusNotificationRequest(char *status)
  1585. {
  1586. mtrace();
  1587. int result = FAIL;
  1588. char message[110]={0};
  1589. char guid[37]={0};
  1590. char tempdata[65]={0};
  1591. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1592. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1593. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1594. random_uuid(guid);
  1595. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1596. LWS_Send(message);
  1597. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1598. if(hashmap_operation(0, guid, tempdata) == 1)
  1599. {
  1600. result = PASS;
  1601. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1602. }
  1603. //#ifdef SystemLogMessage
  1604. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1605. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1606. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1607. //#endif
  1608. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1609. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1610. //record status
  1611. if(strcmp(status,"Idle")==0)
  1612. {
  1613. DiagnosticsStatusNotificationStatus = 0;
  1614. }
  1615. else if(strcmp(status,"Uploaded")==0)
  1616. {
  1617. DiagnosticsStatusNotificationStatus = 1;
  1618. }
  1619. else if(strcmp(status,"UploadFailed")==0)
  1620. {
  1621. DiagnosticsStatusNotificationStatus = 2;
  1622. }
  1623. else if(strcmp(status,"Uploading")==0)
  1624. {
  1625. DiagnosticsStatusNotificationStatus = 3;
  1626. }
  1627. return result;
  1628. }
  1629. int sendFirmwareStatusNotificationRequest(char *status)
  1630. {
  1631. mtrace();
  1632. int result = FAIL;
  1633. char message[110]={0};
  1634. char guid[37]={0};
  1635. char tempdata[65]={0};
  1636. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1637. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1638. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1639. random_uuid(guid);
  1640. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1641. LWS_Send(message);
  1642. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1643. 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*/)
  1644. {
  1645. result = PASS;
  1646. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1647. }
  1648. //#ifdef SystemLogMessage
  1649. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1650. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1651. //#endif
  1652. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1653. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1654. //record status
  1655. if(strcmp(status,"Downloaded")==0)
  1656. {
  1657. FirmwareStatusNotificationStatus = 0;
  1658. }
  1659. else if(strcmp(status,"DownloadFailed")==0)
  1660. {
  1661. FirmwareStatusNotificationStatus = 1;
  1662. }
  1663. else if(strcmp(status,"Downloading")==0)
  1664. {
  1665. FirmwareStatusNotificationStatus = 2;
  1666. }
  1667. else if(strcmp(status,"Idle")==0)
  1668. {
  1669. FirmwareStatusNotificationStatus = 3;
  1670. }
  1671. else if(strcmp(status,"InstallationFailed")==0)
  1672. {
  1673. FirmwareStatusNotificationStatus = 4;
  1674. }
  1675. else if(strcmp(status,"Installing")==0)
  1676. {
  1677. FirmwareStatusNotificationStatus = 5;
  1678. }
  1679. else if(strcmp(status,"Installed")==0)
  1680. {
  1681. FirmwareStatusNotificationStatus = 6;
  1682. }
  1683. return result;
  1684. }
  1685. int sendHeartbeatRequest(int gun_index)
  1686. {
  1687. mtrace();
  1688. int result = FAIL;
  1689. char message[80]={0};
  1690. char guid[37]={0};
  1691. char tempdata[65]={0};
  1692. random_uuid(guid);
  1693. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1694. , MESSAGE_TYPE_CALL
  1695. , guid );
  1696. LWS_Send(message);
  1697. sprintf(tempdata, "Heartbeat,%d", 0);
  1698. 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*/)
  1699. {
  1700. result = PASS;
  1701. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1702. }
  1703. return result;
  1704. }
  1705. int sendStartTransactionRequest(int gun_index)
  1706. {
  1707. mtrace();
  1708. int result = FAIL;
  1709. char message[250]={0};
  1710. char guid[37]={0};
  1711. struct timeval tmnow;
  1712. struct tm *tm;
  1713. char buf[28];//, usec_buf[6];
  1714. char tempdata[65]={0};
  1715. int tempIndex = 0;
  1716. DEBUG_INFO("sendStartTransactionRequest...");
  1717. gettimeofday(&tmnow, NULL);
  1718. time_t t;
  1719. t = time(NULL);
  1720. /*UTC time and date*/
  1721. tm = gmtime(&t);
  1722. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1723. #if 0 // remove temporally
  1724. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1725. strcat(buf,".");
  1726. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1727. strcat(buf,usec_buf);
  1728. #endif
  1729. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1730. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1731. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1732. // clear StartTransaction Response
  1733. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1734. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1735. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1736. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1737. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1738. if(gunType[gun_index] == 'J')
  1739. {
  1740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1741. {
  1742. tempIndex = ((gun_index==2) ? 1: 0);
  1743. }
  1744. else
  1745. {
  1746. tempIndex = gun_index;
  1747. }
  1748. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1749. {
  1750. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  1751. {
  1752. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1753. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1754. }
  1755. }
  1756. }
  1757. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1758. {
  1759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1760. {
  1761. tempIndex = ((gun_index==2) ? 1: 0);
  1762. }
  1763. else
  1764. {
  1765. tempIndex = gun_index;
  1766. }
  1767. for (int index = 0; index < CCS_QUANTITY; index++)
  1768. {
  1769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  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. }
  1776. else if(gunType[gun_index] == 'G')
  1777. {
  1778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1779. {
  1780. tempIndex = ((gun_index==2) ? 1: 0);
  1781. }
  1782. else
  1783. {
  1784. tempIndex = gun_index;
  1785. }
  1786. for (int index = 0; index < GB_QUANTITY; index++)
  1787. {
  1788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1789. {
  1790. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1791. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1792. }
  1793. }
  1794. }
  1795. else
  1796. {
  1797. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1798. {
  1799. tempIndex = 2;
  1800. }
  1801. else
  1802. {
  1803. tempIndex = gun_index;
  1804. }
  1805. for (int index = 0; index < AC_QUANTITY; index++)
  1806. {
  1807. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1808. {
  1809. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  1810. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1811. }
  1812. }
  1813. }
  1814. random_uuid(guid);
  1815. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1816. , MESSAGE_TYPE_CALL
  1817. , guid
  1818. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1819. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1820. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1821. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1822. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1823. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1824. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1825. {
  1826. result = PASS;
  1827. }
  1828. strcpy(queuedata, message);
  1829. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1830. if(GetTransactionQueueNum() == 1)
  1831. {
  1832. LWS_Send(message);
  1833. }
  1834. return result;
  1835. }
  1836. int sendStatusNotificationRequest(int gun_index)
  1837. {
  1838. mtrace();
  1839. int result = FAIL;
  1840. char message[600]={0};
  1841. char guid[37];
  1842. int currentStatus = 0;
  1843. struct timeval tmnow;
  1844. struct tm *tm;
  1845. char buf[28];//, usec_buf[6];
  1846. char tempdata[65]={0};
  1847. int tempIndex = 0;
  1848. gettimeofday(&tmnow, NULL);
  1849. time_t t;
  1850. t = time(NULL);
  1851. /*UTC time and date*/
  1852. tm = gmtime(&t);
  1853. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1854. #if 0 // remove temporally
  1855. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1856. strcat(buf,".");
  1857. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1858. strcat(buf,usec_buf);
  1859. #endif
  1860. printf("%s",buf);
  1861. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1862. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1863. // it's option
  1864. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1865. /*
  1866. enum _SYSTEM_STATUS
  1867. {
  1868. S_BOOTING = 0,
  1869. S_IDLE, = 1
  1870. S_AUTHORIZING, =2
  1871. S_REASSIGN_CHECK, =3
  1872. S_REASSIGN, =4
  1873. S_PRECHARGE, =5
  1874. S_PREPARING_FOR_EV, =6
  1875. S_PREPARING_FOR_EVSE, =7
  1876. S_CHARGING, =8
  1877. S_TERMINATING, =9
  1878. S_COMPLETE, =10
  1879. S_ALARM, =11
  1880. S_FAULT =12
  1881. }
  1882. */
  1883. //check Transaction active
  1884. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1885. if(gunType[gun_index] == 'J')
  1886. {
  1887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1888. {
  1889. tempIndex = ((gun_index==2) ? 1: 0);
  1890. }
  1891. else
  1892. {
  1893. tempIndex = gun_index;
  1894. }
  1895. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1896. {
  1897. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1898. {
  1899. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  1900. {
  1901. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1902. {
  1903. currentStatus = 1; //OCPP Status: Preparing
  1904. }
  1905. else
  1906. {
  1907. currentStatus = 0; //OCPP Status: Available
  1908. }
  1909. }
  1910. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1911. {
  1912. currentStatus = 1; //OCPP Status: Preparing
  1913. }
  1914. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1915. {
  1916. currentStatus = 2; //OCPP Status: Charging
  1917. }
  1918. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1919. {
  1920. currentStatus = 5; //OCPP Status: Finishing
  1921. }
  1922. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  1923. {
  1924. currentStatus = 4; //OCPP Status: SuspendedEV
  1925. }
  1926. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  1927. {
  1928. currentStatus = 7; //OCPP Status: Unavailable
  1929. }
  1930. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  1931. {
  1932. currentStatus = 8; //OCPP Status: Faulted
  1933. }
  1934. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1935. {
  1936. currentStatus = 6; //OCPP Status: Reserved
  1937. }
  1938. } //end of the same index
  1939. }//end of for CHAdeMO_QUANTITY
  1940. }
  1941. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1942. {
  1943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1944. {
  1945. tempIndex = ((gun_index==2) ? 1: 0);
  1946. }
  1947. else
  1948. {
  1949. tempIndex = gun_index;
  1950. }
  1951. for (int index = 0; index < CCS_QUANTITY; index++)
  1952. {
  1953. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1954. {
  1955. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1956. {
  1957. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1958. {
  1959. currentStatus = 1; //OCPP Status: Preparing
  1960. }
  1961. else
  1962. {
  1963. currentStatus = 0; //OCPP Status: Available
  1964. }
  1965. }
  1966. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1967. {
  1968. currentStatus = 1; //OCPP Status: Preparing
  1969. }
  1970. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1971. {
  1972. currentStatus = 2; //OCPP Status: Charging
  1973. }
  1974. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1975. {
  1976. currentStatus = 5; //OCPP Status: Finishing
  1977. }
  1978. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  1979. {
  1980. currentStatus = 4; //OCPP Status: SuspendedEV
  1981. }
  1982. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  1983. {
  1984. currentStatus = 7; //OCPP Status : Unavailable
  1985. }
  1986. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  1987. {
  1988. currentStatus = 8; //OCPP Status: Faulted
  1989. }
  1990. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1991. {
  1992. currentStatus = 6; //OCPP Status: Reserved
  1993. }
  1994. } //end of the same index
  1995. } // end of for CCS_QUANTITY
  1996. }
  1997. else if(gunType[gun_index] == 'G')
  1998. {
  1999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2000. {
  2001. tempIndex = ((gun_index==2) ? 1: 0);
  2002. }
  2003. else
  2004. {
  2005. tempIndex = gun_index;
  2006. }
  2007. for (int index = 0; index < GB_QUANTITY; index++)
  2008. {
  2009. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2010. {
  2011. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2012. {
  2013. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2014. {
  2015. currentStatus = 1; //OCPP Status: Preparing
  2016. }
  2017. else
  2018. {
  2019. currentStatus = 0; //OCPP Status: Available
  2020. }
  2021. }
  2022. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  2023. {
  2024. currentStatus = 1; //OCPP Status: Preparing
  2025. }
  2026. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2027. {
  2028. currentStatus = 2; //OCPP Status: Charging
  2029. }
  2030. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2031. {
  2032. currentStatus = 5; //OCPP Status: Finishing
  2033. }
  2034. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2035. {
  2036. currentStatus = 4; //OCPP Status: SuspendedEV
  2037. }
  2038. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  2039. {
  2040. currentStatus = 7; //OCPP Status: Unavailable
  2041. }
  2042. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2043. {
  2044. currentStatus = 8; //OCPP Status: Faulted
  2045. }
  2046. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2047. {
  2048. currentStatus = 6; //OCPP Status: Reserved
  2049. }
  2050. } //end of the same index
  2051. } // end of for GB_QUANTITY
  2052. }
  2053. else
  2054. {
  2055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2056. {
  2057. tempIndex = 2;
  2058. }
  2059. else
  2060. {
  2061. tempIndex = gun_index;
  2062. }
  2063. for (int index = 0; index < AC_QUANTITY; index++)
  2064. {
  2065. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2066. {
  2067. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  2068. {
  2069. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  2070. {
  2071. currentStatus = 1; //OCPP Status: Preparing
  2072. }
  2073. else
  2074. {
  2075. currentStatus = 0; //OCPP Status: Available
  2076. }
  2077. }
  2078. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  2079. {
  2080. currentStatus = 1; //OCPP Status: Preparing
  2081. }
  2082. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  2083. {
  2084. currentStatus = 2; //OCPP Status: Charging
  2085. }
  2086. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  2087. {
  2088. currentStatus = 5; //OCPP Status: Finishing
  2089. }
  2090. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2091. {
  2092. currentStatus = 4; //OCPP Status: SuspendedEV
  2093. }
  2094. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  2095. {
  2096. currentStatus = 7; //OCPP Status: Unavailable
  2097. }
  2098. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2099. {
  2100. currentStatus = 8; //OCPP Status: Faulted
  2101. }
  2102. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2103. {
  2104. currentStatus = 6; //OCPP Status: Reserved
  2105. }
  2106. }//end of the same index
  2107. }//end of for AC_QUANTITY
  2108. }
  2109. //it's option
  2110. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2111. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2112. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2113. random_uuid(guid);
  2114. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2115. , MESSAGE_TYPE_CALL
  2116. , guid
  2117. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2118. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2119. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2120. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2121. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2122. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2123. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2124. LWS_Send(message);
  2125. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2126. 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*/)
  2127. {
  2128. //DEBUG_ERROR("statusNotification mapitem pass");
  2129. result = PASS;
  2130. }
  2131. return result;
  2132. }
  2133. int sendStopTransactionRequest(int gun_index)
  2134. {
  2135. mtrace();
  2136. int result = FAIL;
  2137. //char message[1500]={0};
  2138. char guid[37]={0};
  2139. char tempdata[65]={0};
  2140. int tempIndex = 0;
  2141. //int idx_sample=0;
  2142. DEBUG_ERROR("sendStopTransactionRequest \n");
  2143. memset(queuedata, 0, sizeof(queuedata));
  2144. //ENERGY_ACTIVE_IMPORT_REGISTER
  2145. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2146. if(gunType[gun_index] == 'J')
  2147. {
  2148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2149. {
  2150. tempIndex = ((gun_index==2) ? 1: 0);
  2151. }
  2152. else
  2153. {
  2154. tempIndex = gun_index;
  2155. }
  2156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2157. {
  2158. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2159. {
  2160. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  2161. }
  2162. }// END OF CHAdeMO_QUANTITY
  2163. }
  2164. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2165. {
  2166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2167. {
  2168. tempIndex = ((gun_index==2) ? 1: 0);
  2169. }
  2170. else
  2171. {
  2172. tempIndex = gun_index;
  2173. }
  2174. for (int index = 0; index < CCS_QUANTITY; index++)
  2175. {
  2176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2177. {
  2178. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  2179. }
  2180. }// END OF CCS_QUANTITY
  2181. }
  2182. else if(gunType[gun_index] == 'G')
  2183. {
  2184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2185. {
  2186. tempIndex = ((gun_index==2) ? 1: 0);
  2187. }
  2188. else
  2189. {
  2190. tempIndex = gun_index;
  2191. }
  2192. for (int index = 0; index < GB_QUANTITY; index++)
  2193. {
  2194. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2195. {
  2196. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  2197. }
  2198. }// END OF GB_QUANTITY
  2199. }
  2200. else
  2201. {
  2202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2203. {
  2204. tempIndex = 2;
  2205. }
  2206. else
  2207. {
  2208. tempIndex = gun_index;
  2209. }
  2210. for (int index = 0; index < AC_QUANTITY; index++)
  2211. {
  2212. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2213. {
  2214. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  2215. }
  2216. }// END OF AC_QUANTITY
  2217. }
  2218. //Stop Transaction Time
  2219. struct timeval tmnow;
  2220. struct tm *tm;
  2221. char buf[28];//, usec_buf[6];
  2222. gettimeofday(&tmnow, NULL);
  2223. time_t t;
  2224. t = time(NULL);
  2225. /*UTC time and date*/
  2226. tm = gmtime(&t);
  2227. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2229. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2230. random_uuid(guid);
  2231. /***********************************transactionData******************************************************/
  2232. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2234. //=================================
  2235. // Transaction_Begin
  2236. //=================================
  2237. // Energy.Active.Export.Interval
  2238. //idx_sample=0;
  2239. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  2240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2243. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2244. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2245. {
  2246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2247. }
  2248. else
  2249. {
  2250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2251. }
  2252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2254. //=================================
  2255. // Transaction_End
  2256. //=================================
  2257. //Current.Export
  2258. //idx_sample=1;
  2259. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  2260. if(gunType[gun_index] == 'J')
  2261. {
  2262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2263. {
  2264. tempIndex = ((gun_index==2) ? 1: 0);
  2265. }
  2266. else
  2267. {
  2268. tempIndex = gun_index;
  2269. }
  2270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2271. {
  2272. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2273. {
  2274. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2275. }
  2276. }// End of for CHAdeMO_QUANTITY
  2277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2278. }
  2279. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2280. {
  2281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2282. {
  2283. tempIndex = ((gun_index==2) ? 1: 0);
  2284. }
  2285. else
  2286. {
  2287. tempIndex = gun_index;
  2288. }
  2289. for (int index = 0; index < CCS_QUANTITY; index++)
  2290. {
  2291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2292. {
  2293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2294. }
  2295. }// End of for CCS_QUANTITY
  2296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2297. }
  2298. else if(gunType[gun_index] == 'G')
  2299. {
  2300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2301. {
  2302. tempIndex = ((gun_index==2) ? 1: 0);
  2303. }
  2304. else
  2305. {
  2306. tempIndex = gun_index;
  2307. }
  2308. for (int index = 0; index < GB_QUANTITY; index++)
  2309. {
  2310. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2311. {
  2312. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2313. }
  2314. }// End of for GB_QUANTITY
  2315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2316. }
  2317. else
  2318. {
  2319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2320. {
  2321. tempIndex = 2;
  2322. }
  2323. else
  2324. {
  2325. tempIndex = gun_index;
  2326. }
  2327. for (int index = 0; index < AC_QUANTITY; index++)
  2328. {
  2329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2330. {
  2331. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2332. }
  2333. }// End of for AC_QUANTITY
  2334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2335. }
  2336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  2339. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2342. //Energy.Active.Export.Interval
  2343. //idx_sample=2;
  2344. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2345. if(gunType[gun_index] == 'J')
  2346. {
  2347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2348. {
  2349. tempIndex = ((gun_index==2) ? 1: 0);
  2350. }
  2351. else
  2352. {
  2353. tempIndex = gun_index;
  2354. }
  2355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2356. {
  2357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2358. {
  2359. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2360. }
  2361. }// END OF CHAdeMO_QUANTITY
  2362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2363. }
  2364. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2365. {
  2366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2367. {
  2368. tempIndex = ((gun_index==2) ? 1: 0);
  2369. }
  2370. else
  2371. {
  2372. tempIndex = gun_index;
  2373. }
  2374. for (int index = 0; index < CCS_QUANTITY; index++)
  2375. {
  2376. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2377. {
  2378. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2379. }
  2380. }// END OF CCS_QUANTITY
  2381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2382. }
  2383. else if(gunType[gun_index] == 'G')
  2384. {
  2385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2386. {
  2387. tempIndex = ((gun_index==2) ? 1: 0);
  2388. }
  2389. else
  2390. {
  2391. tempIndex = gun_index;
  2392. }
  2393. for (int index = 0; index < GB_QUANTITY; index++)
  2394. {
  2395. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2396. {
  2397. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2398. }
  2399. }// END OF GB_QUANTITY
  2400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2401. }
  2402. else
  2403. {
  2404. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2405. {
  2406. tempIndex = 2;
  2407. }
  2408. else
  2409. {
  2410. tempIndex = gun_index;
  2411. }
  2412. for (int index = 0; index < AC_QUANTITY; index++)
  2413. {
  2414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2415. {
  2416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2417. }
  2418. }// END OF AC_QUANTITY
  2419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2420. }
  2421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  2424. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2427. //Power.Active.Export
  2428. //idx_sample=3;
  2429. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2430. if(gunType[gun_index] == 'J')
  2431. {
  2432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2433. {
  2434. tempIndex = ((gun_index==2) ? 1: 0);
  2435. }
  2436. else
  2437. {
  2438. tempIndex = gun_index;
  2439. }
  2440. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2441. {
  2442. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2443. {
  2444. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2445. }
  2446. } // End for CHAdeMO_QUANTITY
  2447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2448. }
  2449. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2450. {
  2451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2452. {
  2453. tempIndex = ((gun_index==2) ? 1: 0);
  2454. }
  2455. else
  2456. {
  2457. tempIndex = gun_index;
  2458. }
  2459. for (int index = 0; index < CCS_QUANTITY; index++)
  2460. {
  2461. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2462. {
  2463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2464. }
  2465. } // END for CCS_QUANTITY
  2466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2467. }
  2468. else if(gunType[gun_index] == 'G')
  2469. {
  2470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2471. {
  2472. tempIndex = ((gun_index==2) ? 1: 0);
  2473. }
  2474. else
  2475. {
  2476. tempIndex = gun_index;
  2477. }
  2478. for (int index = 0; index < GB_QUANTITY; index++)
  2479. {
  2480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2481. {
  2482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2483. }
  2484. }// END for GB_QUANTITY
  2485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2486. }
  2487. else
  2488. {
  2489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2490. {
  2491. tempIndex = 2;
  2492. }
  2493. else
  2494. {
  2495. tempIndex = gun_index;
  2496. }
  2497. for (int index = 0; index < AC_QUANTITY; index++)
  2498. {
  2499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2500. {
  2501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2502. }
  2503. } // END for AC_QUANTITY
  2504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2505. }
  2506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  2509. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2512. //Voltage
  2513. //idx_sample=4;
  2514. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2515. if(gunType[gun_index] == 'J')
  2516. {
  2517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2518. {
  2519. tempIndex = ((gun_index==2) ? 1: 0);
  2520. }
  2521. else
  2522. {
  2523. tempIndex = gun_index;
  2524. }
  2525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2526. {
  2527. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2528. {
  2529. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2530. }
  2531. } // END OF FOR CHAdeMO_QUANTITY
  2532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2533. }
  2534. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2535. {
  2536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2537. {
  2538. tempIndex = ((gun_index==2) ? 1: 0);
  2539. }
  2540. else
  2541. {
  2542. tempIndex = gun_index;
  2543. }
  2544. for (int index = 0; index < CCS_QUANTITY; index++)
  2545. {
  2546. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2547. {
  2548. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2549. }
  2550. } // END OF FOR CCS_QUANTITY
  2551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2552. }
  2553. else if(gunType[gun_index] == 'G')
  2554. {
  2555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2556. {
  2557. tempIndex = ((gun_index==2) ? 1: 0);
  2558. }
  2559. else
  2560. {
  2561. tempIndex = gun_index;
  2562. }
  2563. for (int index = 0; index < GB_QUANTITY; index++)
  2564. {
  2565. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2566. {
  2567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2568. }
  2569. } // END OF FOR GB_QUANTITY
  2570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2571. }
  2572. else
  2573. {
  2574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2575. {
  2576. tempIndex = 2;
  2577. }
  2578. else
  2579. {
  2580. tempIndex = gun_index;
  2581. }
  2582. for (int index = 0; index < AC_QUANTITY; index++)
  2583. {
  2584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2585. {
  2586. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2587. }
  2588. } // END OF FOR AC_QUANTITY
  2589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2590. }
  2591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2594. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2597. //SoC
  2598. //idx_sample=5;
  2599. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2600. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2601. {
  2602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2603. {
  2604. tempIndex = ((gun_index==2) ? 1: 0);
  2605. }
  2606. else
  2607. {
  2608. tempIndex = gun_index;
  2609. }
  2610. if(gunType[gun_index] == 'J')
  2611. {
  2612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2613. {
  2614. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2615. {
  2616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2617. }
  2618. }
  2619. }
  2620. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2621. {
  2622. for (int index = 0; index < CCS_QUANTITY; index++)
  2623. {
  2624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2625. {
  2626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2627. }
  2628. }
  2629. }
  2630. else if(gunType[gun_index] == 'G')
  2631. {
  2632. for (int index = 0; index < GB_QUANTITY; index++)
  2633. {
  2634. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2635. {
  2636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2637. }
  2638. }
  2639. }
  2640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2646. } // END FOR DC CASE
  2647. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2648. {
  2649. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2650. ,MESSAGE_TYPE_CALL
  2651. ,guid
  2652. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2653. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2654. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2655. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2656. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2657. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2658. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2659. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2660. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2661. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2662. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2663. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2664. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2665. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2666. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2667. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2668. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2669. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2670. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2671. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2672. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2673. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2674. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2675. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2676. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2677. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2678. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2679. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2680. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2681. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2682. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2683. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2684. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2686. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2687. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2699. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2700. );
  2701. }
  2702. else
  2703. {
  2704. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2705. ,MESSAGE_TYPE_CALL
  2706. ,guid
  2707. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2708. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2709. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2710. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2711. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2712. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2722. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2723. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2724. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2725. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2726. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2727. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2728. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2729. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2730. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2731. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2732. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2733. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2734. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2735. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2748. );
  2749. }
  2750. #if 1 // for TempStopTransaction
  2751. //Delete TempStopTransaction
  2752. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  2753. {
  2754. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  2755. }
  2756. #endif
  2757. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2758. if(hashmap_operation(0, guid, tempdata) == 1)
  2759. {
  2760. result = PASS;
  2761. DEBUG_INFO("StopTransaction mapitem pass\n");
  2762. }
  2763. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2764. if(GetTransactionQueueNum() == 1)
  2765. {
  2766. LWS_Send(queuedata);
  2767. }
  2768. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2769. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2770. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  2771. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2772. {
  2773. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2774. }
  2775. //for test
  2776. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2777. return result;
  2778. }
  2779. int sendMeterValuesRequest(int gun_index)
  2780. {
  2781. mtrace();
  2782. int result = FAIL;
  2783. // char message[1500]={0};
  2784. char guid[37]={0};
  2785. //int idx_sample=0;
  2786. //int length = 0;
  2787. char tempdata[65]={0};
  2788. int tempIndex = 0;
  2789. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2790. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2791. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2792. {
  2793. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2794. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2795. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2796. return result;
  2797. }
  2798. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2799. {
  2800. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2801. }
  2802. memset(queuedata, 0, sizeof(queuedata));
  2803. //set value
  2804. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2805. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2806. random_uuid(guid);
  2807. //UTC Date time
  2808. struct timeval tmnow;
  2809. struct tm *tm;
  2810. char buf[28];//, usec_buf[6];
  2811. gettimeofday(&tmnow, NULL);
  2812. time_t t;
  2813. t = time(NULL);
  2814. /*UTC time and date*/
  2815. tm = gmtime(&t);
  2816. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2818. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2819. //idx_sample=0;
  2820. //********************************(1)Current.Export************************************************/
  2821. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2822. if(gunType[gun_index] == 'J')
  2823. {
  2824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2825. {
  2826. tempIndex = ((gun_index==2) ? 1: 0);
  2827. }
  2828. else
  2829. {
  2830. tempIndex = gun_index;
  2831. }
  2832. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2833. {
  2834. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2835. {
  2836. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2837. }
  2838. }
  2839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2840. }
  2841. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2842. {
  2843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2844. {
  2845. tempIndex = ((gun_index==2) ? 1: 0);
  2846. }
  2847. else
  2848. {
  2849. tempIndex = gun_index;
  2850. }
  2851. for (int index = 0; index < CCS_QUANTITY; index++)
  2852. {
  2853. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2854. {
  2855. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2856. }
  2857. }
  2858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2859. }
  2860. else if(gunType[gun_index] == 'G')
  2861. {
  2862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2863. {
  2864. tempIndex = ((gun_index==2) ? 1: 0);
  2865. }
  2866. else
  2867. {
  2868. tempIndex = gun_index;
  2869. }
  2870. for (int index = 0; index < GB_QUANTITY; index++)
  2871. {
  2872. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2873. {
  2874. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2875. }
  2876. }
  2877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2878. }
  2879. else
  2880. {
  2881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2882. {
  2883. tempIndex = 2;
  2884. }
  2885. else
  2886. {
  2887. tempIndex = gun_index;
  2888. }
  2889. for (int index = 0; index < AC_QUANTITY; index++)
  2890. {
  2891. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2892. {
  2893. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2894. }
  2895. }
  2896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2897. }
  2898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  2901. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2904. //idx_sample=1;
  2905. //********************************(2)Energy.Active.Import.Register ************************************************/
  2906. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2907. if(gunType[gun_index] == 'J')
  2908. {
  2909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2910. {
  2911. tempIndex = ((gun_index==2) ? 1: 0);
  2912. }
  2913. else
  2914. {
  2915. tempIndex = gun_index;
  2916. }
  2917. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2918. {
  2919. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2920. {
  2921. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  2922. }
  2923. }
  2924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2925. }
  2926. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2927. {
  2928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2929. {
  2930. tempIndex = ((gun_index==2) ? 1: 0);
  2931. }
  2932. else
  2933. {
  2934. tempIndex = gun_index;
  2935. }
  2936. for (int index = 0; index < CCS_QUANTITY; index++)
  2937. {
  2938. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2939. {
  2940. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  2941. }
  2942. }
  2943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2944. }
  2945. else if(gunType[gun_index] == 'G')
  2946. {
  2947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2948. {
  2949. tempIndex = ((gun_index==2) ? 1: 0);
  2950. }
  2951. else
  2952. {
  2953. tempIndex = gun_index;
  2954. }
  2955. for (int index = 0; index < GB_QUANTITY; index++)
  2956. {
  2957. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2958. {
  2959. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  2960. }
  2961. }
  2962. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2963. }
  2964. else
  2965. {
  2966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2967. {
  2968. tempIndex = 2;
  2969. }
  2970. else
  2971. {
  2972. tempIndex = gun_index;
  2973. }
  2974. for (int index = 0; index < AC_QUANTITY; index++)
  2975. {
  2976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2977. {
  2978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  2979. }
  2980. }
  2981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2982. }
  2983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  2986. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2988. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2989. //idx_sample=2;
  2990. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2991. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2992. if(gunType[gun_index] == 'J')
  2993. {
  2994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2995. {
  2996. tempIndex = ((gun_index==2) ? 1: 0);
  2997. }
  2998. else
  2999. {
  3000. tempIndex = gun_index;
  3001. }
  3002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3003. {
  3004. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3005. {
  3006. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  3007. }
  3008. } // END OF FOR CHAdeMO_QUANTITY
  3009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3010. }
  3011. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3012. {
  3013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3014. {
  3015. tempIndex = ((gun_index==2) ? 1: 0);
  3016. }
  3017. else
  3018. {
  3019. tempIndex = gun_index;
  3020. }
  3021. for (int index = 0; index < CCS_QUANTITY; index++)
  3022. {
  3023. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  3024. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3025. {
  3026. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  3027. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  3028. }
  3029. } // END OF CCS_QUANTITY
  3030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3031. }
  3032. else if(gunType[gun_index] == 'G')
  3033. {
  3034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3035. {
  3036. tempIndex = ((gun_index==2) ? 1: 0);
  3037. }
  3038. else
  3039. {
  3040. tempIndex = gun_index;
  3041. }
  3042. for (int index = 0; index < GB_QUANTITY; index++)
  3043. {
  3044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3045. {
  3046. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  3047. }
  3048. } // END OF GB_QUANTITY
  3049. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3050. }
  3051. else
  3052. {
  3053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3054. {
  3055. tempIndex = 2;
  3056. }
  3057. else
  3058. {
  3059. tempIndex = gun_index;
  3060. }
  3061. for (int index = 0; index < AC_QUANTITY; index++)
  3062. {
  3063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3064. {
  3065. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  3066. }
  3067. }
  3068. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3069. }
  3070. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3071. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  3072. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  3073. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  3074. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  3075. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3076. //idx_sample=3;
  3077. //********************************(4)Power.Active.Export************************************************/
  3078. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3079. if(gunType[gun_index] == 'J')
  3080. {
  3081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3082. {
  3083. tempIndex = ((gun_index==2) ? 1: 0);
  3084. }
  3085. else
  3086. {
  3087. tempIndex = gun_index;
  3088. }
  3089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3090. {
  3091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3092. {
  3093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  3094. }
  3095. } // END OF FOR
  3096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3097. }
  3098. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3099. {
  3100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3101. {
  3102. tempIndex = ((gun_index==2) ? 1: 0);
  3103. }
  3104. else
  3105. {
  3106. tempIndex = gun_index;
  3107. }
  3108. for (int index = 0; index < CCS_QUANTITY; index++)
  3109. {
  3110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3111. {
  3112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  3113. }
  3114. }
  3115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3116. }
  3117. else if(gunType[gun_index] == 'G')
  3118. {
  3119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3120. {
  3121. tempIndex = ((gun_index==2) ? 1: 0);
  3122. }
  3123. else
  3124. {
  3125. tempIndex = gun_index;
  3126. }
  3127. for (int index = 0; index < GB_QUANTITY; index++)
  3128. {
  3129. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3130. {
  3131. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  3132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  3133. }
  3134. }
  3135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3136. }
  3137. else
  3138. {
  3139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3140. {
  3141. tempIndex = 2;
  3142. }
  3143. else
  3144. {
  3145. tempIndex = gun_index;
  3146. }
  3147. for (int index = 0; index < AC_QUANTITY; index++)
  3148. {
  3149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3150. {
  3151. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  3152. }
  3153. }
  3154. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3155. }
  3156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3157. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  3158. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  3159. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  3161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  3162. //idx_sample=4;
  3163. //***********************************************(5)VOLTAGE******************************************************/
  3164. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3165. if(gunType[gun_index] == 'J')
  3166. {
  3167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3168. {
  3169. tempIndex = ((gun_index==2) ? 1: 0);
  3170. }
  3171. else
  3172. {
  3173. tempIndex = gun_index;
  3174. }
  3175. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3176. {
  3177. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3178. {
  3179. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  3180. }
  3181. }
  3182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3183. }
  3184. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3185. {
  3186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3187. {
  3188. tempIndex = ((gun_index==2) ? 1: 0);
  3189. }
  3190. else
  3191. {
  3192. tempIndex = gun_index;
  3193. }
  3194. for (int index = 0; index < CCS_QUANTITY; index++)
  3195. {
  3196. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3197. {
  3198. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  3199. }
  3200. }
  3201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3202. }
  3203. else if(gunType[gun_index] == 'G')
  3204. {
  3205. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3206. {
  3207. tempIndex = ((gun_index==2) ? 1: 0);
  3208. }
  3209. else
  3210. {
  3211. tempIndex = gun_index;
  3212. }
  3213. for (int index = 0; index < GB_QUANTITY; index++)
  3214. {
  3215. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3216. {
  3217. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  3218. }
  3219. }
  3220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3221. }
  3222. else
  3223. {
  3224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3225. {
  3226. tempIndex = 2;
  3227. }
  3228. else
  3229. {
  3230. tempIndex = gun_index;
  3231. }
  3232. for (int index = 0; index < AC_QUANTITY; index++)
  3233. {
  3234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3235. {
  3236. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  3237. }
  3238. }
  3239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  3240. }
  3241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3242. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  3243. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  3244. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  3246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3247. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3248. {
  3249. //idx_sample=5;
  3250. //sampledValue = NULL;
  3251. //***********************************************(6)SOC******************************************************/
  3252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3253. {
  3254. tempIndex = ((gun_index==2) ? 1: 0);
  3255. }
  3256. else
  3257. {
  3258. tempIndex = gun_index;
  3259. }
  3260. if(gunType[gun_index] == 'J')
  3261. {
  3262. //tempIndex = ((gun_index==2) ? 1: 0);
  3263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3264. {
  3265. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3266. {
  3267. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  3268. }
  3269. }
  3270. }
  3271. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3272. {
  3273. //tempIndex = ((gun_index==2) ? 1: 0);
  3274. for (int index = 0; index < CCS_QUANTITY; index++)
  3275. {
  3276. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3277. {
  3278. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  3279. }
  3280. }
  3281. }
  3282. else if(gunType[gun_index] == 'G')
  3283. {
  3284. //tempIndex = ((gun_index==2) ? 1: 0);
  3285. for (int index = 0; index < GB_QUANTITY; index++)
  3286. {
  3287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3288. {
  3289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  3290. }
  3291. }
  3292. }
  3293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  3295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  3296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  3297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  3298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  3299. }
  3300. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3301. {
  3302. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3303. ,MESSAGE_TYPE_CALL
  3304. ,guid
  3305. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3306. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3307. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3308. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3309. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3310. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3311. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3312. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3313. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3314. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3315. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3316. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3317. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3318. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3319. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3320. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3321. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3322. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3323. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3324. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3325. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3326. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3327. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3328. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3329. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3330. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3331. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3332. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3333. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3334. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3335. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3336. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  3337. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  3338. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  3339. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  3340. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  3341. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  3342. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  3343. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  3344. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  3345. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  3346. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  3347. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  3348. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  3349. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  3350. );
  3351. }
  3352. else
  3353. {
  3354. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3355. ,MESSAGE_TYPE_CALL
  3356. ,guid
  3357. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3358. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3359. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3360. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3361. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3362. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3363. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3364. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3365. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3366. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3367. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3368. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3369. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3370. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3371. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3372. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3373. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3374. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3375. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3376. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3377. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3378. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3379. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3380. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3381. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3382. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3383. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3384. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3385. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3386. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3387. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3388. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  3389. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  3390. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  3391. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  3392. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  3393. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  3394. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  3395. );
  3396. }
  3397. // Put request guid to hash map
  3398. sprintf(tempdata, "MeterValues,%d", (gun_index));
  3399. 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*/)
  3400. {
  3401. result = PASS;
  3402. DEBUG_INFO("MeterValues mapitem pass\n");
  3403. }
  3404. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3405. if(GetTransactionQueueNum() == 1)
  3406. {
  3407. LWS_Send(queuedata);
  3408. }
  3409. return result;
  3410. }
  3411. //==========================================
  3412. // send confirm routine
  3413. //==========================================
  3414. int sendCancelReservationConfirmation(char *uuid,char *payload)
  3415. {
  3416. mtrace();
  3417. int result = FAIL;
  3418. char message[100]={0};
  3419. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  3420. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3421. LWS_Send(message);
  3422. result = TRUE;
  3423. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  3424. return result;
  3425. }
  3426. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  3427. {
  3428. mtrace();
  3429. int result = FAIL;
  3430. char message[100]={0};
  3431. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  3432. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3433. LWS_Send(message);
  3434. result = TRUE;
  3435. return result;
  3436. }
  3437. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  3438. {
  3439. mtrace();
  3440. int result = FAIL;
  3441. char message[100]={0};
  3442. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  3443. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3444. LWS_Send(message);
  3445. result = TRUE;
  3446. return result;
  3447. }
  3448. int sendClearCacheConfirmation(char *uuid,char *payload)
  3449. {
  3450. mtrace();
  3451. int result = FAIL;
  3452. char message[500]={0};
  3453. // int count = 0;
  3454. // int gun_index = 0;
  3455. // char guid[37];
  3456. // [ 3, "1570592744204", { "status": "Accepted" } ]
  3457. DEBUG_ERROR("sendClearCacheConfirmation\n");
  3458. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3459. LWS_Send(message);
  3460. return result;
  3461. }
  3462. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  3463. {
  3464. mtrace();
  3465. int result = FAIL;
  3466. char message[500]={0};
  3467. // [ 3, "1571284268200", { "status": "Unknown" } ]
  3468. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  3469. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3470. LWS_Send(message);
  3471. return result;
  3472. }
  3473. int sendDataTransferConfirmation(char *uuid,char *payload)
  3474. {
  3475. mtrace();
  3476. char statusStr[20]={0};
  3477. char dataStr[10]={0};
  3478. char sstr[20]={0};
  3479. int c = 0;
  3480. char *loc;
  3481. int result = FAIL;
  3482. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3483. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3484. /**********************status**************************/
  3485. loc = strstr(payload, "status");
  3486. memset(sstr ,0, sizeof(sstr) );
  3487. c = 0;
  3488. while (loc[3+strlen("status")+c] != '\"')
  3489. {
  3490. sstr[c] = loc[3+strlen("status")+c];
  3491. c++;
  3492. }
  3493. sstr[c] = '\0';
  3494. strcpy(statusStr, sstr);
  3495. /**********************data**************************/
  3496. loc = strstr(payload, "data");
  3497. memset(sstr ,0, sizeof(sstr) );
  3498. c = 0;
  3499. while (loc[3+strlen("data")+c] != '\"')
  3500. {
  3501. sstr[c] = loc[3+strlen("data")+c];
  3502. c++;
  3503. }
  3504. sstr[c] = '\0';
  3505. strcpy(dataStr, sstr);
  3506. return result;
  3507. }
  3508. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3509. {
  3510. mtrace();
  3511. int result = FAIL;
  3512. char message[1000]={0};
  3513. double diff_f = 0.0;
  3514. int diff_i = 0;
  3515. int diffSeconds = 0;
  3516. struct tm tp;
  3517. int TimeZero = FALSE;
  3518. int CompositeScheduleIndex = 0;
  3519. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  3520. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  3521. {
  3522. TimeZero = TRUE;
  3523. }
  3524. else
  3525. {
  3526. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3527. }
  3528. if(TimeZero == FALSE)
  3529. {
  3530. tp.tm_isdst = -1;
  3531. time_t utc = mktime(&tp);
  3532. time_t t = time(NULL);
  3533. diff_f = difftime(t, utc);
  3534. diff_i = (int)diff_f;
  3535. diffSeconds = diff_i % 86400;//86400 seconds/day
  3536. }
  3537. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3538. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3539. #if 0 //remove temporally
  3540. 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}"
  3541. ,MESSAGE_TYPE_CALLRESULT
  3542. ,uuid
  3543. ,payload
  3544. ,connectorIdInt
  3545. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3546. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3547. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3548. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3549. #endif
  3550. if(nPeriod == 0)
  3551. {
  3552. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  3553. {
  3554. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  3555. ,MESSAGE_TYPE_CALLRESULT
  3556. ,uuid
  3557. ,payload
  3558. ,connectorIdInt);
  3559. }
  3560. else
  3561. {
  3562. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3563. ,MESSAGE_TYPE_CALLRESULT
  3564. ,uuid
  3565. ,payload
  3566. ,connectorIdInt
  3567. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3568. }
  3569. }
  3570. else
  3571. {
  3572. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3573. ,MESSAGE_TYPE_CALLRESULT
  3574. ,uuid
  3575. ,payload
  3576. ,connectorIdInt
  3577. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3578. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3579. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3580. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3581. int len = nPeriod;
  3582. //Last Period StartPriod is less than diffSeconds
  3583. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds) || (diffSeconds == 0))
  3584. {
  3585. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3586. , 0
  3587. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3588. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3589. }
  3590. else
  3591. {
  3592. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3593. {
  3594. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) < diffSeconds) && ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod % 86400) > diffSeconds))//if (idx_sample == 0)
  3595. {
  3596. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3597. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3598. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3599. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3600. }
  3601. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3602. {
  3603. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3604. , ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  3605. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3606. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3607. }
  3608. }
  3609. }
  3610. sprintf(message + strlen(message), "]}}]");
  3611. }
  3612. LWS_Send(message);
  3613. result = TRUE;
  3614. return result;
  3615. }
  3616. int sendGetConfigurationConfirmation(char *uuid)
  3617. {
  3618. mtrace();
  3619. int result = FAIL;
  3620. int MaxKeySupported = 0;
  3621. int sentConfigurationNumber= 0;
  3622. int sentunConfigurationNumber= 0;
  3623. char message[4000]={0};
  3624. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3625. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3626. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3627. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3628. ,MESSAGE_TYPE_CALLRESULT
  3629. ,uuid );
  3630. //configuration key
  3631. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3632. {
  3633. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3634. {
  3635. if (sentConfigurationNumber == 0)
  3636. {
  3637. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3638. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3639. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3640. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3641. }
  3642. else
  3643. {
  3644. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3645. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3646. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3647. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3648. }
  3649. sentConfigurationNumber = sentConfigurationNumber + 1;
  3650. }
  3651. }
  3652. sprintf(message + strlen(message), "]");
  3653. if(UnknownKeynum != 0)
  3654. {
  3655. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3656. //unkown key
  3657. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3658. {
  3659. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3660. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3661. if(sentunConfigurationNumber == 0)
  3662. {
  3663. sprintf(message + strlen(message), "\"%s\""
  3664. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3665. }
  3666. else
  3667. {
  3668. sprintf(message + strlen(message), ",\"%s\""
  3669. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3670. }
  3671. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3672. }
  3673. sprintf(message + strlen(message), "]");
  3674. }
  3675. sprintf(message + strlen(message), "}]");
  3676. LWS_Send(message);
  3677. return result;
  3678. }
  3679. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3680. {
  3681. mtrace();
  3682. int result = FAIL;
  3683. char message[400]={0};
  3684. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3685. if(strcmp(payload,"")==0)
  3686. {
  3687. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3688. }
  3689. else
  3690. {
  3691. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3692. }
  3693. LWS_Send(message);
  3694. result = TRUE;
  3695. return result;
  3696. }
  3697. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3698. {
  3699. mtrace();
  3700. int result = FAIL;
  3701. char message[80]={0};
  3702. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3703. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3704. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3705. LWS_Send(message);
  3706. result = TRUE;
  3707. return result;
  3708. }
  3709. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3710. {
  3711. mtrace();
  3712. int result = FAIL;
  3713. char message[80]={0};
  3714. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3715. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3716. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3717. LWS_Send(message);
  3718. result = TRUE;
  3719. return result;
  3720. }
  3721. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3722. {
  3723. mtrace();
  3724. int result = FAIL;
  3725. char message[80]={0};
  3726. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3727. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3728. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3729. LWS_Send(message);
  3730. result = TRUE;
  3731. return result;
  3732. }
  3733. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3734. {
  3735. mtrace();
  3736. int result = FAIL;
  3737. char message[80]={0};
  3738. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3739. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3740. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3741. LWS_Send(message);
  3742. result = TRUE;
  3743. return result;
  3744. }
  3745. int sendResetConfirmation(char *uuid,char *payload)
  3746. {
  3747. mtrace();
  3748. int result = FAIL;
  3749. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3750. char message[80]={0};
  3751. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3752. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3753. LWS_Send(message);
  3754. result = TRUE;
  3755. return result;
  3756. }
  3757. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3758. {
  3759. mtrace();
  3760. int result = FAIL;
  3761. char message[500]={0};
  3762. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3763. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3764. LWS_Send(message);
  3765. result = TRUE;
  3766. return result;
  3767. }
  3768. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3769. {
  3770. mtrace();
  3771. int result = FAIL;
  3772. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3773. char message[80]={0};
  3774. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3775. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3776. LWS_Send(message);
  3777. result = TRUE;
  3778. return result;
  3779. }
  3780. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3781. {
  3782. mtrace();
  3783. int result = FAIL;
  3784. char message[80]={0};
  3785. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3786. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3787. LWS_Send(message);
  3788. result = TRUE;
  3789. return result;
  3790. }
  3791. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3792. {
  3793. mtrace();
  3794. int result = FAIL;
  3795. char message[80]={0};
  3796. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3797. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3798. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3799. LWS_Send(message);
  3800. result = TRUE;
  3801. return result;
  3802. }
  3803. int sendUpdateFirmwareConfirmation(char *uuid)
  3804. {
  3805. mtrace();
  3806. int result = FAIL;
  3807. char message[60]={0};
  3808. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3809. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3810. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3811. LWS_Send(message);
  3812. result = TRUE;
  3813. return result;
  3814. }
  3815. //==========================================
  3816. // send CallError routine
  3817. //==========================================
  3818. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3819. {
  3820. mtrace();
  3821. //int result = FAIL;
  3822. char message[220]={0};
  3823. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3824. #ifdef SystemLogMessage
  3825. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3826. uniqueId, action, errorCode, errorDescription);
  3827. #endif
  3828. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3829. LWS_Send(message);
  3830. //result = TRUE;
  3831. }
  3832. //==========================================
  3833. // Handle server request routine Start
  3834. //==========================================
  3835. #define GUN_NUM 1
  3836. int handleCancelReservationRequest(char *uuid, char *payload)
  3837. {
  3838. mtrace();
  3839. int result = FAIL;
  3840. int gunNO = 0;
  3841. int reservationIdInt =0;
  3842. char comfirmstr[20];
  3843. int c = 0;
  3844. int copyTo = 0;
  3845. char *loc;
  3846. char sstr[100]={0};
  3847. DEBUG_INFO("handle CancelReservationRequest\n");
  3848. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3849. c = 0;
  3850. copyTo = 0;
  3851. loc = strstr(payload, "reservationId");
  3852. memset(sstr ,0, sizeof(sstr) );
  3853. while (loc[strlen("reservationId")+2+c] != '}')
  3854. {
  3855. if(loc[strlen("interval")+2+c] != ' ')
  3856. {
  3857. sstr[copyTo] = loc[strlen("reservationId")+2+c];
  3858. copyTo = copyTo + 1;
  3859. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3860. }
  3861. c++;
  3862. }
  3863. sstr[copyTo] = '\0';
  3864. reservationIdInt = atoi(sstr);
  3865. memset(comfirmstr, 0, sizeof comfirmstr);
  3866. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3867. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3868. //check Transaction active
  3869. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3871. {
  3872. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3873. {
  3874. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3875. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3876. if(gunType[2] == 'J')
  3877. {
  3878. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  3879. }
  3880. else
  3881. {
  3882. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3883. }
  3884. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3885. goto end;
  3886. }
  3887. }
  3888. for (int index = 0; index < CCS_QUANTITY; index++)
  3889. {
  3890. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3891. {
  3892. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3893. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3894. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  3895. {
  3896. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  3897. }
  3898. else
  3899. {
  3900. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3901. }
  3902. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3903. goto end;
  3904. }
  3905. }
  3906. for (int index = 0; index < GB_QUANTITY; index++)
  3907. {
  3908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3909. {
  3910. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3911. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3912. if(gunType[2] == 'G')
  3913. {
  3914. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  3915. }
  3916. else
  3917. {
  3918. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3919. }
  3920. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3921. goto end;
  3922. }
  3923. }
  3924. for (int index = 0; index < AC_QUANTITY; index++)
  3925. {
  3926. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3927. {
  3928. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3929. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3930. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3931. {
  3932. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  3933. }
  3934. else
  3935. {
  3936. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3937. }
  3938. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3939. goto end;
  3940. }
  3941. }
  3942. //The reservationId does NOT match the reservationId
  3943. sendCancelReservationConfirmation(uuid, comfirmstr);
  3944. end:
  3945. // Fill in ocpp packet uuid
  3946. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3947. return result;
  3948. }
  3949. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3950. {
  3951. mtrace();
  3952. int result = FAIL;
  3953. int gunIndex = 0;
  3954. char sstr[90]={0},sstrtemp[50]={ 0 };
  3955. char typeStr[16]={0};
  3956. char comfirmstr[20];
  3957. int specificId = FALSE;
  3958. char *loc;
  3959. //int intervalInt = 0;
  3960. int c = 0;
  3961. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3962. strcpy(sstrtemp, stringtrimspace(payload));
  3963. /*** connectorId ****/
  3964. loc = strstr(sstrtemp, "connectorId");
  3965. memset(sstr ,0, sizeof(sstr) );
  3966. c = 0;
  3967. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') ) // 2: ":
  3968. {
  3969. sstr[c] = loc[strlen("connectorId")+2+c];
  3970. c++;
  3971. }
  3972. sstr[c] = '\0';
  3973. gunIndex = atoi(sstr);
  3974. /***type ****/
  3975. loc = strstr(sstrtemp, "type");
  3976. memset(sstr ,0, sizeof(sstr) );
  3977. c = 0;
  3978. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3979. {
  3980. sstr[c] = loc[3+strlen("type")+c];
  3981. c++;
  3982. }
  3983. sstr[c] = '\0';
  3984. strcpy(typeStr, sstr);
  3985. if(gunIndex != 0)
  3986. {
  3987. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3988. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3989. }
  3990. else
  3991. {
  3992. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3993. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3994. }
  3995. memset(comfirmstr, 0, sizeof comfirmstr);
  3996. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3997. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3998. {
  3999. specificId = TRUE;
  4000. }
  4001. if(specificId == FALSE)
  4002. goto end;
  4003. if(gunIndex != 0)
  4004. {
  4005. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  4006. }
  4007. else
  4008. {
  4009. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  4010. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  4011. }
  4012. /*
  4013. enum SYSTEM_STATUS
  4014. {
  4015. SYS_MODE_BOOTING = 0,
  4016. SYS_MODE_IDLE = 1,
  4017. SYS_MODE_AUTHORIZING = 2,
  4018. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  4019. SYS_MODE_REASSIGN = 4,
  4020. SYS_MODE_PREPARING = 5,
  4021. SYS_MODE_PREPARE_FOR_EV = 6,
  4022. SYS_MODE_PREPARE_FOR_EVSE = 7,
  4023. SYS_MODE_CHARGING = 8,
  4024. SYS_MODE_TERMINATING = 9,
  4025. SYS_MODE_COMPLETE = 10,
  4026. SYS_MODE_ALARM = 11,
  4027. SYS_MODE_FAULT = 12,
  4028. SYS_MODE_RESERVATION = 13,
  4029. SYS_MODE_BOOKING = 14,
  4030. SYS_MODE_MAINTAIN = 15,
  4031. SYS_MODE_DEBUG = 16,
  4032. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  4033. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  4034. SYS_MODE_UPDATE = 19
  4035. };
  4036. */
  4037. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  4038. {
  4039. //check Transaction active
  4040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4041. {
  4042. if ((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')))
  4043. {
  4044. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  4045. {
  4046. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4047. }
  4048. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4049. {
  4050. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4051. }
  4052. else
  4053. {
  4054. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4055. }
  4056. goto end;
  4057. }
  4058. }//END FOR CHAdeMO_QUANTITY
  4059. for (int index = 0; index < CCS_QUANTITY; index++)
  4060. {
  4061. if ((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))))
  4062. {
  4063. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  4064. {
  4065. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4066. }
  4067. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4068. {
  4069. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4070. }
  4071. else
  4072. {
  4073. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4074. }
  4075. goto end;
  4076. }
  4077. }//END FOR CCS_QUANTITY
  4078. for (int index = 0; index < GB_QUANTITY; index++)
  4079. {
  4080. if ((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))
  4081. {
  4082. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  4083. {
  4084. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4085. }
  4086. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4087. {
  4088. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4089. }
  4090. else
  4091. {
  4092. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4093. }
  4094. goto end;
  4095. }
  4096. }// END FOR GB_QUANTITY
  4097. for (int index = 0; index < AC_QUANTITY; index++)
  4098. {
  4099. if ((gunIndex == 0) || ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))))
  4100. {
  4101. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  4102. {
  4103. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4104. }
  4105. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4106. {
  4107. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4108. }
  4109. else
  4110. {
  4111. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4112. }
  4113. goto end;
  4114. }
  4115. }//END FOR AC_QUANTITY
  4116. }//END FOR AvailabilityTypeStr[Inoperative]
  4117. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  4118. {
  4119. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  4120. //check Transaction active
  4121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4122. {
  4123. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4124. {
  4125. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4126. goto end;
  4127. }
  4128. }//END FOR CHAdeMO_QUANTITY
  4129. for (int index = 0; index < CCS_QUANTITY; index++)
  4130. {
  4131. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4132. {
  4133. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4134. goto end;
  4135. }
  4136. }//END FOR CCS_QUANTITY
  4137. for (int index = 0; index < GB_QUANTITY; index++)
  4138. {
  4139. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4140. {
  4141. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  4142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4143. goto end;
  4144. }
  4145. }// END FOR GB_QUANTITY
  4146. for (int index = 0; index < AC_QUANTITY; index++)
  4147. {
  4148. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4149. {
  4150. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4151. goto end;
  4152. }
  4153. }//END FOR CHAdeMO_QUANTITY
  4154. }//END FOR AvailabilityTypeStr[Operative]
  4155. end:
  4156. if(gunIndex != 0)
  4157. {
  4158. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  4159. }
  4160. else
  4161. {
  4162. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  4163. }
  4164. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  4165. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  4166. return result;
  4167. }
  4168. int handleChangeConfigurationRequest(char *uuid, char *payload)
  4169. {
  4170. mtrace();
  4171. int result = FAIL;
  4172. char sstr[100]={0},sstrtemp[160]={ 0 };
  4173. char keystr[40]={0};
  4174. char valuestr[100]={0};
  4175. char *loc;
  4176. int c = 0;
  4177. char comfirmstr[20]={0};
  4178. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  4179. strcpy(sstrtemp, stringtrimspace(payload));
  4180. /***key ****/
  4181. loc = strstr(sstrtemp, "key");
  4182. memset(sstr ,0, sizeof(sstr) );
  4183. c = 0;
  4184. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  4185. {
  4186. sstr[c] = loc[3+strlen("key")+c];
  4187. c++;
  4188. }
  4189. sstr[c] = '\0';
  4190. strcpy(keystr, sstr);
  4191. //DEBUG_INFO( "keystr=%s\n",keystr);
  4192. /***value ****/
  4193. loc = strstr(sstrtemp, "value");
  4194. memset(sstr ,0, sizeof(sstr) );
  4195. c = 0;
  4196. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  4197. {
  4198. sstr[c] = loc[3+strlen("value")+c];
  4199. c++;
  4200. }
  4201. sstr[c] = '\0';
  4202. strcpy(valuestr, sstr);
  4203. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  4204. if((uuid==NULL) || (payload ==NULL) )
  4205. {
  4206. #ifdef Debug
  4207. DEBUG_INFO("payload is null\n");
  4208. #endif
  4209. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4210. }
  4211. else
  4212. {
  4213. int status = setKeyValue(keystr, valuestr);
  4214. switch(status)
  4215. {
  4216. case ConfigurationStatus_Accepted:
  4217. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  4218. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  4219. StoreConfigurationTable();
  4220. break;
  4221. case ConfigurationStatus_Rejected:
  4222. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4223. break;
  4224. case RebootRequired:
  4225. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  4226. StoreConfigurationTable();
  4227. break;
  4228. case NotSupported:
  4229. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  4230. break;
  4231. default:
  4232. break;
  4233. }
  4234. }
  4235. //confirmation.setStatus(ConfigurationStatus.Rejected);
  4236. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  4237. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  4238. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  4239. {
  4240. ChageWebSocketPingInterval(atoi(valuestr));
  4241. }
  4242. return result;
  4243. }
  4244. int handleClearCacheRequest(char *uuid, char *payload)
  4245. {
  4246. mtrace();
  4247. int result = FAIL;
  4248. char comfirmstr[20];
  4249. int fd;
  4250. char rmFileCmd[100]={0};
  4251. struct stat stats;
  4252. DEBUG_INFO("handle ClearCacheRequest\n");
  4253. stat("/Storage/OCPP", &stats);
  4254. // Check for directory existence
  4255. if (S_ISDIR(stats.st_mode) == 1)
  4256. {
  4257. //DEBUG_ERROR("\n OCPP directory exist \n");
  4258. }
  4259. else
  4260. {
  4261. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  4262. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  4263. system(rmFileCmd);
  4264. }
  4265. memset(rmFileCmd, 0, sizeof rmFileCmd);
  4266. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  4267. {
  4268. DEBUG_INFO("AuthorizationCache file exist.\n");
  4269. }
  4270. else
  4271. {
  4272. DEBUG_INFO("AuthorizationCache file not exist\n");
  4273. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  4274. if(log == NULL)
  4275. {
  4276. DEBUG_INFO("AuthorizationCache file is NULL\n");
  4277. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4278. goto end;
  4279. }
  4280. else
  4281. {
  4282. fclose(log);
  4283. }
  4284. }
  4285. fd = open(AuthorizationCache_JSON,O_RDWR);
  4286. if(fd < 0)
  4287. {
  4288. DEBUG_INFO("open AuthorizationCache file failed\n");
  4289. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4290. }
  4291. else
  4292. {
  4293. DEBUG_INFO("open AuthorizationCache file successful\n");
  4294. //* 清空? 件 */
  4295. ftruncate(fd,0);
  4296. //* ? 新设置? 件? 移??*/
  4297. lseek(fd,0,SEEK_SET);
  4298. close(fd);
  4299. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  4300. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  4301. }
  4302. end:
  4303. sendClearCacheConfirmation(uuid, comfirmstr);
  4304. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  4305. return result;
  4306. }
  4307. int handleClearChargingProfileRequest(char *uuid, char *payload)
  4308. {
  4309. mtrace();
  4310. int result = FAIL;
  4311. int resultRename;
  4312. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  4313. char chargingProfilePurposeStr[26]={0};
  4314. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  4315. char tempchargingProfilePurposeStr[26]={0};
  4316. char sstr[160]={0},sstrtemp[160]={ 0 };//sstr[200]={ 0 };
  4317. char str[100]={0};
  4318. int c = 0;
  4319. //int i = 0;
  4320. //char * pch;
  4321. char *loc;
  4322. char fname[200]={0};
  4323. char comfirmstr[20]={0};
  4324. char word[1600]={0};
  4325. int clearflag = FALSE;
  4326. int chargingProfileIdIsNULL = FALSE;
  4327. int connectorIsNULL = FALSE;
  4328. int chargingProfilePurposeIsNULL = FALSE;
  4329. int stackLevelIsNULL = FALSE;
  4330. //int GotoEnd = FALSE;
  4331. FILE *fptr1, *fptr2;
  4332. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  4333. int n_chargingProfile=0;
  4334. int isEmptyFile = FALSE;
  4335. char sLineWord[1600]={0};
  4336. char chargingProfiles[10][100]={0};
  4337. int ChargeProfileCount = 0;
  4338. char ch;
  4339. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  4340. strcpy(sstrtemp, stringtrimspace(payload));
  4341. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  4342. //***id ****/
  4343. c = 0;
  4344. loc = strstr(sstrtemp, "id");
  4345. memset(sstr ,0, sizeof(sstr) );
  4346. if(loc == NULL)
  4347. {
  4348. chargingProfileIdIsNULL = TRUE;
  4349. }
  4350. else
  4351. {
  4352. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  4353. {
  4354. sstr[c] = loc[strlen("id")+2+c];
  4355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4356. c++;
  4357. }
  4358. sstr[c] = '\0';
  4359. chargingProfileIdInt = atoi(sstr);
  4360. }
  4361. //***connectorId ****/
  4362. c=0;
  4363. loc = strstr(sstrtemp, "connectorId");
  4364. memset(sstr ,0, sizeof(sstr) );
  4365. if(loc == NULL)
  4366. {
  4367. connectorIsNULL = TRUE;
  4368. }
  4369. else
  4370. {
  4371. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  4372. {
  4373. sstr[c] = loc[strlen("connectorId")+2+c];
  4374. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4375. c++;
  4376. }
  4377. sstr[c] = '\0';
  4378. connectorIdInt = atoi(sstr);
  4379. }
  4380. //***chargingProfilePurpose ****/
  4381. loc = strstr(sstrtemp, "chargingProfilePurpose");
  4382. memset(sstr ,0, sizeof(sstr) );
  4383. c = 0;
  4384. if(loc == NULL)
  4385. {
  4386. chargingProfilePurposeIsNULL = TRUE;
  4387. }
  4388. else
  4389. {
  4390. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  4391. {
  4392. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4393. c++;
  4394. }
  4395. sstr[c] = '\0';
  4396. strcpy(chargingProfilePurposeStr, sstr);
  4397. }
  4398. //***stackLevel ****/
  4399. c=0;
  4400. loc = strstr(sstrtemp, "stackLevel");
  4401. memset(sstr ,0, sizeof(sstr) );
  4402. if(loc == NULL)
  4403. {
  4404. stackLevelIsNULL = TRUE;
  4405. }
  4406. else
  4407. {
  4408. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  4409. {
  4410. sstr[c] = loc[strlen("stackLevel")+2+c];
  4411. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4412. c++;
  4413. }
  4414. sstr[c] = '\0';
  4415. stackLevelInt = atoi(sstr);
  4416. }
  4417. if(connectorIsNULL == FALSE)
  4418. {
  4419. switch(connectorIdInt)
  4420. {
  4421. case 0:
  4422. if(chargingProfilePurposeIsNULL == TRUE)
  4423. {
  4424. int l = 0;
  4425. strcpy(fname, ChargePointMaxProfile_JSON);
  4426. if((access(fname,F_OK))!=-1)
  4427. {
  4428. strcpy(chargingProfiles[l], fname);
  4429. l = l + 1;
  4430. }
  4431. strcpy(fname, TxDefaultProfile_0_JSON);
  4432. if((access(fname,F_OK))!=-1)
  4433. {
  4434. strcpy(chargingProfiles[l], fname);
  4435. l = l + 1;
  4436. }
  4437. ChargeProfileCount = l;
  4438. }
  4439. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  4440. {
  4441. strcpy(fname, ChargePointMaxProfile_JSON);
  4442. if((access(fname,F_OK))!=-1)
  4443. {
  4444. strcpy(chargingProfiles[0], fname);
  4445. ChargeProfileCount = 1;
  4446. }
  4447. }
  4448. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4449. {
  4450. strcpy(fname, TxDefaultProfile_0_JSON);
  4451. if((access(fname,F_OK))!=-1)
  4452. {
  4453. strcpy(chargingProfiles[0], fname);
  4454. ChargeProfileCount = 1;
  4455. }
  4456. }
  4457. break;
  4458. default:
  4459. if(chargingProfilePurposeIsNULL == TRUE)
  4460. {
  4461. int m = 0;
  4462. memset(fname, 0, sizeof fname);
  4463. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4464. if((access(fname,F_OK))!=-1)
  4465. {
  4466. strcpy(chargingProfiles[m], fname);
  4467. m = m + 1;
  4468. }
  4469. memset(fname, 0, sizeof fname);
  4470. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4471. if((access(fname,F_OK))!=-1)
  4472. {
  4473. strcpy(chargingProfiles[m], fname);
  4474. m = m + 1;
  4475. }
  4476. ChargeProfileCount = m;
  4477. }
  4478. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4479. {
  4480. //strcpy(fname, TxDefaultProfile_1_JSON);
  4481. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4482. if((access(fname,F_OK))!=-1)
  4483. {
  4484. strcpy(chargingProfiles[0], fname);
  4485. ChargeProfileCount = 1;
  4486. }
  4487. }
  4488. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  4489. {
  4490. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4491. if((access(fname,F_OK))!=-1)
  4492. {
  4493. strcpy(chargingProfiles[0], fname);
  4494. ChargeProfileCount = 1;
  4495. }
  4496. //strcpy(fname, TxProfile_1_JSON);
  4497. }
  4498. //strcpy(fname, ChargePointMaxProfile_JSON );
  4499. break;
  4500. }
  4501. }
  4502. else // Check all Charging Profiles
  4503. {
  4504. int i = 0;
  4505. char fnametemp[200]={0};
  4506. ChargeProfileCount = 0;
  4507. //Check ChargePointMaxProfile.json exit
  4508. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  4509. {
  4510. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  4511. i = i + 1;
  4512. }
  4513. //Check TxDefaultProfile_0.json exit
  4514. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  4515. {
  4516. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  4517. i = i + 1;
  4518. }
  4519. //Check TxDefaultProfile_%d.json
  4520. for(int j=1; j <= gunTotalNumber; j++)
  4521. {
  4522. memset(fnametemp, 0, sizeof fnametemp);
  4523. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  4524. if((access(fnametemp,F_OK))!=-1)
  4525. {
  4526. strcpy(chargingProfiles[i], fnametemp);
  4527. i = i + 1;
  4528. }
  4529. }
  4530. //Check TxProfile_%d.json
  4531. for(int j=1; j <= gunTotalNumber; j++)
  4532. {
  4533. memset(fnametemp, 0, sizeof fnametemp);
  4534. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  4535. if((access(fnametemp,F_OK))!=-1)
  4536. {
  4537. strcpy(chargingProfiles[i], fnametemp);
  4538. i = i + 1;
  4539. }
  4540. }
  4541. ChargeProfileCount = i;
  4542. }// End connectorIsNULL is TRUE
  4543. if(ChargeProfileCount == 0)
  4544. {
  4545. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4546. goto end;
  4547. }
  4548. #if 0
  4549. fptr1 = fopen(fname, "r");
  4550. if (!fptr1)
  4551. {
  4552. //file not exist
  4553. DEBUG_INFO("Unable to open the input file!!\n");
  4554. fptr1 = fopen(fname, "w+");
  4555. }
  4556. fclose(fptr1);
  4557. #endif
  4558. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  4559. {
  4560. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4561. goto end;
  4562. }
  4563. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  4564. {
  4565. memset(str, 0, sizeof str);
  4566. // clear temp file
  4567. sprintf(str,"rm -f %s",temp);
  4568. system(str);
  4569. for(int k=0; k < ChargeProfileCount; k++)
  4570. {
  4571. memset(str, 0, sizeof str);
  4572. //clear file in C
  4573. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4574. system(str);
  4575. }
  4576. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4577. goto end;
  4578. }
  4579. else if(connectorIsNULL == TRUE)
  4580. {
  4581. for(int k=0; k < ChargeProfileCount; k++)
  4582. {
  4583. fptr1 = fopen(chargingProfiles[k], "r");
  4584. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  4585. //Check Charging Profile Count
  4586. while(fscanf(fptr1, "%s", word) != EOF)
  4587. {
  4588. //DEBUG_INFO("word=%s\n",word);
  4589. if(strstr(word, "chargingProfileId")!= NULL)
  4590. {
  4591. //DEBUG_INFO("test chargingProfileId \n");
  4592. n_chargingProfile = n_chargingProfile + 1;
  4593. //DEBUG_INFO("chargingProfileId Found\n");
  4594. }
  4595. }
  4596. rewind(fptr1);
  4597. //search Charging Profile Element
  4598. //int i= 0;
  4599. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4600. {
  4601. //------------------------tempconnectorIdInt------------------------//
  4602. loc = strstr(sLineWord, "connectorId");
  4603. c = 0;
  4604. memset(sstr ,0, sizeof(sstr) );
  4605. while (loc[strlen("connectorId")+2+c] != ',')
  4606. {
  4607. sstr[c] = loc[strlen("connectorId")+2+c];
  4608. c++;
  4609. }
  4610. sstr[c] = '\0';
  4611. tempconnectorIdInt = atoi(sstr);
  4612. printf("file's gun number is %d\n", tempconnectorIdInt);
  4613. //--------------------------chargingProfileId--------------------//
  4614. c = 0;
  4615. loc = strstr(sLineWord, "chargingProfileId");
  4616. memset(sstr ,0, sizeof(sstr) );
  4617. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4618. {
  4619. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4620. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4621. c++;
  4622. }
  4623. sstr[c] = '\0';
  4624. tempchargingProfileIdInt = atoi(sstr);
  4625. //stackLevel
  4626. c = 0;
  4627. loc = strstr(sLineWord, "stackLevel");
  4628. memset(sstr ,0, sizeof(sstr) );
  4629. while (loc[strlen("stackLevel")+2+c] != ',')
  4630. {
  4631. sstr[c] = loc[strlen("stackLevel")+2+c];
  4632. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4633. c++;
  4634. }
  4635. sstr[c] = '\0';
  4636. tempstackLevelInt = atoi(sstr);
  4637. c = 0;
  4638. loc = strstr(sLineWord, "chargingProfilePurpose");
  4639. memset(sstr ,0, sizeof(sstr) );
  4640. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4641. {
  4642. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4643. c++;
  4644. }
  4645. sstr[c] = '\0';
  4646. strcpy(tempchargingProfilePurposeStr, sstr);
  4647. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4648. {
  4649. //------- not write to fptr2-------//
  4650. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4651. //clearflag = TRUE;
  4652. }
  4653. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4654. {
  4655. //------- not write to fptr2-------//
  4656. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4657. }
  4658. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4659. {
  4660. //------- not write to fptr2-------//
  4661. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4662. }
  4663. else
  4664. {
  4665. fprintf(fptr2, sLineWord);//writing data into file
  4666. }
  4667. memset(sLineWord, 0, sizeof sLineWord);
  4668. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4669. if(clearflag == TRUE)
  4670. {
  4671. fclose(fptr1);
  4672. fclose(fptr2);
  4673. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4674. system(str);
  4675. // clear temp file
  4676. sprintf(str,"rm -f %s",temp);
  4677. system(str);
  4678. }
  4679. else
  4680. {
  4681. fclose(fptr1);
  4682. fclose(fptr2);
  4683. memset(str, 0, sizeof str);
  4684. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4685. system(str);
  4686. resultRename = rename(temp, chargingProfiles[k]);
  4687. if(resultRename == 0)
  4688. {
  4689. DEBUG_INFO("File ChargingProfile renamed successfully");
  4690. }
  4691. else
  4692. {
  4693. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4694. }
  4695. if(comfirmstr[0]== 0)
  4696. {
  4697. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4698. }
  4699. //Check chargingProfile is empty file
  4700. /*------ Read the file ----------------*/
  4701. fptr1=fopen(chargingProfiles[k],"r");
  4702. ch=fgetc(fptr1);
  4703. rewind(fptr1);
  4704. memset(sLineWord, 0, sizeof sLineWord);
  4705. if(ch!=EOF)
  4706. {
  4707. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4708. {
  4709. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4710. if(sLineWord[0]=='\0')
  4711. {
  4712. isEmptyFile = TRUE;
  4713. break;
  4714. }
  4715. else
  4716. {
  4717. isEmptyFile = FALSE;
  4718. break;
  4719. }
  4720. }
  4721. }
  4722. fclose(fptr1);
  4723. if(isEmptyFile == TRUE)
  4724. {
  4725. memset(str, 0, sizeof str);
  4726. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4727. system(str);
  4728. }
  4729. }
  4730. }// End of while(int k=0; k < ChargePointCount; k++)
  4731. }
  4732. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4733. {
  4734. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4735. for(int k=0; k < ChargeProfileCount; k++)
  4736. {
  4737. fptr1 = fopen(chargingProfiles[k], "r");
  4738. fptr2 = fopen(temp, "w+");
  4739. //Check Charging Profile Count
  4740. while(fscanf(fptr1, "%s", word) != EOF)
  4741. {
  4742. //DEBUG_INFO("word=%s\n",word);
  4743. if(strstr(word, "chargingProfileId")!= NULL)
  4744. {
  4745. //DEBUG_INFO("test chargingProfileId \n");
  4746. n_chargingProfile = n_chargingProfile + 1;
  4747. //DEBUG_INFO("chargingProfileId Found\n");
  4748. }
  4749. }
  4750. rewind(fptr1);
  4751. //search Charging Profile Element
  4752. //int i= 0;
  4753. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4754. {
  4755. //*************************tempconnectorIdInt*********************************/
  4756. loc = strstr(sLineWord, "connectorId");
  4757. c = 0;
  4758. memset(sstr ,0, sizeof(sstr) );
  4759. while (loc[strlen("connectorId")+2+c] != ',')
  4760. {
  4761. sstr[c] = loc[strlen("connectorId")+2+c];
  4762. c++;
  4763. }
  4764. sstr[c] = '\0';
  4765. tempconnectorIdInt = atoi(sstr);
  4766. //chargingProfileId
  4767. c = 0;
  4768. loc = strstr(sLineWord, "chargingProfileId");
  4769. memset(sstr ,0, sizeof(sstr) );
  4770. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4771. {
  4772. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4773. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4774. c++;
  4775. }
  4776. sstr[c] = '\0';
  4777. tempchargingProfileIdInt = atoi(sstr);
  4778. //stackLevel
  4779. c = 0;
  4780. loc = strstr(sLineWord, "stackLevel");
  4781. memset(sstr ,0, sizeof(sstr) );
  4782. while (loc[strlen("stackLevel")+2+c] != ',')
  4783. {
  4784. sstr[c] = loc[strlen("stackLevel")+2+c];
  4785. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4786. c++;
  4787. }
  4788. sstr[c] = '\0';
  4789. tempstackLevelInt = atoi(sstr);
  4790. c = 0;
  4791. loc = strstr(sLineWord, "chargingProfilePurpose");
  4792. memset(sstr ,0, sizeof(sstr) );
  4793. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4794. {
  4795. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4796. c++;
  4797. }
  4798. sstr[c] = '\0';
  4799. strcpy(tempchargingProfilePurposeStr, sstr);
  4800. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4801. {
  4802. //------- not write to fptr2-------//
  4803. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4804. //clearflag = TRUE;
  4805. }
  4806. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4807. {
  4808. //------- not write to fptr2-------//
  4809. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4810. }
  4811. else if(stackLevelIsNULL == TRUE)
  4812. {
  4813. //Clear Whole File
  4814. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4815. clearflag = TRUE;
  4816. break;
  4817. }
  4818. else
  4819. {
  4820. fprintf(fptr2, sLineWord);//writing data into file
  4821. }
  4822. memset(sLineWord, 0, sizeof sLineWord);
  4823. }
  4824. if(clearflag == TRUE)
  4825. {
  4826. fclose(fptr1);
  4827. fclose(fptr2);
  4828. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4829. system(str);
  4830. // clear temp file
  4831. sprintf(str,"rm -f %s",temp);
  4832. system(str);
  4833. }
  4834. else
  4835. {
  4836. fclose(fptr1);
  4837. fclose(fptr2);
  4838. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4839. system(str);
  4840. resultRename = rename(temp, chargingProfiles[k]);
  4841. if(resultRename == 0)
  4842. {
  4843. DEBUG_INFO("File ChargingProfile renamed successfully");
  4844. }
  4845. else
  4846. {
  4847. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4848. }
  4849. if(comfirmstr[0]== 0)
  4850. {
  4851. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4852. }
  4853. //Check chargingProfile is empty file
  4854. /*------ Read the file ----------------*/
  4855. fptr1=fopen(chargingProfiles[k],"r");
  4856. ch=fgetc(fptr1);
  4857. rewind(fptr1);
  4858. memset(sLineWord, 0, sizeof sLineWord);
  4859. if(ch!=EOF)
  4860. {
  4861. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4862. {
  4863. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4864. if(sLineWord[0]=='\0')
  4865. {
  4866. isEmptyFile = TRUE;
  4867. break;
  4868. }
  4869. else
  4870. {
  4871. isEmptyFile = FALSE;
  4872. break;
  4873. }
  4874. }
  4875. }
  4876. fclose(fptr1);
  4877. if(isEmptyFile == TRUE)
  4878. {
  4879. memset(str, 0, sizeof str);
  4880. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4881. system(str);
  4882. }
  4883. /*------- End of reading ---------------*/
  4884. }
  4885. } // while(int k=0; k < ChargeProfileCount; k++)
  4886. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4887. end:
  4888. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4889. return result;
  4890. }
  4891. int handleDataTransferRequest(char *uuid, char *payload)
  4892. {
  4893. mtrace();
  4894. int result = FAIL;
  4895. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4896. char tempvendorId[255]={0};
  4897. char tempmessageId[50]={0};
  4898. char tempdata[50]={0};
  4899. char sstr[160]={0};//sstr[200]={ 0 };
  4900. char message[80]={0};
  4901. int c = 0;
  4902. char *loc;
  4903. DEBUG_INFO("handle DataTransferRequest\n");
  4904. if((uuid != NULL) && (payload != NULL))
  4905. {
  4906. //===============================
  4907. // vendorId
  4908. //===============================
  4909. c = 0;
  4910. loc = strstr(payload, "vendorId");
  4911. while (loc[strlen("vendorId")+3+c] != '\"')
  4912. {
  4913. sstr[c] = loc[strlen("vendorId")+3+c];
  4914. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4915. c++;
  4916. }
  4917. sstr[c] = '\0';
  4918. strcpy(tempvendorId,sstr);
  4919. //===============================
  4920. // messageId
  4921. //===============================
  4922. memset(sstr ,0, sizeof(sstr) );
  4923. c = 0;
  4924. loc = strstr(payload, "messageId");
  4925. while (loc[strlen("messageId")+3+c] != '\"')
  4926. {
  4927. sstr[c] = loc[strlen("messageId")+3+c];
  4928. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4929. c++;
  4930. }
  4931. sstr[c] = '\0';
  4932. strcpy(tempmessageId,sstr);
  4933. //===============================
  4934. // data
  4935. //===============================
  4936. memset(sstr ,0, sizeof(sstr) );
  4937. c = 0;
  4938. loc = strstr(payload, "data");
  4939. printf("loc=%s\n",loc);
  4940. while (loc[strlen("data")+3+c] != '\"')
  4941. {
  4942. sstr[c] = loc[strlen("data")+3+c];
  4943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4944. c++;
  4945. }
  4946. sstr[c] = '\0';
  4947. strcpy(tempdata,sstr);
  4948. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4949. }
  4950. else
  4951. {
  4952. char guid[37]={0};
  4953. random_uuid(guid);
  4954. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4955. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4956. }
  4957. LWS_Send(message);
  4958. return result;
  4959. }
  4960. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4961. {
  4962. mtrace();
  4963. int result = FAIL;
  4964. int connectorIdInt, durationInt;
  4965. char chargingRateUnitStr[4]={0};
  4966. //int tempconnectorIdInt,
  4967. int tempdurationInt;
  4968. float tempminChargingRateFloat = 0.0;
  4969. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4970. int tempStartPeriodInt=0;
  4971. float tempLimitInt=0.0;//0.1;
  4972. int tempNumberPhasesInt=0;
  4973. char fname[200];
  4974. char comfirmstr[20];
  4975. //float totallimit =0.0;
  4976. float MinChargingRate =0.0;
  4977. //double diff_t;
  4978. //struct tm tp;
  4979. FILE *fptr1;
  4980. int c = 0;
  4981. //int i = 0;
  4982. char * pch;
  4983. char *loc;
  4984. char sstr[200]={ 0 },sstrtemp[50]={ 0 };
  4985. int n_chargingProfile = 0;
  4986. int n_SchedulePeriods = 0;
  4987. char SchedulePeriodList[10][200]={0};
  4988. char sLineWord[1600]={0};
  4989. //int n_periods = 0;
  4990. char word[1000]={0};
  4991. int confirmPeriods = 0;
  4992. struct StructProfile ChargePointMaxProfile;
  4993. struct StructProfile TxDefaultProfile;
  4994. struct StructProfile TxProfile;
  4995. struct StructProfile TxDefaultProfiletemp[2]={0};
  4996. int TxDefaultProfileFileIsNull=FALSE;
  4997. int ChargePointMaxProfileIsNull=FALSE;
  4998. int TxProfileIsNull=FALSE;
  4999. int CompositeSceduleIndex = 0;
  5000. char ChargePointMaxProfileScheduleStr[30]={0};
  5001. char TxDefaultProfileScheduleStr[30]={0};
  5002. char TxProfileScheduleStr[30]={0};
  5003. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  5004. strcpy(sstrtemp, stringtrimspace(payload));
  5005. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  5006. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  5007. memset(&TxProfile,0,sizeof(struct StructProfile));
  5008. c=0;
  5009. loc = strstr(sstrtemp, "connectorId");
  5010. memset(sstr ,0, sizeof(sstr) );
  5011. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5012. {
  5013. sstr[c] = loc[strlen("connectorId")+2+c];
  5014. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5015. c++;
  5016. }
  5017. sstr[c] = '\0';
  5018. connectorIdInt = atoi(sstr);
  5019. c=0;
  5020. loc = strstr(sstrtemp, "duration");
  5021. memset(sstr ,0, sizeof(sstr) );
  5022. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5023. {
  5024. sstr[c] = loc[strlen("duration")+2+c];
  5025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5026. c++;
  5027. }
  5028. sstr[c] = '\0';
  5029. durationInt = atoi(sstr);
  5030. c = 0;
  5031. loc = strstr(sstrtemp, "chargingRateUnit");
  5032. memset(sstr ,0, sizeof(sstr) );
  5033. if(loc == NULL)
  5034. {
  5035. }
  5036. else
  5037. {
  5038. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5039. {
  5040. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5041. c++;
  5042. }
  5043. sstr[c] = '\0';
  5044. strcpy(chargingRateUnitStr, sstr);
  5045. }
  5046. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  5047. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  5048. if(connectorIdInt==0) // connectorId is 0
  5049. {
  5050. //******************************ChargePointMaxProfile*****************************************************/
  5051. strcpy(fname, ChargePointMaxProfile_JSON );
  5052. char word[30]={0};
  5053. char sLineWord[1060]={0};
  5054. int n_chargingProfile=0;
  5055. ChargePointMaxProfileIsNull=TRUE;
  5056. if((access(fname,F_OK))!=-1)
  5057. {
  5058. fptr1 = fopen(fname, "r");
  5059. int c;
  5060. c = fgetc(fptr1);
  5061. //DEBUG_INFO("c:%d\n",c);
  5062. rewind(fptr1);
  5063. if(c == EOF)
  5064. {
  5065. DEBUG_INFO("\n End of file ChargingProfile reached.");
  5066. ChargePointMaxProfileIsNull=TRUE;
  5067. fclose(fptr1);
  5068. }
  5069. else
  5070. {
  5071. ChargePointMaxProfileIsNull=FALSE;
  5072. while(fscanf(fptr1, "%s", word) != EOF)
  5073. {
  5074. if(strcmp(word, "chargingProfileId") == 0)
  5075. {
  5076. n_chargingProfile = n_chargingProfile + 1;
  5077. printf("Found\n");
  5078. }
  5079. }
  5080. rewind(fptr1);
  5081. //search Charging Profile Element
  5082. int i= 0;
  5083. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5084. #if 0
  5085. /***********connectorId****************/
  5086. c = 0;
  5087. loc = strstr(sLineWord, "connectorId");
  5088. // printf("loc=%s\n",loc);
  5089. memset(sstr ,0, sizeof(sstr) );
  5090. while (loc[strlen("connectorId")+2+c] != ',')
  5091. {
  5092. sstr[c] = loc[strlen("connectorId")+2+c];
  5093. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5094. c++;
  5095. }
  5096. sstr[c] = '\0';
  5097. tempconnectorIdInt = atoi(sstr);
  5098. #endif
  5099. //***********validFrom**************/
  5100. c = 0;
  5101. loc = strstr(sLineWord, "validFrom");
  5102. //DEBUG_INFO("loc=%s\n",loc);
  5103. memset(sstr ,0, sizeof(sstr) );
  5104. if(loc != NULL)
  5105. {
  5106. while (loc[3+strlen("validFrom")+c] != '\"')
  5107. {
  5108. sstr[c] = loc[3+strlen("validFrom")+c];
  5109. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5110. c++;
  5111. }
  5112. sstr[c] = '\0';
  5113. DEBUG_INFO("validFrom=%s\n",sstr);
  5114. strcpy(tempvalidFromStr,sstr);
  5115. }
  5116. else
  5117. {
  5118. strcpy(tempvalidFromStr,"");
  5119. }
  5120. //**********startSchedule**********/
  5121. c = 0;
  5122. loc = strstr(sLineWord, "startSchedule");
  5123. //DEBUG_INFO("loc=%s\n",loc);
  5124. memset(sstr ,0, sizeof(sstr) );
  5125. if(loc != NULL)
  5126. {
  5127. while (loc[3+strlen("startSchedule")+c] != '\"')
  5128. {
  5129. sstr[c] = loc[3+strlen("startSchedule")+c];
  5130. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5131. c++;
  5132. }
  5133. sstr[c] = '\0';
  5134. strcpy(tempstartScheduleStr, sstr);
  5135. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5136. }
  5137. else
  5138. {
  5139. strcpy(tempstartScheduleStr, "");
  5140. strcpy(ChargePointMaxProfileScheduleStr, "");
  5141. }
  5142. //**********chargingRateUnit**********/
  5143. c = 0;
  5144. loc = strstr(sLineWord, "chargingRateUnit");
  5145. memset(sstr ,0, sizeof(sstr) );
  5146. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5147. {
  5148. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5149. c++;
  5150. }
  5151. sstr[c] = '\0';
  5152. strcpy(tempchargingRateUnitStr, sstr);
  5153. //**********minChargingRate*******/
  5154. c = 0;
  5155. loc = strstr(sLineWord, "minChargingRate");
  5156. //printf("loc=%s\n",loc);
  5157. if(loc != NULL)
  5158. {
  5159. memset(sstr ,0, sizeof(sstr) );
  5160. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5161. {
  5162. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5163. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5164. c++;
  5165. }
  5166. sstr[c] = '\0';
  5167. tempminChargingRateFloat = atof(sstr);
  5168. }
  5169. else
  5170. {
  5171. tempminChargingRateFloat = 0.0;
  5172. }
  5173. //
  5174. #if 0
  5175. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5176. tp.tm_isdst = -1;
  5177. time_t utc = mktime(&tp);
  5178. // current time
  5179. time_t t = time(NULL);
  5180. #endif
  5181. //diff_t = difftime(t, utc);
  5182. //parsing strings to words
  5183. i = 0;
  5184. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5185. loc = loc+3+strlen("chargingSchedulePeriod");
  5186. pch = strtok(loc ,"{");
  5187. while (pch != NULL)
  5188. {
  5189. strcpy(SchedulePeriodList[i], pch);
  5190. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5191. //printf ("%s\n",pch);
  5192. pch = strtok (NULL, "{");
  5193. i = i + 1;
  5194. }
  5195. n_SchedulePeriods = i;
  5196. for(int i=0;i<n_SchedulePeriods;i++)
  5197. {
  5198. //*************startPeriod****************/
  5199. c = 0;
  5200. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5201. memset(sstr ,0, sizeof(sstr) );
  5202. while (loc[strlen("startPeriod")+2+c] != ',')
  5203. {
  5204. sstr[c] = loc[strlen("startPeriod")+2+c];
  5205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5206. c++;
  5207. }
  5208. sstr[c] = '\0';
  5209. tempStartPeriodInt = atoi(sstr);
  5210. //*************limit****************/
  5211. c = 0;
  5212. loc = strstr(SchedulePeriodList[i], "limit");
  5213. memset(sstr ,0, sizeof(sstr) );
  5214. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5215. {
  5216. sstr[c] = loc[strlen("limit")+2+c];
  5217. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5218. c++;
  5219. }
  5220. sstr[c] = '\0';
  5221. tempLimitInt = atof(sstr);
  5222. //*************numberPhases****************/
  5223. c = 0;
  5224. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5225. memset(sstr ,0, sizeof(sstr) );
  5226. if(loc != NULL)
  5227. {
  5228. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5229. {
  5230. sstr[c] = loc[strlen("numberPhases")+2+c];
  5231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5232. c++;
  5233. }
  5234. sstr[c] = '\0';
  5235. tempNumberPhasesInt = atoi(sstr);
  5236. }
  5237. else
  5238. {
  5239. tempNumberPhasesInt = 0;
  5240. }
  5241. ChargePointMaxProfile.Duration = durationInt;
  5242. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5243. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5244. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5245. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5246. }
  5247. if(MinChargingRate < tempminChargingRateFloat)
  5248. MinChargingRate = tempminChargingRateFloat;
  5249. }
  5250. }// End of file ChargingProfile
  5251. } //THE END OF ACCESS ChargePointMaxProfile
  5252. //******************************TxDefaultProfile***********************************************/
  5253. strcpy(fname, TxDefaultProfile_0_JSON);
  5254. memset(word, 0, 30);
  5255. memset(sLineWord, 0, 1060);
  5256. //char word[30]={0};
  5257. //char sLineWord[1060]={0};
  5258. n_chargingProfile=0;
  5259. TxDefaultProfileFileIsNull=TRUE;
  5260. if((access(fname,F_OK))!=-1)
  5261. {
  5262. fptr1 = fopen(fname, "r");
  5263. c = 0;
  5264. c = fgetc(fptr1);
  5265. //DEBUG_INFO("c:%d\n",c);
  5266. rewind(fptr1);
  5267. if(c == EOF)
  5268. {
  5269. DEBUG_INFO("\n End of file ChargingProfile reached.");
  5270. TxDefaultProfileFileIsNull=TRUE;
  5271. fclose(fptr1);
  5272. }
  5273. else
  5274. {
  5275. TxDefaultProfileFileIsNull=FALSE;
  5276. while(fscanf(fptr1, "%s", word) != EOF)
  5277. {
  5278. if(strcmp(word, "chargingProfileId") == 0)
  5279. {
  5280. n_chargingProfile = n_chargingProfile + 1;
  5281. printf("Found\n");
  5282. }
  5283. }
  5284. rewind(fptr1);
  5285. //search Charging Profile Element
  5286. int i= 0;
  5287. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5288. #if 0
  5289. /***********connectorId****************/
  5290. c = 0;
  5291. loc = strstr(sLineWord, "connectorId");
  5292. // printf("loc=%s\n",loc);
  5293. memset(sstr ,0, sizeof(sstr) );
  5294. while (loc[strlen("connectorId")+2+c] != ',')
  5295. {
  5296. sstr[c] = loc[strlen("connectorId")+2+c];
  5297. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5298. c++;
  5299. }
  5300. sstr[c] = '\0';
  5301. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  5302. tempconnectorIdInt = atoi(sstr);
  5303. #endif
  5304. //***********validFrom**************/
  5305. c = 0;
  5306. loc = strstr(sLineWord, "validFrom");
  5307. //DEBUG_INFO("loc=%s\n",loc);
  5308. memset(sstr ,0, sizeof(sstr) );
  5309. if(loc != NULL)
  5310. {
  5311. while (loc[3+strlen("validFrom")+c] != '\"')
  5312. {
  5313. sstr[c] = loc[3+strlen("validFrom")+c];
  5314. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5315. c++;
  5316. }
  5317. sstr[c] = '\0';
  5318. DEBUG_INFO("validFrom=%s\n",sstr);
  5319. strcpy(tempvalidFromStr,sstr);
  5320. }
  5321. else
  5322. {
  5323. strcpy(tempvalidFromStr,"");
  5324. }
  5325. //**********startSchedule**********/
  5326. c = 0;
  5327. loc = strstr(sLineWord, "startSchedule");
  5328. //DEBUG_INFO("loc=%s\n",loc);
  5329. memset(sstr ,0, sizeof(sstr) );
  5330. if(loc != NULL)
  5331. {
  5332. while (loc[3+strlen("startSchedule")+c] != '\"')
  5333. {
  5334. sstr[c] = loc[3+strlen("startSchedule")+c];
  5335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5336. c++;
  5337. }
  5338. sstr[c] = '\0';
  5339. strcpy(tempstartScheduleStr, sstr);
  5340. strcpy(TxDefaultProfileScheduleStr, sstr);
  5341. }
  5342. else
  5343. {
  5344. strcpy(tempstartScheduleStr, "");
  5345. strcpy(TxDefaultProfileScheduleStr, "");
  5346. }
  5347. //**********chargingRateUnit**********/
  5348. c = 0;
  5349. loc = strstr(sLineWord, "chargingRateUnit");
  5350. memset(sstr ,0, sizeof(sstr) );
  5351. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5352. {
  5353. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5354. c++;
  5355. }
  5356. sstr[c] = '\0';
  5357. strcpy(tempchargingRateUnitStr, sstr);
  5358. //**********minChargingRate*******/
  5359. c = 0;
  5360. loc = strstr(sLineWord, "minChargingRate");
  5361. //printf("loc=%s\n",loc);
  5362. if(loc != NULL)
  5363. {
  5364. memset(sstr ,0, sizeof(sstr) );
  5365. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5366. {
  5367. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5369. c++;
  5370. }
  5371. sstr[c] = '\0';
  5372. tempminChargingRateFloat = atof(sstr);
  5373. }
  5374. else
  5375. {
  5376. tempminChargingRateFloat = 0.0;
  5377. }
  5378. #if 0
  5379. //
  5380. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5381. tp.tm_isdst = -1;
  5382. time_t utc = mktime(&tp);
  5383. // current time
  5384. time_t t = time(NULL);
  5385. //diff_t = difftime(t, utc);
  5386. #endif
  5387. //parsing strings to words
  5388. i = 0;
  5389. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5390. loc = loc+3+strlen("chargingSchedulePeriod");
  5391. pch = strtok(loc ,"{");
  5392. while (pch != NULL)
  5393. {
  5394. strcpy(SchedulePeriodList[i], pch);
  5395. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5396. //printf ("%s\n",pch);
  5397. pch = strtok (NULL, "{");
  5398. i = i + 1;
  5399. }
  5400. n_SchedulePeriods = i;
  5401. for(int i=0;i<n_SchedulePeriods;i++)
  5402. {
  5403. //*************startPeriod****************/
  5404. c = 0;
  5405. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5406. memset(sstr ,0, sizeof(sstr) );
  5407. while (loc[strlen("startPeriod")+2+c] != ',')
  5408. {
  5409. sstr[c] = loc[strlen("startPeriod")+2+c];
  5410. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5411. c++;
  5412. }
  5413. sstr[c] = '\0';
  5414. tempStartPeriodInt = atoi(sstr);
  5415. //*************limit****************/
  5416. c = 0;
  5417. loc = strstr(SchedulePeriodList[i], "limit");
  5418. memset(sstr ,0, sizeof(sstr) );
  5419. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5420. {
  5421. sstr[c] = loc[strlen("limit")+2+c];
  5422. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5423. c++;
  5424. }
  5425. sstr[c] = '\0';
  5426. tempLimitInt = atof(sstr);
  5427. //*************numberPhases****************/
  5428. c = 0;
  5429. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5430. memset(sstr ,0, sizeof(sstr) );
  5431. if(loc != NULL)
  5432. {
  5433. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5434. {
  5435. sstr[c] = loc[strlen("numberPhases")+2+c];
  5436. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5437. c++;
  5438. }
  5439. sstr[c] = '\0';
  5440. tempNumberPhasesInt = atoi(sstr);
  5441. }
  5442. else
  5443. {
  5444. tempNumberPhasesInt = 0;
  5445. }
  5446. TxDefaultProfile.Duration = durationInt;
  5447. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5448. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5449. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5450. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5451. }
  5452. if(MinChargingRate < tempminChargingRateFloat)
  5453. MinChargingRate = tempminChargingRateFloat;
  5454. }
  5455. }
  5456. }// the end of ACCESS TxDefaultProfile
  5457. //--------------------- Composite Schedule-----------------------------//
  5458. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  5459. {
  5460. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5461. struct tm tp;
  5462. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5463. tp.tm_isdst = -1;
  5464. time_t utc = mktime(&tp);
  5465. time_t t = time(NULL);
  5466. double diff_f = difftime(t, utc);
  5467. int diff_i; //= (int)diff_f;
  5468. int quotient; //= diff_i / 86400;//86400 seconds/day
  5469. int period = 0;
  5470. if(diff_f >= 0)
  5471. {
  5472. diff_i = (int)diff_f;
  5473. quotient = diff_i / 86400;
  5474. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5475. {
  5476. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5477. {
  5478. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  5479. {
  5480. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5481. }
  5482. else
  5483. {
  5484. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5485. }
  5486. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5487. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5488. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5489. period = period + 1;
  5490. }
  5491. }
  5492. }
  5493. confirmPeriods = period;
  5494. }
  5495. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  5496. {
  5497. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5498. struct tm tp;
  5499. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5500. tp.tm_isdst = -1;
  5501. time_t utc = mktime(&tp);
  5502. time_t t = time(NULL);
  5503. double diff_f = difftime(t, utc);
  5504. int diff_i; // = (int)diff_f;
  5505. int quotient; // = diff_i / 86400;//86400 seconds/day
  5506. int period = 0;
  5507. if(diff_f >= 0)
  5508. {
  5509. diff_i = (int)diff_f;
  5510. quotient = diff_i / 86400;//86400 seconds/day
  5511. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5512. {
  5513. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5514. {
  5515. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5516. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5517. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5518. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5519. period = period + 1;
  5520. }
  5521. }
  5522. }
  5523. confirmPeriods = period;
  5524. }
  5525. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  5526. {
  5527. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  5528. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  5529. {
  5530. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  5531. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  5532. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  5533. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5534. }
  5535. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  5536. }
  5537. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  5538. {
  5539. confirmPeriods = 0;
  5540. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5541. //goto end;
  5542. }
  5543. //* Define temporary variables */
  5544. struct tm *gtime;
  5545. time_t now;
  5546. char buf[28];
  5547. /* Read the current system time */
  5548. time(&now);
  5549. /* Convert the system time to GMT (now UTC) */
  5550. gtime = gmtime(&now);
  5551. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5552. // make .conf
  5553. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5554. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5555. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5556. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5557. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5558. }
  5559. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  5560. {
  5561. //*****************************ChargePointMaxProfile******************************************/
  5562. strcpy(fname, ChargePointMaxProfile_JSON);
  5563. ChargePointMaxProfileIsNull=TRUE;
  5564. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  5565. {
  5566. fptr1 = fopen(fname, "r");
  5567. int c;
  5568. c = fgetc(fptr1);
  5569. //DEBUG_INFO("c:%d\n",c);
  5570. rewind(fptr1);
  5571. if(c == EOF)
  5572. {
  5573. DEBUG_INFO("\n End of file reached.");
  5574. ChargePointMaxProfileIsNull=TRUE;
  5575. fclose(fptr1);
  5576. }
  5577. else
  5578. {
  5579. ChargePointMaxProfileIsNull=FALSE;
  5580. while(fscanf(fptr1, "%s", word) != EOF)
  5581. {
  5582. if(strcmp(word, "chargingProfileId") == 0)
  5583. {
  5584. n_chargingProfile = n_chargingProfile + 1;
  5585. }
  5586. }
  5587. rewind(fptr1);
  5588. //search Charging Profile Element
  5589. int i = 0;
  5590. int j = 0;
  5591. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5592. #if 0
  5593. /***********connectorId****************/
  5594. c = 0;
  5595. loc = strstr(sLineWord, "connectorId");
  5596. memset(sstr ,0, sizeof(sstr) );
  5597. while (loc[strlen("connectorId")+2+c] != ',')
  5598. {
  5599. sstr[c] = loc[strlen("connectorId")+2+c];
  5600. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5601. c++;
  5602. }
  5603. sstr[c] = '\0';
  5604. tempconnectorIdInt = atoi(sstr);
  5605. #endif
  5606. //***********validFrom**************/
  5607. c = 0;
  5608. loc = strstr(sLineWord, "validFrom");
  5609. if(loc != NULL)
  5610. {
  5611. memset(sstr ,0, sizeof(sstr) );
  5612. while (loc[3+strlen("validFrom")+c] != '\"')
  5613. {
  5614. sstr[c] = loc[3+strlen("validFrom")+c];
  5615. c++;
  5616. }
  5617. sstr[c] = '\0';
  5618. strcpy(tempvalidFromStr,sstr);
  5619. }
  5620. else
  5621. {
  5622. strcpy(tempvalidFromStr,"");
  5623. }
  5624. //***********validFrom**************/
  5625. c = 0;
  5626. loc = strstr(sLineWord, "duration");
  5627. if(loc != NULL)
  5628. {
  5629. memset(sstr ,0, sizeof(sstr) );
  5630. while (loc[2+strlen("duration")+c] != ',')
  5631. {
  5632. sstr[c] = loc[2+strlen("duration")+c];
  5633. c++;
  5634. }
  5635. sstr[c] = '\0';
  5636. tempdurationInt = atoi(sstr);
  5637. }
  5638. else
  5639. {
  5640. tempdurationInt = 0;
  5641. }
  5642. //**********startSchedule**********/
  5643. c = 0;
  5644. loc = strstr(sLineWord, "startSchedule");
  5645. memset(sstr ,0, sizeof(sstr) );
  5646. if(loc != NULL)
  5647. {
  5648. while (loc[3+strlen("startSchedule")+c] != '\"')
  5649. {
  5650. sstr[c] = loc[3+strlen("startSchedule")+c];
  5651. c++;
  5652. }
  5653. sstr[c] = '\0';
  5654. strcpy(tempstartScheduleStr, sstr);
  5655. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5656. }
  5657. else
  5658. {
  5659. strcpy(tempstartScheduleStr, "");
  5660. strcpy(ChargePointMaxProfileScheduleStr, "");
  5661. }
  5662. //**********chargingRateUnit**********/
  5663. c = 0;
  5664. loc = strstr(sLineWord, "chargingRateUnit");
  5665. memset(sstr ,0, sizeof(sstr) );
  5666. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5667. {
  5668. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5669. c++;
  5670. }
  5671. sstr[c] = '\0';
  5672. strcpy(tempchargingRateUnitStr, sstr);
  5673. //**********minChargingRate*******/
  5674. c = 0;
  5675. loc = strstr(sLineWord, "minChargingRate");
  5676. if(loc != NULL)
  5677. {
  5678. memset(sstr ,0, sizeof(sstr) );
  5679. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5680. {
  5681. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5682. c++;
  5683. }
  5684. sstr[c] = '\0';
  5685. tempminChargingRateFloat = atof(sstr);
  5686. }
  5687. else
  5688. {
  5689. tempminChargingRateFloat = 0.0;
  5690. }
  5691. #if 0
  5692. //
  5693. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5694. tp.tm_isdst = -1;
  5695. time_t utc = mktime(&tp);
  5696. time_t t = time(NULL);
  5697. //diff_t = difftime(t, utc);
  5698. #endif
  5699. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5700. //DEBUG_INFO(" debug 5 -1\n");
  5701. //parsing strings to words
  5702. i = 0;
  5703. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5704. loc = loc+3+strlen("chargingSchedulePeriod");
  5705. pch = strtok(loc ,"{");
  5706. while (pch != NULL)
  5707. {
  5708. strcpy(SchedulePeriodList[i], pch);
  5709. pch = strtok (NULL, "{");
  5710. i = i + 1;
  5711. }
  5712. n_SchedulePeriods = i;
  5713. for(int i=0;i<n_SchedulePeriods;i++)
  5714. {
  5715. //*************startPeriod****************/
  5716. c = 0;
  5717. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5718. memset(sstr ,0, sizeof(sstr) );
  5719. while (loc[strlen("startPeriod")+2+c] != ',')
  5720. {
  5721. sstr[c] = loc[strlen("startPeriod")+2+c];
  5722. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5723. c++;
  5724. }
  5725. sstr[c] = '\0';
  5726. tempStartPeriodInt = atoi(sstr);
  5727. //*************limit****************/
  5728. c = 0;
  5729. loc = strstr(SchedulePeriodList[i], "limit");
  5730. memset(sstr ,0, sizeof(sstr) );
  5731. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5732. {
  5733. sstr[c] = loc[strlen("limit")+2+c];
  5734. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5735. c++;
  5736. }
  5737. sstr[c] = '\0';
  5738. tempLimitInt = atof(sstr);
  5739. //*************numberPhases****************/
  5740. c = 0;
  5741. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5742. memset(sstr ,0, sizeof(sstr) );
  5743. if(loc != NULL)
  5744. {
  5745. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5746. {
  5747. sstr[c] = loc[strlen("numberPhases")+2+c];
  5748. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5749. c++;
  5750. }
  5751. sstr[c] = '\0';
  5752. tempNumberPhasesInt = atoi(sstr);
  5753. }
  5754. else
  5755. {
  5756. tempNumberPhasesInt = 0;
  5757. }
  5758. if(j == 0)
  5759. {
  5760. ChargePointMaxProfile.Duration = tempdurationInt;
  5761. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5762. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5763. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5764. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5765. }
  5766. }
  5767. if(MinChargingRate < tempminChargingRateFloat)
  5768. {
  5769. MinChargingRate = tempminChargingRateFloat;
  5770. }
  5771. if(confirmPeriods < n_SchedulePeriods)
  5772. {
  5773. confirmPeriods = n_SchedulePeriods;
  5774. }
  5775. j = j + 1;
  5776. }
  5777. fclose(fptr1);
  5778. }
  5779. }// the end of access file ChargePointMaxProfile
  5780. //****************************TxDefaultProfile************************************************/
  5781. memset(fname, 0, sizeof fname);
  5782. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5783. TxDefaultProfileFileIsNull=TRUE;
  5784. if((access(fname,F_OK))!=-1)
  5785. {
  5786. fptr1 = fopen(fname, "r");
  5787. c = 0;
  5788. c = fgetc(fptr1);
  5789. //DEBUG_INFO("c:%d\n",c);
  5790. rewind(fptr1);
  5791. if(c == EOF)
  5792. {
  5793. DEBUG_INFO("\n End of file reached.");
  5794. TxDefaultProfileFileIsNull=TRUE;
  5795. fclose(fptr1);
  5796. }
  5797. else
  5798. {
  5799. TxDefaultProfileFileIsNull=FALSE;
  5800. while(fscanf(fptr1, "%s", word) != EOF)
  5801. {
  5802. if(strcmp(word, "chargingProfileId") == 0)
  5803. {
  5804. n_chargingProfile = n_chargingProfile + 1;
  5805. }
  5806. }
  5807. rewind(fptr1);
  5808. //search Charging Profile Element
  5809. int i = 0;
  5810. int j = 0;
  5811. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5812. //DEBUG_INFO(" 1-1\n");
  5813. #if 0
  5814. /***********connectorId****************/
  5815. c = 0;
  5816. loc = strstr(sLineWord, "connectorId");
  5817. memset(sstr ,0, sizeof(sstr) );
  5818. while (loc[strlen("connectorId")+2+c] != ',')
  5819. {
  5820. sstr[c] = loc[strlen("connectorId")+2+c];
  5821. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5822. c++;
  5823. }
  5824. sstr[c] = '\0';
  5825. tempconnectorIdInt = atoi(sstr);
  5826. #endif
  5827. //***********validFrom**************/
  5828. c = 0;
  5829. loc = strstr(sLineWord, "validFrom");
  5830. if(loc != NULL)
  5831. {
  5832. memset(sstr ,0, sizeof(sstr) );
  5833. while (loc[3+strlen("validFrom")+c] != '\"')
  5834. {
  5835. sstr[c] = loc[3+strlen("validFrom")+c];
  5836. c++;
  5837. }
  5838. sstr[c] = '\0';
  5839. strcpy(tempvalidFromStr,sstr);
  5840. }
  5841. else
  5842. {
  5843. strcpy(tempvalidFromStr,"");
  5844. }
  5845. //***********duration**************/
  5846. c = 0;
  5847. loc = strstr(sLineWord, "duration");
  5848. if(loc != NULL)
  5849. {
  5850. memset(sstr ,0, sizeof(sstr) );
  5851. while (loc[2+strlen("duration")+c] != ',')
  5852. {
  5853. sstr[c] = loc[2+strlen("duration")+c];
  5854. c++;
  5855. }
  5856. sstr[c] = '\0';
  5857. tempdurationInt = atoi(sstr);
  5858. }
  5859. else
  5860. {
  5861. tempdurationInt = 0;
  5862. }
  5863. //**********startSchedule**********/
  5864. c = 0;
  5865. loc = strstr(sLineWord, "startSchedule");
  5866. memset(sstr ,0, sizeof(sstr) );
  5867. if(loc != NULL)
  5868. {
  5869. while (loc[3+strlen("startSchedule")+c] != '\"')
  5870. {
  5871. sstr[c] = loc[3+strlen("startSchedule")+c];
  5872. c++;
  5873. }
  5874. sstr[c] = '\0';
  5875. strcpy(tempstartScheduleStr, sstr);
  5876. strcpy(TxDefaultProfileScheduleStr, sstr);
  5877. }
  5878. else
  5879. {
  5880. strcpy(tempstartScheduleStr, "");
  5881. strcpy(TxDefaultProfileScheduleStr, "");
  5882. }
  5883. //**********chargingRateUnit**********/
  5884. c = 0;
  5885. loc = strstr(sLineWord, "chargingRateUnit");
  5886. memset(sstr ,0, sizeof(sstr) );
  5887. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5888. {
  5889. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5890. c++;
  5891. }
  5892. sstr[c] = '\0';
  5893. strcpy(tempchargingRateUnitStr, sstr);
  5894. //**********minChargingRate*******/
  5895. c = 0;
  5896. loc = strstr(sLineWord, "minChargingRate");
  5897. if(loc != NULL)
  5898. {
  5899. memset(sstr ,0, sizeof(sstr) );
  5900. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5901. {
  5902. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5903. c++;
  5904. }
  5905. sstr[c] = '\0';
  5906. tempminChargingRateFloat = atof(sstr);
  5907. }
  5908. else
  5909. {
  5910. tempminChargingRateFloat = 0.0;
  5911. }
  5912. #if 0
  5913. //
  5914. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5915. tp.tm_isdst = -1;
  5916. time_t utc = mktime(&tp);
  5917. time_t t = time(NULL);
  5918. //diff_t = difftime(t, utc);
  5919. #endif
  5920. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5921. //parsing strings to words
  5922. i = 0;
  5923. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5924. loc = loc+3+strlen("chargingSchedulePeriod");
  5925. pch = strtok(loc ,"{");
  5926. while (pch != NULL)
  5927. {
  5928. strcpy(SchedulePeriodList[i], pch);
  5929. pch = strtok (NULL, "{");
  5930. i = i + 1;
  5931. }
  5932. n_SchedulePeriods = i;
  5933. for(int i=0;i<n_SchedulePeriods;i++)
  5934. {
  5935. //*************startPeriod****************/
  5936. c = 0;
  5937. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5938. memset(sstr ,0, sizeof(sstr) );
  5939. while (loc[strlen("startPeriod")+2+c] != ',')
  5940. {
  5941. sstr[c] = loc[strlen("startPeriod")+2+c];
  5942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5943. c++;
  5944. }
  5945. sstr[c] = '\0';
  5946. tempStartPeriodInt = atoi(sstr);
  5947. //*************limit****************/
  5948. c = 0;
  5949. loc = strstr(SchedulePeriodList[i], "limit");
  5950. memset(sstr ,0, sizeof(sstr) );
  5951. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5952. {
  5953. sstr[c] = loc[strlen("limit")+2+c];
  5954. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5955. c++;
  5956. }
  5957. sstr[c] = '\0';
  5958. tempLimitInt = atof(sstr);
  5959. //*************numberPhases****************/
  5960. c = 0;
  5961. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5962. memset(sstr ,0, sizeof(sstr) );
  5963. if(loc != NULL)
  5964. {
  5965. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5966. {
  5967. sstr[c] = loc[strlen("numberPhases")+2+c];
  5968. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5969. c++;
  5970. }
  5971. sstr[c] = '\0';
  5972. tempNumberPhasesInt = atoi(sstr);
  5973. }
  5974. else
  5975. {
  5976. tempNumberPhasesInt = 0;
  5977. }
  5978. if(j == 0)
  5979. {
  5980. TxDefaultProfile.Duration = tempdurationInt;
  5981. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5982. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5983. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5984. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5985. }
  5986. else
  5987. {
  5988. //other stack level charging Profile
  5989. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5990. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5991. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5992. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5993. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5994. }
  5995. }
  5996. if(MinChargingRate < tempminChargingRateFloat)
  5997. MinChargingRate = tempminChargingRateFloat;
  5998. if(confirmPeriods < n_SchedulePeriods)
  5999. confirmPeriods = n_SchedulePeriods;
  6000. j = j + 1;
  6001. //DEBUG_INFO(" 1-2\n");
  6002. }
  6003. fclose(fptr1);
  6004. //Stacking Charging Profiles
  6005. for(int l=0; l <(j-1) ;l++)
  6006. {
  6007. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  6008. {
  6009. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  6010. {
  6011. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  6012. {
  6013. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  6014. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  6015. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  6016. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  6017. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  6018. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  6019. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  6020. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  6021. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  6022. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  6023. }
  6024. else
  6025. {
  6026. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  6027. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  6028. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  6029. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  6030. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  6031. }
  6032. }
  6033. }
  6034. }
  6035. //end of Stacking Charging Profiles
  6036. }
  6037. }// the end of ACCESS TxDefaultProfile
  6038. //****************************TxProfile************************************************/
  6039. memset(fname, 0, sizeof fname);
  6040. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6041. TxProfileIsNull=TRUE;
  6042. if((access(fname,F_OK))!=-1)
  6043. {
  6044. fptr1 = fopen(fname, "r");
  6045. c = 0;
  6046. c = fgetc(fptr1);
  6047. //DEBUG_INFO("c:%d\n",c);
  6048. rewind(fptr1);
  6049. if(c == EOF)
  6050. {
  6051. DEBUG_INFO("\n End of file reached.");
  6052. TxProfileIsNull=TRUE;
  6053. fclose(fptr1);
  6054. }
  6055. else
  6056. {
  6057. TxProfileIsNull=FALSE;
  6058. while(fscanf(fptr1, "%s", word) != EOF)
  6059. {
  6060. if(strcmp(word, "chargingProfileId") == 0)
  6061. {
  6062. n_chargingProfile = n_chargingProfile + 1;
  6063. }
  6064. }
  6065. rewind(fptr1);
  6066. //search Charging Profile Element
  6067. int i= 0;
  6068. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  6069. #if 0
  6070. /***********connectorId****************/
  6071. c = 0;
  6072. loc = strstr(sLineWord, "connectorId");
  6073. memset(sstr ,0, sizeof(sstr) );
  6074. while (loc[strlen("connectorId")+2+c] != ',')
  6075. {
  6076. sstr[c] = loc[strlen("connectorId")+2+c];
  6077. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6078. c++;
  6079. }
  6080. sstr[c] = '\0';
  6081. tempconnectorIdInt = atoi(sstr);
  6082. #endif
  6083. //***********validFrom**************/
  6084. c = 0;
  6085. loc = strstr(sLineWord, "validFrom");
  6086. if(loc != NULL)
  6087. {
  6088. memset(sstr ,0, sizeof(sstr) );
  6089. while (loc[3+strlen("validFrom")+c] != '\"')
  6090. {
  6091. sstr[c] = loc[3+strlen("validFrom")+c];
  6092. c++;
  6093. }
  6094. sstr[c] = '\0';
  6095. strcpy(tempvalidFromStr,sstr);
  6096. }
  6097. else
  6098. {
  6099. strcpy(tempvalidFromStr,"");
  6100. }
  6101. //**********startSchedule**********/
  6102. c = 0;
  6103. loc = strstr(sLineWord, "startSchedule");
  6104. memset(sstr ,0, sizeof(sstr) );
  6105. if(loc != NULL)
  6106. {
  6107. while (loc[3+strlen("startSchedule")+c] != '\"')
  6108. {
  6109. sstr[c] = loc[3+strlen("startSchedule")+c];
  6110. c++;
  6111. }
  6112. sstr[c] = '\0';
  6113. strcpy(tempstartScheduleStr, sstr);
  6114. strcpy(TxProfileScheduleStr, sstr);
  6115. }
  6116. else
  6117. {
  6118. strcpy(tempstartScheduleStr, "");
  6119. strcpy(TxProfileScheduleStr, "");
  6120. }
  6121. //**********chargingRateUnit**********/
  6122. c = 0;
  6123. loc = strstr(sLineWord, "chargingRateUnit");
  6124. memset(sstr ,0, sizeof(sstr) );
  6125. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6126. {
  6127. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6128. c++;
  6129. }
  6130. sstr[c] = '\0';
  6131. strcpy(tempchargingRateUnitStr, sstr);
  6132. //**********minChargingRate*******/
  6133. c = 0;
  6134. loc = strstr(sLineWord, "minChargingRate");
  6135. if(loc != NULL)
  6136. {
  6137. memset(sstr ,0, sizeof(sstr) );
  6138. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  6139. {
  6140. sstr[c] = loc[2+strlen("minChargingRate")+c];
  6141. c++;
  6142. }
  6143. sstr[c] = '\0';
  6144. tempminChargingRateFloat = atof(sstr);
  6145. }
  6146. else
  6147. {
  6148. tempminChargingRateFloat = 0.0;
  6149. }
  6150. #if 0
  6151. //
  6152. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6153. tp.tm_isdst = -1;
  6154. time_t utc = mktime(&tp);
  6155. time_t t = time(NULL);
  6156. //diff_t = difftime(t, utc);
  6157. #endif
  6158. //DEBUG_INFO("diff_t=%f\n",diff_t);
  6159. //parsing strings to words
  6160. i = 0;
  6161. loc = strstr(sLineWord, "chargingSchedulePeriod");
  6162. loc = loc+3+strlen("chargingSchedulePeriod");
  6163. pch = strtok(loc ,"{");
  6164. while (pch != NULL)
  6165. {
  6166. strcpy(SchedulePeriodList[i], pch);
  6167. pch = strtok (NULL, "{");
  6168. i = i + 1;
  6169. }
  6170. n_SchedulePeriods = i;
  6171. for(int i=0;i<n_SchedulePeriods;i++)
  6172. {
  6173. //*************startPeriod****************/
  6174. c = 0;
  6175. loc = strstr(SchedulePeriodList[i], "startPeriod");
  6176. memset(sstr ,0, sizeof(sstr) );
  6177. while (loc[strlen("startPeriod")+2+c] != ',')
  6178. {
  6179. sstr[c] = loc[strlen("startPeriod")+2+c];
  6180. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6181. c++;
  6182. }
  6183. sstr[c] = '\0';
  6184. tempStartPeriodInt = atoi(sstr);
  6185. //*************limit****************/
  6186. c = 0;
  6187. loc = strstr(SchedulePeriodList[i], "limit");
  6188. memset(sstr ,0, sizeof(sstr) );
  6189. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  6190. {
  6191. sstr[c] = loc[strlen("limit")+2+c];
  6192. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6193. c++;
  6194. }
  6195. sstr[c] = '\0';
  6196. tempLimitInt = atof(sstr);
  6197. //*************numberPhases****************/
  6198. c = 0;
  6199. loc = strstr(SchedulePeriodList[i], "numberPhases");
  6200. memset(sstr ,0, sizeof(sstr) );
  6201. if(loc != NULL)
  6202. {
  6203. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  6204. {
  6205. sstr[c] = loc[strlen("numberPhases")+2+c];
  6206. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6207. c++;
  6208. }
  6209. sstr[c] = '\0';
  6210. tempNumberPhasesInt = atoi(sstr);
  6211. }
  6212. else
  6213. {
  6214. tempNumberPhasesInt = 0;
  6215. }
  6216. TxProfile.Duration = durationInt;
  6217. TxProfile.TotalPeriod = n_SchedulePeriods;
  6218. TxProfile.Period[i].Limit = tempLimitInt;
  6219. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  6220. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  6221. }
  6222. if(MinChargingRate < tempminChargingRateFloat)
  6223. MinChargingRate = tempminChargingRateFloat;
  6224. if(confirmPeriods < n_SchedulePeriods)
  6225. confirmPeriods = n_SchedulePeriods;
  6226. }
  6227. fclose(fptr1);
  6228. }
  6229. }// the end of ACCESS TxProfile
  6230. //CompositeSchedule
  6231. int period=0;
  6232. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  6233. {
  6234. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  6235. struct tm tp;
  6236. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6237. tp.tm_isdst = -1;
  6238. time_t utc = mktime(&tp);
  6239. time_t t = time(NULL);
  6240. double diff_f = difftime(t, utc);
  6241. int diff_i; // = (int)diff_f;
  6242. int quotient; // = diff_i / 86400;//86400 seconds/day
  6243. //int remainder = diff_i % 86400;
  6244. for(int k=0; k < TxProfile.TotalPeriod;k++)
  6245. {
  6246. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  6247. {
  6248. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  6249. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6250. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6251. period = period + 1;
  6252. }
  6253. else
  6254. {
  6255. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  6256. {
  6257. }
  6258. else
  6259. {
  6260. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6261. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6262. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6263. period = period + 1;
  6264. }
  6265. }
  6266. }
  6267. if( diff_f >= 0)
  6268. {
  6269. diff_i = (int)diff_f;
  6270. quotient = diff_i / 86400;//86400 seconds/day
  6271. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6272. {
  6273. if(((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)&& ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod %86400) > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  6274. {
  6275. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6276. {
  6277. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6278. }
  6279. else
  6280. {
  6281. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6282. }
  6283. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6284. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  6285. period = period + 1;
  6286. }
  6287. }
  6288. // Check Last Period
  6289. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  6290. {
  6291. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6292. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  6293. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  6294. period = period + 1;
  6295. }
  6296. } // diff_f >= 0
  6297. }
  6298. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  6299. {
  6300. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6301. struct tm tp;
  6302. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6303. tp.tm_isdst = -1;
  6304. time_t utc = mktime(&tp);
  6305. time_t t = time(NULL);
  6306. double diff_f = difftime(t, utc);
  6307. int diff_i;// = (int)diff_f;
  6308. int quotient; // = diff_i / 86400;//86400 seconds/day
  6309. //int remainder = diff_i % 86400;
  6310. if(diff_f >= 0)
  6311. {
  6312. diff_i = (int)diff_f;
  6313. quotient = diff_i / 86400;//86400 seconds/day
  6314. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6315. {
  6316. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6317. {
  6318. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6319. {
  6320. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6321. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6322. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6323. period = period + 1;
  6324. }
  6325. else
  6326. {
  6327. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6328. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6329. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6330. period = period + 1;
  6331. }
  6332. }
  6333. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6334. {
  6335. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6336. {
  6337. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6338. {
  6339. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6340. {
  6341. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6342. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6343. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6344. period = period + 1;
  6345. }
  6346. else
  6347. {
  6348. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6349. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6350. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6351. period = period + 1;
  6352. }
  6353. }
  6354. }
  6355. }
  6356. }
  6357. } // end diff_f >= 0
  6358. }
  6359. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  6360. {
  6361. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6362. struct tm tp;
  6363. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6364. tp.tm_isdst = -1;
  6365. time_t utc = mktime(&tp);
  6366. time_t t = time(NULL);
  6367. double diff_f = difftime(t, utc);
  6368. int diff_i; // = (int)diff_f;
  6369. int quotient; // = diff_i / 86400;//86400 seconds/day
  6370. //int remainder = diff_i % 86400;
  6371. if(diff_f >= 0)
  6372. {
  6373. diff_i = (int)diff_f;
  6374. quotient = diff_i / 86400;//86400 seconds/day
  6375. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6376. {
  6377. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6378. {
  6379. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6380. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6381. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6382. period = period + 1;
  6383. }
  6384. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6385. {
  6386. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6387. {
  6388. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6389. {
  6390. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6391. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6392. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6393. period = period + 1;
  6394. }
  6395. }
  6396. }
  6397. }
  6398. } // diff_f >= 0
  6399. }
  6400. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  6401. {
  6402. confirmPeriods = 0;
  6403. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6404. //goto end;
  6405. }
  6406. confirmPeriods = period;
  6407. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  6408. //---- Define StartSchedule----/
  6409. struct tm *gtime;
  6410. time_t now;
  6411. char buf[28];
  6412. //---Read the current system time---/
  6413. time(&now);
  6414. //---Convert the system time to GMT (now UTC)---/
  6415. gtime = gmtime(&now);
  6416. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  6417. // make .conf
  6418. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  6419. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  6420. //DEBUG_INFO(" debug 11\n");
  6421. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  6422. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  6423. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6424. }
  6425. else
  6426. {
  6427. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6428. }
  6429. //end:
  6430. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  6431. return result;
  6432. }
  6433. int handleGetConfigurationRequest(char *uuid, char *payload)
  6434. {
  6435. mtrace();
  6436. int result = FAIL;
  6437. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  6438. //struct json_object *jsonitem;
  6439. int MaxKeySupported = 0;
  6440. int n_keys = 0;
  6441. char requestKey[43][50]={0};
  6442. char search[]="[";
  6443. char sstr[500]={ 0 },sstrtemp[60]={ 0 };
  6444. //int pos;
  6445. int l, c = 0;
  6446. int i = 0;
  6447. char *delim = "\",\"";
  6448. char * pch;
  6449. strcpy(sstrtemp, stringtrimspace(payload));
  6450. char *loc = strstr(sstrtemp, search);
  6451. //********************* Parsing String ***********************************/
  6452. if(loc == NULL) {
  6453. DEBUG_INFO("no key match in Configuration \n");
  6454. }
  6455. else {
  6456. //pos = loc - payload;
  6457. l = strlen(loc)-4;
  6458. while (c < l)
  6459. {
  6460. sstr[c] = loc[c+2];
  6461. c++;
  6462. }
  6463. sstr[c] = '\0';
  6464. //parsing strings to words
  6465. pch = strtok(sstr,delim);
  6466. if(pch == NULL)
  6467. {
  6468. strcpy(requestKey[0], sstr);
  6469. }
  6470. else
  6471. {
  6472. while (pch != NULL)
  6473. {
  6474. strcpy(requestKey[i], pch);
  6475. pch = strtok (NULL, delim);
  6476. i = i + 1;
  6477. }
  6478. n_keys = i;
  6479. }
  6480. }
  6481. UnknownKeynum = 0;
  6482. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  6483. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  6484. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6485. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6486. if(n_keys != 0)
  6487. {
  6488. for(int i=0;i<n_keys;i++)
  6489. {
  6490. getKeyValue(requestKey[i]);
  6491. //json_object_put(jsonitem);
  6492. }
  6493. }
  6494. else
  6495. {
  6496. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6497. getKeyValue("");
  6498. }
  6499. processUnkownKey();
  6500. sendGetConfigurationConfirmation(uuid);
  6501. return result;
  6502. }
  6503. static char fnamePlusPath[100]={0};
  6504. static char fnamePWithNoPath[60]={0};
  6505. void checkUploadLog(void)
  6506. {
  6507. FILE *fp;
  6508. /* Open the command for reading. */
  6509. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6510. if (fp == NULL) {
  6511. printf("Failed to run command\n" );
  6512. exit(1);
  6513. }
  6514. int ftppathlen = 0;
  6515. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6516. int i = 0;
  6517. /* Read the output a line at a time - output it. */
  6518. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6519. if(i==0)
  6520. {
  6521. ftppathlen = strlen(fnamePlusPath);
  6522. printf("%s\n", fnamePlusPath);
  6523. fnamePlusPath[ftppathlen]='\0';
  6524. break;
  6525. }
  6526. i= i+1;
  6527. }
  6528. /* close */
  6529. pclose(fp);
  6530. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6531. {
  6532. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6533. {
  6534. fnamePlusPath[k]='\0';
  6535. }
  6536. }
  6537. i=1;
  6538. //char fname[60]={0};
  6539. while(i < ftppathlen)
  6540. {
  6541. int len=ftppathlen-i;
  6542. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6543. {
  6544. printf("compare '/' all right\n");
  6545. break;
  6546. }
  6547. i=i+1;
  6548. }
  6549. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6550. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6551. fnamePWithNoPath[i+1] = '\0';
  6552. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6553. {
  6554. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6555. {
  6556. fnamePWithNoPath[j]='\0';
  6557. }
  6558. }
  6559. FILE* fp1 = fopen(fnamePlusPath, "r");
  6560. if (fp1)
  6561. {
  6562. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6563. // file exists
  6564. fclose(fp1);
  6565. }
  6566. else
  6567. {
  6568. // file doesn't exist
  6569. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6570. }
  6571. }
  6572. static char GetDiagnosticspayloadData[300]={0};
  6573. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6574. {
  6575. mtrace();
  6576. int result = FAIL;
  6577. pthread_t t; // pthread 變數
  6578. system("exec /root/logPackTools 'log' 6");
  6579. #if 0
  6580. //char buffer [128];
  6581. time (&rawtime);
  6582. //printf("%ld\n", rawtime);
  6583. timeinfo = localtime (&rawtime);
  6584. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6585. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6586. if((access(fnamePlusPath,F_OK))!=-1)
  6587. {
  6588. DEBUG_INFO("fnamePlusPath exist.\n");
  6589. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6590. }
  6591. else
  6592. {
  6593. DEBUG_INFO("fnamePlusPath not exist!\n");
  6594. }
  6595. #endif
  6596. checkUploadLog();
  6597. memset(GetDiagnosticspayloadData, 0, 300);
  6598. strcpy(GetDiagnosticspayloadData, stringtrimspace(payload));
  6599. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  6600. pthread_create(&t, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6601. return result;
  6602. }
  6603. void* GetDiagnosticsProcess(void* data)
  6604. {
  6605. pthread_detach(pthread_self());
  6606. mtrace();
  6607. int retriesInt=0, retryIntervalInt=0;
  6608. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6609. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6610. 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};
  6611. int port=0;
  6612. char sstr[260]={ 0 };//sstr[200]={ 0 };
  6613. int c = 0;
  6614. char *loc;
  6615. int isSuccess = FALSE;
  6616. char ftpbuf[200]={0};
  6617. //char temp[100]={0};
  6618. char * pch;
  6619. // [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"}]
  6620. char str[300]={ 0 };
  6621. strcpy(str,(const char*)GetDiagnosticspayloadData);
  6622. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6623. DEBUG_INFO("GetDiagnosticsProcess\n");
  6624. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6625. //****************location*******************/
  6626. c = 0;
  6627. memset(sstr ,0, sizeof(sstr) );
  6628. loc = strstr(str, "location");
  6629. while (loc[3+strlen("location")+c] != '\"')
  6630. {
  6631. sstr[c] = loc[3+strlen("location")+c];
  6632. c++;
  6633. }
  6634. sstr[c] = '\0';
  6635. strcpy(locationstr,sstr);
  6636. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6637. if(strcmp(locationstr,"")==0)
  6638. {
  6639. DEBUG_INFO("location is <Empty>!\n");
  6640. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6641. goto end;
  6642. }
  6643. //****************retries*******************/
  6644. c = 0;
  6645. loc = strstr(str, "retries");
  6646. if(loc == NULL)
  6647. {
  6648. retriesIsNULL = TRUE;
  6649. }
  6650. else
  6651. {
  6652. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6653. {
  6654. sstr[c] = loc[strlen("retries")+2+c];
  6655. c++;
  6656. }
  6657. sstr[c] = '\0';
  6658. retriesInt = atoi(sstr);
  6659. }
  6660. if(retriesIsNULL == TRUE)
  6661. {
  6662. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6663. }
  6664. //****************retryInterval*******************/
  6665. c = 0;
  6666. loc = strstr(str, "retryInterval");
  6667. if(loc == NULL)
  6668. {
  6669. retryIntervalIsNULL = TRUE;
  6670. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6671. }
  6672. else
  6673. {
  6674. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6675. {
  6676. sstr[c] = loc[strlen("retryInterval")+2+c];
  6677. c++;
  6678. }
  6679. sstr[c] = '\0';
  6680. retryIntervalInt = atoi(sstr);
  6681. }
  6682. //****************startTime*******************/
  6683. c = 0;
  6684. memset(sstr ,0, sizeof(sstr) );
  6685. loc = strstr(str, "startTime");
  6686. if(loc == NULL)
  6687. {
  6688. startTimeIsNULL = TRUE;
  6689. }
  6690. else
  6691. {
  6692. while (loc[3+strlen("startTime")+c] != '\"')
  6693. {
  6694. sstr[c] = loc[3+strlen("startTime")+c];
  6695. c++;
  6696. }
  6697. sstr[c] = '\0';
  6698. strcpy(startTimestr,sstr);
  6699. }
  6700. //****************stopTime*******************/
  6701. c = 0;
  6702. memset(sstr ,0, sizeof(sstr) );
  6703. loc = strstr(str, "stopTime");
  6704. if(loc == NULL)
  6705. {
  6706. stopTimeIsNULL = TRUE;
  6707. }
  6708. else
  6709. {
  6710. while (loc[3+strlen("stopTime")+c] != '\"')
  6711. {
  6712. sstr[c] = loc[3+strlen("stopTime")+c];
  6713. c++;
  6714. }
  6715. sstr[c] = '\0';
  6716. strcpy(stopTimestr,sstr);
  6717. }
  6718. memset(protocol, 0, sizeof(protocol));
  6719. memset(user, 0, sizeof(user) );
  6720. memset(password, 0, sizeof(password));
  6721. memset(host, 0, sizeof(host));
  6722. memset(path, 0, sizeof(path));
  6723. memset(ftppath, 0, sizeof(ftppath));
  6724. memset(host1, 0, sizeof(host1));
  6725. memset(path1, 0, sizeof(path1));
  6726. /*location: ftp://user:password@host:port/path*/
  6727. #if 0
  6728. time_t rawtime;
  6729. struct tm * timeinfo;
  6730. //char buffer [128];
  6731. time (&rawtime);
  6732. //printf("%ld\n", rawtime);
  6733. timeinfo = localtime (&rawtime);
  6734. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6735. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6736. #endif
  6737. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6738. if((access(fnamePlusPath,F_OK))!=-1)
  6739. {
  6740. DEBUG_INFO("fnamePlusPath exist.\n");
  6741. }
  6742. else
  6743. {
  6744. DEBUG_INFO("fnamePlusPath not exist!\n");
  6745. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6746. goto end;
  6747. }
  6748. pch=strchr(locationstr,'@');
  6749. if(pch==NULL)
  6750. {
  6751. sscanf(locationstr,
  6752. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6753. protocol, host, &port, path);
  6754. strcpy(user,"anonymous");
  6755. strcpy(password,"");
  6756. }
  6757. else
  6758. {
  6759. //DEBUG_INFO("pch=%s\n", pch);
  6760. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6761. protocol, user, password, host, &port, path);
  6762. }
  6763. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6764. {
  6765. DEBUG_INFO("protocol is not ftp/http ! \n");
  6766. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6767. goto end;
  6768. }
  6769. if(strncmp(locationstr,"http", 4) == 0)
  6770. {
  6771. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6772. sprintf(ftppath,"/%s", path);
  6773. do{
  6774. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6775. sleep(retryIntervalInt);
  6776. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6777. if(!isSuccess)
  6778. {
  6779. DEBUG_INFO("Diagnostics fail.\n");
  6780. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6781. }
  6782. else
  6783. {
  6784. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6785. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6786. }
  6787. }
  6788. else
  6789. {
  6790. sscanf(host,"%[^/]%s",host1, path1);
  6791. sprintf(ftppath,"%s", path1);
  6792. int ftppathlen=strlen(ftppath);
  6793. int i=1;
  6794. char filenametemp[50];
  6795. while(i < ftppathlen)
  6796. {
  6797. int len=ftppathlen-i;
  6798. if(ftppath[len]== 47) // '/' ascll code: 47
  6799. {
  6800. DEBUG_INFO("find '/' all right\n");
  6801. break;
  6802. }
  6803. i=i+1;
  6804. }
  6805. memset(filenametemp, 0, sizeof(filenametemp));
  6806. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6807. filenametemp[i+1] = 0;
  6808. memset(ftpbuf, 0, sizeof(ftpbuf));
  6809. if(port == 0)
  6810. port = 21;
  6811. do{
  6812. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6813. sleep(retryIntervalInt);
  6814. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6815. if(!isSuccess)
  6816. {
  6817. DEBUG_INFO("Diagnostics fail.\n");
  6818. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6819. }
  6820. else
  6821. {
  6822. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6823. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6824. }
  6825. }
  6826. end:
  6827. DiagnosticsStatusNotificationStatus = 0; //Idle
  6828. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6829. }
  6830. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6831. {
  6832. mtrace();
  6833. int result = FAIL;
  6834. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6835. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6836. {
  6837. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6838. localversion = -1;
  6839. }
  6840. else
  6841. {
  6842. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6843. OCPP_getListVerion();
  6844. }
  6845. //from db.OCPP_getListVerion
  6846. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6847. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6848. sendGetLocalListVersionConfirmation(uuid,"");
  6849. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6850. return result;
  6851. }
  6852. int handleRemoteStartRequest(char *uuid, char *payload)
  6853. {
  6854. mtrace();
  6855. int result = FAIL;
  6856. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6857. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6858. int tempIndex = 0;
  6859. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6860. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6861. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6862. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6863. int chargingSchedulePeriodCount = 0;
  6864. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6865. int c = 0;
  6866. char *loc;
  6867. char comfirmstr[20]={0};
  6868. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6869. if(server_pending == TRUE)
  6870. {
  6871. return 0;
  6872. }
  6873. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6874. strcpy(sstrtemp, stringtrimspace(payload));
  6875. //**********connectorId****************/
  6876. c = 0;
  6877. memset(sstr ,0, sizeof(sstr) );
  6878. loc = strstr(sstrtemp, "connectorId");
  6879. if(loc == NULL)
  6880. {
  6881. connectorIdIsNULL = TRUE;
  6882. }
  6883. else
  6884. {
  6885. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6886. {
  6887. sstr[c] = loc[strlen("connectorId")+2+c];
  6888. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6889. c++;
  6890. }
  6891. sstr[c] = '\0';
  6892. connectorIdInt = atoi(sstr);
  6893. }
  6894. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6895. {
  6896. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6897. goto end;
  6898. }
  6899. //****************idTag*******************/
  6900. c = 0;
  6901. memset(sstr ,0, sizeof(sstr) );
  6902. loc = strstr(sstrtemp, "idTag");
  6903. while (loc[3+strlen("idTag")+c] != '\"')
  6904. {
  6905. sstr[c] = loc[3+strlen("idTag")+c];
  6906. c++;
  6907. }
  6908. sstr[c] = '\0';
  6909. strcpy(idTagstr,sstr);
  6910. //****************chargingProfile*******************/
  6911. c = 0;
  6912. memset(sstr ,0, sizeof(sstr) );
  6913. loc = strstr(sstrtemp, "chargingProfile");
  6914. if(loc == NULL)
  6915. {
  6916. chargingProfileIsNULL = TRUE;
  6917. }
  6918. else
  6919. {
  6920. //****************chargingProfileId*******************/
  6921. c=0;
  6922. loc = strstr(sstrtemp, "chargingProfileId");
  6923. memset(sstr ,0, sizeof(sstr) );
  6924. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6925. {
  6926. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6927. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6928. c++;
  6929. }
  6930. sstr[c] = '\0';
  6931. chargingProfileIdInt = atoi(sstr);
  6932. //****************transactionId*******************/
  6933. loc = strstr(sstrtemp, "transactionId");
  6934. if(loc == NULL)
  6935. {
  6936. transactionIdIsNULL = TRUE;
  6937. }
  6938. else
  6939. {
  6940. c=0;
  6941. memset(sstr ,0, sizeof(sstr) );
  6942. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6943. {
  6944. sstr[c] = loc[strlen("transactionId")+2+c];
  6945. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6946. c++;
  6947. }
  6948. sstr[c] = '\0';
  6949. transactionIdInt = atoi(sstr);
  6950. }
  6951. //****************stackLevel*******************/
  6952. c=0;
  6953. loc = strstr(sstrtemp, "stackLevel");
  6954. memset(sstr ,0, sizeof(sstr) );
  6955. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6956. {
  6957. sstr[c] = loc[strlen("stackLevel")+2+c];
  6958. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6959. c++;
  6960. }
  6961. sstr[c] = '\0';
  6962. stackLevelInt = atoi(sstr);
  6963. //****************chargingProfilePurpose*******************/
  6964. c = 0;
  6965. memset(sstr ,0, sizeof(sstr) );
  6966. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6967. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6968. {
  6969. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6970. c++;
  6971. }
  6972. sstr[c] = '\0';
  6973. strcpy(chargingProfilePurposestr,sstr);
  6974. //****************chargingProfileKind*******************/
  6975. c = 0;
  6976. memset(sstr ,0, sizeof(sstr) );
  6977. loc = strstr(sstrtemp, "chargingProfileKind");
  6978. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6979. {
  6980. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6981. c++;
  6982. }
  6983. sstr[c] = '\0';
  6984. strcpy(chargingProfileKindstr,sstr);
  6985. //****************recurrencyKind*******************/
  6986. loc = strstr(sstrtemp, "recurrencyKind");
  6987. if(loc == NULL)
  6988. {
  6989. recurrencyKindIsNULL = TRUE;
  6990. }
  6991. else
  6992. {
  6993. c = 0;
  6994. memset(sstr ,0, sizeof(sstr) );
  6995. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6996. {
  6997. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6998. c++;
  6999. }
  7000. sstr[c] = '\0';
  7001. strcpy(recurrencyKindstr,sstr);
  7002. }
  7003. //****************validFrom*******************/
  7004. loc = strstr(sstrtemp, "validFrom");
  7005. if(loc == NULL)
  7006. {
  7007. validFromIsNULL = TRUE;
  7008. }
  7009. else
  7010. {
  7011. c = 0;
  7012. memset(sstr ,0, sizeof(sstr) );
  7013. while (loc[3+strlen("validFrom")+c] != '\"')
  7014. {
  7015. sstr[c] = loc[3+strlen("validFrom")+c];
  7016. c++;
  7017. }
  7018. sstr[c] = '\0';
  7019. strcpy(validFromstr,sstr);
  7020. }
  7021. //****************validTo*******************/
  7022. loc = strstr(sstrtemp, "validTo");
  7023. if(loc == NULL)
  7024. {
  7025. validToIsNULL = TRUE;
  7026. }
  7027. else
  7028. {
  7029. c = 0;
  7030. memset(sstr ,0, sizeof(sstr) );
  7031. while (loc[3+strlen("validTo")+c] != '\"')
  7032. {
  7033. sstr[c] = loc[3+strlen("validTo")+c];
  7034. c++;
  7035. }
  7036. sstr[c] = '\0';
  7037. strcpy(validTostr,sstr);
  7038. }
  7039. //****************chargingSchedule*******************/
  7040. loc = strstr(sstrtemp, "chargingSchedule");
  7041. if(loc != NULL)
  7042. {
  7043. //****************duration*******************/
  7044. loc = strstr(sstrtemp, "duration");
  7045. if(loc == NULL)
  7046. {
  7047. durationIsNULL = TRUE;
  7048. }
  7049. else
  7050. {
  7051. c=0;
  7052. memset(sstr ,0, sizeof(sstr) );
  7053. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  7054. {
  7055. sstr[c] = loc[strlen("duration")+2+c];
  7056. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7057. c++;
  7058. }
  7059. sstr[c] = '\0';
  7060. durationInt = atoi(sstr);
  7061. }
  7062. //****************startSchedule******************/
  7063. loc = strstr(sstrtemp, "startSchedule");
  7064. if(loc == NULL)
  7065. {
  7066. startScheduleIsNULL = TRUE;
  7067. }
  7068. else
  7069. {
  7070. c = 0;
  7071. memset(sstr ,0, sizeof(sstr) );
  7072. while (loc[3+strlen("startSchedule")+c] != '\"')
  7073. {
  7074. sstr[c] = loc[3+strlen("startSchedule")+c];
  7075. c++;
  7076. }
  7077. sstr[c] = '\0';
  7078. strcpy(startSchedulestr,sstr);
  7079. }
  7080. //****************chargingRateUnit*******************/
  7081. c = 0;
  7082. memset(sstr ,0, sizeof(sstr) );
  7083. loc = strstr(sstrtemp, "chargingRateUnit");
  7084. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7085. {
  7086. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7087. c++;
  7088. }
  7089. sstr[c] = '\0';
  7090. strcpy(chargingRateUnitstr,sstr);
  7091. //****************minChargingRate*******************/
  7092. loc = strstr(sstrtemp, "minChargingRate");
  7093. if(loc == NULL)
  7094. {
  7095. minChargingRateIsNULL = TRUE;
  7096. }
  7097. else
  7098. {
  7099. c=0;
  7100. memset(sstr ,0, sizeof(sstr) );
  7101. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  7102. {
  7103. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7104. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7105. c++;
  7106. }
  7107. sstr[c] = '\0';
  7108. minChargingRateflaot = atof(sstr);
  7109. }
  7110. //****************chargingSchedulePeriod count*******************/
  7111. int what_len = strlen("startPeriod");
  7112. char *where = sstrtemp;
  7113. while ((where = strstr(where, "startPeriod"))) {
  7114. where += what_len;
  7115. chargingSchedulePeriodCount++;
  7116. }
  7117. where = sstrtemp;
  7118. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7119. {
  7120. //****************startPeriod*******************/
  7121. c=0;
  7122. loc = strstr(where, "startPeriod");
  7123. memset(sstr ,0, sizeof(sstr) );
  7124. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7125. {
  7126. sstr[c] = loc[strlen("startPeriod")+2+c];
  7127. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7128. c++;
  7129. }
  7130. sstr[c] = '\0';
  7131. startPeriodInt[periodNums] = atoi(sstr);
  7132. //****************limit*******************/
  7133. c=0;
  7134. loc = strstr(where, "limit");
  7135. memset(sstr ,0, sizeof(sstr) );
  7136. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7137. {
  7138. sstr[c] = loc[strlen("limit")+2+c];
  7139. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7140. c++;
  7141. }
  7142. sstr[c] = '\0';
  7143. limitflaot[periodNums] = atof(sstr);
  7144. //****************numberPhases*******************/
  7145. loc = strstr(where, "numberPhases");
  7146. if(loc == NULL)
  7147. {
  7148. numberPhasesIsNULL = TRUE;
  7149. }
  7150. else
  7151. {
  7152. c=0;
  7153. memset(sstr ,0, sizeof(sstr) );
  7154. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7155. {
  7156. sstr[c] = loc[strlen("numberPhases")+2+c];
  7157. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7158. c++;
  7159. }
  7160. sstr[c] = '\0';
  7161. numberPhasesInt[periodNums] = atoi(sstr);
  7162. }
  7163. where = loc;
  7164. } // END FOR chargingSchedulePeriodCount
  7165. }// END IF chargingSchedule
  7166. } // END chargingProfile
  7167. /*
  7168. enum _SYSTEM_STATUS
  7169. {
  7170. S_BOOTING = 0,
  7171. S_IDLE, = 1
  7172. S_AUTHORIZING, =2
  7173. S_REASSIGN_CHECK, =3
  7174. S_REASSIGN, =4
  7175. S_PRECHARGE, =5
  7176. S_PREPARING_FOR_EV, =6
  7177. S_PREPARING_FOR_EVSE, =7
  7178. S_CHARGING, =8
  7179. S_TERMINATING, =9
  7180. S_COMPLETE, =10
  7181. S_ALARM, =11
  7182. S_FAULT =12
  7183. }
  7184. */
  7185. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7186. {
  7187. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7188. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7189. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7190. //check Transaction active
  7191. if(gunType[connectorIdInt -1] == 'J')
  7192. {
  7193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7194. {
  7195. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7196. }
  7197. else
  7198. {
  7199. tempIndex = connectorIdInt -1;
  7200. }
  7201. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7202. {
  7203. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7204. {
  7205. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7206. {
  7207. //Reserved
  7208. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7209. }
  7210. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7211. {
  7212. //Reserved
  7213. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7214. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7215. goto end;
  7216. }
  7217. else
  7218. {
  7219. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7220. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7221. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7222. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7223. {
  7224. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7225. goto end;
  7226. }
  7227. }//END FOR ELSE
  7228. }
  7229. }// END FOR CHAdeMO_QUANTITY
  7230. }
  7231. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7232. {
  7233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7234. {
  7235. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7236. }
  7237. else
  7238. {
  7239. tempIndex = connectorIdInt -1;
  7240. }
  7241. for (int index = 0; index < CCS_QUANTITY; index++)
  7242. {
  7243. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7244. {
  7245. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7246. {
  7247. //Reserved
  7248. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7249. }
  7250. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7251. {
  7252. //Reserved
  7253. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7254. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7255. goto end;
  7256. }
  7257. else
  7258. {
  7259. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7260. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7261. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7262. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7263. {
  7264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7265. goto end;
  7266. }
  7267. }// END FOR ELSE
  7268. }
  7269. }// END FOR CCS_QUANTITY
  7270. }
  7271. else if(gunType[connectorIdInt -1] == 'G')
  7272. {
  7273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7274. {
  7275. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7276. }
  7277. else
  7278. {
  7279. tempIndex = connectorIdInt -1;
  7280. }
  7281. for (int index = 0; index < GB_QUANTITY; index++)
  7282. {
  7283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7284. {
  7285. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7286. {
  7287. //Reserved
  7288. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7289. }
  7290. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7291. {
  7292. //Reserved
  7293. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7294. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7295. goto end;
  7296. }
  7297. else
  7298. {
  7299. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7300. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7301. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7302. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7303. {
  7304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7305. goto end;
  7306. }
  7307. }// END FOR ELSE
  7308. }
  7309. } // END FOR GB_QUANTITY
  7310. }
  7311. else
  7312. {
  7313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7314. {
  7315. tempIndex = 2;
  7316. }
  7317. else
  7318. {
  7319. tempIndex = connectorIdInt -1;
  7320. }
  7321. for (int index = 0; index < AC_QUANTITY; index++)
  7322. {
  7323. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7324. {
  7325. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7326. {
  7327. //Reserved
  7328. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7329. }
  7330. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7331. {
  7332. //Reserved
  7333. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7335. goto end;
  7336. }
  7337. else
  7338. {
  7339. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7340. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7341. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7342. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7343. {
  7344. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7345. goto end;
  7346. }
  7347. }//END FOR ELSE
  7348. }
  7349. }// END FOR AC_QUANTITY
  7350. }
  7351. if(chargingProfileIsNULL == FALSE)
  7352. {
  7353. //ChargingProfile
  7354. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7355. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7356. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7357. if(recurrencyKindIsNULL == FALSE) //OPTION
  7358. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7359. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7360. if(transactionIdIsNULL == FALSE) // OPTION
  7361. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7362. if(validFromIsNULL == FALSE) // OPTION
  7363. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7364. if(validToIsNULL == FALSE) //OPTION
  7365. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7366. //ChargingSchedule
  7367. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7368. if(durationIsNULL == FALSE) //OPTION
  7369. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7370. if(minChargingRateIsNULL == FALSE) //OPTION
  7371. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7372. if(startScheduleIsNULL == FALSE) //OPTION
  7373. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7374. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7375. {
  7376. //ChargingSchedulePeriod
  7377. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7378. if(numberPhasesIsNULL == FALSE)
  7379. {
  7380. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7381. }
  7382. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7383. }
  7384. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7385. {
  7386. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7387. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7388. //memset idTag
  7389. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7390. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7391. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7392. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7393. }
  7394. else
  7395. {
  7396. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7397. }
  7398. }
  7399. else
  7400. {
  7401. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7402. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7403. //memset idTag
  7404. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7405. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7406. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7407. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7408. }
  7409. }
  7410. else
  7411. {
  7412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7413. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7414. }
  7415. end:
  7416. if(connectorIdIsNULL == FALSE)
  7417. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7418. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7419. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7420. //OCPP send RemoteStartConfirmation by first.
  7421. sendRemoteStartConfirmation(uuid, comfirmstr);
  7422. return result;
  7423. }
  7424. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7425. {
  7426. mtrace();
  7427. int result = FAIL;
  7428. int match = FALSE;
  7429. int GunNO = 0;
  7430. int tempIndex = 0;
  7431. int transactionIdInt=0;
  7432. int transactionIdIsNULL= FALSE;
  7433. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7434. int c = 0;
  7435. char *loc;
  7436. char comfirmstr[20];
  7437. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7438. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7439. if(server_pending == TRUE)
  7440. {
  7441. return 0;
  7442. }
  7443. strcpy(sstrtemp, stringtrimspace(payload));
  7444. c=0;
  7445. loc = strstr(sstrtemp, "transactionId");
  7446. if(loc == NULL)
  7447. {
  7448. transactionIdIsNULL= TRUE;
  7449. }
  7450. else
  7451. {
  7452. memset(sstr ,0, sizeof(sstr) );
  7453. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7454. {
  7455. sstr[c] = loc[strlen("transactionId")+2+c];
  7456. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7457. c++;
  7458. }
  7459. sstr[c] = '\0';
  7460. transactionIdInt = atoi(sstr);
  7461. }
  7462. if(transactionIdIsNULL == FALSE)
  7463. {
  7464. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7465. {
  7466. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7467. {
  7468. //check Transaction active
  7469. if(gunType[gun_index] == 'J')
  7470. {
  7471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7472. {
  7473. tempIndex = ((gun_index==2) ? 1: 0);
  7474. }
  7475. else
  7476. {
  7477. tempIndex = gun_index;
  7478. }
  7479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7480. {
  7481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7482. {
  7483. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7484. {
  7485. match = TRUE;
  7486. GunNO = gun_index;
  7487. }
  7488. }
  7489. }// END FOR CHAdeMO_QUANTITY
  7490. }
  7491. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7492. {
  7493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7494. {
  7495. tempIndex = ((gun_index==2) ? 1: 0);
  7496. }
  7497. else
  7498. {
  7499. tempIndex = gun_index;
  7500. }
  7501. for (int index = 0; index < CCS_QUANTITY; index++)
  7502. {
  7503. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7504. {
  7505. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7506. {
  7507. match = TRUE;
  7508. GunNO = gun_index;
  7509. }
  7510. }
  7511. }// END FOR CCS_QUANTITY
  7512. }
  7513. else if(gunType[gun_index] == 'G')
  7514. {
  7515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7516. {
  7517. tempIndex = ((gun_index==2) ? 1: 0);
  7518. }
  7519. else
  7520. {
  7521. tempIndex = gun_index;
  7522. }
  7523. for (int index = 0; index < GB_QUANTITY; index++)
  7524. {
  7525. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7526. {
  7527. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7528. {
  7529. match = TRUE;
  7530. GunNO = gun_index;
  7531. }
  7532. }
  7533. }// END FOR GB_QUANTITY
  7534. }
  7535. else
  7536. {
  7537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7538. {
  7539. tempIndex = 2;
  7540. }
  7541. else
  7542. {
  7543. tempIndex = gun_index;
  7544. }
  7545. for (int index = 0; index < AC_QUANTITY; index++)
  7546. {
  7547. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7548. {
  7549. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7550. {
  7551. match = TRUE;
  7552. GunNO = gun_index;
  7553. }
  7554. }
  7555. }// END FOR CHAdeMO_QUANTITY
  7556. } // END FOR AC ELSE
  7557. }// CHECK IF ResponseTransactionId == transactionIdInt
  7558. }//END FOR
  7559. if( match == TRUE)
  7560. {
  7561. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7562. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7563. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7564. }
  7565. else
  7566. {
  7567. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7568. }
  7569. }
  7570. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7571. return result;
  7572. }
  7573. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7574. {
  7575. mtrace();
  7576. int result = FAIL;
  7577. int connectorIdInt=0, reservationIdInt=0;
  7578. int tempIndex = 0;
  7579. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7580. char comfirmstr[20]={0};
  7581. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7582. int c = 0;
  7583. char *loc;
  7584. //char *ptr;
  7585. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  7586. strcpy(sstrtemp, stringtrimspace(payload));
  7587. //***(1)connectorId ****/
  7588. c=0;
  7589. loc = strstr(sstrtemp, "connectorId");
  7590. memset(sstr ,0, sizeof(sstr) );
  7591. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7592. {
  7593. sstr[c] = loc[strlen("connectorId")+2+c];
  7594. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7595. c++;
  7596. }
  7597. sstr[c] = '\0';
  7598. connectorIdInt = atoi(sstr);
  7599. //***(2)expiryDate ****/
  7600. loc = strstr(sstrtemp, "expiryDate");
  7601. memset(sstr ,0, sizeof(sstr) );
  7602. c = 0;
  7603. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7604. {
  7605. sstr[c] = loc[3+strlen("expiryDate")+c];
  7606. c++;
  7607. }
  7608. sstr[c] = '\0';
  7609. strcpy(expiryDatestr, sstr);
  7610. //***(3)idTag ****/
  7611. loc = strstr(sstrtemp, "idTag");
  7612. memset(sstr ,0, sizeof(sstr) );
  7613. c = 0;
  7614. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7615. {
  7616. sstr[c] = loc[3+strlen("idTag")+c];
  7617. c++;
  7618. }
  7619. sstr[c] = '\0';
  7620. strcpy(idTagstr, sstr);
  7621. //***(4)parentIdTag ****/
  7622. loc = strstr(sstrtemp, "parentIdTag");
  7623. memset(sstr ,0, sizeof(sstr) );
  7624. c = 0;
  7625. if(loc == NULL)
  7626. {
  7627. strcpy(parentIdTagstr, "");
  7628. }
  7629. else
  7630. {
  7631. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7632. {
  7633. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7634. c++;
  7635. }
  7636. sstr[c] = '\0';
  7637. strcpy(parentIdTagstr, sstr);
  7638. }
  7639. //***(5)reservationId ****/
  7640. c=0;
  7641. loc = strstr(sstrtemp, "reservationId");
  7642. memset(sstr ,0, sizeof(sstr) );
  7643. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7644. {
  7645. sstr[c] = loc[strlen("reservationId")+2+c];
  7646. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7647. c++;
  7648. }
  7649. sstr[c] = '\0';
  7650. reservationIdInt = atoi(sstr);
  7651. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7652. /*
  7653. enum SYSTEM_STATUS
  7654. {
  7655. SYS_MODE_BOOTING = 0,
  7656. SYS_MODE_IDLE = 1,
  7657. SYS_MODE_AUTHORIZING = 2,
  7658. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7659. SYS_MODE_REASSIGN = 4,
  7660. SYS_MODE_PREPARING = 5,
  7661. SYS_MODE_PREPARE_FOR_EV = 6,
  7662. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7663. SYS_MODE_CHARGING = 8,
  7664. SYS_MODE_TERMINATING = 9,
  7665. SYS_MODE_COMPLETE = 10,
  7666. SYS_MODE_ALARM = 11,
  7667. SYS_MODE_FAULT = 12,
  7668. SYS_MODE_RESERVATION = 13,
  7669. SYS_MODE_BOOKING = 14,
  7670. SYS_MODE_MAINTAIN = 15,
  7671. SYS_MODE_DEBUG = 16,
  7672. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7673. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7674. SYS_MODE_UPDATE = 19
  7675. };
  7676. */
  7677. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7678. {
  7679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7680. goto end;
  7681. }
  7682. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7683. {
  7684. //check Transaction active
  7685. if(gunType[connectorIdInt -1] == 'J')
  7686. {
  7687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7688. {
  7689. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7690. }
  7691. else
  7692. {
  7693. tempIndex = connectorIdInt -1;
  7694. }
  7695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7696. {
  7697. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7698. {
  7699. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7700. {
  7701. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7702. {
  7703. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7704. {
  7705. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7707. }
  7708. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  7709. {
  7710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7711. }
  7712. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7713. {
  7714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7715. }
  7716. else
  7717. {
  7718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7719. }
  7720. }
  7721. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  7722. {
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7724. }
  7725. }
  7726. else
  7727. {
  7728. //replace reservation
  7729. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7731. }
  7732. }
  7733. } // END FOR CHAdeMO_QUANTITY
  7734. }
  7735. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7736. {
  7737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7738. {
  7739. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7740. }
  7741. else
  7742. {
  7743. tempIndex = connectorIdInt -1;
  7744. }
  7745. for (int index = 0; index < CCS_QUANTITY; index++)
  7746. {
  7747. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7748. {
  7749. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7750. {
  7751. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7752. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7753. {
  7754. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7755. {
  7756. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7758. }
  7759. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  7760. {
  7761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7762. }
  7763. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7764. {
  7765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7766. }
  7767. else
  7768. {
  7769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7770. }
  7771. }
  7772. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  7773. {
  7774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7775. }
  7776. }
  7777. else
  7778. {
  7779. //replace reservation
  7780. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7782. }
  7783. }
  7784. } // END FOR CCS_QUANTITY
  7785. }
  7786. else if(gunType[connectorIdInt -1] == 'G')
  7787. {
  7788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7789. {
  7790. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7791. }
  7792. else
  7793. {
  7794. tempIndex = connectorIdInt -1;
  7795. }
  7796. for (int index = 0; index < GB_QUANTITY; index++)
  7797. {
  7798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7799. {
  7800. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7801. {
  7802. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7803. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7804. {
  7805. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7806. {
  7807. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7809. }
  7810. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  7811. {
  7812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7813. }
  7814. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7815. {
  7816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7817. }
  7818. else
  7819. {
  7820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7821. }
  7822. }
  7823. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  7824. {
  7825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7826. }
  7827. }
  7828. else
  7829. {
  7830. //replace reservation
  7831. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7833. }
  7834. }
  7835. }// END FOR GB_QUANTITY
  7836. }
  7837. else
  7838. {
  7839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7840. {
  7841. tempIndex = 2;
  7842. }
  7843. else
  7844. {
  7845. tempIndex = (connectorIdInt -1);
  7846. }
  7847. for (int index = 0; index < AC_QUANTITY; index++)
  7848. {
  7849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7850. {
  7851. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7852. {
  7853. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7854. {
  7855. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7856. {
  7857. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  7858. {
  7859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7860. }
  7861. else
  7862. {
  7863. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7864. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7865. }
  7866. }
  7867. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  7868. {
  7869. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7870. }
  7871. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7872. {
  7873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7874. }
  7875. else
  7876. {
  7877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7878. }
  7879. }
  7880. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  7881. {
  7882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7883. }
  7884. }
  7885. else
  7886. {
  7887. //replace reservation
  7888. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7889. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7890. }
  7891. }
  7892. } // END FOR AC_QUANTITY
  7893. }
  7894. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7895. }
  7896. else if(connectorIdInt == 0)
  7897. {
  7898. //check Transaction active
  7899. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7900. {
  7901. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7902. {
  7903. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  7904. {
  7905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7906. goto end;
  7907. }
  7908. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7909. {
  7910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7911. goto end;
  7912. }
  7913. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7914. {
  7915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7916. goto end;
  7917. }
  7918. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7919. {
  7920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7921. goto end;
  7922. }
  7923. }
  7924. }// END FOR CHAdeMO_QUANTITY
  7925. for (int index = 0; index < CCS_QUANTITY; index++)
  7926. {
  7927. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7928. {
  7929. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  7930. {
  7931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7932. goto end;
  7933. }
  7934. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7935. {
  7936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7937. goto end;
  7938. }
  7939. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7940. {
  7941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7942. goto end;
  7943. }
  7944. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7945. {
  7946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7947. goto end;
  7948. }
  7949. }
  7950. } // END FOR CCS_QUANTITY
  7951. for (int index = 0; index < GB_QUANTITY; index++)
  7952. {
  7953. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7954. {
  7955. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  7956. {
  7957. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7958. goto end;
  7959. }
  7960. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7961. {
  7962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7963. goto end;
  7964. }
  7965. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING) ) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7966. {
  7967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7968. goto end;
  7969. }
  7970. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7971. {
  7972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7973. goto end;
  7974. }
  7975. }
  7976. } // END FOR GB_QUANTITY
  7977. for (int index = 0; index < AC_QUANTITY; index++)
  7978. {
  7979. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7980. {
  7981. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  7982. {
  7983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7984. goto end;
  7985. }
  7986. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7987. {
  7988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7989. goto end;
  7990. }
  7991. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7992. {
  7993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7994. goto end;
  7995. }
  7996. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7997. {
  7998. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  7999. {
  8000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8001. goto end;
  8002. }
  8003. }
  8004. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8005. {
  8006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8007. goto end;
  8008. }
  8009. }
  8010. }// END FOR AC_QUANTITY
  8011. //The connectorId is 0
  8012. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8014. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8015. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8016. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8017. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8018. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8019. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8020. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8021. result = TRUE;
  8022. return result;
  8023. }
  8024. else
  8025. {
  8026. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8027. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8028. }
  8029. if(strcmp(comfirmstr,"Accepted") == 0)
  8030. {
  8031. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8032. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8033. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8034. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8035. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8036. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8037. result = TRUE;
  8038. return result;
  8039. }
  8040. end:
  8041. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8042. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8043. return result;
  8044. }
  8045. int handleResetRequest(char *uuid, char *payload)
  8046. {
  8047. mtrace();
  8048. int result = FAIL;
  8049. char sstr[10]={0},sstrtemp[30]={ 0 };
  8050. char typestr[10]={0};
  8051. char comfirmstr[20]={0};
  8052. int c = 0;
  8053. char *loc;
  8054. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  8055. DEBUG_INFO("handleResetRequest ...\n");
  8056. strcpy(sstrtemp, stringtrimspace(payload));
  8057. loc = strstr(sstrtemp, "type");
  8058. memset(sstr ,0, sizeof(sstr) );
  8059. c = 0;
  8060. while (loc[3+strlen("type")+c] != '\"')
  8061. {
  8062. sstr[c] = loc[3+strlen("type")+c];
  8063. c++;
  8064. }
  8065. sstr[c] = '\0';
  8066. strcpy(typestr,sstr);
  8067. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8068. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  8069. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8070. {
  8071. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8072. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8073. result = TRUE;
  8074. return result;
  8075. }
  8076. else
  8077. {
  8078. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8079. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8080. goto errorend;
  8081. }
  8082. errorend:
  8083. sendResetConfirmation(uuid, comfirmstr);
  8084. return result;
  8085. }
  8086. int handleSendLocalListRequest(char *uuid, char *payload)
  8087. {
  8088. mtrace();
  8089. int result = FAIL;
  8090. int listVersionInt;
  8091. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8092. char listsearch[]="listVersion";
  8093. char updateTypesearch[]="updateType";
  8094. char localAuthorizationListsearch[]="localAuthorizationList";
  8095. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8096. char CardList[500][160]={0};
  8097. char updateTypestr[15]={0};
  8098. char idTagstr[20]={0};
  8099. char parentIdTag[20]={0};
  8100. char expiryDate[30]={0};
  8101. char idTagstatus[16]={0};
  8102. int c = 0;
  8103. int i = 0;
  8104. char *delim1 = "}";
  8105. char * pch;
  8106. char *loc;
  8107. //char *ptr;
  8108. char comfirmstr[20];
  8109. //int n_localAuthorizations = 0;
  8110. int checkState_Faulted = FALSE;
  8111. DEBUG_INFO("handleSendLocalListRequest\n");
  8112. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8113. {
  8114. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8115. goto end;
  8116. }
  8117. //check Charge Point state
  8118. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8119. {
  8120. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8121. {
  8122. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8123. }
  8124. }
  8125. for (int index = 0; index < CCS_QUANTITY; index++)
  8126. {
  8127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8128. {
  8129. checkState_Faulted = TRUE; //OCPP Status
  8130. }
  8131. }
  8132. for (int index = 0; index < GB_QUANTITY; index++)
  8133. {
  8134. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8135. {
  8136. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8137. }
  8138. }
  8139. //check Charge Point state
  8140. for (int index = 0; index < AC_QUANTITY; index++)
  8141. {
  8142. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8143. {
  8144. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8145. }
  8146. }
  8147. if(checkState_Faulted == TRUE)
  8148. {
  8149. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8150. goto end;
  8151. }
  8152. //Filter payload space
  8153. strcpy(sstrtemp, stringtrimspace(payload));
  8154. //listVersion
  8155. c = 0;
  8156. loc = strstr(sstrtemp, listsearch);
  8157. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8158. {
  8159. sstr[c] = loc[strlen("listVersion")+2+c];
  8160. c++;
  8161. }
  8162. sstr[c] = '\0';
  8163. listVersionInt = atoi(sstr);
  8164. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8165. //updateType
  8166. loc = strstr(sstrtemp, updateTypesearch);
  8167. c = 0;
  8168. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8169. {
  8170. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8171. c++;
  8172. }
  8173. sstr[c] = '\0';
  8174. strcpy(updateTypestr, sstr);
  8175. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8176. //localAuthorizationList
  8177. memset(sstr ,0, sizeof(sstr) );
  8178. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8179. if(loc != NULL) // localAuthorizationList is not NULL
  8180. {
  8181. //Check UpdateType
  8182. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8183. {
  8184. //Local list full update
  8185. printf("Local list full update.\n");
  8186. OCPP_getListVerion();
  8187. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8188. {
  8189. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8190. goto end;
  8191. }
  8192. OCPP_cleanLocalList();
  8193. }
  8194. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8195. {
  8196. //Local list different update
  8197. printf("Local list different update.\n");
  8198. OCPP_getListVerion();
  8199. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8200. {
  8201. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8202. goto end;
  8203. }
  8204. }
  8205. else
  8206. {
  8207. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8208. goto end;
  8209. }
  8210. c = 0;
  8211. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8212. {
  8213. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8215. c++;
  8216. }
  8217. sstr[c] = '\0';
  8218. //DEBUG_INFO("sstr=%s\n", sstr);
  8219. //parsing strings to words
  8220. i = 0;
  8221. pch = strtok(sstr,delim1);
  8222. while (pch != NULL)
  8223. {
  8224. strcpy(CardList[i], pch);
  8225. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8226. pch = strtok (NULL, delim1);
  8227. i = i + 1;
  8228. }
  8229. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8230. //local Authorizations List Numbers
  8231. //n_localAuthorizations = i;
  8232. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8233. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8234. c= 0;
  8235. while(c < i) // i is CardList Number
  8236. {
  8237. //Search "IdToken"
  8238. memset(sstr ,0, sizeof(sstr) );
  8239. loc = strstr(CardList[c], "idTag");
  8240. int j = 0;
  8241. while (loc[3+strlen("idTag")+j] != '\"')
  8242. {
  8243. sstr[j] = loc[3+strlen("idTag")+j];
  8244. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8245. j++;
  8246. }
  8247. sstr[j] = '\0';
  8248. strcpy(idTagstr, sstr);
  8249. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8250. //Search "expiryDate"
  8251. memset(sstr ,0, sizeof(sstr) );
  8252. loc = strstr(CardList[c], "expiryDate");
  8253. j = 0;
  8254. if(loc != NULL)
  8255. {
  8256. while (loc[3+strlen("expiryDate")+j] != '\"')
  8257. {
  8258. sstr[j] = loc[3+strlen("expiryDate")+j];
  8259. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8260. j++;
  8261. }
  8262. sstr[j] = '\0';
  8263. strcpy(expiryDate, sstr);
  8264. }
  8265. else
  8266. {
  8267. strcpy(expiryDate, "");
  8268. }
  8269. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8270. //Search "parentIdTag"
  8271. memset(sstr ,0, sizeof(sstr) );
  8272. loc = strstr(CardList[c], "parentIdTag");
  8273. j = 0;
  8274. if(loc != NULL)
  8275. {
  8276. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8277. {
  8278. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8279. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8280. j++;
  8281. }
  8282. sstr[j] = '\0';
  8283. strcpy(parentIdTag, sstr);
  8284. }
  8285. else
  8286. {
  8287. strcpy(parentIdTag, "");
  8288. }
  8289. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8290. //Search "status"
  8291. memset(sstr ,0, sizeof(sstr) );
  8292. loc = strstr(CardList[c], "status");
  8293. j = 0;
  8294. while (loc[3+strlen("status")+j] != '\"')
  8295. {
  8296. sstr[j] = loc[3+strlen("status")+j];
  8297. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8298. j++;
  8299. }
  8300. sstr[j] = '\0';
  8301. strcpy(idTagstatus, sstr);
  8302. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8303. OCPP_getIdTag(idTagstr);
  8304. //OCPP_getIdTag("test"); For Test
  8305. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8306. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8307. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8308. {
  8309. //Local list full update
  8310. DEBUG_INFO("Local list full update.\n");
  8311. // update list
  8312. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8313. //DEBUG_INFO("Local list full update. 1\n");
  8314. //OCPP_get_TableAuthlocalAllData();
  8315. //DEBUG_INFO("Local list full update. 2\n");
  8316. }
  8317. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8318. {
  8319. #if 0
  8320. if(strcmp(idTagstr, idTagAuthorization) == 0)
  8321. {
  8322. //OCPP_deleteIdTag(idTagstr);
  8323. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  8324. }
  8325. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  8326. {
  8327. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  8328. }
  8329. #endif
  8330. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8331. }
  8332. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8333. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8334. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8335. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8336. c++;
  8337. }
  8338. }
  8339. else
  8340. {
  8341. //Check UpdateType
  8342. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8343. {
  8344. //Local list full update
  8345. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8346. OCPP_cleanLocalList();
  8347. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8348. goto end;
  8349. }
  8350. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8351. {
  8352. //Local list different update
  8353. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8354. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8355. goto end;
  8356. }
  8357. }
  8358. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8359. end:
  8360. sendSendLocalListConfirmation(uuid, comfirmstr);
  8361. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8362. return result;
  8363. }
  8364. #define MAX 200
  8365. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8366. {
  8367. mtrace();
  8368. int result = FAIL;
  8369. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8370. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8371. char chargingProfilePurposeStr[30]={0};
  8372. char chargingProfileKindStr[16]={0};
  8373. char recurrencyKindStr[10]={0};
  8374. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8375. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8376. int chargingSchedulePeriodCount = 0;
  8377. //int updateflag = FALSE;
  8378. char comfirmstr[20]={0};
  8379. int meet= FALSE;
  8380. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8381. int c = 0;
  8382. char *loc;
  8383. FILE *fptr1;//, *fptr2;
  8384. //int lno=0;//, linectr = 0;
  8385. //int modifyflag = FALSE;
  8386. char filename[MAX]={0};
  8387. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8388. //int resultRename=0;
  8389. char rmFileCmd[50]={0};
  8390. char tempchargingProfilePurposeStr[30]={0};
  8391. char word[1600]={0};
  8392. int n_chargingProfile = 0;
  8393. //[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}}}]
  8394. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8395. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8396. //Filter string space
  8397. strcpy(sstrtemp, stringtrimspace(payload));
  8398. //*********************connectorId***************************/
  8399. loc = strstr(sstrtemp, "connectorId");
  8400. c = 0;
  8401. memset(sstr ,0, sizeof(sstr) );
  8402. while (loc[strlen("connectorId")+2+c] != ',')
  8403. {
  8404. sstr[c] = loc[strlen("connectorId")+2+c];
  8405. c++;
  8406. }
  8407. sstr[c] = '\0';
  8408. connectorIdInt = atoi(sstr);
  8409. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8410. {
  8411. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8412. }
  8413. else
  8414. {
  8415. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8416. }
  8417. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8418. //*********************chargingProfileId***************************/
  8419. loc = strstr(sstrtemp, "chargingProfileId");
  8420. c = 0;
  8421. memset(sstr ,0, sizeof(sstr) );
  8422. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8423. {
  8424. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8425. c++;
  8426. }
  8427. sstr[c] = '\0';
  8428. chargingProfileIdInt = atoi(sstr);
  8429. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8430. {
  8431. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8432. }
  8433. else
  8434. {
  8435. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8436. }
  8437. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8438. //*********************transactionId***************************/
  8439. loc = strstr(sstrtemp, "transactionId");
  8440. if(loc != NULL)
  8441. {
  8442. c = 0;
  8443. memset(sstr ,0, sizeof(sstr) );
  8444. while (loc[strlen("transactionId")+2+c] != ',')
  8445. {
  8446. sstr[c] = loc[strlen("transactionId")+2+c];
  8447. c++;
  8448. }
  8449. sstr[c] = '\0';
  8450. transactionIdInt = atoi(sstr);
  8451. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8452. {
  8453. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8454. }
  8455. else
  8456. {
  8457. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8458. }
  8459. }
  8460. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8461. //*********************stackLevel***************************/
  8462. loc = strstr(sstrtemp, "stackLevel");
  8463. c = 0;
  8464. memset(sstr ,0, sizeof(sstr) );
  8465. while (loc[strlen("stackLevel")+2+c] != ',')
  8466. {
  8467. sstr[c] = loc[strlen("stackLevel")+2+c];
  8468. c++;
  8469. }
  8470. sstr[c] = '\0';
  8471. stackLevelInt = atoi(sstr);
  8472. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8473. {
  8474. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8475. }
  8476. else
  8477. {
  8478. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8479. }
  8480. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8481. //*********************chargingProfilePurpose***************************/
  8482. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8483. c = 0;
  8484. memset(sstr ,0, sizeof(sstr) );
  8485. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8486. {
  8487. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8488. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8489. c++;
  8490. }
  8491. sstr[c] = '\0';
  8492. strcpy(chargingProfilePurposeStr,sstr);
  8493. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8495. {
  8496. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8497. }
  8498. else
  8499. {
  8500. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8501. }
  8502. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8503. //*********************chargingProfileKind***************************/
  8504. loc = strstr(sstrtemp, "chargingProfileKind");
  8505. c = 0;
  8506. memset(sstr ,0, sizeof(sstr) );
  8507. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8508. {
  8509. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8511. c++;
  8512. }
  8513. sstr[c] = '\0';
  8514. strcpy(chargingProfileKindStr,sstr);
  8515. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8516. {
  8517. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8518. }
  8519. else
  8520. {
  8521. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8522. }
  8523. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8524. //*********************recurrencyKind***************************/
  8525. loc = strstr(sstrtemp, "recurrencyKind");
  8526. if(loc != NULL)
  8527. {
  8528. c = 0;
  8529. memset(sstr ,0, sizeof(sstr) );
  8530. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8531. {
  8532. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8533. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8534. c++;
  8535. }
  8536. sstr[c] = '\0';
  8537. strcpy(recurrencyKindStr,sstr);
  8538. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8539. {
  8540. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8541. }
  8542. else
  8543. {
  8544. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8545. }
  8546. }
  8547. else
  8548. {
  8549. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8550. {
  8551. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8552. }
  8553. else
  8554. {
  8555. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8556. }
  8557. }
  8558. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8559. //*********************validFrom***************************/
  8560. loc = strstr(sstrtemp, "validFrom");
  8561. if(loc != NULL)
  8562. {
  8563. c = 0;
  8564. memset(sstr ,0, sizeof(sstr) );
  8565. while (loc[3+strlen("validFrom")+c] != '\"')
  8566. {
  8567. sstr[c] = loc[3+strlen("validFrom")+c];
  8568. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8569. c++;
  8570. }
  8571. sstr[c] = '\0';
  8572. strcpy(validFromStr,sstr);
  8573. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8574. {
  8575. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8576. }
  8577. else
  8578. {
  8579. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8580. }
  8581. }
  8582. else
  8583. {
  8584. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8585. {
  8586. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8587. }
  8588. else
  8589. {
  8590. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8591. }
  8592. }
  8593. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8594. //*********************validTo***************************/
  8595. loc = strstr(sstrtemp, "validTo");
  8596. if(loc != NULL)
  8597. {
  8598. c = 0;
  8599. memset(sstr ,0, sizeof(sstr) );
  8600. while (loc[3+strlen("validTo")+c] != '\"')
  8601. {
  8602. sstr[c] = loc[3+strlen("validTo")+c];
  8603. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8604. c++;
  8605. }
  8606. sstr[c] = '\0';
  8607. strcpy(validToStr,sstr);
  8608. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8609. {
  8610. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8611. }
  8612. else
  8613. {
  8614. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8615. }
  8616. }
  8617. else
  8618. {
  8619. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8620. {
  8621. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8622. }
  8623. else
  8624. {
  8625. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8626. }
  8627. }
  8628. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8629. //*********************duration***************************/
  8630. loc = strstr(sstrtemp, "duration");
  8631. if(loc != NULL)
  8632. {
  8633. c = 0;
  8634. memset(sstr ,0, sizeof(sstr) );
  8635. while (loc[strlen("duration")+2+c] != ',')
  8636. {
  8637. sstr[c] = loc[strlen("duration")+2+c];
  8638. c++;
  8639. }
  8640. sstr[c] = '\0';
  8641. durationInt = atoi(sstr);
  8642. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8643. {
  8644. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8645. }
  8646. else
  8647. {
  8648. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8649. }
  8650. }
  8651. else
  8652. {
  8653. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8654. {
  8655. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8656. }
  8657. else
  8658. {
  8659. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8660. }
  8661. }
  8662. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8663. //*********************startSchedule***************************/
  8664. loc = strstr(sstrtemp, "startSchedule");
  8665. if(loc != NULL)
  8666. {
  8667. c = 0;
  8668. memset(sstr ,0, sizeof(sstr) );
  8669. while (loc[3+strlen("startSchedule")+c] != '\"')
  8670. {
  8671. sstr[c] = loc[3+strlen("startSchedule")+c];
  8672. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8673. c++;
  8674. }
  8675. sstr[c] = '\0';
  8676. strcpy(startScheduleStr,sstr);
  8677. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8678. {
  8679. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8680. }
  8681. else
  8682. {
  8683. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8684. }
  8685. }
  8686. else
  8687. {
  8688. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8689. {
  8690. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8691. }
  8692. else
  8693. {
  8694. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8695. }
  8696. }
  8697. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8698. //*********************chargingRateUnit***************************/
  8699. loc = strstr(sstrtemp, "chargingRateUnit");
  8700. if(loc != NULL)
  8701. {
  8702. c = 0;
  8703. memset(sstr ,0, sizeof(sstr) );
  8704. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8705. {
  8706. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8707. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8708. c++;
  8709. }
  8710. sstr[c] = '\0';
  8711. strcpy(chargingRateUnitStr,sstr);
  8712. #if 0
  8713. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8714. {
  8715. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8716. goto end;
  8717. }
  8718. #endif
  8719. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8720. {
  8721. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8722. }
  8723. else
  8724. {
  8725. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8726. }
  8727. }
  8728. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8729. //****************chargingSchedulePeriod count start*******************/
  8730. int what_len = strlen("startPeriod");
  8731. char tempChargingProfile[1600]={0};
  8732. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8733. char *where = tempChargingProfile;
  8734. if (what_len)
  8735. {
  8736. while ((where = strstr(where, "startPeriod"))) {
  8737. where += what_len;
  8738. chargingSchedulePeriodCount++;
  8739. }
  8740. }
  8741. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8742. {
  8743. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8744. goto end;
  8745. }
  8746. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8747. //where = payload;
  8748. int templength = 0;
  8749. //int searchstart = 0;
  8750. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8751. {
  8752. //****************startPeriod*******************/
  8753. c=0;
  8754. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8755. memset(sstr ,0, sizeof(sstr) );
  8756. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8757. {
  8758. sstr[c] = loc[strlen("startPeriod")+2+c];
  8759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8760. c++;
  8761. }
  8762. sstr[c] = '\0';
  8763. startPeriodInt[periodNums] = atoi(sstr);
  8764. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8765. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8766. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8767. {
  8768. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8769. }
  8770. else
  8771. {
  8772. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8773. }
  8774. templength = strlen("startPeriod")+2+c;
  8775. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8776. //****************limit*******************/
  8777. c=0;
  8778. loc = strstr(tempChargingProfile + templength, "limit");
  8779. memset(sstr ,0, sizeof(sstr) );
  8780. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8781. {
  8782. sstr[c] = loc[strlen("limit")+2+c];
  8783. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8784. c++;
  8785. }
  8786. sstr[c] = '\0';
  8787. limitflaot[periodNums] = atof(sstr);
  8788. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8789. {
  8790. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8791. }
  8792. else
  8793. {
  8794. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8795. }
  8796. templength = templength + strlen("limit")+2+c;
  8797. //****************numberPhases*******************/
  8798. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8799. if(loc != NULL)
  8800. {
  8801. c=0;
  8802. memset(sstr ,0, sizeof(sstr) );
  8803. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8804. {
  8805. sstr[c] = loc[strlen("numberPhases")+2+c];
  8806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8807. c++;
  8808. }
  8809. sstr[c] = '\0';
  8810. numberPhasesInt[periodNums] = atoi(sstr);
  8811. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8812. {
  8813. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8814. }
  8815. else
  8816. {
  8817. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8818. }
  8819. templength = templength + strlen("numberPhases")+2+c;
  8820. }
  8821. //where = loc;
  8822. }
  8823. //****************chargingSchedulePeriod count end*******************/
  8824. //*********************minChargingRate***************************/
  8825. loc = strstr(sstrtemp, "minChargingRate");
  8826. if(loc != NULL)
  8827. {
  8828. c = 0;
  8829. memset(sstr ,0, sizeof(sstr) );
  8830. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8831. {
  8832. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8833. c++;
  8834. }
  8835. sstr[c] = '\0';
  8836. minChargingRateFloat = atof(sstr);
  8837. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8838. {
  8839. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8840. }
  8841. else
  8842. {
  8843. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8844. }
  8845. }
  8846. else
  8847. {
  8848. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8849. {
  8850. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8851. }
  8852. else
  8853. {
  8854. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8855. }
  8856. }
  8857. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8858. {
  8859. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8860. if(connectorIdInt != 0)
  8861. {
  8862. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8863. goto end;
  8864. }
  8865. strcpy(filename, ChargePointMaxProfile_JSON );
  8866. fptr1 = fopen(filename, "r");
  8867. if (!fptr1)
  8868. {
  8869. //file not exist
  8870. DEBUG_INFO("Unable to open the input file!!\n");
  8871. fptr1 = fopen(filename, "w+");
  8872. }
  8873. else
  8874. {
  8875. //Check Charging Profile Count
  8876. while(fscanf(fptr1, "%s", word) != EOF)
  8877. {
  8878. //DEBUG_INFO("word=%s\n",word);
  8879. if(strstr(word, "chargingProfileId")!= NULL)
  8880. {
  8881. //DEBUG_INFO("test chargingProfileId \n");
  8882. n_chargingProfile = n_chargingProfile + 1;
  8883. //DEBUG_INFO("chargingProfileId Found\n");
  8884. }
  8885. }
  8886. }
  8887. fclose(fptr1);
  8888. }
  8889. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8890. {
  8891. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8892. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8893. {
  8894. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8895. goto end;
  8896. }
  8897. memset(filename, 0, sizeof filename);
  8898. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8899. fptr1 = fopen(filename, "r");
  8900. if (!fptr1)
  8901. {
  8902. //file not exist
  8903. //DEBUG_INFO("Unable to open the input file!!\n");
  8904. fptr1 = fopen(filename, "w+");
  8905. }
  8906. else
  8907. {
  8908. //Check Charging Profile Count
  8909. while(fscanf(fptr1, "%s", word) != EOF)
  8910. {
  8911. //DEBUG_INFO("word=%s\n",word);
  8912. if(strstr(word, "chargingProfileId")!= NULL)
  8913. {
  8914. //DEBUG_INFO("test chargingProfileId \n");
  8915. n_chargingProfile = n_chargingProfile + 1;
  8916. //DEBUG_INFO("chargingProfileId Found\n");
  8917. }
  8918. }
  8919. }
  8920. fclose(fptr1);
  8921. }
  8922. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8923. {
  8924. //printf("set chargingProfile 1-4\n");
  8925. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8926. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8927. if(connectorIdInt == 0)
  8928. {
  8929. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8930. goto end;
  8931. }
  8932. int tempIndex = 0;
  8933. //check Transaction active
  8934. if(gunType[connectorIdInt -1] == 'J')
  8935. {
  8936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8937. {
  8938. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8939. }
  8940. else
  8941. {
  8942. tempIndex = connectorIdInt -1;
  8943. }
  8944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8945. {
  8946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8947. {
  8948. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8949. {
  8950. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8951. {
  8952. meet = TRUE;
  8953. break;
  8954. }
  8955. }
  8956. }
  8957. }
  8958. }
  8959. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8960. {
  8961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8962. {
  8963. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8964. }
  8965. else
  8966. {
  8967. tempIndex = connectorIdInt -1;
  8968. }
  8969. for (int index = 0; index < CCS_QUANTITY; index++)
  8970. {
  8971. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8972. {
  8973. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8974. {
  8975. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8976. {
  8977. meet = TRUE;
  8978. break;
  8979. }
  8980. }
  8981. }
  8982. }
  8983. }
  8984. else if(gunType[connectorIdInt -1] == 'G')
  8985. {
  8986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8987. {
  8988. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8989. }
  8990. else
  8991. {
  8992. tempIndex = connectorIdInt -1;
  8993. }
  8994. for (int index = 0; index < GB_QUANTITY; index++)
  8995. {
  8996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8997. {
  8998. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8999. {
  9000. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9001. {
  9002. meet = TRUE;
  9003. break;
  9004. }
  9005. }
  9006. }
  9007. }
  9008. }
  9009. else
  9010. {
  9011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9012. {
  9013. tempIndex = 2;
  9014. }
  9015. else
  9016. {
  9017. tempIndex = (connectorIdInt -1);
  9018. }
  9019. for (int index = 0; index < AC_QUANTITY; index++)
  9020. {
  9021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9022. {
  9023. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  9024. {
  9025. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9026. {
  9027. meet = TRUE;
  9028. break;
  9029. }
  9030. }
  9031. }
  9032. }
  9033. }
  9034. //check Transaction active
  9035. if(meet == FALSE)
  9036. {
  9037. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9038. goto end;
  9039. }
  9040. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9041. {
  9042. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9043. goto end;
  9044. }
  9045. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9046. fptr1 = fopen(filename, "r");
  9047. if (!fptr1)
  9048. {
  9049. //file not exist
  9050. DEBUG_INFO("Unable to open the input file!!\n");
  9051. fptr1 = fopen(filename, "w+");
  9052. }
  9053. else
  9054. {
  9055. //Check Charging Profile Count
  9056. while(fscanf(fptr1, "%s", word) != EOF)
  9057. {
  9058. //DEBUG_INFO("word=%s\n",word);
  9059. if(strstr(word, "chargingProfileId")!= NULL)
  9060. {
  9061. //DEBUG_INFO("test chargingProfileId \n");
  9062. n_chargingProfile = n_chargingProfile + 1;
  9063. //DEBUG_INFO("chargingProfileId Found\n");
  9064. }
  9065. }
  9066. }
  9067. fclose(fptr1);
  9068. }
  9069. // Check ChargeProfileMaxStackLevel
  9070. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9071. {
  9072. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9073. goto end;
  9074. }
  9075. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9076. {
  9077. int i = 0;
  9078. char fnametemp[200]={0};
  9079. n_chargingProfile = 0;
  9080. //Check ChargePointMaxProfile.json exit
  9081. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9082. {
  9083. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9084. //Check Charging Profile Count
  9085. while(fscanf(fptr1, "%s", word) != EOF)
  9086. {
  9087. //DEBUG_INFO("word=%s\n",word);
  9088. if(strstr(word, "chargingProfileId")!= NULL)
  9089. {
  9090. //DEBUG_INFO("test chargingProfileId \n");
  9091. n_chargingProfile = n_chargingProfile + 1;
  9092. i = i + 1;
  9093. //DEBUG_INFO("chargingProfileId Found\n");
  9094. }
  9095. memset(word, 0, sizeof word);
  9096. }
  9097. fclose(fptr1);
  9098. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9099. }
  9100. //Check TxDefaultProfile_0.json exit
  9101. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9102. {
  9103. i = 0;
  9104. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9105. //Check Charging Profile Count
  9106. while(fscanf(fptr1, "%s", word) != EOF)
  9107. {
  9108. //DEBUG_INFO("word=%s\n",word);
  9109. if(strstr(word, "chargingProfileId")!= NULL)
  9110. {
  9111. //DEBUG_INFO("test chargingProfileId \n");
  9112. n_chargingProfile = n_chargingProfile + 1;
  9113. i = i + 1;
  9114. //DEBUG_INFO("chargingProfileId Found\n");
  9115. }
  9116. memset(word, 0, sizeof word);
  9117. }
  9118. fclose(fptr1);
  9119. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9120. }
  9121. //Check TxDefaultProfile_%d.json
  9122. for(int j=1; j <= gunTotalNumber; j++)
  9123. {
  9124. memset(fnametemp, 0, sizeof fnametemp);
  9125. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9126. if((access(fnametemp,F_OK))!=-1)
  9127. {
  9128. i = 0;
  9129. fptr1 = fopen(fnametemp, "r");
  9130. //Check Charging Profile Count
  9131. while(fscanf(fptr1, "%s", word) != EOF)
  9132. {
  9133. //DEBUG_INFO("word=%s\n",word);
  9134. if(strstr(word, "chargingProfileId")!= NULL)
  9135. {
  9136. //DEBUG_INFO("test chargingProfileId \n");
  9137. n_chargingProfile = n_chargingProfile + 1;
  9138. i = i + 1;
  9139. //DEBUG_INFO("chargingProfileId Found\n");
  9140. }
  9141. memset(word, 0, sizeof word);
  9142. }
  9143. fclose(fptr1);
  9144. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9145. }
  9146. }
  9147. //Check TxProfile_%d.json
  9148. for(int j=1; j <= gunTotalNumber; j++)
  9149. {
  9150. memset(fnametemp, 0, sizeof fnametemp);
  9151. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9152. if((access(fnametemp,F_OK))!=-1)
  9153. {
  9154. i = 0;
  9155. fptr1 = fopen(fnametemp, "r");
  9156. //Check Charging Profile Count
  9157. while(fscanf(fptr1, "%s", word) != EOF)
  9158. {
  9159. //DEBUG_INFO("word=%s\n",word);
  9160. if(strstr(word, "chargingProfileId")!= NULL)
  9161. {
  9162. //DEBUG_INFO("test chargingProfileId \n");
  9163. n_chargingProfile = n_chargingProfile + 1;
  9164. i = i + 1;
  9165. //DEBUG_INFO("chargingProfileId Found\n");
  9166. }
  9167. memset(word, 0, sizeof word);
  9168. }
  9169. fclose(fptr1);
  9170. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9171. }
  9172. }
  9173. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9174. {
  9175. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9176. goto end;
  9177. }
  9178. }
  9179. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9180. //**********************************Write to File********************************************************/
  9181. FILE *infile;
  9182. FILE *outfile;
  9183. // open file for writing
  9184. infile = fopen (filename, "r");
  9185. outfile = fopen (tempfile, "w");
  9186. int d =0;
  9187. d = fgetc(infile);
  9188. //DEBUG_INFO("d:%d\n",d);
  9189. rewind(infile);
  9190. //*检测到文件结束标识返回1,否则返回0。*/
  9191. if(d == EOF)
  9192. {
  9193. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9194. fprintf(outfile,"%s\n",payload);
  9195. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9196. fclose(infile);
  9197. fclose(outfile);
  9198. sprintf(rmFileCmd,"rm -f %s",filename);
  9199. system(rmFileCmd);
  9200. rename(tempfile, filename);
  9201. sleep(1);
  9202. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9203. //system(rmFileCmd);
  9204. }
  9205. else
  9206. {
  9207. char buf[1000]={0};
  9208. int ChargingProfileAdded = FALSE;
  9209. while (fgets(buf, sizeof(buf), infile) != NULL)
  9210. {
  9211. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9212. //*************************tempconnectorIdInt*********************************/
  9213. loc = strstr(buf, "connectorId");
  9214. c = 0;
  9215. memset(sstr ,0, sizeof(sstr) );
  9216. while (loc[strlen("connectorId")+2+c] != ',')
  9217. {
  9218. sstr[c] = loc[strlen("connectorId")+2+c];
  9219. c++;
  9220. }
  9221. sstr[c] = '\0';
  9222. tempconnectorIdInt = atoi(sstr);
  9223. //*************************tempchargingProfileIdInt*********************************/
  9224. loc = strstr(buf, "chargingProfileId");
  9225. c = 0;
  9226. memset(sstr ,0, sizeof(sstr) );
  9227. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9228. {
  9229. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9230. c++;
  9231. }
  9232. sstr[c] = '\0';
  9233. tempchargingProfileIdInt = atoi(sstr);
  9234. //*************************tempstackLevelInt*********************************/
  9235. loc = strstr(buf, "stackLevel");
  9236. c = 0;
  9237. memset(sstr ,0, sizeof(sstr) );
  9238. while (loc[strlen("stackLevel")+2+c] != ',')
  9239. {
  9240. sstr[c] = loc[strlen("stackLevel")+2+c];
  9241. c++;
  9242. }
  9243. sstr[c] = '\0';
  9244. tempstackLevelInt = atoi(sstr);
  9245. //*************************tempchargingProfilePurposeStr*********************************/
  9246. loc = strstr(payload, "chargingProfilePurpose");
  9247. c = 0;
  9248. memset(sstr ,0, sizeof(sstr) );
  9249. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9250. {
  9251. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9253. c++;
  9254. }
  9255. sstr[c] = '\0';
  9256. strcpy(tempchargingProfilePurposeStr,sstr);
  9257. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9258. {
  9259. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9260. {
  9261. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9262. if(ChargingProfileAdded == FALSE)
  9263. {
  9264. fprintf(outfile,"%s\n",payload);
  9265. ChargingProfileAdded = TRUE;
  9266. }
  9267. }
  9268. else
  9269. {
  9270. if(tempstackLevelInt < stackLevelInt)
  9271. {
  9272. if(ChargingProfileAdded == FALSE)
  9273. {
  9274. fprintf(outfile,"%s\n",payload);
  9275. ChargingProfileAdded = TRUE;
  9276. fprintf(outfile,"%s\n",buf);
  9277. }
  9278. else
  9279. {
  9280. fprintf(outfile,"%s\n",buf);
  9281. }
  9282. }
  9283. else
  9284. {
  9285. if(ChargingProfileAdded == FALSE)
  9286. {
  9287. fprintf(outfile,"%s\n",buf);
  9288. fprintf(outfile,"%s\n",payload);
  9289. ChargingProfileAdded = TRUE;
  9290. }
  9291. else
  9292. {
  9293. fprintf(outfile,"%s\n",buf);
  9294. }
  9295. }
  9296. }
  9297. }
  9298. else
  9299. {
  9300. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9301. {
  9302. if(ChargingProfileAdded == FALSE)
  9303. {
  9304. fprintf(outfile,"%s\n",payload);
  9305. ChargingProfileAdded = TRUE;
  9306. fprintf(outfile,"%s\n",buf);
  9307. }
  9308. else
  9309. {
  9310. fprintf(outfile,"%s\n",buf);
  9311. }
  9312. }
  9313. else if(tempstackLevelInt < stackLevelInt)
  9314. {
  9315. if(ChargingProfileAdded == FALSE)
  9316. {
  9317. fprintf(outfile,"%s\n",payload);
  9318. ChargingProfileAdded = TRUE;
  9319. fprintf(outfile,"%s\n",buf);
  9320. }
  9321. else
  9322. {
  9323. fprintf(outfile,"%s\n",buf);
  9324. }
  9325. }
  9326. else
  9327. {
  9328. if(ChargingProfileAdded == FALSE)
  9329. {
  9330. fprintf(outfile,"%s\n",buf);
  9331. fprintf(outfile,"%s\n",payload);
  9332. ChargingProfileAdded = TRUE;
  9333. }
  9334. else
  9335. {
  9336. fprintf(outfile,"%s\n",buf);
  9337. }
  9338. }
  9339. }
  9340. } // end of while loop
  9341. fclose(infile);
  9342. fclose(outfile);
  9343. sprintf(rmFileCmd,"rm -f %s",filename);
  9344. system(rmFileCmd);
  9345. rename(tempfile, filename);
  9346. sleep(1);
  9347. result = TRUE;
  9348. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9349. }
  9350. end:
  9351. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9352. return result;
  9353. return result;
  9354. }
  9355. int handleTriggerMessageRequest(char *uuid, char *payload)
  9356. {
  9357. mtrace();
  9358. int result = FAIL;
  9359. int connectorIdIsNULL = FALSE;
  9360. int connectorIdInt =0;
  9361. char sstr[40]={0},sstrtemp[100]={ 0 };
  9362. char requestedMessagestr[40]={0};
  9363. char comfirmstr[20]={0};
  9364. int c = 0;
  9365. char *loc;
  9366. DEBUG_INFO("handleTriggerMessageRequest\n");
  9367. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9368. strcpy(sstrtemp, stringtrimspace(payload));
  9369. c = 0;
  9370. loc = strstr(sstrtemp, "requestedMessage");
  9371. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9372. {
  9373. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9374. c++;
  9375. }
  9376. sstr[c] = '\0';
  9377. strcpy(requestedMessagestr, sstr);
  9378. c = 0;
  9379. loc = strstr(sstrtemp, "connectorId");
  9380. if(loc == NULL)
  9381. {
  9382. connectorIdIsNULL = TRUE;
  9383. }
  9384. else
  9385. {
  9386. memset(sstr ,0, sizeof(sstr) );
  9387. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9388. {
  9389. sstr[c] = loc[strlen("connectorId")+2+c];
  9390. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9391. c++;
  9392. }
  9393. sstr[c] = '\0';
  9394. connectorIdInt = atoi(sstr);
  9395. }
  9396. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9397. {
  9398. //connectorIdInt = json_object_get_int(connectorId);
  9399. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9400. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9401. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9402. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9403. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9404. }
  9405. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9406. {
  9407. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9408. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9409. return TRUE;
  9410. }
  9411. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9412. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9413. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9414. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9415. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9416. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9417. {
  9418. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9419. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9420. return TRUE;
  9421. }
  9422. else
  9423. {
  9424. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9425. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9426. }
  9427. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9428. {
  9429. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  9430. {
  9431. FirmwareStatusNotificationStatus = 3;
  9432. }
  9433. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9434. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9435. }
  9436. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9437. {
  9438. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9439. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9440. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9441. }
  9442. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9443. {
  9444. sendBootNotificationRequest();
  9445. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9446. }
  9447. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9448. {
  9449. sendHeartbeatRequest(connectorIdInt);
  9450. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9451. }
  9452. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9453. {
  9454. if(connectorIdIsNULL == FALSE)
  9455. {
  9456. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9457. {
  9458. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9459. sendMeterValuesRequest(connectorIdInt -1);
  9460. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9461. }
  9462. }
  9463. else
  9464. {
  9465. for(int idx=0;idx< gunTotalNumber;idx++)
  9466. {
  9467. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9468. sendMeterValuesRequest(idx);
  9469. }
  9470. }
  9471. }
  9472. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9473. {
  9474. if(connectorIdIsNULL == FALSE)
  9475. {
  9476. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9477. {
  9478. sendStatusNotificationRequest(connectorIdInt -1);
  9479. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9480. }
  9481. }
  9482. else
  9483. {
  9484. for(int idx=0;idx< gunTotalNumber;idx++)
  9485. sendStatusNotificationRequest(idx);
  9486. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9487. }
  9488. }
  9489. return result;
  9490. }
  9491. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9492. {
  9493. mtrace();
  9494. int result = FAIL;
  9495. char sstr[6]={0},sstrtemp[50]={ 0 };
  9496. int connectorIdInt =0;
  9497. char comfirmstr[20]={0};
  9498. int c = 0;
  9499. int tempIndex = 0;
  9500. char *loc;
  9501. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9502. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9503. strcpy(sstrtemp, stringtrimspace(payload));
  9504. c = 0;
  9505. loc = strstr(sstrtemp, "connectorId");
  9506. memset(sstr ,0, sizeof(sstr) );
  9507. while (loc[strlen("connectorId")+2+c] != '}')
  9508. {
  9509. sstr[c] = loc[strlen("connectorId")+2+c];
  9510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9511. c++;
  9512. }
  9513. sstr[c] = '\0';
  9514. connectorIdInt = atoi(sstr);
  9515. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9516. if(gunTotalNumber == 0)
  9517. {
  9518. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9519. goto end;
  9520. }
  9521. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9522. {
  9523. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9524. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9525. goto end;
  9526. }
  9527. else
  9528. {
  9529. //check Transaction active
  9530. if(gunType[connectorIdInt-1] == 'J')
  9531. {
  9532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9533. {
  9534. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9535. }
  9536. else
  9537. {
  9538. tempIndex = connectorIdInt -1;
  9539. }
  9540. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9541. {
  9542. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9543. {
  9544. //stop Transaction
  9545. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9546. }
  9547. }
  9548. }
  9549. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9550. {
  9551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9552. {
  9553. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9554. }
  9555. else
  9556. {
  9557. tempIndex = connectorIdInt -1;
  9558. }
  9559. for (int index = 0; index < CCS_QUANTITY; index++)
  9560. {
  9561. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9562. {
  9563. //stop Transaction
  9564. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9565. }
  9566. }
  9567. }
  9568. else if(gunType[connectorIdInt-1] == 'G')
  9569. {
  9570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9571. {
  9572. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9573. }
  9574. else
  9575. {
  9576. tempIndex = connectorIdInt -1;
  9577. }
  9578. for (int index = 0; index < GB_QUANTITY; index++)
  9579. {
  9580. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9581. {
  9582. //stop Transaction
  9583. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9584. }
  9585. }
  9586. }
  9587. else
  9588. {
  9589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9590. {
  9591. tempIndex = 2;
  9592. }
  9593. else
  9594. {
  9595. tempIndex = connectorIdInt-1;
  9596. }
  9597. for (int index = 0; index < AC_QUANTITY; index++)
  9598. {
  9599. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9600. {
  9601. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9602. }
  9603. }
  9604. }
  9605. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9606. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9607. result = TRUE;
  9608. return result;
  9609. }
  9610. end:
  9611. //json_object_put(obj); --- remove temporally
  9612. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9613. return result;
  9614. }
  9615. static char UpdateFirmwarepayloadData[300]={0};
  9616. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9617. {
  9618. mtrace();
  9619. int result = FAIL;
  9620. pthread_t t;
  9621. sendUpdateFirmwareConfirmation(uuid);
  9622. memset(UpdateFirmwarepayloadData, 0, 300);
  9623. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9624. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9625. ////pthread_join(t, NULL); //
  9626. //pthread_detach(t);
  9627. //sendUpdateFirmwareConfirmation(uuid);
  9628. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9629. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9630. return result;
  9631. }
  9632. void *UpdateFirmwareProcess(void *data)
  9633. {
  9634. pthread_detach(pthread_self());
  9635. mtrace();
  9636. int retriesInt =0, retryIntervalInt=0;
  9637. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9638. int port=0;
  9639. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9640. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9641. //char comfirmstr[20];
  9642. int isSuccess = 0;
  9643. char ftpbuf[200];
  9644. char temp[100];
  9645. char * pch;
  9646. int retriesISNULL=FALSE;
  9647. int retryInterval=FALSE;
  9648. int c = 0;
  9649. //int i = 0;
  9650. char *loc;
  9651. char sstr[300]={ 0 };
  9652. char str[300]={ 0 };
  9653. //char *str = (char*) data; // ? ?輸入資 ?
  9654. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9655. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9656. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9657. //***************location **************/
  9658. loc = strstr(str, "location");
  9659. memset(sstr ,0, sizeof(sstr) );
  9660. c = 0;
  9661. while (loc[3+strlen("location")+c] != '\"')
  9662. {
  9663. sstr[c] = loc[3+strlen("location")+c];
  9664. c++;
  9665. }
  9666. sstr[c] = '\0';
  9667. strcpy(locationstr, sstr);
  9668. //***************retries**************/
  9669. c = 0;
  9670. loc = strstr(str, "retries");
  9671. if(loc == NULL)
  9672. {
  9673. retriesISNULL=TRUE;
  9674. }
  9675. else
  9676. {
  9677. memset(sstr ,0, sizeof(sstr) );
  9678. while (loc[strlen("retries")+2+c] != ',')
  9679. {
  9680. sstr[c] = loc[strlen("retries")+2+c];
  9681. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9682. c++;
  9683. }
  9684. sstr[c] = '\0';
  9685. }
  9686. if(retriesISNULL == FALSE)
  9687. {
  9688. retriesInt = atoi(sstr);
  9689. }
  9690. //***************retrieveDate **************/
  9691. loc = strstr(str, "retrieveDate");
  9692. memset(sstr ,0, sizeof(sstr) );
  9693. c = 0;
  9694. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9695. {
  9696. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9697. c++;
  9698. }
  9699. sstr[c] = '\0';
  9700. strcpy(retrieveDatestr, sstr);
  9701. //***************retryInterval **************/
  9702. c = 0;
  9703. loc = strstr(str, "retryInterval");
  9704. memset(sstr ,0, sizeof(sstr) );
  9705. if(loc == NULL)
  9706. {
  9707. retryInterval=TRUE;
  9708. }
  9709. else
  9710. {
  9711. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9712. {
  9713. sstr[c] = loc[strlen("retryInterval")+2+c];
  9714. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9715. c++;
  9716. }
  9717. sstr[c] = '\0';
  9718. }
  9719. if(retryInterval==FALSE)
  9720. {
  9721. retryIntervalInt = atoi(sstr);
  9722. }
  9723. memset(ftppath, 0, sizeof(ftppath));
  9724. memset(path, 0, sizeof(path));
  9725. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9726. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9727. if(strncmp(locationstr,"http", 4) == 0)
  9728. {
  9729. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9730. protocol, host, path);
  9731. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9732. // protocol, user, password, host, path);
  9733. sprintf(ftppath,"/%s", path);
  9734. //DEBUG_INFO("protocol =%s\n",protocol);
  9735. //DEBUG_INFO("host =%s\n",host);
  9736. //DEBUG_INFO("path =%s\n",path);
  9737. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9738. int ftppathlen=strlen(ftppath);
  9739. int i=1;
  9740. char filenametemp[50];
  9741. while(i < ftppathlen)
  9742. {
  9743. int len=ftppathlen-i;
  9744. if(ftppath[len]== 47) // '/' ascll code: 47
  9745. {
  9746. DEBUG_INFO("compare '/' all right\n");
  9747. break;
  9748. }
  9749. i=i+1;
  9750. }
  9751. memset(filenametemp, 0, sizeof(filenametemp));
  9752. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9753. filenametemp[i+1] = 0;
  9754. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9755. do{
  9756. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9757. sleep(retryIntervalInt);
  9758. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9759. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9760. if(!isSuccess)
  9761. {
  9762. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9763. }
  9764. else
  9765. {
  9766. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9767. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9768. //isUpdateRequest = TRUE;
  9769. }
  9770. }
  9771. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9772. {
  9773. memset(ftpbuf, 0, sizeof(ftpbuf));
  9774. memset(temp, 0, sizeof(temp));
  9775. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9776. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9777. int ftppathlen=strlen(ftpbuf);
  9778. int i=1;
  9779. char filenametemp[50];
  9780. while(i < ftppathlen)
  9781. {
  9782. int len=ftppathlen-i;
  9783. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9784. {
  9785. DEBUG_INFO(" compare '/' all right\n");
  9786. break;
  9787. }
  9788. i=i+1;
  9789. }
  9790. memset(filenametemp, 0, sizeof(filenametemp));
  9791. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9792. filenametemp[i+1] = 0;
  9793. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9794. pch=strchr(temp,'@');
  9795. if(pch==NULL)
  9796. {
  9797. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9798. protocol, host, &port, path);
  9799. strcpy(user,"anonymous");
  9800. strcpy(password,"");
  9801. }
  9802. else
  9803. {
  9804. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9805. protocol, user, password, host, &port, path);
  9806. }
  9807. sscanf(host,"%[^/]%s",host1, path1);
  9808. sprintf(ftppath,"%s", path1);
  9809. //DEBUG_INFO("protocol =%s\n",protocol);
  9810. //DEBUG_INFO("user =%s\n",user);
  9811. //DEBUG_INFO("password =%s\n",password);
  9812. //DEBUG_INFO("host1 =%s\n",host1);
  9813. //DEBUG_INFO("port =%d\n",port);
  9814. //DEBUG_INFO("path1 =%s\n",path1);
  9815. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9816. //ftpFile(host, user, password, port, ftppath, fname);
  9817. //download firmware pthred
  9818. if(port == 0)
  9819. {
  9820. port = 21;
  9821. }
  9822. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9823. do{
  9824. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9825. sleep(retryIntervalInt);
  9826. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9827. if(!isSuccess)
  9828. {
  9829. //BulldogUtil.sleepMs(interval*1000);
  9830. DEBUG_INFO("Update firmware request and download file fail.\n");
  9831. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9832. }
  9833. else
  9834. {
  9835. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9836. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9837. //isUpdateRequest = TRUE;
  9838. }
  9839. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9840. }
  9841. else
  9842. {
  9843. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9844. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9845. }
  9846. pthread_exit(NULL);
  9847. }
  9848. //==========================================
  9849. // Handle server response routine
  9850. //==========================================
  9851. void handleAuthorizeResponse(char *payload, int gun_index)
  9852. {
  9853. mtrace();
  9854. char expiryDatestr[30]={0};
  9855. char parentIdTagstr[20]={0};
  9856. char statusstr[20]={0};
  9857. char expiryDatestrtemp[30]={0};
  9858. char parentIdTagstrtemp[20]={0};
  9859. char IdTagstrtemp[20]={0};
  9860. char statusstrtemp[20]={0};
  9861. int expiryDateISNULL=FALSE;
  9862. int parentIdTagISNULL=FALSE;
  9863. char sstr[160]={0},sstrtemp[160]={0};
  9864. char* filename = AuthorizationCache_JSON;
  9865. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9866. int c = 0;
  9867. char *loc;
  9868. int resultRename=0;
  9869. int responseIdTagInfoAsZero= 0;
  9870. char rmFileCmd[50]={0};
  9871. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9872. strcpy(sstrtemp, stringtrimspace(payload));
  9873. //***********expiryDate*************/
  9874. loc = strstr(sstrtemp, "expiryDate");
  9875. memset(sstr ,0, sizeof(sstr) );
  9876. c = 0;
  9877. if(loc == NULL)
  9878. {
  9879. expiryDateISNULL = TRUE;
  9880. }
  9881. else
  9882. {
  9883. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9884. {
  9885. sstr[c] = loc[3+strlen("expiryDate")+c];
  9886. c++;
  9887. }
  9888. sstr[c] = '\0';
  9889. strcpy(expiryDatestr, sstr);
  9890. }
  9891. //***********parentIdTag*************/
  9892. loc = strstr(sstrtemp, "parentIdTag");
  9893. memset(sstr ,0, sizeof(sstr) );
  9894. c = 0;
  9895. if(loc == NULL)
  9896. {
  9897. parentIdTagISNULL = TRUE;
  9898. }
  9899. else
  9900. {
  9901. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9902. {
  9903. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9904. c++;
  9905. }
  9906. sstr[c] = '\0';
  9907. strcpy(parentIdTagstr, sstr);
  9908. }
  9909. //***********status*************/
  9910. loc = strstr(sstrtemp, "status");
  9911. memset(sstr ,0, sizeof(sstr) );
  9912. c = 0;
  9913. while (loc[3+strlen("status")+c] != '\"')
  9914. {
  9915. sstr[c] = loc[3+strlen("status")+c];
  9916. c++;
  9917. }
  9918. sstr[c] = '\0';
  9919. strcpy(statusstr, sstr);
  9920. if(expiryDateISNULL == FALSE)
  9921. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9922. if(parentIdTagISNULL == FALSE)
  9923. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9924. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9925. //Update idTag information to authorization cache if supproted
  9926. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9927. {
  9928. if((access(filename,F_OK))!=-1)
  9929. {
  9930. printf("AuthorizationCache exist.\n");
  9931. }
  9932. else
  9933. {
  9934. printf("AuthorizationCache not exist\n");
  9935. FILE *log = fopen(filename, "w+");
  9936. if(log == NULL)
  9937. {
  9938. printf("log is NULL\n");
  9939. goto out;
  9940. }
  9941. else
  9942. {
  9943. fclose(log);
  9944. }
  9945. }
  9946. FILE *infile;
  9947. FILE *outfile;
  9948. // open file for writing
  9949. infile = fopen (filename, "r");
  9950. outfile = fopen (tempfile, "w");
  9951. //*检测到文件结束标识返回1,否则返回0。*/
  9952. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9953. int c;
  9954. c = fgetc(infile);
  9955. //DEBUG_INFO("c:%d\n",c);
  9956. rewind(infile);
  9957. if(c == EOF)
  9958. {
  9959. DEBUG_INFO("Orignal File is NULL\n");
  9960. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9961. {
  9962. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9963. }
  9964. else
  9965. {
  9966. strcpy(expiryDatestrtemp, "");
  9967. }
  9968. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9969. {
  9970. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9971. }
  9972. else
  9973. {
  9974. //write Authorize IdTag
  9975. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9976. }
  9977. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9978. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9979. fclose(infile);
  9980. fclose(outfile);
  9981. sprintf(rmFileCmd,"rm -f %s",filename);
  9982. system(rmFileCmd);
  9983. resultRename = rename(tempfile, filename);
  9984. if(resultRename == 0)
  9985. {
  9986. printf("File renamed successfully");
  9987. }
  9988. else
  9989. {
  9990. printf("Error: unable to rename the file");
  9991. }
  9992. }
  9993. else
  9994. {
  9995. char buf[160]={0};
  9996. while (fgets(buf, sizeof(buf), infile) != NULL)
  9997. {
  9998. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9999. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  10000. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  10001. memset(statusstr, 0, sizeof(statusstrtemp));
  10002. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  10003. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  10004. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  10005. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  10006. //------------------IdTag-----------------------
  10007. loc = strstr(buf, "idTag");
  10008. memset(sstr ,0, sizeof(sstr) );
  10009. c = 0;
  10010. while (loc[3+strlen("idTag")+c] != '\"')
  10011. {
  10012. sstr[c] = loc[3+strlen("idTag")+c];
  10013. c++;
  10014. }
  10015. sstr[c] = '\0';
  10016. strcpy(IdTagstrtemp,sstr);
  10017. //*********************expiryDate***************/
  10018. loc = strstr(buf, "expiryDate");
  10019. memset(sstr ,0, sizeof(sstr) );
  10020. c = 0;
  10021. while (loc[3+strlen("expiryDate")+c] != '\"')
  10022. {
  10023. sstr[c] = loc[3+strlen("expiryDate")+c];
  10024. c++;
  10025. }
  10026. sstr[c] = '\0';
  10027. strcpy(expiryDatestr,sstr);
  10028. //*********************parentIdTag***************/
  10029. loc = strstr(buf, "parentIdTag");
  10030. memset(sstr ,0, sizeof(sstr) );
  10031. c = 0;
  10032. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10033. {
  10034. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10035. c++;
  10036. }
  10037. sstr[c] = '\0';
  10038. strcpy(parentIdTagstr,sstr);
  10039. //*********************status***************/
  10040. loc = strstr(buf, "status");
  10041. memset(sstr ,0, sizeof(sstr) );
  10042. c = 0;
  10043. while (loc[3+strlen("status")+c] != '\"')
  10044. {
  10045. sstr[c] = loc[3+strlen("status")+c];
  10046. c++;
  10047. }
  10048. sstr[c] = '\0';
  10049. strcpy(statusstr,sstr);
  10050. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  10051. {
  10052. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  10053. responseIdTagInfoAsZero = 1;
  10054. }
  10055. else
  10056. {
  10057. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  10058. }
  10059. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  10060. {
  10061. //modify item
  10062. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  10063. {
  10064. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  10065. }
  10066. else
  10067. {
  10068. strcpy(expiryDatestrtemp, "");
  10069. }
  10070. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  10071. {
  10072. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  10073. }
  10074. else
  10075. {
  10076. strcpy(parentIdTagstrtemp, parentIdTagstr);
  10077. }
  10078. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  10079. }
  10080. else
  10081. {
  10082. //wrie original item
  10083. strcpy(expiryDatestrtemp, expiryDatestr);
  10084. strcpy(parentIdTagstrtemp, parentIdTagstr);
  10085. strcpy(statusstrtemp, statusstr);
  10086. }
  10087. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  10088. }
  10089. fclose(infile);
  10090. fclose(outfile);
  10091. sprintf(rmFileCmd,"rm -f %s",filename);
  10092. system(rmFileCmd);
  10093. resultRename = rename(tempfile, filename);
  10094. if(resultRename == 0)
  10095. {
  10096. DEBUG_INFO("File renamed successfully");
  10097. }
  10098. else
  10099. {
  10100. DEBUG_INFO("Error: unable to rename the file");
  10101. }
  10102. }
  10103. }
  10104. out:
  10105. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10106. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10107. authorizeRetryTimes = 0;
  10108. }
  10109. char * strtrimc( char * s )
  10110. {
  10111. char * p1 = s;
  10112. char * p2 = s;
  10113. while(*p1 != '\0')
  10114. {
  10115. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  10116. {
  10117. if(*p1 != ',')
  10118. {
  10119. p1 ++;
  10120. }
  10121. else
  10122. {
  10123. break;
  10124. }
  10125. }
  10126. if(*p1 != ',')
  10127. {
  10128. * p2 ++ = *p1 ++;
  10129. //printf("p2=%s\n",p2);
  10130. }
  10131. else
  10132. {
  10133. break;
  10134. }
  10135. }
  10136. *p2 = '\0';
  10137. return (s);
  10138. }
  10139. void handleBootNotificationResponse(char *payload, int gun_index)
  10140. {
  10141. mtrace();
  10142. char sstr[140]={0}, sstrtemp[140]={0};//sstr[200]={ 0 };
  10143. char statusStr[12]={0};
  10144. char currentTimeStr[30]={0};
  10145. char *loc;
  10146. int intervalInt = 0;
  10147. int c = 0;
  10148. //double diff_t;
  10149. struct tm tp;
  10150. char buf[28]={0};
  10151. char timebuf[50]={0};
  10152. DEBUG_INFO("handleBootNotificationResponse ...\n");
  10153. //Filter string space
  10154. strcpy(sstrtemp, stringtrimspace(payload));
  10155. //*** interval ****/
  10156. c = 0;
  10157. loc = strstr(sstrtemp, "interval");
  10158. //printf("loc=%s\n",loc);
  10159. memset(sstr ,0, sizeof(sstr) );
  10160. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  10161. {
  10162. sstr[c] = loc[strlen("interval")+2+c];
  10163. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10164. c++;
  10165. }
  10166. sstr[c] = '\0';
  10167. //DEBUG_INFO("id=%d\n",atoi(sstr));
  10168. intervalInt = atoi(sstr);
  10169. //***status ****/
  10170. loc = strstr(sstrtemp, "status");
  10171. memset(sstr ,0, sizeof(sstr) );
  10172. c = 0;
  10173. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  10174. {
  10175. sstr[c] = loc[3+strlen("status")+c];
  10176. c++;
  10177. }
  10178. sstr[c] = '\0';
  10179. strcpy(statusStr, sstr);
  10180. //***currentTime ****/
  10181. loc = strstr(sstrtemp, "currentTime");
  10182. //printf("loc=%s\n",loc);
  10183. memset(sstr ,0, sizeof(sstr) );
  10184. c = 0;
  10185. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  10186. {
  10187. sstr[c] = loc[3+strlen("currentTime")+c];
  10188. c++;
  10189. }
  10190. sstr[c] = '\0';
  10191. strcpy(currentTimeStr, sstr);
  10192. //BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10193. //HeartBeatWaitTime = BootNotificationInterval;
  10194. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10195. BootNotificationInterval = intervalInt;
  10196. HeartBeatWaitTime = intervalInt;
  10197. clientTime.Heartbeat=time((time_t*)NULL);
  10198. //write back to ShmOCPP16Data->BootNotification
  10199. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10200. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10201. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10202. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  10203. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  10204. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  10205. {
  10206. server_sign = TRUE;
  10207. server_pending =FALSE;
  10208. }
  10209. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10210. {
  10211. server_pending = TRUE;
  10212. }
  10213. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10214. tp.tm_isdst = -1;
  10215. //time_t utc = mktime(&tp);
  10216. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10217. memset(timebuf, 0, sizeof timebuf);
  10218. sprintf(timebuf,"date -s '%s'",buf);
  10219. //DEBUG_INFO("timebuf=%s\n",timebuf);
  10220. system(timebuf);
  10221. //==============================================
  10222. // RTC sync
  10223. //==============================================
  10224. system("/sbin/hwclock -w --systohc");
  10225. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10226. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10227. }
  10228. void handleDataTransferResponse(char *payload, int gun_index)
  10229. {
  10230. char sstr[160]={0};//sstr[200]={ 0 };
  10231. int c = 0;
  10232. char *loc;
  10233. DEBUG_INFO("handleDataTransferResponse ...\n");
  10234. loc = strstr(payload, "status");
  10235. printf("loc=%s\n",loc);
  10236. c = 0;
  10237. while (loc[3+strlen("status")+c] != '\"')
  10238. {
  10239. sstr[c] = loc[3+strlen("status")+c];
  10240. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10241. c++;
  10242. }
  10243. sstr[c] = '\0';
  10244. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10245. }
  10246. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10247. {
  10248. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10249. //struct json_object *obj;
  10250. // obj = json_tokener_parse(payload);
  10251. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10252. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10253. //No fields are defined.
  10254. }
  10255. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10256. {
  10257. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10258. //struct json_object *obj;
  10259. // obj = json_tokener_parse(payload);
  10260. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10261. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10262. //No fields are defined.
  10263. }
  10264. void handleHeartbeatResponse(char *payload, int gun_index)
  10265. {
  10266. mtrace();
  10267. //double diff_t;
  10268. struct tm tp;
  10269. char buf[28]={0};
  10270. char timebuf[50]={0},sstrtemp[100]={0};
  10271. char sstr[30]={ 0 };
  10272. int c = 0;
  10273. char *loc;
  10274. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  10275. if(FirstHeartBeat == 0)
  10276. {
  10277. FirstHeartBeat = 1;
  10278. DEBUG_INFO("FirstHeartBeat \n");
  10279. }
  10280. HeartBeatWithNOResponse = 0;
  10281. strcpy(sstrtemp, stringtrimspace(payload));
  10282. c = 0;
  10283. loc = strstr(sstrtemp, "currentTime");
  10284. memset(sstr ,0, sizeof(sstr) );
  10285. while (loc[3+strlen("currentTime")+c] != '\"')
  10286. {
  10287. sstr[c] = loc[3+strlen("currentTime")+c];
  10288. c++;
  10289. }
  10290. sstr[c] = '\0';
  10291. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  10292. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10293. tp.tm_isdst = -1;
  10294. //time_t utc = mktime(&tp);
  10295. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10296. memset(timebuf, 0, sizeof timebuf);
  10297. sprintf(timebuf,"date -s '%s'",buf);
  10298. system(timebuf);
  10299. //==============================================
  10300. // RTC sync
  10301. //==============================================
  10302. system("/sbin/hwclock -w --systohc");
  10303. //===============================================
  10304. //Print Out HeartBeat log
  10305. //===============================================
  10306. {
  10307. double diff_t;
  10308. struct tm tp,tp1;
  10309. // BootNotification Receive Time
  10310. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10311. tp.tm_isdst = -1;
  10312. time_t BootNotificationReceiveTime = mktime(&tp);
  10313. //HeartBeat Receive Time
  10314. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10315. tp1.tm_isdst = -1;
  10316. time_t HeartBeatReceiveTime = mktime(&tp1);
  10317. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10318. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10319. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10320. {
  10321. HeartBeatCountPerHour = (int)diff_t / 3600;
  10322. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10323. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10324. }
  10325. }
  10326. }
  10327. void handleMeterValuesResponse(char *payload, int gun_index)
  10328. {
  10329. mtrace();
  10330. //struct json_object *obj;
  10331. DEBUG_INFO("handleMeterValuesResponse ...\n");
  10332. //No fields are defined.
  10333. }
  10334. void handleStartTransactionResponse(char *payload, int gun_index)
  10335. {
  10336. mtrace();
  10337. char sstr[28]={ 0 },sstrtemp[200]={ 0 };
  10338. int c = 0;
  10339. int copyTo = 0;
  10340. char *loc;
  10341. //int transactionIdInt = 0;
  10342. FILE *outfile;
  10343. char data[100]={0};
  10344. //char *delim = ":";
  10345. //char requestKey[2][50]={0};
  10346. //char * pch;
  10347. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  10348. DEBUG_INFO("handleStartTransactionResponse\n");
  10349. //****************expiryDate********************/
  10350. strcpy(sstrtemp, stringtrimspace(payload));
  10351. loc = strstr(sstrtemp, "expiryDate");
  10352. if(loc == NULL)
  10353. {
  10354. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  10355. }
  10356. else
  10357. {
  10358. #if 0
  10359. c = 0;
  10360. memset(sstr ,0, sizeof(sstr) );
  10361. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10362. memset(requestKey ,0, sizeof(requestKey) );
  10363. strcpy(sstrtemp,loc+strlen("expiryDate")+2); // 2: ":
  10364. //printf("sstrtemp=%s\n",sstrtemp);
  10365. //parsing strings to words
  10366. pch = strtok(sstrtemp,",");
  10367. while (pch != NULL)
  10368. {
  10369. strcpy(requestKey[c], pch);
  10370. pch = strtok (NULL, ",");
  10371. c = c + 1;
  10372. }
  10373. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10374. //strcpy(currentTimeStr, strtrimc(requestKey[0]));
  10375. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", stringtrim(requestKey[0]));
  10376. #endif
  10377. #if 1
  10378. c = 0;
  10379. memset(sstr ,0, sizeof(sstr) );
  10380. while (loc[3+strlen("expiryDate")+c] != '\"')
  10381. {
  10382. sstr[c] = loc[3+strlen("expiryDate")+c];
  10383. c++;
  10384. }
  10385. sstr[c] = '\0';
  10386. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10387. #endif
  10388. }
  10389. //****************parentIdTag********************/
  10390. loc = strstr(sstrtemp, "parentIdTag");
  10391. if(loc == NULL)
  10392. {
  10393. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  10394. }
  10395. else
  10396. {
  10397. #if 0
  10398. c = 0;
  10399. memset(sstr ,0, sizeof(sstr) );
  10400. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10401. memset(requestKey ,0, sizeof(requestKey) );
  10402. strcpy(sstrtemp,loc);
  10403. //printf("sstrtemp=%s\n",sstrtemp);
  10404. //parsing strings to words
  10405. pch = strtok(sstrtemp,delim);
  10406. while (pch != NULL)
  10407. {
  10408. strcpy(requestKey[c], pch);
  10409. pch = strtok (NULL, delim);
  10410. c = c + 1;
  10411. }
  10412. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10413. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", strtrimc(requestKey[1]));
  10414. #endif
  10415. #if 1
  10416. c = 0;
  10417. memset(sstr ,0, sizeof(sstr) );
  10418. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10419. {
  10420. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10421. c++;
  10422. }
  10423. sstr[c] = '\0';
  10424. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10425. #endif
  10426. }
  10427. //****************status********************/
  10428. loc = strstr(sstrtemp, "status");
  10429. if(loc == NULL)
  10430. {
  10431. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  10432. }
  10433. else
  10434. {
  10435. #if 0
  10436. c = 0;
  10437. memset(sstr ,0, sizeof(sstr) );
  10438. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10439. memset(requestKey ,0, sizeof(requestKey) );
  10440. strcpy(sstrtemp,loc);
  10441. //printf("sstrtemp=%s\n",sstrtemp);
  10442. //parsing strings to words
  10443. pch = strtok(sstrtemp,delim);
  10444. while (pch != NULL)
  10445. {
  10446. strcpy(requestKey[c], pch);
  10447. pch = strtok (NULL, delim);
  10448. c = c + 1;
  10449. }
  10450. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10451. //strcpy(statusStr, strtrimc(requestKey[1]));
  10452. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", strtrimc(requestKey[1]));
  10453. #endif
  10454. #if 1
  10455. c = 0;
  10456. memset(sstr ,0, sizeof(sstr) );
  10457. while (loc[3+strlen("status")+c] != '\"')
  10458. {
  10459. sstr[c] = loc[3+strlen("status")+c];
  10460. c++;
  10461. }
  10462. sstr[c] = '\0';
  10463. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10464. #endif
  10465. }
  10466. //****************transactionId********************/
  10467. c=0;
  10468. copyTo = 0;
  10469. loc = strstr(sstrtemp, "transactionId");
  10470. memset(sstr ,0, sizeof(sstr) );
  10471. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  10472. {
  10473. if(loc[strlen("transactionId")+2+c] != ' ')
  10474. {
  10475. sstr[copyTo] = loc[strlen("transactionId")+2+c];
  10476. copyTo = copyTo + 1;
  10477. }
  10478. c++;
  10479. }
  10480. sstr[copyTo] = '\0';
  10481. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  10482. //transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  10483. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10484. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10485. //-----------Start : write to the Queue TransactionId file -----------------//
  10486. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10487. {
  10488. //DEBUG_INFO("QueueTransactionId exist.\n");
  10489. }
  10490. else
  10491. {
  10492. //DEBUG_INFO("QueueTransactionId not exist\n");
  10493. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10494. if(log == NULL)
  10495. {
  10496. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10497. return ;
  10498. }
  10499. else
  10500. {
  10501. fclose(log);
  10502. }
  10503. }
  10504. // open file for writing
  10505. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10506. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10507. {
  10508. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10509. //DEBUG_INFO("data=%s\n",data);
  10510. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10511. fputs(data, outfile);
  10512. //fputs("\n", outfile);
  10513. fclose (outfile);
  10514. }
  10515. //-------------End: write to the Queue TransactionId file------------------------------------------//
  10516. //TransactionId[gun_index] = transactionIdInt;
  10517. //DEBUG_INFO("gun_index: %d\n", gun_index);
  10518. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  10519. #ifdef SystemLogMessage
  10520. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10521. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10522. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10523. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10524. #endif
  10525. }
  10526. void handleStatusNotificationResponse(char *payload, int gun_index)
  10527. {
  10528. mtrace();
  10529. printf("handleStatusNotificationResponse\n");
  10530. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10531. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10532. }
  10533. void handleStopTransactionnResponse(char *payload, int gun_index)
  10534. {
  10535. mtrace();
  10536. char sstr[30]={ 0 },sstrtemp[140]={ 0 };
  10537. int c = 0;
  10538. char *loc;
  10539. //char *delim = ":";
  10540. //char requestKey[3][50]={0};
  10541. //char * pch;
  10542. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  10543. strcpy(sstrtemp, stringtrimspace(payload));
  10544. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10545. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10546. loc = strstr(sstrtemp, "idTagInfo");
  10547. //***********************idTagInfo************************/
  10548. if(loc != NULL)
  10549. {
  10550. //***********************expiryDate************************/
  10551. loc = strstr(sstrtemp, "expiryDate");
  10552. if(loc != NULL)
  10553. {
  10554. memset(sstr ,0, sizeof(sstr) );
  10555. c = 0;
  10556. while (loc[3+strlen("expiryDate")+c] != '\"')
  10557. {
  10558. sstr[c] = loc[3+strlen("expiryDate")+c];
  10559. c++;
  10560. }
  10561. sstr[c] = '\0';
  10562. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10563. }
  10564. //***********************parentIdTag************************/
  10565. loc = strstr(sstrtemp, "parentIdTag");
  10566. if(loc != NULL)
  10567. {
  10568. memset(sstr ,0, sizeof(sstr) );
  10569. c = 0;
  10570. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10571. {
  10572. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10573. c++;
  10574. }
  10575. sstr[c] = '\0';
  10576. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10577. }
  10578. //***********************status************************/
  10579. loc = strstr(sstrtemp, "status");
  10580. memset(sstr ,0, sizeof(sstr) );
  10581. c = 0;
  10582. while (loc[3+strlen("status")+c] != '\"')
  10583. {
  10584. sstr[c] = loc[3+strlen("status")+c];
  10585. c++;
  10586. }
  10587. sstr[c] = '\0';
  10588. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10589. }
  10590. #ifdef SystemLogMessage
  10591. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10592. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10593. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10594. #endif
  10595. }
  10596. //==========================================
  10597. // Handle Error routine
  10598. //==========================================
  10599. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10600. {
  10601. mtrace();
  10602. #ifdef SystemLogMessage
  10603. DEBUG_INFO("errorCode: %s\n", errorCode);
  10604. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10605. DEBUG_INFO("errorDetails: %s\n", payload);
  10606. #endif
  10607. }
  10608. //===============================================
  10609. // Common routine
  10610. //===============================================
  10611. int initialConfigurationTable(void)
  10612. {
  10613. //clock_t start_t, end_t, total_t;
  10614. FILE *fp;
  10615. FILE *outfile;
  10616. char str[200]={0};
  10617. char sstr[100]={0};
  10618. int c = 0;
  10619. char *loc;
  10620. printf("initialConfigurationTable \n");
  10621. //start_t = clock();
  10622. //printf("Starting of the program, start_t = %ld\n", start_t);
  10623. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10624. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10625. {
  10626. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10627. if(outfile == NULL) {
  10628. DEBUG_INFO("Error opening file");
  10629. return FALSE;
  10630. }
  10631. /*Core Profile*/
  10632. //AllowOfflineTxForUnknownId
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10634. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10638. //AuthorizationCacheEnabled
  10639. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10643. //AuthorizeRemoteTxRequests
  10644. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10648. //BlinkRepeat
  10649. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10653. //ClockAlignedDataInterval
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10658. //ConnectionTimeOut
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10663. //GetConfigurationMaxKeys
  10664. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10668. // HeartbeatInterval
  10669. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10673. // LightIntensity
  10674. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10678. // LocalAuthorizeOffline
  10679. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10683. // LocalPreAuthorize
  10684. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10688. // MaxEnergyOnInvalidId
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10692. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10694. // MeterValuesAlignedData
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10699. // MeterValuesAlignedDataMaxLength
  10700. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10704. // MeterValuesSampledData
  10705. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10709. // MeterValuesSampledDataMaxLength
  10710. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  10714. // MeterValueSampleInterval
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10719. // MinimumStatusDuration
  10720. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10723. server_cycle_Status = 120; //StatusNotification cycle
  10724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10725. // NumberOfConnectors
  10726. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10728. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10729. {
  10730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10731. }
  10732. else
  10733. {
  10734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10735. }
  10736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10737. // ResetRetries
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10742. // ConnectorPhaseRotation
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10747. // ConnectorPhaseRotationMaxLength
  10748. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10752. // StopTransactionOnEVSideDisconnect
  10753. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10757. // StopTransactionOnInvalidId
  10758. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10762. // StopTxnAlignedData
  10763. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10767. // StopTxnAlignedDataMaxLength
  10768. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10772. // StopTxnSampledData
  10773. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10777. // StopTxnSampledDataMaxLength
  10778. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10780. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10781. {
  10782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10783. }
  10784. else
  10785. {
  10786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10787. }
  10788. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10790. // SupportedFeatureProfiles
  10791. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10795. // SupportedFeatureProfilesMaxLength
  10796. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10800. // TransactionMessageAttempts
  10801. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10804. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10806. // TransactionMessageRetryInterval
  10807. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10810. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10812. // UnlockConnectorOnEVSideDisconnect
  10813. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10817. // WebSocketPingInterval
  10818. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10822. //* Local Auth List Management Profile*/
  10823. #if 0
  10824. //For OCTT Test Case
  10825. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10828. #endif
  10829. #if 1
  10830. //LocalAuthListEnabled
  10831. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10835. #endif
  10836. //LocalAuthListMaxLength
  10837. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10841. //SendLocalListMaxLength
  10842. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10846. //ReserveConnectorZeroSupported
  10847. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10851. //* Smart Charging Profile */
  10852. //ChargeProfileMaxStackLevel
  10853. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10857. // ChargingScheduleAllowedChargingRateUnit
  10858. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10862. // ChargingScheduleMaxPeriods
  10863. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10867. // ConnectorSwitch3to1PhaseSupported
  10868. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10872. // MaxChargingProfilesInstalled
  10873. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10877. fclose(outfile);
  10878. }
  10879. else
  10880. {
  10881. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10882. char keystr[60]={0};
  10883. char readonlystr[10]={0};
  10884. char valuestr[100]={0};
  10885. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10886. if(fp == NULL) {
  10887. DEBUG_INFO("Error opening file");
  10888. return FALSE;
  10889. }
  10890. while( fgets (str, sizeof(str), fp)!=NULL )
  10891. {
  10892. //DEBUG_INFO("Get Configuration \n");
  10893. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10894. //*************************key*********************************/
  10895. loc = strstr(str, "key");
  10896. c = 0;
  10897. memset(sstr ,0, sizeof(sstr) );
  10898. while (loc[strlen("key")+3+c] != '\"')
  10899. {
  10900. sstr[c] = loc[strlen("key")+3+c];
  10901. c++;
  10902. }
  10903. sstr[c] = '\0';
  10904. strcpy(keystr,sstr);
  10905. //*************************readonly*********************************/
  10906. loc = strstr(str, "readonly");
  10907. c = 0;
  10908. memset(sstr ,0, sizeof(sstr) );
  10909. while (loc[strlen("readonly")+2+c] != ',')
  10910. {
  10911. sstr[c] = loc[strlen("readonly")+2+c];
  10912. c++;
  10913. }
  10914. sstr[c] = '\0';
  10915. strcpy(readonlystr,sstr);
  10916. //*************************value*********************************/
  10917. loc = strstr(str, "value");
  10918. c = 0;
  10919. memset(sstr ,0, sizeof(sstr) );
  10920. while (loc[strlen("value")+3+c] != '\"')
  10921. {
  10922. sstr[c] = loc[strlen("value")+3+c];
  10923. c++;
  10924. }
  10925. sstr[c] = '\0';
  10926. strcpy(valuestr,sstr);
  10927. // DEBUG_INFO("keystr=%s\n",keystr);
  10928. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10929. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10930. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10931. {
  10932. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10933. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10935. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10936. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10937. }
  10938. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10939. {
  10940. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10941. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10943. }
  10944. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10945. {
  10946. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10948. }
  10949. if(strcmp(keystr, "BlinkRepeat") == 0)
  10950. {
  10951. //Charger.BlinkRepeat = Integer.parseInt(value);
  10952. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10954. }
  10955. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10956. {
  10957. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10959. }
  10960. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10961. {
  10962. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10964. }
  10965. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10966. {
  10967. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10969. }
  10970. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10971. {
  10972. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10974. HeartBeatWaitTime = atoi(valuestr);
  10975. }
  10976. if(strcmp(keystr, "LightIntensity") == 0)
  10977. {
  10978. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10980. }
  10981. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10982. {
  10983. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10985. }
  10986. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10987. {
  10988. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10990. }
  10991. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10992. {
  10993. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10995. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10996. }
  10997. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10998. {
  10999. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11001. }
  11002. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11003. {
  11004. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11006. }
  11007. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11008. {
  11009. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11011. }
  11012. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11013. {
  11014. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11016. }
  11017. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11018. {
  11019. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11021. }
  11022. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11023. {
  11024. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11026. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11027. }
  11028. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11029. {
  11030. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11032. }
  11033. if(strcmp(keystr, "ResetRetries") == 0)
  11034. {
  11035. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11037. }
  11038. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11039. {
  11040. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11042. }
  11043. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11044. {
  11045. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11047. }
  11048. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11049. {
  11050. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11052. }
  11053. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11054. {
  11055. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11057. }
  11058. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11059. {
  11060. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11062. }
  11063. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11064. {
  11065. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11067. }
  11068. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11069. {
  11070. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11072. }
  11073. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11074. {
  11075. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11077. }
  11078. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11079. {
  11080. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11082. }
  11083. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11084. {
  11085. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11087. }
  11088. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11089. {
  11090. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11092. TransactionMessageAttemptsValue = atoi(valuestr);
  11093. }
  11094. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11095. {
  11096. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11098. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11099. }
  11100. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11101. {
  11102. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11104. }
  11105. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11106. {
  11107. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11109. }
  11110. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11111. {
  11112. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11114. }
  11115. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11116. {
  11117. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11119. }
  11120. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11121. {
  11122. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11124. }
  11125. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11126. {
  11127. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11129. }
  11130. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11131. {
  11132. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11134. }
  11135. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11136. {
  11137. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11139. }
  11140. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11141. {
  11142. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11144. }
  11145. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11146. {
  11147. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11149. }
  11150. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11151. {
  11152. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11154. }
  11155. }
  11156. fclose(fp);
  11157. }
  11158. //end_t = clock();
  11159. //printf("End of the big loop, end_t = %ld\n", end_t);
  11160. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  11161. //printf("Total time taken by CPU: %f\n", total_t );
  11162. return 0;
  11163. }
  11164. void StoreConfigurationTable(void)
  11165. {
  11166. FILE *outfile;
  11167. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11168. if(outfile == NULL)
  11169. {
  11170. DEBUG_INFO("Error opening file");
  11171. return ;
  11172. }
  11173. /*Core Profile*/
  11174. //AllowOfflineTxForUnknownId
  11175. /*
  11176. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11177. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11180. */
  11181. //DEBUG_INFO("data=%s\n",data);
  11182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11183. //AuthorizationCacheEnabled
  11184. /*
  11185. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11188. */
  11189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11190. //AuthorizeRemoteTxRequests
  11191. /*
  11192. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11195. */
  11196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11197. //BlinkRepeat
  11198. /*
  11199. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11202. */
  11203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11204. //ClockAlignedDataInterval
  11205. /*
  11206. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11209. */
  11210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11211. //ConnectionTimeOut
  11212. /*
  11213. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11216. */
  11217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11218. //GetConfigurationMaxKeys
  11219. /*
  11220. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11223. */
  11224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11225. // HeartbeatInterval
  11226. /*
  11227. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11230. */
  11231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11232. // LightIntensity
  11233. /*
  11234. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11237. */
  11238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11239. // LocalAuthorizeOffline
  11240. /*
  11241. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11244. */
  11245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11246. // LocalPreAuthorize
  11247. /*
  11248. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11251. */
  11252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11253. // MaxEnergyOnInvalidId
  11254. /*
  11255. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11258. */
  11259. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11261. // MeterValuesAlignedData
  11262. /*
  11263. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11266. */
  11267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11268. // MeterValuesAlignedDataMaxLength
  11269. /*
  11270. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11273. */
  11274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11275. // MeterValuesSampledData
  11276. /*
  11277. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11280. */
  11281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11282. // MeterValuesSampledDataMaxLength
  11283. /*
  11284. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11287. */
  11288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11289. // MeterValueSampleInterval
  11290. /*
  11291. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11294. */
  11295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11296. // MinimumStatusDuration
  11297. /*
  11298. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11301. */
  11302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11303. // NumberOfConnectors
  11304. /*
  11305. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11307. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11308. {
  11309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11310. }
  11311. else
  11312. {
  11313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11314. }
  11315. */
  11316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11317. // ResetRetries
  11318. /*
  11319. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11322. */
  11323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11324. // ConnectorPhaseRotation
  11325. /*
  11326. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11329. */
  11330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11331. // ConnectorPhaseRotationMaxLength
  11332. /*
  11333. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11336. */
  11337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11338. // StopTransactionOnEVSideDisconnect
  11339. /*
  11340. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11343. */
  11344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11345. // StopTransactionOnInvalidId
  11346. /*
  11347. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11350. */
  11351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11352. // StopTxnAlignedData
  11353. /*
  11354. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11357. */
  11358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11359. // StopTxnAlignedDataMaxLength
  11360. /*
  11361. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11364. */
  11365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11366. // StopTxnSampledData
  11367. /*
  11368. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11371. */
  11372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11373. // StopTxnSampledDataMaxLength
  11374. /*
  11375. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11378. */
  11379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11380. // SupportedFeatureProfiles
  11381. /*
  11382. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11385. */
  11386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11387. // SupportedFeatureProfilesMaxLength
  11388. /*
  11389. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11392. */
  11393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11394. // TransactionMessageAttempts
  11395. /*
  11396. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11399. */
  11400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11401. // TransactionMessageRetryInterval
  11402. /*
  11403. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11406. */
  11407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11408. // UnlockConnectorOnEVSideDisconnect
  11409. /*
  11410. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11413. */
  11414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11415. // WebSocketPingInterval
  11416. /*
  11417. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11420. */
  11421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11422. //* Local Auth List Management Profile*/
  11423. //LocalAuthListEnabled
  11424. /*
  11425. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11428. */
  11429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11430. //LocalAuthListMaxLength
  11431. /*
  11432. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11435. */
  11436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11437. //SendLocalListMaxLength
  11438. /*
  11439. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11442. */
  11443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11444. //ReserveConnectorZeroSupported
  11445. /*
  11446. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11449. */
  11450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11451. //* Smart Charging Profile */
  11452. //ChargeProfileMaxStackLevel
  11453. /*
  11454. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11457. */
  11458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11459. // ChargingScheduleAllowedChargingRateUnit
  11460. /*
  11461. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11464. */
  11465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11466. // ChargingScheduleMaxPeriods
  11467. /*
  11468. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11471. */
  11472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11473. // ConnectorSwitch3to1PhaseSupported
  11474. /*
  11475. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11478. */
  11479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11480. // MaxChargingProfilesInstalled
  11481. /*
  11482. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11485. */
  11486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11487. fclose(outfile);
  11488. }
  11489. void getKeyValue(char *keyReq)
  11490. {
  11491. int isEmpty = FALSE;
  11492. int isKnowKey = FALSE;
  11493. //int unKnowIndex = 0;
  11494. DEBUG_INFO("getKeyValue \n");
  11495. DEBUG_INFO("keyReq=%s \n",keyReq);
  11496. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11497. isEmpty = TRUE;
  11498. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11505. }
  11506. else
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11509. }
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11511. isKnowKey = TRUE;
  11512. }
  11513. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11520. }
  11521. else
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11524. }
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11526. isKnowKey = TRUE;
  11527. }
  11528. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11535. }
  11536. else
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11539. }
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11541. isKnowKey = TRUE;
  11542. }
  11543. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11550. }
  11551. else
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11554. }
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11556. isKnowKey = TRUE;
  11557. }
  11558. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11565. }
  11566. else
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11569. }
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11571. isKnowKey = TRUE;
  11572. }
  11573. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11580. }
  11581. else
  11582. {
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11584. }
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11586. isKnowKey = TRUE;
  11587. }
  11588. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11595. }
  11596. else
  11597. {
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11599. }
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11601. isKnowKey = TRUE;
  11602. }
  11603. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11610. }
  11611. else
  11612. {
  11613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11614. }
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11616. isKnowKey = TRUE;
  11617. }
  11618. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11619. {
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11625. }
  11626. else
  11627. {
  11628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11629. }
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11631. isKnowKey = TRUE;
  11632. }
  11633. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11634. {
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11640. }
  11641. else
  11642. {
  11643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11644. }
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11646. isKnowKey = TRUE;
  11647. }
  11648. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11649. {
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11655. }
  11656. else
  11657. {
  11658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11659. }
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11661. isKnowKey = TRUE;
  11662. }
  11663. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11670. }
  11671. else
  11672. {
  11673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11674. }
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11676. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11677. isKnowKey = TRUE;
  11678. }
  11679. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11680. {
  11681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11684. {
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11686. }
  11687. else
  11688. {
  11689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11690. }
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11692. isKnowKey = TRUE;
  11693. }
  11694. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11695. {
  11696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11699. {
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11701. }
  11702. else
  11703. {
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11705. }
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11707. isKnowKey = TRUE;
  11708. }
  11709. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11710. {
  11711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11714. {
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11716. }
  11717. else
  11718. {
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11720. }
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11722. isKnowKey = TRUE;
  11723. }
  11724. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11725. {
  11726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11729. {
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11731. }
  11732. else
  11733. {
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11735. }
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11737. isKnowKey = TRUE;
  11738. }
  11739. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11740. {
  11741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11744. {
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11746. }
  11747. else
  11748. {
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11750. }
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11752. isKnowKey = TRUE;
  11753. }
  11754. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11755. {
  11756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11759. {
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11761. }
  11762. else
  11763. {
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11765. }
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11767. isKnowKey = TRUE;
  11768. }
  11769. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11770. {
  11771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11774. {
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11776. }
  11777. else
  11778. {
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11780. }
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11782. isKnowKey = TRUE;
  11783. }
  11784. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11785. {
  11786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11789. {
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11791. }
  11792. else
  11793. {
  11794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11795. }
  11796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11797. isKnowKey = TRUE;
  11798. }
  11799. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11800. {
  11801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11804. {
  11805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11806. }
  11807. else
  11808. {
  11809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11810. }
  11811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11812. isKnowKey = TRUE;
  11813. }
  11814. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11815. {
  11816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11819. {
  11820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11821. }
  11822. else
  11823. {
  11824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11825. }
  11826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11827. isKnowKey = TRUE;
  11828. }
  11829. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11830. {
  11831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11834. {
  11835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11836. }
  11837. else
  11838. {
  11839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11840. }
  11841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11842. isKnowKey = TRUE;
  11843. }
  11844. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11845. {
  11846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11849. {
  11850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11851. }
  11852. else
  11853. {
  11854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11855. }
  11856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11857. isKnowKey = TRUE;
  11858. }
  11859. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11860. {
  11861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11864. {
  11865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11866. }
  11867. else
  11868. {
  11869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11870. }
  11871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11872. isKnowKey = TRUE;
  11873. }
  11874. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11875. {
  11876. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11879. {
  11880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11881. }
  11882. else
  11883. {
  11884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11885. }
  11886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11887. isKnowKey = TRUE;
  11888. }
  11889. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11890. {
  11891. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11894. {
  11895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11896. }
  11897. else
  11898. {
  11899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11900. }
  11901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11902. isKnowKey = TRUE;
  11903. }
  11904. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11905. {
  11906. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11909. {
  11910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11911. }
  11912. else
  11913. {
  11914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11915. }
  11916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11917. isKnowKey = TRUE;
  11918. }
  11919. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11920. {
  11921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11924. {
  11925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11926. }
  11927. else
  11928. {
  11929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11930. }
  11931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11932. isKnowKey = TRUE;
  11933. }
  11934. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11935. {
  11936. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11939. {
  11940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11941. }
  11942. else
  11943. {
  11944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11945. }
  11946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11947. isKnowKey = TRUE;
  11948. }
  11949. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11950. {
  11951. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11953. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11954. {
  11955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11956. }
  11957. else
  11958. {
  11959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11960. }
  11961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11962. isKnowKey = TRUE;
  11963. }
  11964. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11965. {
  11966. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11969. {
  11970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11971. }
  11972. else
  11973. {
  11974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11975. }
  11976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11977. isKnowKey = TRUE;
  11978. }
  11979. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11980. {
  11981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11984. {
  11985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11986. }
  11987. else
  11988. {
  11989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11990. }
  11991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11992. isKnowKey = TRUE;
  11993. }
  11994. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11995. {
  11996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11999. {
  12000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12001. }
  12002. else
  12003. {
  12004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12005. }
  12006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12007. isKnowKey = TRUE;
  12008. }
  12009. #if 0
  12010. //For OCTT Test Case
  12011. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  12012. {
  12013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  12014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  12015. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12016. {
  12017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12018. }
  12019. else
  12020. {
  12021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12022. }
  12023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12024. isKnowKey = TRUE;
  12025. }
  12026. #endif
  12027. #if 1
  12028. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12029. {
  12030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12032. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12033. {
  12034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12035. }
  12036. else
  12037. {
  12038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12039. }
  12040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12041. isKnowKey = TRUE;
  12042. }
  12043. #endif
  12044. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12045. {
  12046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12048. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12049. {
  12050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12051. }
  12052. else
  12053. {
  12054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12055. }
  12056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12057. isKnowKey = TRUE;
  12058. }
  12059. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12060. {
  12061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12063. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12064. {
  12065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12066. }
  12067. else
  12068. {
  12069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12070. }
  12071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12072. isKnowKey = TRUE;
  12073. }
  12074. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12075. {
  12076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12078. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12079. {
  12080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12081. }
  12082. else
  12083. {
  12084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12085. }
  12086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12087. isKnowKey = TRUE;
  12088. }
  12089. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12090. {
  12091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12093. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12094. {
  12095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12096. }
  12097. else
  12098. {
  12099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12100. }
  12101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12102. isKnowKey = TRUE;
  12103. }
  12104. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12105. {
  12106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12108. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12109. {
  12110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12111. }
  12112. else
  12113. {
  12114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12115. }
  12116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12117. isKnowKey = TRUE;
  12118. }
  12119. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12120. {
  12121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12123. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12124. {
  12125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12126. }
  12127. else
  12128. {
  12129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12130. }
  12131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12132. isKnowKey = TRUE;
  12133. }
  12134. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12135. {
  12136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12138. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12139. {
  12140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12141. }
  12142. else
  12143. {
  12144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12145. }
  12146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12147. isKnowKey = TRUE;
  12148. }
  12149. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12150. {
  12151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12153. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12154. {
  12155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12156. }
  12157. else
  12158. {
  12159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12160. }
  12161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12162. isKnowKey = TRUE;
  12163. }
  12164. //=========================================================
  12165. if(!isEmpty && !isKnowKey)
  12166. {
  12167. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12168. strcpy(unknownkey[UnknownKeynum], keyReq);
  12169. UnknownKeynum = UnknownKeynum + 1;
  12170. }
  12171. }
  12172. void processUnkownKey(void)
  12173. {
  12174. DEBUG_INFO("processUnkownKey\n");
  12175. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12176. for(int index=0; index < UnknownKeynum; index++)
  12177. {
  12178. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12179. {
  12180. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12181. }
  12182. }
  12183. }
  12184. int setKeyValue(char *key, char *value)
  12185. {
  12186. int isSuccess = NotSupported;
  12187. int check_ascii=0;
  12188. char str[10]={0};
  12189. #ifdef Debug
  12190. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  12191. #endif
  12192. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12193. {
  12194. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12196. {
  12197. strcpy(str, (const char*)value);
  12198. for(int i = 0; str[i]; i++){
  12199. str[i] = tolower(str[i]);
  12200. }
  12201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12202. isSuccess = ConfigurationStatus_Accepted;
  12203. }
  12204. else
  12205. {
  12206. isSuccess = ConfigurationStatus_Rejected;
  12207. }
  12208. }
  12209. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12210. {
  12211. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12213. {
  12214. strcpy(str, (const char*)value);
  12215. for(int i = 0; str[i]; i++){
  12216. str[i] = tolower(str[i]);
  12217. }
  12218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12219. isSuccess = ConfigurationStatus_Accepted;
  12220. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  12221. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12222. }
  12223. else
  12224. {
  12225. isSuccess = ConfigurationStatus_Rejected;
  12226. }
  12227. }
  12228. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12229. {
  12230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12231. {
  12232. strcpy(str, (const char*)value);
  12233. for(int i = 0; str[i]; i++)
  12234. {
  12235. str[i] = tolower(str[i]);
  12236. }
  12237. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12239. isSuccess = ConfigurationStatus_Accepted;
  12240. }
  12241. else
  12242. {
  12243. isSuccess = ConfigurationStatus_Rejected;
  12244. }
  12245. }
  12246. if(strcmp(key, "BlinkRepeat") == 0)
  12247. {
  12248. //Charger.BlinkRepeat = Integer.parseInt(value);
  12249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12250. {
  12251. check_ascii = value[0];
  12252. if( (check_ascii < 48) || (check_ascii > 57) )
  12253. {
  12254. isSuccess = ConfigurationStatus_Rejected;
  12255. }
  12256. else
  12257. {
  12258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12259. isSuccess = ConfigurationStatus_Accepted;
  12260. }
  12261. }
  12262. else
  12263. {
  12264. isSuccess = ConfigurationStatus_Rejected;
  12265. }
  12266. }
  12267. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12268. {
  12269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12270. {
  12271. check_ascii = value[0];
  12272. if( (check_ascii < 48) || (check_ascii > 57) )
  12273. {
  12274. isSuccess = ConfigurationStatus_Rejected;
  12275. }
  12276. else
  12277. {
  12278. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12280. isSuccess = ConfigurationStatus_Accepted;
  12281. }
  12282. }
  12283. else
  12284. {
  12285. isSuccess = ConfigurationStatus_Rejected;
  12286. }
  12287. }
  12288. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12289. {
  12290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12291. {
  12292. check_ascii = value[0];
  12293. if( (check_ascii < 48) || (check_ascii > 57) )
  12294. {
  12295. isSuccess = ConfigurationStatus_Rejected;
  12296. }
  12297. else
  12298. {
  12299. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12301. isSuccess = ConfigurationStatus_Accepted;
  12302. }
  12303. }
  12304. else
  12305. {
  12306. isSuccess = ConfigurationStatus_Rejected;
  12307. }
  12308. }
  12309. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12310. {
  12311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12312. {
  12313. check_ascii = value[0];
  12314. if( (check_ascii < 48) || (check_ascii > 57) )
  12315. {
  12316. isSuccess = ConfigurationStatus_Rejected;
  12317. }
  12318. else
  12319. {
  12320. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12322. isSuccess = ConfigurationStatus_Accepted;
  12323. }
  12324. }
  12325. else
  12326. {
  12327. isSuccess = ConfigurationStatus_Rejected;
  12328. }
  12329. }
  12330. if(strcmp(key, "HeartbeatInterval") == 0)
  12331. {
  12332. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12333. {
  12334. check_ascii = value[0];
  12335. if( (check_ascii < 48) || (check_ascii > 57) )
  12336. {
  12337. isSuccess = ConfigurationStatus_Rejected;
  12338. }
  12339. else
  12340. {
  12341. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12343. HeartBeatWaitTime = atoi(value);
  12344. isSuccess = ConfigurationStatus_Accepted;
  12345. }
  12346. }
  12347. else
  12348. {
  12349. isSuccess = ConfigurationStatus_Rejected;
  12350. }
  12351. }
  12352. if(strcmp(key, "LightIntensity") == 0)
  12353. {
  12354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12355. {
  12356. check_ascii = value[0];
  12357. if( (check_ascii < 48) || (check_ascii > 57) )
  12358. {
  12359. isSuccess = ConfigurationStatus_Rejected;
  12360. }
  12361. else
  12362. {
  12363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12364. isSuccess = ConfigurationStatus_Accepted;
  12365. }
  12366. }
  12367. else
  12368. {
  12369. isSuccess = ConfigurationStatus_Rejected;
  12370. }
  12371. }
  12372. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12373. {
  12374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12375. {
  12376. strcpy(str, (const char*)value);
  12377. for(int i = 0; str[i]; i++)
  12378. {
  12379. str[i] = tolower(str[i]);
  12380. }
  12381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12382. isSuccess = ConfigurationStatus_Accepted;
  12383. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12384. }
  12385. else
  12386. {
  12387. isSuccess = ConfigurationStatus_Rejected;
  12388. }
  12389. }
  12390. if(strcmp(key, "LocalPreAuthorize") == 0)
  12391. {
  12392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12393. {
  12394. strcpy(str, (const char*)value);
  12395. for(int i = 0; str[i]; i++)
  12396. {
  12397. str[i] = tolower(str[i]);
  12398. }
  12399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12400. isSuccess = ConfigurationStatus_Accepted;
  12401. }
  12402. else
  12403. {
  12404. isSuccess = ConfigurationStatus_Rejected;
  12405. }
  12406. }
  12407. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12408. {
  12409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12410. {
  12411. check_ascii = value[0];
  12412. if( (check_ascii < 48) || (check_ascii > 57) )
  12413. {
  12414. isSuccess = ConfigurationStatus_Rejected;
  12415. }
  12416. else
  12417. {
  12418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12419. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12420. isSuccess = ConfigurationStatus_Accepted;
  12421. }
  12422. }
  12423. else
  12424. {
  12425. isSuccess = ConfigurationStatus_Rejected;
  12426. }
  12427. }
  12428. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12429. {
  12430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12431. {
  12432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12433. isSuccess = ConfigurationStatus_Accepted;
  12434. }
  12435. else
  12436. {
  12437. isSuccess = ConfigurationStatus_Rejected;
  12438. }
  12439. }
  12440. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12441. {
  12442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12443. {
  12444. check_ascii = value[0];
  12445. if( (check_ascii < 48) || (check_ascii > 57) )
  12446. {
  12447. isSuccess = ConfigurationStatus_Rejected;
  12448. }
  12449. else
  12450. {
  12451. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12453. isSuccess = ConfigurationStatus_Accepted;
  12454. }
  12455. }
  12456. else
  12457. {
  12458. isSuccess = ConfigurationStatus_Rejected;
  12459. }
  12460. }
  12461. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12462. {
  12463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12464. {
  12465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12466. isSuccess = ConfigurationStatus_Accepted;
  12467. }
  12468. else
  12469. {
  12470. isSuccess = ConfigurationStatus_Rejected;
  12471. }
  12472. }
  12473. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12474. {
  12475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12476. {
  12477. check_ascii = value[0];
  12478. if( (check_ascii < 48) || (check_ascii > 57) )
  12479. {
  12480. isSuccess = ConfigurationStatus_Rejected;
  12481. }
  12482. else
  12483. {
  12484. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12486. isSuccess = ConfigurationStatus_Accepted;
  12487. }
  12488. }
  12489. else
  12490. {
  12491. isSuccess = ConfigurationStatus_Rejected;
  12492. }
  12493. }
  12494. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12495. {
  12496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12497. {
  12498. check_ascii = value[0];
  12499. if( (check_ascii < 48) || (check_ascii > 57) )
  12500. {
  12501. isSuccess = ConfigurationStatus_Rejected;
  12502. }
  12503. else
  12504. {
  12505. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12507. isSuccess = ConfigurationStatus_Accepted;
  12508. }
  12509. }
  12510. else
  12511. {
  12512. isSuccess = ConfigurationStatus_Rejected;
  12513. }
  12514. }
  12515. if(strcmp(key, "MinimumStatusDuration") == 0)
  12516. {
  12517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12518. {
  12519. check_ascii = value[0];
  12520. if( (check_ascii < 48) || (check_ascii > 57) )
  12521. {
  12522. isSuccess = ConfigurationStatus_Rejected;
  12523. }
  12524. else
  12525. {
  12526. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12527. {
  12528. isSuccess = ConfigurationStatus_Rejected;
  12529. }
  12530. else
  12531. {
  12532. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12534. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12535. isSuccess = ConfigurationStatus_Accepted;
  12536. }
  12537. }
  12538. }
  12539. else
  12540. {
  12541. isSuccess = ConfigurationStatus_Rejected;
  12542. }
  12543. }
  12544. if(strcmp(key, "NumberOfConnectors") == 0)
  12545. {
  12546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12547. {
  12548. check_ascii = value[0];
  12549. if( (check_ascii < 48) || (check_ascii > 57) )
  12550. {
  12551. isSuccess = ConfigurationStatus_Rejected;
  12552. }
  12553. else
  12554. {
  12555. //Charger.ResetRetries = Integer.parseInt(value);
  12556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12557. isSuccess = ConfigurationStatus_Accepted;
  12558. }
  12559. }
  12560. else
  12561. {
  12562. isSuccess = ConfigurationStatus_Rejected;
  12563. }
  12564. }
  12565. if(strcmp(key, "ResetRetries") == 0)
  12566. {
  12567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12568. {
  12569. check_ascii = value[0];
  12570. if( (check_ascii < 48) || (check_ascii > 57) )
  12571. {
  12572. isSuccess = ConfigurationStatus_Rejected;
  12573. }
  12574. else
  12575. {
  12576. //Charger.ResetRetries = Integer.parseInt(value);
  12577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12578. isSuccess = ConfigurationStatus_Accepted;
  12579. }
  12580. }
  12581. else
  12582. {
  12583. isSuccess = ConfigurationStatus_Rejected;
  12584. }
  12585. }
  12586. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12587. {
  12588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12589. {
  12590. strcpy(str, (const char*)value);
  12591. for(int i = 0; str[i]; i++)
  12592. {
  12593. str[i] = tolower(str[i]);
  12594. }
  12595. if(strcmp(str, "notapplicable")== 0)
  12596. {
  12597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12598. isSuccess = ConfigurationStatus_Accepted;
  12599. }
  12600. else if(strcmp(str, "unknown")== 0)
  12601. {
  12602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12603. isSuccess = ConfigurationStatus_Accepted;
  12604. }
  12605. else if(strcmp(str, "rst")== 0)
  12606. {
  12607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12608. isSuccess = ConfigurationStatus_Accepted;
  12609. }
  12610. else if(strcmp(str, "rts")== 0)
  12611. {
  12612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12613. isSuccess = ConfigurationStatus_Accepted;
  12614. }
  12615. else if(strcmp(str, "srt")== 0)
  12616. {
  12617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12618. isSuccess = ConfigurationStatus_Accepted;
  12619. }
  12620. else if(strcmp(str, "str")== 0)
  12621. {
  12622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12623. isSuccess = ConfigurationStatus_Accepted;
  12624. }
  12625. else if(strcmp(str, "trs")== 0)
  12626. {
  12627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12628. isSuccess = ConfigurationStatus_Accepted;
  12629. }
  12630. else if(strcmp(str, "tsr")== 0)
  12631. {
  12632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12633. isSuccess = ConfigurationStatus_Accepted;
  12634. }
  12635. else
  12636. {
  12637. isSuccess = ConfigurationStatus_Rejected;
  12638. }
  12639. }
  12640. else
  12641. {
  12642. isSuccess = ConfigurationStatus_Rejected;
  12643. }
  12644. }
  12645. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12646. {
  12647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12648. {
  12649. check_ascii = value[0];
  12650. if( (check_ascii < 48) || (check_ascii > 57) )
  12651. {
  12652. isSuccess = ConfigurationStatus_Rejected;
  12653. }
  12654. else
  12655. {
  12656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12657. isSuccess = ConfigurationStatus_Accepted;
  12658. }
  12659. }
  12660. else
  12661. {
  12662. isSuccess = ConfigurationStatus_Rejected;
  12663. }
  12664. }
  12665. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12666. {
  12667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12668. {
  12669. strcpy(str, (const char*)value);
  12670. for(int i = 0; str[i]; i++)
  12671. {
  12672. str[i] = tolower(str[i]);
  12673. }
  12674. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12676. isSuccess = ConfigurationStatus_Accepted;
  12677. }
  12678. else
  12679. {
  12680. isSuccess = ConfigurationStatus_Rejected;
  12681. }
  12682. }
  12683. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12684. {
  12685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12686. {
  12687. strcpy(str, (const char*)value);
  12688. for(int i = 0; str[i]; i++)
  12689. {
  12690. str[i] = tolower(str[i]);
  12691. }
  12692. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12694. isSuccess = ConfigurationStatus_Accepted;
  12695. }
  12696. else
  12697. {
  12698. isSuccess = ConfigurationStatus_Rejected;
  12699. }
  12700. }
  12701. if(strcmp(key, "StopTxnAlignedData") == 0)
  12702. {
  12703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12704. {
  12705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12706. isSuccess = ConfigurationStatus_Accepted;
  12707. }
  12708. else
  12709. {
  12710. isSuccess = ConfigurationStatus_Rejected;
  12711. }
  12712. }
  12713. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12714. {
  12715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12716. {
  12717. check_ascii = value[0];
  12718. if( (check_ascii < 48) || (check_ascii > 57) )
  12719. {
  12720. isSuccess = ConfigurationStatus_Rejected;
  12721. }
  12722. else
  12723. {
  12724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12725. isSuccess = ConfigurationStatus_Accepted;
  12726. }
  12727. }
  12728. else
  12729. {
  12730. isSuccess = ConfigurationStatus_Rejected;
  12731. }
  12732. }
  12733. if(strcmp(key, "StopTxnSampledData") == 0)
  12734. {
  12735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12736. {
  12737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12738. isSuccess = ConfigurationStatus_Accepted;
  12739. }
  12740. else
  12741. {
  12742. isSuccess = ConfigurationStatus_Rejected;
  12743. }
  12744. }
  12745. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12746. {
  12747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12748. {
  12749. check_ascii = value[0];
  12750. if( (check_ascii < 48) || (check_ascii > 57) )
  12751. {
  12752. isSuccess = ConfigurationStatus_Rejected;
  12753. }
  12754. else
  12755. {
  12756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12757. isSuccess = ConfigurationStatus_Accepted;
  12758. }
  12759. }
  12760. else
  12761. {
  12762. isSuccess = ConfigurationStatus_Rejected;
  12763. }
  12764. }
  12765. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12766. {
  12767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12768. {
  12769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12770. isSuccess = ConfigurationStatus_Accepted;
  12771. }
  12772. else
  12773. {
  12774. isSuccess = ConfigurationStatus_Rejected;
  12775. }
  12776. }
  12777. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12778. {
  12779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12780. {
  12781. check_ascii = value[0];
  12782. if( (check_ascii < 48) || (check_ascii > 57) )
  12783. {
  12784. isSuccess = ConfigurationStatus_Rejected;
  12785. }
  12786. else
  12787. {
  12788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12789. isSuccess = ConfigurationStatus_Accepted;
  12790. }
  12791. }
  12792. else
  12793. {
  12794. isSuccess = ConfigurationStatus_Rejected;
  12795. }
  12796. }
  12797. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12798. {
  12799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12800. {
  12801. check_ascii = value[0];
  12802. if( (check_ascii < 48) || (check_ascii > 57) )
  12803. {
  12804. isSuccess = ConfigurationStatus_Rejected;
  12805. }
  12806. else
  12807. {
  12808. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12810. TransactionMessageAttemptsValue = atoi(value);
  12811. isSuccess = ConfigurationStatus_Accepted;
  12812. }
  12813. }
  12814. else
  12815. {
  12816. isSuccess = ConfigurationStatus_Rejected;
  12817. }
  12818. }
  12819. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12820. {
  12821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12822. {
  12823. check_ascii = value[0];
  12824. if( (check_ascii < 48) || (check_ascii > 57) )
  12825. {
  12826. isSuccess = ConfigurationStatus_Rejected;
  12827. }
  12828. else
  12829. {
  12830. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12832. TransactionMessageRetryIntervalValue = atoi(value);
  12833. isSuccess = ConfigurationStatus_Accepted;
  12834. }
  12835. }
  12836. else
  12837. {
  12838. isSuccess = ConfigurationStatus_Rejected;
  12839. }
  12840. }
  12841. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12842. {
  12843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12844. {
  12845. strcpy(str, (const char*)value);
  12846. for(int i = 0; str[i]; i++)
  12847. {
  12848. str[i] = tolower(str[i]);
  12849. }
  12850. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12852. isSuccess = ConfigurationStatus_Accepted;
  12853. }
  12854. else
  12855. {
  12856. isSuccess = ConfigurationStatus_Rejected;
  12857. }
  12858. }
  12859. if(strcmp(key, "WebSocketPingInterval") == 0)
  12860. {
  12861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12862. {
  12863. check_ascii = value[0];
  12864. if( (check_ascii < 48) || (check_ascii > 57) )
  12865. {
  12866. isSuccess = ConfigurationStatus_Rejected;
  12867. }
  12868. else
  12869. {
  12870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12871. isSuccess = ConfigurationStatus_Accepted;
  12872. }
  12873. }
  12874. else
  12875. {
  12876. isSuccess = ConfigurationStatus_Rejected;
  12877. }
  12878. }
  12879. #if 0
  12880. //For OCPP Test Case
  12881. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12882. {
  12883. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12884. {
  12885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12886. isSuccess = ConfigurationStatus_Accepted;
  12887. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12888. }
  12889. else
  12890. {
  12891. isSuccess = ConfigurationStatus_Rejected;
  12892. }
  12893. }
  12894. #endif
  12895. #if 1
  12896. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12897. {
  12898. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12899. {
  12900. strcpy(str, (const char*)value);
  12901. for(int i = 0; str[i]; i++)
  12902. {
  12903. str[i] = tolower(str[i]);
  12904. }
  12905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12906. isSuccess = ConfigurationStatus_Accepted;
  12907. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12908. }
  12909. else
  12910. {
  12911. isSuccess = ConfigurationStatus_Rejected;
  12912. }
  12913. }
  12914. #endif
  12915. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12916. {
  12917. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12918. {
  12919. check_ascii = value[0];
  12920. if( (check_ascii < 48) || (check_ascii > 57) )
  12921. {
  12922. isSuccess = ConfigurationStatus_Rejected;
  12923. }
  12924. else
  12925. {
  12926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12927. isSuccess = ConfigurationStatus_Accepted;
  12928. }
  12929. }
  12930. else
  12931. {
  12932. isSuccess = ConfigurationStatus_Rejected;
  12933. }
  12934. }
  12935. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12936. {
  12937. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12938. {
  12939. check_ascii = value[0];
  12940. if( (check_ascii < 48) || (check_ascii > 57) )
  12941. {
  12942. isSuccess = ConfigurationStatus_Rejected;
  12943. }
  12944. else
  12945. {
  12946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12947. isSuccess = ConfigurationStatus_Accepted;
  12948. }
  12949. }
  12950. else
  12951. {
  12952. isSuccess = ConfigurationStatus_Rejected;
  12953. }
  12954. }
  12955. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12956. {
  12957. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12958. {
  12959. strcpy(str, (const char*)value);
  12960. for(int i = 0; str[i]; i++)
  12961. {
  12962. str[i] = tolower(str[i]);
  12963. }
  12964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12965. isSuccess = ConfigurationStatus_Accepted;
  12966. }
  12967. else
  12968. {
  12969. isSuccess = ConfigurationStatus_Rejected;
  12970. }
  12971. }
  12972. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12973. {
  12974. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12975. {
  12976. check_ascii = value[0];
  12977. if( (check_ascii < 48) || (check_ascii > 57) )
  12978. {
  12979. isSuccess = ConfigurationStatus_Rejected;
  12980. }
  12981. else
  12982. {
  12983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12984. isSuccess = ConfigurationStatus_Accepted;
  12985. }
  12986. }
  12987. else
  12988. {
  12989. isSuccess = ConfigurationStatus_Rejected;
  12990. }
  12991. }
  12992. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12993. {
  12994. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12995. {
  12996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12997. isSuccess = ConfigurationStatus_Accepted;
  12998. }
  12999. else
  13000. {
  13001. isSuccess = ConfigurationStatus_Rejected;
  13002. }
  13003. }
  13004. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13005. {
  13006. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13007. {
  13008. check_ascii = value[0];
  13009. if( (check_ascii < 48) || (check_ascii > 57) )
  13010. {
  13011. isSuccess = ConfigurationStatus_Rejected;
  13012. }
  13013. else
  13014. {
  13015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13016. isSuccess = ConfigurationStatus_Accepted;
  13017. }
  13018. }
  13019. else
  13020. {
  13021. isSuccess = ConfigurationStatus_Rejected;
  13022. }
  13023. }
  13024. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13025. {
  13026. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13027. {
  13028. strcpy(str, (const char*)value);
  13029. for(int i = 0; str[i]; i++)
  13030. {
  13031. str[i] = tolower(str[i]);
  13032. }
  13033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13034. isSuccess = ConfigurationStatus_Accepted;
  13035. }
  13036. else
  13037. {
  13038. isSuccess = ConfigurationStatus_Rejected;
  13039. }
  13040. }
  13041. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13042. {
  13043. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13044. {
  13045. check_ascii = value[0];
  13046. if( (check_ascii < 48) || (check_ascii > 57) )
  13047. {
  13048. isSuccess = ConfigurationStatus_Rejected;
  13049. }
  13050. else
  13051. {
  13052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13053. isSuccess = ConfigurationStatus_Accepted;
  13054. }
  13055. }
  13056. else
  13057. {
  13058. isSuccess = ConfigurationStatus_Rejected;
  13059. }
  13060. }
  13061. return isSuccess;
  13062. }
  13063. int updateSetting(char *key, char *value)
  13064. {
  13065. mtrace();
  13066. int isSuccess = FALSE;
  13067. char string[1000]={0}, buffer[1000]={0};
  13068. char strtemp[50]={0};
  13069. char sstr[50]={ 0 };//sstr[200]={ 0 };
  13070. int pos, c = 0;
  13071. char *loc;
  13072. int pos1=0;
  13073. FILE *f = fopen("/var/www/settings1", "r");
  13074. if(f == NULL)
  13075. {
  13076. #ifdef Debug
  13077. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  13078. #endif
  13079. return isSuccess;
  13080. }
  13081. fseek(f, 0, SEEK_END);
  13082. long fsize = ftell(f);
  13083. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  13084. fread(string, 1, fsize, f);
  13085. fclose(f);
  13086. string[fsize] = 0;
  13087. loc = strstr(string, key);
  13088. if(loc != NULL)
  13089. {
  13090. DEBUG_INFO("key exist!\n");
  13091. pos = loc - string-1;
  13092. f = fopen("/var/www/settings1", "w");
  13093. strncpy(buffer, string, pos);
  13094. fprintf(f, "%s", buffer);
  13095. memset(sstr ,0, sizeof(sstr) );
  13096. c = 0;
  13097. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  13098. {
  13099. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  13100. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13101. c++;
  13102. }
  13103. sstr[c] = '\0';
  13104. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  13105. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  13106. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  13107. memset(buffer ,0, sizeof(buffer) );
  13108. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  13109. //printf("buffer=%s",buffer);
  13110. fprintf(f, "%s", buffer);
  13111. fclose(f);
  13112. }
  13113. else
  13114. {
  13115. printf("key not exist!\n");
  13116. f = fopen("/var/www/settings1", "w+");
  13117. fputs(string, f);
  13118. fseek(f, -1, SEEK_CUR);
  13119. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  13120. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  13121. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  13122. fclose(f);
  13123. }
  13124. isSuccess = TRUE;
  13125. return isSuccess;
  13126. }
  13127. int TransactionMessageAttemptsGet(void)
  13128. {
  13129. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13130. }
  13131. int FirstHeartBeatResponse(void)
  13132. {
  13133. return FirstHeartBeat;
  13134. }
  13135. int TransactionMessageRetryIntervalGet(void)
  13136. {
  13137. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13138. }
  13139. #define SA struct sockaddr
  13140. #define MAXBUF 1024
  13141. //static int m_socket_data;
  13142. //static int sockfd;
  13143. int ReadHttpStatus(int sock){
  13144. //char c;
  13145. char buff[1024]="",*ptr=buff+1;
  13146. int bytes_received, status;
  13147. DEBUG_INFO("Begin Response ..\n");
  13148. while((bytes_received = recv(sock, ptr, 1, 0))){
  13149. if(bytes_received==-1){
  13150. perror("ReadHttpStatus");
  13151. exit(1);
  13152. }
  13153. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13154. ptr++;
  13155. }
  13156. *ptr=0;
  13157. ptr=buff+1;
  13158. sscanf(ptr,"%*s %d ", &status);
  13159. DEBUG_INFO("%s\n",ptr);
  13160. DEBUG_INFO("status=%d\n",status);
  13161. DEBUG_INFO("End Response ..\n");
  13162. return (bytes_received>0)?status:0;
  13163. }
  13164. //the only filed that it parsed is 'Content-Length'
  13165. int ParseHeader(int sock){
  13166. //char c;
  13167. char buff[1024]="",*ptr=buff+4;
  13168. int bytes_received;
  13169. DEBUG_INFO("Begin HEADER ..\n");
  13170. while((bytes_received = recv(sock, ptr, 1, 0))){
  13171. if(bytes_received==-1){
  13172. perror("Parse Header");
  13173. exit(1);
  13174. }
  13175. if(
  13176. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13177. (ptr[-1]=='\r') && (*ptr=='\n' )
  13178. ) break;
  13179. ptr++;
  13180. }
  13181. *ptr=0;
  13182. ptr=buff+4;
  13183. //printf("%s",ptr);
  13184. if(bytes_received){
  13185. ptr=strstr(ptr,"Content-Length:");
  13186. if(ptr){
  13187. sscanf(ptr,"%*s %d",&bytes_received);
  13188. }else
  13189. bytes_received=-1; //unknown size
  13190. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13191. }
  13192. DEBUG_INFO("End HEADER ..\n");
  13193. return bytes_received ;
  13194. }
  13195. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13196. {
  13197. char rmFileCmd[100]={0};
  13198. char FilePath[100]={0};
  13199. char ftpbuf[200];
  13200. int systemresult;
  13201. //DEBUG_INFO("filename=%s\n",filename);
  13202. //DEBUG_INFO("url=%s\n",url);
  13203. sprintf(FilePath,"/mnt/%s",filename);
  13204. if((access(FilePath,F_OK))!=-1)
  13205. {
  13206. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13207. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13208. system(rmFileCmd);
  13209. }
  13210. memset(ftpbuf, 0, sizeof(ftpbuf));
  13211. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13212. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13213. systemresult = system(ftpbuf);
  13214. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13215. if(systemresult != 0)
  13216. {
  13217. DEBUG_INFO("http DownLoad error!\n");
  13218. return FALSE;
  13219. }
  13220. return TRUE;
  13221. }
  13222. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13223. {
  13224. char rmFileCmd[100]={0};
  13225. char FilePath[100]={0};
  13226. char ftpbuf[200];
  13227. int systemresult;
  13228. //char temp[100];
  13229. #if 0
  13230. struct hostent* server;
  13231. char *IPbuffer;
  13232. server = gethostbyname(location);
  13233. // To convert an Internet network
  13234. // address into ASCII string
  13235. IPbuffer = inet_ntoa(*((struct in_addr*)
  13236. server->h_addr_list[0]));
  13237. #endif
  13238. sprintf(FilePath,"/mnt/%s",filename);
  13239. if((access(FilePath,F_OK))!=-1)
  13240. {
  13241. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13242. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13243. system(rmFileCmd);
  13244. }
  13245. memset(ftpbuf, 0, sizeof(ftpbuf));
  13246. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13247. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13248. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13249. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13250. systemresult = system(ftpbuf);
  13251. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13252. if(systemresult != 0)
  13253. {
  13254. printf("wget error!\n");
  13255. return FALSE;
  13256. }
  13257. return TRUE;
  13258. }
  13259. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13260. {
  13261. char rmFileCmd[100]={0};
  13262. char FilePath[100]={0};
  13263. char ftpbuf[200];
  13264. char filenametemp[60]={0};
  13265. int systemresult;
  13266. //DEBUG_INFO("filename=%s\n",filename);
  13267. //DEBUG_INFO("url=%s\n",url);
  13268. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13269. if((access(FilePath,F_OK))!=-1)
  13270. {
  13271. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13272. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13273. system(rmFileCmd);
  13274. }
  13275. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13276. if(fp == NULL)
  13277. {
  13278. DEBUG_INFO("log is NULL\n");
  13279. return FALSE;
  13280. }
  13281. else
  13282. {
  13283. fprintf(fp, "%s\n", url);
  13284. sscanf(filename, "%*2[.]%s", filenametemp);
  13285. fprintf(fp, "%s\n", filenametemp);
  13286. fclose(fp);
  13287. }
  13288. memset(ftpbuf, 0, sizeof(ftpbuf));
  13289. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13290. systemresult = system(ftpbuf);
  13291. DEBUG_INFO("systemresult=%d\n",systemresult);
  13292. if(systemresult != 0)
  13293. {
  13294. DEBUG_INFO("http upload error!\n");
  13295. return FALSE;
  13296. }
  13297. return TRUE;
  13298. }
  13299. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13300. {
  13301. struct hostent* server;
  13302. char *IPbuffer;
  13303. char ftpbuf[200];
  13304. int systemresult;
  13305. // To retrieve host information
  13306. server = gethostbyname(location);
  13307. // To convert an Internet network
  13308. // address into ASCII string
  13309. IPbuffer = inet_ntoa(*((struct in_addr*)
  13310. server->h_addr_list[0]));
  13311. memset(ftpbuf, 0, sizeof(ftpbuf));
  13312. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13313. /* format : ftpput -u username -p passwd IP target source*/
  13314. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13315. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13316. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13317. systemresult = system(ftpbuf);
  13318. DEBUG_INFO("systemresult=%d\n",systemresult);
  13319. if(systemresult != 0)
  13320. {
  13321. DEBUG_INFO("ftpput error!\n");
  13322. return FALSE;
  13323. }
  13324. return TRUE;
  13325. }
  13326. int SettingChargingRecord(int target, int transactionId)
  13327. {
  13328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13329. {
  13330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13331. {
  13332. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13333. {
  13334. addBuff(target, transactionId, 0);
  13335. return TRUE;
  13336. }
  13337. }
  13338. for (int index = 0; index < CCS_QUANTITY; index++)
  13339. {
  13340. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13341. {
  13342. addBuff(target, transactionId, 0);
  13343. return TRUE;
  13344. }
  13345. }
  13346. for (int index = 0; index < GB_QUANTITY; index++)
  13347. {
  13348. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13349. {
  13350. addBuff(target, transactionId, 0);
  13351. return TRUE;
  13352. }
  13353. }
  13354. }
  13355. else
  13356. {
  13357. for (int index = 0; index < AC_QUANTITY; index++)
  13358. {
  13359. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13360. {
  13361. addBuff(target, transactionId, 0);
  13362. return TRUE;
  13363. }
  13364. }
  13365. }
  13366. return FALSE;
  13367. }
  13368. int addBuff(int gun_idx, int user_id, int cmd_sn)
  13369. {
  13370. int isSuccess = FALSE;
  13371. //char *query = NULL;
  13372. sqlite3_stmt *stmt;
  13373. int rc; // return code
  13374. char str[20];
  13375. sprintf(str,"%d",user_id);
  13376. 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 */
  13377. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  13378. rc = sqlite3_step(stmt); /* 3 */
  13379. if (rc != SQLITE_DONE) {
  13380. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  13381. goto out;
  13382. }
  13383. sqlite3_finalize(stmt);
  13384. // free(query);
  13385. out:
  13386. //----------------------
  13387. // close SQLite database
  13388. //----------------------
  13389. sqlite3_close(db);
  13390. printf("database closed.\n");
  13391. return isSuccess;
  13392. }
  13393. /**
  13394. * Place the contents of the specified file into a memory buffer
  13395. *
  13396. * @param[in] filename The path and name of the file to read
  13397. * @param[out] filebuffer A pointer to the contents in memory
  13398. * @return status 0 success, 1 on failure
  13399. */
  13400. int get_file_contents(const char* filename, char** outbuffer) {
  13401. FILE* file = NULL;
  13402. long filesize;
  13403. const int blocksize = 1;
  13404. size_t readsize;
  13405. char* filebuffer;
  13406. // Open the file
  13407. file = fopen(filename, "r");
  13408. if (NULL == file)
  13409. {
  13410. printf("'%s' not opened\n", filename);
  13411. exit(EXIT_FAILURE);
  13412. }
  13413. // Determine the file size
  13414. fseek(file, 0, SEEK_END);
  13415. filesize = ftell(file);
  13416. rewind (file);
  13417. // Allocate memory for the file contents
  13418. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13419. *outbuffer = filebuffer;
  13420. if (filebuffer == NULL)
  13421. {
  13422. fputs ("malloc out-of-memory", stderr);
  13423. exit(EXIT_FAILURE);
  13424. }
  13425. // Read in the file
  13426. readsize = fread(filebuffer, blocksize, filesize, file);
  13427. if (readsize != filesize)
  13428. {
  13429. fputs ("didn't read file completely",stderr);
  13430. exit(EXIT_FAILURE);
  13431. }
  13432. // Clean exit
  13433. fclose(file);
  13434. return EXIT_SUCCESS;
  13435. }
  13436. static int selectSqlCount = 0;
  13437. static int callback(void *data, int argc, char **argv, char **azColName){
  13438. int i;
  13439. //printf("%s: ", (const char*)data);
  13440. selectSqlCount = argc;
  13441. for(i = 0; i<argc; i++){
  13442. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13443. }
  13444. //printf("\n");
  13445. return 0;
  13446. }
  13447. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13448. //int i;
  13449. //printf("%s:\n", (const char*)data);
  13450. localversion = argv[5] ? atoi(argv[5]) : 0;
  13451. //printf("localversion=%d\n", localversion);
  13452. return 0;
  13453. }
  13454. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13455. //int i;
  13456. //printf("%s:\n", (const char*)data);
  13457. //idTag
  13458. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13459. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13460. //parentIdTag
  13461. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13462. //expir_date
  13463. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13464. //status
  13465. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13466. //version
  13467. idTagQuery.listVersionInt = atoi(argv[5]);
  13468. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13469. return 0;
  13470. }
  13471. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  13472. #if 0
  13473. int i;
  13474. //printf("%s:\n", (const char*)data);
  13475. for(i=0; i<argc; i++){
  13476. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  13477. }
  13478. //printf("");
  13479. #endif
  13480. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13481. // printf("localversion=%d\n", localversion);
  13482. return 0;
  13483. }
  13484. /** sqlite3_exec的回调。
  13485. *
  13486. * 向控制台打印查询的结果。
  13487. *
  13488. * @param in data 传递给回调函数的数据。
  13489. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  13490. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  13491. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  13492. * @return 状态码。
  13493. */
  13494. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13495. {
  13496. for (int i = 0; i < n_columns; i++)
  13497. {
  13498. DEBUG_INFO("%s/t", col_values[i]);
  13499. }
  13500. DEBUG_INFO("/n");
  13501. return 0;
  13502. }
  13503. void OCPP_getListVerion()
  13504. {
  13505. int rc = 0;
  13506. // const char* data = "Callback function called";
  13507. char sql[100];
  13508. char zErrMsg[100];
  13509. memset(sql, 0, 100);
  13510. memset(zErrMsg, 0, 100);
  13511. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  13512. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13513. /* Execute SQL statement */
  13514. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13515. DEBUG_INFO("rc=%d\n",rc);
  13516. if( rc != SQLITE_OK ){
  13517. DEBUG_INFO("SQL error: %s", zErrMsg);
  13518. //sqlite3_free(zErrMsg);
  13519. }
  13520. }
  13521. void OCPP_getIdTag(char idTag[])
  13522. {
  13523. int rc = 0;
  13524. // const char* data = "Callback function called";
  13525. char sql[100];
  13526. char zErrMsg[100];
  13527. memset(sql, 0, 100);
  13528. memset(zErrMsg, 0, 100);
  13529. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  13530. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13531. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13532. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13533. /* Execute SQL statement */
  13534. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13535. if( rc != SQLITE_OK ){
  13536. DEBUG_INFO("SQL error: %s", zErrMsg);
  13537. //sqlite3_free(zErrMsg);
  13538. }
  13539. //return ver;
  13540. }
  13541. void OCPP_get_TableAuthlocalAllData(void)
  13542. {
  13543. int rc = 0;
  13544. // const char* data = "Callback function called";
  13545. char sql[100];
  13546. char zErrMsg[100];
  13547. memset(sql, 0, 100);
  13548. memset(zErrMsg, 0, 100);
  13549. sprintf(sql,"select * from ocpp_auth_local ");
  13550. /* Execute SQL statement */
  13551. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13552. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  13553. if( rc != SQLITE_OK ){
  13554. DEBUG_INFO("SQL error: %s", zErrMsg);
  13555. //sqlite3_free(zErrMsg);
  13556. }
  13557. //return ver;
  13558. }
  13559. int OCPP_cleanLocalList()
  13560. {
  13561. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13562. char *errMsg = 0;
  13563. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13564. if (SQLITE_OK != rc)
  13565. {
  13566. DEBUG_INFO("%s\n",errMsg);
  13567. return FALSE;
  13568. }
  13569. else
  13570. {
  13571. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  13572. }
  13573. return TRUE;
  13574. }
  13575. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13576. {
  13577. int isSuccess = FALSE;
  13578. int ret = 0;
  13579. //const char* data = "Callback function called";
  13580. char sql[300];
  13581. char zErrMsg[200];
  13582. memset(sql, 0, 300);
  13583. memset(zErrMsg, 0, 200);
  13584. 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);
  13585. //* Execute SQL statement */
  13586. //zErrMsg = 0;
  13587. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13588. if( ret != SQLITE_OK ){
  13589. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13590. // free(zErrMsg);
  13591. // free(sql);
  13592. return isSuccess;
  13593. }
  13594. memset(sql, 0, 300);
  13595. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13596. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13597. if( ret != SQLITE_OK ){
  13598. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13599. // free(zErrMsg);
  13600. // free(sql);
  13601. return isSuccess;
  13602. }
  13603. // DEBUG_INFO("successfully Insert records created\n");
  13604. isSuccess = TRUE;
  13605. return isSuccess;
  13606. }
  13607. void OCPP_deleteIdTag(char idTag[])
  13608. {
  13609. //int ver = 0;
  13610. //int isSuccess = FALSE;
  13611. int rc = 0;
  13612. char sql[100];
  13613. char zErrMsg[100];
  13614. memset(sql, 0, 100);
  13615. memset(zErrMsg, 0, 100);
  13616. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13617. //* Execute SQL statement */
  13618. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13619. if( rc != SQLITE_OK ){
  13620. DEBUG_INFO("SQL error: %s", zErrMsg);
  13621. //sqlite3_free(zErrMsg);
  13622. }
  13623. }
  13624. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13625. {
  13626. int isSuccess = FALSE;
  13627. int ret = 0;
  13628. const char* data = "Callback function called";
  13629. char sql[200];
  13630. char zErrMsg[100];
  13631. memset(sql, 0, 200);
  13632. memset(zErrMsg, 0, 100);
  13633. //* selectFromTable */
  13634. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  13635. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13636. //* Execute SQL statement */
  13637. selectSqlCount = 0;
  13638. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13639. if( ret != SQLITE_OK ){
  13640. printf("Error SQL: %s\n", zErrMsg);
  13641. }
  13642. printf("successfully select operation done\n");
  13643. memset(sql, 0, 200);
  13644. memset(zErrMsg, 0, 100);
  13645. if(selectSqlCount == 0)
  13646. {
  13647. //Insert
  13648. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  13649. 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);
  13650. DEBUG_INFO("sql:%s\n", sql);
  13651. //* Execute SQL statement */
  13652. //zErrMsg = 0;
  13653. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  13654. if( ret != SQLITE_OK ){
  13655. printf("SQL error: %s\n", zErrMsg);
  13656. return isSuccess;
  13657. }
  13658. DEBUG_INFO("successfully Insert records created\n");
  13659. isSuccess = TRUE;
  13660. }
  13661. else
  13662. {
  13663. //Update
  13664. //* Create merged SQL statement */
  13665. 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);
  13666. /* Execute SQL statement */
  13667. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13668. if( ret != SQLITE_OK ){
  13669. printf("SQL error: %s\n", zErrMsg);
  13670. //sqlite3_free(zErrMsg);
  13671. //sqlite3_free(sql);
  13672. return isSuccess;
  13673. }
  13674. DEBUG_INFO("Successfully operation done \n");
  13675. isSuccess = TRUE;
  13676. }
  13677. return isSuccess;
  13678. }
  13679. int GetOcppServerURL()
  13680. {
  13681. int result = FALSE;
  13682. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  13683. memset(OcppHost, 0, sizeof(OcppHost));
  13684. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  13685. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13686. {
  13687. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  13688. #if 1
  13689. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13690. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13691. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13692. #endif
  13693. #if 0
  13694. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13695. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  13696. OcppProtocol, OcppHost, OcppTempPath);
  13697. OcppPort = 443;
  13698. #endif
  13699. result = TRUE;
  13700. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13701. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13702. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13703. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13704. goto End;
  13705. }
  13706. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13707. {
  13708. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  13709. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13710. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13711. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13712. result = TRUE;
  13713. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13714. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13715. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13716. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13717. goto End;
  13718. }
  13719. else
  13720. {
  13721. strcpy(OcppHost,"");
  13722. }
  13723. End:
  13724. return result;
  13725. }
  13726. int GetOcppPath()
  13727. {
  13728. int result = FALSE;
  13729. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13730. {
  13731. if(OcppTempPath == NULL)
  13732. {
  13733. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13734. }
  13735. else
  13736. {
  13737. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13738. }
  13739. result = TRUE;
  13740. goto End;
  13741. }
  13742. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13743. {
  13744. if(OcppTempPath == NULL)
  13745. {
  13746. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13747. }
  13748. else
  13749. {
  13750. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13751. }
  13752. result = TRUE;
  13753. goto End;
  13754. }
  13755. else
  13756. {
  13757. strcpy(OcppPath,"");
  13758. }
  13759. End:
  13760. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  13761. return result;
  13762. }
  13763. int GetOcppPort()
  13764. {
  13765. return OcppPort;
  13766. }
  13767. int GetOcppConnStatus(void)
  13768. {
  13769. return ShmOCPP16Data->OcppConnStatus;
  13770. }
  13771. void SetOcppConnStatus(uint8_t status)
  13772. {
  13773. ShmOCPP16Data->OcppConnStatus = status;
  13774. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13775. }
  13776. int GetHeartBeatWithNOResponse(void)
  13777. {
  13778. return HeartBeatWithNOResponse;
  13779. }
  13780. void SetHeartBeatWithNOResponse(void)
  13781. {
  13782. HeartBeatWithNOResponse = 0;
  13783. }
  13784. void GetStartTransactionIdTag(int gun_index)
  13785. {
  13786. memset(StartTransactionIdTagTemp, 0 ,sizeof(StartTransactionIdTagTemp));
  13787. strcpy(StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13788. }
  13789. void splitstring(char *src,const char *separator,char **dest,int *num) {
  13790. /*
  13791. src 源字串的首地址(buf的地址)
  13792. separator 指定的分割字元
  13793. dest 接收子字串的陣列
  13794. num 分割後子字串的個數
  13795. */
  13796. char *pNext;
  13797. int count = 0;
  13798. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  13799. return;
  13800. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  13801. return;
  13802. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  13803. while(pNext != NULL) {
  13804. *dest++ = pNext;
  13805. ++count;
  13806. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  13807. }
  13808. *num = count;
  13809. }
  13810. int GetTransactionId(int gunindex, unsigned char idTag[])
  13811. {
  13812. char ch;
  13813. FILE *fptr1;
  13814. int temptransactionId;
  13815. char str[100]={0};
  13816. temptransactionId = 0;
  13817. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13818. {
  13819. return temptransactionId;
  13820. }
  13821. /*------ Read the file ----------------*/
  13822. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13823. if (!fptr1)
  13824. {
  13825. //printf(" File not found or unable to open the input file!!\n");
  13826. return temptransactionId;
  13827. }
  13828. ch=fgetc(fptr1);
  13829. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13830. rewind(fptr1);
  13831. if(ch!=EOF)
  13832. {
  13833. // printf("%c",ch);
  13834. while (fgets(str, 100, fptr1) != NULL)
  13835. {
  13836. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13837. if(str[0]=='\0')
  13838. {
  13839. break;
  13840. }
  13841. char *revbuf[8] = {0}; //存放分割後的子字串
  13842. int num = 0;//分割後子字串的個數
  13843. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13844. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13845. {
  13846. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13847. {
  13848. temptransactionId = atoi(revbuf[2]);
  13849. break;
  13850. }
  13851. }
  13852. }
  13853. }
  13854. fclose(fptr1);
  13855. /*------- End of reading ---------------*/
  13856. return temptransactionId;
  13857. }
  13858. void SetTransactionIdZero(int transactionId)
  13859. {
  13860. //TransactionId[gunindex] = 0;
  13861. char ch;
  13862. FILE *fptr1, *fptr2;
  13863. int temptransactionId = 0;
  13864. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13865. printf("\n Delete a specific line from a file :\n");
  13866. printf("-----------------------------------------\n");
  13867. //scanf("%s",fname);
  13868. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13869. if (!fptr1)
  13870. {
  13871. //printf(" File not found or unable to open the input file!!\n");
  13872. return ;
  13873. }
  13874. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13875. if (!fptr2)
  13876. {
  13877. printf("Unable to open a temporary file to write!!\n");
  13878. fclose(fptr1);
  13879. return ;
  13880. }
  13881. ch=fgetc(fptr1);
  13882. //printf(" Now the content of the file %s is : \n",fname);
  13883. rewind(fptr1);
  13884. if(ch!=EOF)
  13885. {
  13886. // copy all contents to the temporary file except the specific line
  13887. while (fgets(str, 100, fptr1) != NULL)
  13888. {
  13889. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13890. if(str[0]=='\0')
  13891. {
  13892. break;
  13893. }
  13894. char *revbuf[8] = {0}; //存放分割後的子字串
  13895. int num = 0;//分割後子字串的個數
  13896. strcpy(strtemp, str);
  13897. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13898. if(revbuf[2][0] != '\0')
  13899. {
  13900. temptransactionId = atoi(revbuf[2]);
  13901. if(transactionId != temptransactionId)
  13902. {
  13903. fprintf(fptr2, "%s\n", strtemp);
  13904. }
  13905. }
  13906. }
  13907. }
  13908. fclose(fptr1);
  13909. fclose(fptr2);
  13910. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13911. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13912. printf("\n Delete a specific line from a file End\n");
  13913. printf("-----------------------------------------\n");
  13914. /*------ Read the file ----------------*/
  13915. }
  13916. int InternetDisconnect(void)
  13917. {
  13918. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13919. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13920. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13921. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13922. }
  13923. void GetChargingProfileRequest(int gunindex)
  13924. {
  13925. mtrace();
  13926. //int connectorIdInt, durationInt;
  13927. //char chargingRateUnitStr[4]={0};
  13928. int tempdurationInt = 0;
  13929. int tempchargingProfileId = 0;
  13930. int tempstackLevel = 0;
  13931. int temptransactionId = 0;
  13932. float tempminChargingRateFloat = 0.0;
  13933. char tempchargingProfilePurposeStr[24]={0};
  13934. char tempchargingProfileKindStr[12]={0};
  13935. char temprecurrencyKindStr[8]={0};
  13936. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13937. char tempvalidToStr[28]={0};
  13938. int tempStartPeriodInt = 0;
  13939. float tempLimitInt = 0.0;//0.1;
  13940. int tempNumberPhasesInt=0;
  13941. char fname[200];
  13942. //char comfirmstr[20];
  13943. float MinChargingRate =0.0;
  13944. double diff_t;
  13945. struct tm tp;
  13946. FILE *fptr1;//, *fptr2;
  13947. int c = 0;
  13948. char * pch;
  13949. char *loc;
  13950. char sstr[200]={ 0 };
  13951. int n_chargingProfile = 0;
  13952. int n_SchedulePeriods = 0;
  13953. char SchedulePeriodList[10][200]={0};
  13954. char sLineWord[1600]={0};
  13955. char word[1000]={0};
  13956. int confirmPeriods = 0;
  13957. struct StructProfile ChargePointMaxProfile;
  13958. struct StructProfile TxDefaultProfile;
  13959. struct StructProfile TxProfile;
  13960. struct StructProfile TxDefaultProfiletemp[2]={0};
  13961. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13962. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13963. struct StructChargingProfile TxProfile_TEMP={0};
  13964. int TxDefaultProfileFileIsNull=FALSE;
  13965. int ChargePointMaxProfileIsNull=FALSE;
  13966. int TxProfileIsNull=FALSE;
  13967. // int CompositeSceduleIndex = 0;
  13968. char ChargePointMaxProfileScheduleStr[30]={0};
  13969. char TxDefaultProfileScheduleStr[30]={0};
  13970. char TxProfileScheduleStr[30]={0};
  13971. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13972. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13973. memset(&TxProfile,0,sizeof(struct StructProfile));
  13974. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13975. DEBUG_INFO("GetChargingProfileRequest\n");
  13976. //*****************************ChargePointMaxProfile******************************************/
  13977. strcpy(fname, ChargePointMaxProfile_JSON);
  13978. ChargePointMaxProfileIsNull=TRUE;
  13979. DEBUG_INFO("test 1\n");
  13980. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13981. {
  13982. fptr1 = fopen(fname, "r");
  13983. int c;
  13984. c = fgetc(fptr1);
  13985. //DEBUG_INFO("c:%d\n",c);
  13986. rewind(fptr1);
  13987. if(c == EOF)
  13988. {
  13989. DEBUG_INFO("\n End of file reached.");
  13990. ChargePointMaxProfileIsNull=TRUE;
  13991. fclose(fptr1);
  13992. }
  13993. else
  13994. {
  13995. DEBUG_INFO("test 2\n");
  13996. ChargePointMaxProfileIsNull=FALSE;
  13997. while(fscanf(fptr1, "%s", word) != EOF)
  13998. {
  13999. if(strcmp(word, "chargingProfileId") == 0)
  14000. {
  14001. n_chargingProfile = n_chargingProfile + 1;
  14002. }
  14003. }
  14004. rewind(fptr1);
  14005. //search Charging Profile Element
  14006. int i = 0;
  14007. int j = 0;
  14008. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14009. //***********chargingProfileId**************/
  14010. c = 0;
  14011. loc = strstr(sLineWord, "chargingProfileId");
  14012. //DEBUG_INFO("loc=%s\n",loc);
  14013. memset(sstr ,0, sizeof(sstr) );
  14014. if(loc != NULL)
  14015. {
  14016. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14017. {
  14018. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14020. c++;
  14021. }
  14022. sstr[c] = '\0';
  14023. tempchargingProfileId = atoi(sstr);
  14024. }
  14025. else
  14026. {
  14027. tempchargingProfileId = 0;
  14028. }
  14029. //***********stackLevel**************/
  14030. c = 0;
  14031. loc = strstr(sLineWord, "stackLevel");
  14032. //DEBUG_INFO("loc=%s\n",loc);
  14033. memset(sstr ,0, sizeof(sstr) );
  14034. if(loc != NULL)
  14035. {
  14036. while (loc[2+strlen("stackLevel")+c] != '\"')
  14037. {
  14038. sstr[c] = loc[2+strlen("stackLevel")+c];
  14039. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14040. c++;
  14041. }
  14042. sstr[c] = '\0';
  14043. tempstackLevel = atoi(sstr);
  14044. }
  14045. else
  14046. {
  14047. tempstackLevel = 0;
  14048. }
  14049. //***********chargingProfilePurpose **************/
  14050. c = 0;
  14051. loc = strstr(sLineWord, "chargingProfilePurpose");
  14052. //DEBUG_INFO("loc=%s\n",loc);
  14053. memset(sstr ,0, sizeof(sstr) );
  14054. if(loc != NULL)
  14055. {
  14056. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14057. {
  14058. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14059. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14060. c++;
  14061. }
  14062. sstr[c] = '\0';
  14063. strcpy(tempchargingProfilePurposeStr,sstr);
  14064. }
  14065. else
  14066. {
  14067. strcpy(tempchargingProfilePurposeStr,"");
  14068. }
  14069. //***********chargingProfileKind **************/
  14070. c = 0;
  14071. loc = strstr(sLineWord, "chargingProfileKind");
  14072. //DEBUG_INFO("loc=%s\n",loc);
  14073. memset(sstr ,0, sizeof(sstr) );
  14074. if(loc != NULL)
  14075. {
  14076. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14077. {
  14078. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14079. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14080. c++;
  14081. }
  14082. sstr[c] = '\0';
  14083. strcpy(tempchargingProfileKindStr,sstr);
  14084. }
  14085. else
  14086. {
  14087. strcpy(tempchargingProfileKindStr,"");
  14088. }
  14089. //***********recurrencyKind **************/
  14090. c = 0;
  14091. loc = strstr(sLineWord, "recurrencyKind");
  14092. //DEBUG_INFO("loc=%s\n",loc);
  14093. memset(sstr ,0, sizeof(sstr) );
  14094. if(loc != NULL)
  14095. {
  14096. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14097. {
  14098. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14099. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14100. c++;
  14101. }
  14102. sstr[c] = '\0';
  14103. strcpy(temprecurrencyKindStr,sstr);
  14104. }
  14105. else
  14106. {
  14107. strcpy(temprecurrencyKindStr,"");
  14108. }
  14109. //***********validFrom**************/
  14110. c = 0;
  14111. loc = strstr(sLineWord, "validFrom");
  14112. //DEBUG_INFO("loc=%s\n",loc);
  14113. memset(sstr ,0, sizeof(sstr) );
  14114. if(loc != NULL)
  14115. {
  14116. while (loc[3+strlen("validFrom")+c] != '\"')
  14117. {
  14118. sstr[c] = loc[3+strlen("validFrom")+c];
  14119. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14120. c++;
  14121. }
  14122. sstr[c] = '\0';
  14123. strcpy(tempvalidFromStr,sstr);
  14124. }
  14125. else
  14126. {
  14127. strcpy(tempvalidFromStr,"");
  14128. }
  14129. //***********validTo **************/
  14130. c = 0;
  14131. loc = strstr(sLineWord, "validTo");
  14132. //DEBUG_INFO("loc=%s\n",loc);
  14133. memset(sstr ,0, sizeof(sstr) );
  14134. if(loc != NULL)
  14135. {
  14136. while (loc[3+strlen("validTo")+c] != '\"')
  14137. {
  14138. sstr[c] = loc[3+strlen("validTo")+c];
  14139. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14140. c++;
  14141. }
  14142. sstr[c] = '\0';
  14143. strcpy(tempvalidToStr,sstr);
  14144. }
  14145. else
  14146. {
  14147. strcpy(tempvalidToStr,"");
  14148. }
  14149. //***********validFrom**************/
  14150. c = 0;
  14151. loc = strstr(sLineWord, "validFrom");
  14152. if(loc != NULL)
  14153. {
  14154. memset(sstr ,0, sizeof(sstr) );
  14155. while (loc[3+strlen("validFrom")+c] != '\"')
  14156. {
  14157. sstr[c] = loc[3+strlen("validFrom")+c];
  14158. c++;
  14159. }
  14160. sstr[c] = '\0';
  14161. strcpy(tempvalidFromStr,sstr);
  14162. }
  14163. else
  14164. {
  14165. strcpy(tempvalidFromStr,"");
  14166. }
  14167. //***********validTo **************/
  14168. c = 0;
  14169. loc = strstr(sLineWord, "validTo");
  14170. if(loc != NULL)
  14171. {
  14172. memset(sstr ,0, sizeof(sstr) );
  14173. while (loc[3+strlen("validTo")+c] != '\"')
  14174. {
  14175. sstr[c] = loc[3+strlen("validTo")+c];
  14176. c++;
  14177. }
  14178. sstr[c] = '\0';
  14179. strcpy(tempvalidToStr,sstr);
  14180. }
  14181. else
  14182. {
  14183. strcpy(tempvalidToStr,"");
  14184. }
  14185. //***********duration**************/
  14186. c = 0;
  14187. loc = strstr(sLineWord, "duration");
  14188. if(loc != NULL)
  14189. {
  14190. memset(sstr ,0, sizeof(sstr) );
  14191. while (loc[2+strlen("duration")+c] != ',')
  14192. {
  14193. sstr[c] = loc[2+strlen("duration")+c];
  14194. c++;
  14195. }
  14196. sstr[c] = '\0';
  14197. tempdurationInt = atoi(sstr);
  14198. }
  14199. else
  14200. {
  14201. tempdurationInt = 0;
  14202. }
  14203. //**********startSchedule**********/
  14204. c = 0;
  14205. loc = strstr(sLineWord, "startSchedule");
  14206. if(loc != NULL)
  14207. {
  14208. memset(sstr ,0, sizeof(sstr) );
  14209. while (loc[3+strlen("startSchedule")+c] != '\"')
  14210. {
  14211. sstr[c] = loc[3+strlen("startSchedule")+c];
  14212. c++;
  14213. }
  14214. sstr[c] = '\0';
  14215. strcpy(tempstartScheduleStr, sstr);
  14216. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  14217. }
  14218. else
  14219. {
  14220. strcpy(tempstartScheduleStr, "");
  14221. strcpy(ChargePointMaxProfileScheduleStr, "");
  14222. }
  14223. //**********chargingRateUnit**********/
  14224. c = 0;
  14225. loc = strstr(sLineWord, "chargingRateUnit");
  14226. memset(sstr ,0, sizeof(sstr) );
  14227. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14228. {
  14229. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14230. c++;
  14231. }
  14232. sstr[c] = '\0';
  14233. strcpy(tempchargingRateUnitStr, sstr);
  14234. //**********minChargingRate*******/
  14235. c = 0;
  14236. loc = strstr(sLineWord, "minChargingRate");
  14237. if(loc != NULL)
  14238. {
  14239. memset(sstr ,0, sizeof(sstr) );
  14240. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14241. {
  14242. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14243. c++;
  14244. }
  14245. sstr[c] = '\0';
  14246. tempminChargingRateFloat = atof(sstr);
  14247. }
  14248. else
  14249. {
  14250. tempminChargingRateFloat = 0.0;
  14251. }
  14252. //
  14253. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14254. tp.tm_isdst = -1;
  14255. time_t utc = mktime(&tp);
  14256. time_t t = time(NULL);
  14257. diff_t = difftime(t, utc);
  14258. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14259. //parsing strings to words
  14260. i = 0;
  14261. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14262. loc = loc+3+strlen("chargingSchedulePeriod");
  14263. pch = strtok(loc ,"{");
  14264. while (pch != NULL)
  14265. {
  14266. strcpy(SchedulePeriodList[i], pch);
  14267. pch = strtok (NULL, "{");
  14268. i = i + 1;
  14269. }
  14270. n_SchedulePeriods = i;
  14271. for(int i=0;i<n_SchedulePeriods;i++)
  14272. {
  14273. //*************startPeriod****************/
  14274. c = 0;
  14275. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14276. memset(sstr ,0, sizeof(sstr) );
  14277. while (loc[strlen("startPeriod")+2+c] != ',')
  14278. {
  14279. sstr[c] = loc[strlen("startPeriod")+2+c];
  14280. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14281. c++;
  14282. }
  14283. sstr[c] = '\0';
  14284. tempStartPeriodInt = atoi(sstr);
  14285. //*************limit****************/
  14286. c = 0;
  14287. loc = strstr(SchedulePeriodList[i], "limit");
  14288. memset(sstr ,0, sizeof(sstr) );
  14289. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14290. {
  14291. sstr[c] = loc[strlen("limit")+2+c];
  14292. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14293. c++;
  14294. }
  14295. sstr[c] = '\0';
  14296. tempLimitInt = atof(sstr);
  14297. //*************numberPhases****************/
  14298. c = 0;
  14299. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14300. memset(sstr ,0, sizeof(sstr) );
  14301. if(loc != NULL)
  14302. {
  14303. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14304. {
  14305. sstr[c] = loc[strlen("numberPhases")+2+c];
  14306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14307. c++;
  14308. }
  14309. sstr[c] = '\0';
  14310. tempNumberPhasesInt = atoi(sstr);
  14311. }
  14312. else
  14313. {
  14314. tempNumberPhasesInt = 0;
  14315. }
  14316. if(j == 0)
  14317. {
  14318. ChargePointMaxProfile.Duration = tempdurationInt;
  14319. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  14320. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  14321. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14322. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14323. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14324. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  14325. ChargePointMaxProfile_TEMP.TransactionId = 0;
  14326. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14327. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14328. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14329. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14330. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14331. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14332. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14333. }
  14334. }
  14335. if(MinChargingRate < tempminChargingRateFloat)
  14336. {
  14337. MinChargingRate = tempminChargingRateFloat;
  14338. }
  14339. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14340. if(confirmPeriods < n_SchedulePeriods)
  14341. {
  14342. confirmPeriods = n_SchedulePeriods;
  14343. }
  14344. j = j + 1;
  14345. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14346. fclose(fptr1);
  14347. }// end else
  14348. }// the end of access file ChargePointMaxProfile
  14349. DEBUG_INFO("test 3\n");
  14350. //****************************TxDefaultProfile************************************************/
  14351. memset(fname, 0, sizeof fname);
  14352. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  14353. TxDefaultProfileFileIsNull=TRUE;
  14354. if((access(fname,F_OK))!=-1)
  14355. {
  14356. fptr1 = fopen(fname, "r");
  14357. c = 0;
  14358. c = fgetc(fptr1);
  14359. //DEBUG_INFO("c:%d\n",c);
  14360. rewind(fptr1);
  14361. if(c == EOF)
  14362. {
  14363. DEBUG_INFO("\n End of file reached.");
  14364. TxDefaultProfileFileIsNull=TRUE;
  14365. fclose(fptr1);
  14366. }
  14367. else
  14368. {
  14369. TxDefaultProfileFileIsNull=FALSE;
  14370. while(fscanf(fptr1, "%s", word) != EOF)
  14371. {
  14372. if(strcmp(word, "chargingProfileId") == 0)
  14373. {
  14374. n_chargingProfile = n_chargingProfile + 1;
  14375. }
  14376. }
  14377. rewind(fptr1);
  14378. //search Charging Profile Element
  14379. int i = 0;
  14380. int j = 0;
  14381. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14382. {
  14383. #if 0
  14384. //***********connectorId****************/
  14385. c = 0;
  14386. loc = strstr(sLineWord, "connectorId");
  14387. memset(sstr ,0, sizeof(sstr) );
  14388. while (loc[strlen("connectorId")+2+c] != ',')
  14389. {
  14390. sstr[c] = loc[strlen("connectorId")+2+c];
  14391. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14392. c++;
  14393. }
  14394. sstr[c] = '\0';
  14395. tempconnectorIdInt = atoi(sstr);
  14396. #endif
  14397. //***********chargingProfileId**************/
  14398. c = 0;
  14399. loc = strstr(sLineWord, "chargingProfileId");
  14400. //DEBUG_INFO("loc=%s\n",loc);
  14401. memset(sstr ,0, sizeof(sstr) );
  14402. if(loc != NULL)
  14403. {
  14404. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14405. {
  14406. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14407. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14408. c++;
  14409. }
  14410. sstr[c] = '\0';
  14411. tempchargingProfileId = atoi(sstr);
  14412. }
  14413. else
  14414. {
  14415. tempchargingProfileId = 0;
  14416. }
  14417. //***********stackLevel**************/
  14418. c = 0;
  14419. loc = strstr(sLineWord, "stackLevel");
  14420. //DEBUG_INFO("loc=%s\n",loc);
  14421. memset(sstr ,0, sizeof(sstr) );
  14422. if(loc != NULL)
  14423. {
  14424. while (loc[2+strlen("stackLevel")+c] != '\"')
  14425. {
  14426. sstr[c] = loc[2+strlen("stackLevel")+c];
  14427. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14428. c++;
  14429. }
  14430. sstr[c] = '\0';
  14431. tempstackLevel = atoi(sstr);
  14432. }
  14433. else
  14434. {
  14435. tempstackLevel = 0;
  14436. }
  14437. //***********chargingProfilePurpose **************/
  14438. c = 0;
  14439. loc = strstr(sLineWord, "chargingProfilePurpose");
  14440. //DEBUG_INFO("loc=%s\n",loc);
  14441. memset(sstr ,0, sizeof(sstr) );
  14442. if(loc != NULL)
  14443. {
  14444. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14445. {
  14446. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14447. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14448. c++;
  14449. }
  14450. sstr[c] = '\0';
  14451. strcpy(tempchargingProfilePurposeStr,sstr);
  14452. }
  14453. else
  14454. {
  14455. strcpy(tempchargingProfilePurposeStr,"");
  14456. }
  14457. //***********chargingProfileKind **************/
  14458. c = 0;
  14459. loc = strstr(sLineWord, "chargingProfileKind");
  14460. //DEBUG_INFO("loc=%s\n",loc);
  14461. memset(sstr ,0, sizeof(sstr) );
  14462. if(loc != NULL)
  14463. {
  14464. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14465. {
  14466. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14467. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14468. c++;
  14469. }
  14470. sstr[c] = '\0';
  14471. strcpy(tempchargingProfileKindStr,sstr);
  14472. }
  14473. else
  14474. {
  14475. strcpy(tempchargingProfileKindStr,"");
  14476. }
  14477. //***********recurrencyKind **************/
  14478. c = 0;
  14479. loc = strstr(sLineWord, "recurrencyKind");
  14480. //DEBUG_INFO("loc=%s\n",loc);
  14481. memset(sstr ,0, sizeof(sstr) );
  14482. if(loc != NULL)
  14483. {
  14484. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14485. {
  14486. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14487. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14488. c++;
  14489. }
  14490. sstr[c] = '\0';
  14491. strcpy(temprecurrencyKindStr,sstr);
  14492. }
  14493. else
  14494. {
  14495. strcpy(temprecurrencyKindStr,"");
  14496. }
  14497. //***********validFrom**************/
  14498. c = 0;
  14499. loc = strstr(sLineWord, "validFrom");
  14500. if(loc != NULL)
  14501. {
  14502. memset(sstr ,0, sizeof(sstr) );
  14503. while (loc[3+strlen("validFrom")+c] != '\"')
  14504. {
  14505. sstr[c] = loc[3+strlen("validFrom")+c];
  14506. c++;
  14507. }
  14508. sstr[c] = '\0';
  14509. strcpy(tempvalidFromStr,sstr);
  14510. }
  14511. else
  14512. {
  14513. strcpy(tempvalidFromStr,"");
  14514. }
  14515. //***********validTo **************/
  14516. c = 0;
  14517. loc = strstr(sLineWord, "validTo");
  14518. if(loc != NULL)
  14519. {
  14520. memset(sstr ,0, sizeof(sstr) );
  14521. while (loc[3+strlen("validTo")+c] != '\"')
  14522. {
  14523. sstr[c] = loc[3+strlen("validTo")+c];
  14524. c++;
  14525. }
  14526. sstr[c] = '\0';
  14527. strcpy(tempvalidToStr,sstr);
  14528. }
  14529. else
  14530. {
  14531. strcpy(tempvalidToStr,"");
  14532. }
  14533. //***********duration**************/
  14534. c = 0;
  14535. loc = strstr(sLineWord, "duration");
  14536. if(loc != NULL)
  14537. {
  14538. memset(sstr ,0, sizeof(sstr) );
  14539. while (loc[2+strlen("duration")+c] != ',')
  14540. {
  14541. sstr[c] = loc[2+strlen("duration")+c];
  14542. c++;
  14543. }
  14544. sstr[c] = '\0';
  14545. tempdurationInt = atoi(sstr);
  14546. }
  14547. else
  14548. {
  14549. tempdurationInt = 0;
  14550. }
  14551. //**********startSchedule**********/
  14552. c = 0;
  14553. loc = strstr(sLineWord, "startSchedule");
  14554. if(loc != NULL)
  14555. {
  14556. memset(sstr ,0, sizeof(sstr) );
  14557. while (loc[3+strlen("startSchedule")+c] != '\"')
  14558. {
  14559. sstr[c] = loc[3+strlen("startSchedule")+c];
  14560. c++;
  14561. }
  14562. sstr[c] = '\0';
  14563. strcpy(tempstartScheduleStr, sstr);
  14564. strcpy(TxDefaultProfileScheduleStr, sstr);
  14565. }
  14566. else
  14567. {
  14568. strcpy(tempstartScheduleStr, "");
  14569. strcpy(TxDefaultProfileScheduleStr, "");
  14570. }
  14571. //**********chargingRateUnit**********/
  14572. c = 0;
  14573. loc = strstr(sLineWord, "chargingRateUnit");
  14574. memset(sstr ,0, sizeof(sstr) );
  14575. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14576. {
  14577. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14578. c++;
  14579. }
  14580. sstr[c] = '\0';
  14581. strcpy(tempchargingRateUnitStr, sstr);
  14582. //**********minChargingRate*******/
  14583. c = 0;
  14584. loc = strstr(sLineWord, "minChargingRate");
  14585. if(loc != NULL)
  14586. {
  14587. memset(sstr ,0, sizeof(sstr) );
  14588. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14589. {
  14590. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14591. c++;
  14592. }
  14593. sstr[c] = '\0';
  14594. tempminChargingRateFloat = atof(sstr);
  14595. }
  14596. else
  14597. {
  14598. tempminChargingRateFloat = 0.0;
  14599. }
  14600. //
  14601. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14602. tp.tm_isdst = -1;
  14603. time_t utc = mktime(&tp);
  14604. time_t t = time(NULL);
  14605. diff_t = difftime(t, utc);
  14606. printf("diff between startScheduleStr and now =%f\n",diff_t);
  14607. //parsing strings to words
  14608. i = 0;
  14609. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14610. loc = loc+3+strlen("chargingSchedulePeriod");
  14611. pch = strtok(loc ,"{");
  14612. while (pch != NULL)
  14613. {
  14614. strcpy(SchedulePeriodList[i], pch);
  14615. pch = strtok (NULL, "{");
  14616. i = i + 1;
  14617. }
  14618. n_SchedulePeriods = i;
  14619. for(int i=0;i<n_SchedulePeriods;i++)
  14620. {
  14621. //*************startPeriod****************/
  14622. c = 0;
  14623. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14624. memset(sstr ,0, sizeof(sstr) );
  14625. while (loc[strlen("startPeriod")+2+c] != ',')
  14626. {
  14627. sstr[c] = loc[strlen("startPeriod")+2+c];
  14628. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14629. c++;
  14630. }
  14631. sstr[c] = '\0';
  14632. tempStartPeriodInt = atoi(sstr);
  14633. //*************limit****************/
  14634. c = 0;
  14635. loc = strstr(SchedulePeriodList[i], "limit");
  14636. memset(sstr ,0, sizeof(sstr) );
  14637. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14638. {
  14639. sstr[c] = loc[strlen("limit")+2+c];
  14640. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14641. c++;
  14642. }
  14643. sstr[c] = '\0';
  14644. tempLimitInt = atof(sstr);
  14645. //*************numberPhases****************/
  14646. c = 0;
  14647. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14648. memset(sstr ,0, sizeof(sstr) );
  14649. if(loc != NULL)
  14650. {
  14651. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14652. {
  14653. sstr[c] = loc[strlen("numberPhases")+2+c];
  14654. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14655. c++;
  14656. }
  14657. sstr[c] = '\0';
  14658. tempNumberPhasesInt = atoi(sstr);
  14659. }
  14660. else
  14661. {
  14662. tempNumberPhasesInt = 0;
  14663. }
  14664. if(j == 0)
  14665. {
  14666. TxDefaultProfile.Duration = tempdurationInt;
  14667. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  14668. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  14669. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14670. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14671. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14672. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  14673. TxDefaultProfile_TEMP.TransactionId = 0;
  14674. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14675. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14676. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14677. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14678. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14679. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14680. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14681. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14682. }
  14683. else
  14684. {
  14685. //other stack level charging Profile
  14686. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  14687. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  14688. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  14689. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  14690. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  14691. }
  14692. }
  14693. if(MinChargingRate < tempminChargingRateFloat)
  14694. {
  14695. MinChargingRate = tempminChargingRateFloat;
  14696. }
  14697. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14698. if(confirmPeriods < n_SchedulePeriods)
  14699. confirmPeriods = n_SchedulePeriods;
  14700. j = j + 1;
  14701. }
  14702. fclose(fptr1);
  14703. //Stacking Charging Profiles
  14704. for(int l=0; l <(j-1) ;l++)
  14705. {
  14706. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  14707. {
  14708. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  14709. {
  14710. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  14711. {
  14712. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  14713. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  14714. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  14715. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14716. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14717. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14718. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14719. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14720. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14721. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14722. }
  14723. else
  14724. {
  14725. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14726. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14727. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14728. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14729. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14730. }
  14731. }
  14732. }
  14733. }//end of Stacking Charging Profiles
  14734. }// end else
  14735. }// the end of ACCESS TxDefaultProfile
  14736. //****************************TxProfile************************************************/
  14737. memset(fname, 0, sizeof fname);
  14738. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  14739. TxProfileIsNull=TRUE;
  14740. if((access(fname,F_OK))!=-1)
  14741. {
  14742. fptr1 = fopen(fname, "r");
  14743. c = 0;
  14744. c = fgetc(fptr1);
  14745. //DEBUG_INFO("c:%d\n",c);
  14746. rewind(fptr1);
  14747. if(c == EOF)
  14748. {
  14749. DEBUG_INFO("\n End of file reached.");
  14750. TxProfileIsNull=TRUE;
  14751. fclose(fptr1);
  14752. }
  14753. else
  14754. {
  14755. TxProfileIsNull=FALSE;
  14756. while(fscanf(fptr1, "%s", word) != EOF)
  14757. {
  14758. if(strcmp(word, "chargingProfileId") == 0)
  14759. {
  14760. n_chargingProfile = n_chargingProfile + 1;
  14761. }
  14762. }
  14763. rewind(fptr1);
  14764. //search Charging Profile Element
  14765. int i= 0;
  14766. int j= 0;
  14767. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14768. #if 0
  14769. /***********connectorId****************/
  14770. c = 0;
  14771. loc = strstr(sLineWord, "connectorId");
  14772. memset(sstr ,0, sizeof(sstr) );
  14773. while (loc[strlen("connectorId")+2+c] != ',')
  14774. {
  14775. sstr[c] = loc[strlen("connectorId")+2+c];
  14776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14777. c++;
  14778. }
  14779. sstr[c] = '\0';
  14780. tempconnectorIdInt = atoi(sstr);
  14781. #endif
  14782. //***********chargingProfileId**************/
  14783. c = 0;
  14784. loc = strstr(sLineWord, "chargingProfileId");
  14785. memset(sstr ,0, sizeof(sstr) );
  14786. if(loc != NULL)
  14787. {
  14788. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14789. {
  14790. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14791. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14792. c++;
  14793. }
  14794. sstr[c] = '\0';
  14795. tempchargingProfileId = atoi(sstr);
  14796. }
  14797. else
  14798. {
  14799. tempchargingProfileId = 0;
  14800. }
  14801. //***********transactionId **************/
  14802. c = 0;
  14803. loc = strstr(sLineWord, "transactionId");
  14804. //DEBUG_INFO("loc=%s\n",loc);
  14805. memset(sstr ,0, sizeof(sstr) );
  14806. if(loc != NULL)
  14807. {
  14808. while (loc[2+strlen("transactionId")+c] != '\"')
  14809. {
  14810. sstr[c] = loc[2+strlen("transactionId")+c];
  14811. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14812. c++;
  14813. }
  14814. sstr[c] = '\0';
  14815. temptransactionId = atoi(sstr);
  14816. }
  14817. else
  14818. {
  14819. temptransactionId = 0;
  14820. }
  14821. //***********stackLevel**************/
  14822. c = 0;
  14823. loc = strstr(sLineWord, "stackLevel");
  14824. //DEBUG_INFO("loc=%s\n",loc);
  14825. memset(sstr ,0, sizeof(sstr) );
  14826. if(loc != NULL)
  14827. {
  14828. while (loc[2+strlen("stackLevel")+c] != '\"')
  14829. {
  14830. sstr[c] = loc[2+strlen("stackLevel")+c];
  14831. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14832. c++;
  14833. }
  14834. sstr[c] = '\0';
  14835. tempstackLevel = atoi(sstr);
  14836. }
  14837. else
  14838. {
  14839. tempstackLevel = 0;
  14840. }
  14841. //***********chargingProfilePurpose **************/
  14842. c = 0;
  14843. loc = strstr(sLineWord, "chargingProfilePurpose");
  14844. //DEBUG_INFO("loc=%s\n",loc);
  14845. memset(sstr ,0, sizeof(sstr) );
  14846. if(loc != NULL)
  14847. {
  14848. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14849. {
  14850. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14851. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14852. c++;
  14853. }
  14854. sstr[c] = '\0';
  14855. strcpy(tempchargingProfilePurposeStr,sstr);
  14856. }
  14857. else
  14858. {
  14859. strcpy(tempchargingProfilePurposeStr,"");
  14860. }
  14861. //***********chargingProfileKind **************/
  14862. c = 0;
  14863. loc = strstr(sLineWord, "chargingProfileKind");
  14864. //DEBUG_INFO("loc=%s\n",loc);
  14865. memset(sstr ,0, sizeof(sstr) );
  14866. if(loc != NULL)
  14867. {
  14868. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14869. {
  14870. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14871. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14872. c++;
  14873. }
  14874. sstr[c] = '\0';
  14875. strcpy(tempchargingProfileKindStr,sstr);
  14876. }
  14877. else
  14878. {
  14879. strcpy(tempchargingProfileKindStr,"");
  14880. }
  14881. //***********recurrencyKind **************/
  14882. c = 0;
  14883. loc = strstr(sLineWord, "recurrencyKind");
  14884. //DEBUG_INFO("loc=%s\n",loc);
  14885. memset(sstr ,0, sizeof(sstr) );
  14886. if(loc != NULL)
  14887. {
  14888. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14889. {
  14890. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14891. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14892. c++;
  14893. }
  14894. sstr[c] = '\0';
  14895. strcpy(temprecurrencyKindStr,sstr);
  14896. }
  14897. else
  14898. {
  14899. strcpy(temprecurrencyKindStr,"");
  14900. }
  14901. //***********validFrom**************/
  14902. c = 0;
  14903. loc = strstr(sLineWord, "validFrom");
  14904. if(loc != NULL)
  14905. {
  14906. memset(sstr ,0, sizeof(sstr) );
  14907. while (loc[3+strlen("validFrom")+c] != '\"')
  14908. {
  14909. sstr[c] = loc[3+strlen("validFrom")+c];
  14910. c++;
  14911. }
  14912. sstr[c] = '\0';
  14913. strcpy(tempvalidFromStr,sstr);
  14914. }
  14915. else
  14916. {
  14917. strcpy(tempvalidFromStr,"");
  14918. }
  14919. //***********validTo**************/
  14920. c = 0;
  14921. loc = strstr(sLineWord, "validTo");
  14922. if(loc != NULL)
  14923. {
  14924. memset(sstr ,0, sizeof(sstr) );
  14925. while (loc[3+strlen("validTo")+c] != '\"')
  14926. {
  14927. sstr[c] = loc[3+strlen("validTo")+c];
  14928. c++;
  14929. }
  14930. sstr[c] = '\0';
  14931. strcpy(tempvalidToStr,sstr);
  14932. }
  14933. else
  14934. {
  14935. strcpy(tempvalidToStr,"");
  14936. }
  14937. //***********duration**************/
  14938. c = 0;
  14939. loc = strstr(sLineWord, "duration");
  14940. //DEBUG_INFO("loc=%s\n",loc);
  14941. memset(sstr ,0, sizeof(sstr) );
  14942. if(loc != NULL)
  14943. {
  14944. while (loc[2+strlen("duration")+c] != '\"')
  14945. {
  14946. sstr[c] = loc[2+strlen("duration")+c];
  14947. c++;
  14948. }
  14949. sstr[c] = '\0';
  14950. tempdurationInt = atoi(sstr);
  14951. }
  14952. else
  14953. {
  14954. tempdurationInt = 0;
  14955. }
  14956. //**********startSchedule**********/
  14957. c = 0;
  14958. loc = strstr(sLineWord, "startSchedule");
  14959. if(loc != NULL)
  14960. {
  14961. memset(sstr ,0, sizeof(sstr) );
  14962. while (loc[3+strlen("startSchedule")+c] != '\"')
  14963. {
  14964. sstr[c] = loc[3+strlen("startSchedule")+c];
  14965. c++;
  14966. }
  14967. sstr[c] = '\0';
  14968. strcpy(tempstartScheduleStr, sstr);
  14969. strcpy(TxProfileScheduleStr, sstr);
  14970. }
  14971. else
  14972. {
  14973. strcpy(tempstartScheduleStr, "");
  14974. strcpy(TxProfileScheduleStr, "");
  14975. }
  14976. //**********chargingRateUnit**********/
  14977. c = 0;
  14978. loc = strstr(sLineWord, "chargingRateUnit");
  14979. memset(sstr ,0, sizeof(sstr) );
  14980. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14981. {
  14982. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14983. c++;
  14984. }
  14985. sstr[c] = '\0';
  14986. strcpy(tempchargingRateUnitStr, sstr);
  14987. //**********minChargingRate*******/
  14988. c = 0;
  14989. loc = strstr(sLineWord, "minChargingRate");
  14990. if(loc != NULL)
  14991. {
  14992. memset(sstr ,0, sizeof(sstr) );
  14993. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14994. {
  14995. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14996. c++;
  14997. }
  14998. sstr[c] = '\0';
  14999. tempminChargingRateFloat = atof(sstr);
  15000. }
  15001. else
  15002. {
  15003. tempminChargingRateFloat = 0.0;
  15004. }
  15005. //
  15006. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15007. tp.tm_isdst = -1;
  15008. time_t utc = mktime(&tp);
  15009. time_t t = time(NULL);
  15010. diff_t = difftime(t, utc);
  15011. //DEBUG_INFO("diff_t=%f\n",diff_t);
  15012. //parsing strings to words
  15013. i = 0;
  15014. loc = strstr(sLineWord, "chargingSchedulePeriod");
  15015. loc = loc+3+strlen("chargingSchedulePeriod");
  15016. pch = strtok(loc ,"{");
  15017. while (pch != NULL)
  15018. {
  15019. strcpy(SchedulePeriodList[i], pch);
  15020. pch = strtok (NULL, "{");
  15021. i = i + 1;
  15022. }
  15023. n_SchedulePeriods = i;
  15024. for(int i=0;i<n_SchedulePeriods;i++)
  15025. {
  15026. //*************startPeriod****************/
  15027. c = 0;
  15028. loc = strstr(SchedulePeriodList[i], "startPeriod");
  15029. memset(sstr ,0, sizeof(sstr) );
  15030. while (loc[strlen("startPeriod")+2+c] != ',')
  15031. {
  15032. sstr[c] = loc[strlen("startPeriod")+2+c];
  15033. //printf("i=%d sstr=%c\n",c, sstr[c]);
  15034. c++;
  15035. }
  15036. sstr[c] = '\0';
  15037. tempStartPeriodInt = atoi(sstr);
  15038. //*************limit****************/
  15039. c = 0;
  15040. loc = strstr(SchedulePeriodList[i], "limit");
  15041. memset(sstr ,0, sizeof(sstr) );
  15042. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  15043. {
  15044. sstr[c] = loc[strlen("limit")+2+c];
  15045. //printf("i=%d sstr=%c\n",c, sstr[c]);
  15046. c++;
  15047. }
  15048. sstr[c] = '\0';
  15049. tempLimitInt = atof(sstr);
  15050. //*************numberPhases****************/
  15051. c = 0;
  15052. loc = strstr(SchedulePeriodList[i], "numberPhases");
  15053. memset(sstr ,0, sizeof(sstr) );
  15054. if(loc != NULL)
  15055. {
  15056. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  15057. {
  15058. sstr[c] = loc[strlen("numberPhases")+2+c];
  15059. //printf("i=%d sstr=%c\n",c, sstr[c]);
  15060. c++;
  15061. }
  15062. sstr[c] = '\0';
  15063. tempNumberPhasesInt = atoi(sstr);
  15064. }
  15065. else
  15066. {
  15067. tempNumberPhasesInt = 0;
  15068. }
  15069. //TxProfile.Duration = durationInt;
  15070. TxProfile.TotalPeriod = n_SchedulePeriods;
  15071. TxProfile.Period[i].Limit = tempLimitInt;
  15072. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  15073. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  15074. }
  15075. if(MinChargingRate < tempminChargingRateFloat)
  15076. {
  15077. MinChargingRate = tempminChargingRateFloat;
  15078. }
  15079. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  15080. if(confirmPeriods < n_SchedulePeriods)
  15081. confirmPeriods = n_SchedulePeriods;
  15082. if(j == 0)
  15083. {
  15084. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  15085. TxProfile_TEMP.StackLevel = tempstackLevel;
  15086. TxProfile_TEMP.TransactionId = 0;
  15087. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  15088. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  15089. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  15090. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  15091. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  15092. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  15093. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  15094. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  15095. }
  15096. }
  15097. fclose(fptr1);
  15098. }
  15099. }// the end of ACCESS TxProfile
  15100. //-----------------------------------------------CompositeSchedule--------------------------//
  15101. int period=0;
  15102. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  15103. {
  15104. //TxProfile
  15105. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  15106. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  15107. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  15108. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  15109. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15110. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15111. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15112. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15113. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15114. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15115. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15116. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15117. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15118. for(int k=0; k < TxProfile.TotalPeriod;k++)
  15119. {
  15120. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  15121. {
  15122. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15123. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15124. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15125. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15126. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15127. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15128. period = period + 1;
  15129. }
  15130. else
  15131. {
  15132. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  15133. {
  15134. }
  15135. else
  15136. {
  15137. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15138. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15139. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15140. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15141. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15142. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15143. period = period + 1;
  15144. }
  15145. }
  15146. }
  15147. struct tm tp;
  15148. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15149. tp.tm_isdst = -1;
  15150. time_t utc = mktime(&tp);
  15151. time_t t = time(NULL);
  15152. double diff_f = difftime(t, utc);
  15153. int diff_i;// = (int)diff_f;
  15154. int quotient; // = diff_i / 86400;//86400 seconds/day
  15155. if(diff_f >= 0)
  15156. {
  15157. diff_i = (int)diff_f;
  15158. quotient = diff_i / 86400;//86400 seconds/day
  15159. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15160. {
  15161. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  15162. {
  15163. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15164. {
  15165. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15166. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15167. }
  15168. else
  15169. {
  15170. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15171. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15172. }
  15173. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15174. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15175. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15176. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15177. period = period + 1;
  15178. }
  15179. }
  15180. }// end of if(diff_f >= 0)
  15181. }
  15182. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15183. {
  15184. //TxDefaultProfile
  15185. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15186. struct tm tp;
  15187. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15188. tp.tm_isdst = -1;
  15189. time_t utc = mktime(&tp);
  15190. time_t t = time(NULL);
  15191. double diff_f = difftime(t, utc);
  15192. int diff_i;// = (int)diff_f;
  15193. int quotient; // = diff_i / 86400;//86400 seconds/day
  15194. int remainder;
  15195. //---- Define StartSchedule----/
  15196. struct tm *gtime;
  15197. time_t now;
  15198. char buf[28];
  15199. //---Read the current system time---/
  15200. time(&now);
  15201. //---Convert the system time to GMT (now UTC)---/
  15202. gtime = gmtime(&now);
  15203. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15204. if(diff_f >= 0)
  15205. {
  15206. diff_i = (int)diff_f;
  15207. quotient = diff_i / 86400;//86400 seconds/day
  15208. remainder = diff_i % 86400;
  15209. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15210. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15211. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  15213. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15214. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15215. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15216. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15217. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15218. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15219. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15220. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15221. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  15222. {
  15223. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15224. {
  15225. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15226. {
  15227. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15228. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15229. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15230. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15231. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15232. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15233. period = period + 1;
  15234. }
  15235. else
  15236. {
  15237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15238. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15239. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15240. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  15241. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15242. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15243. period = period + 1;
  15244. }
  15245. }
  15246. }
  15247. } // end of diff_f >= 0
  15248. }
  15249. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  15250. {
  15251. //TxDefaultProfile
  15252. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15253. struct tm tp;
  15254. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15255. tp.tm_isdst = -1;
  15256. time_t utc = mktime(&tp);
  15257. time_t t = time(NULL);
  15258. double diff_f = difftime(t, utc);
  15259. int diff_i;// = (int)diff_f;
  15260. int quotient; // = diff_i / 86400;//86400 seconds/day
  15261. int remainder;
  15262. //---- Define StartSchedule----/
  15263. struct tm *gtime;
  15264. time_t now;
  15265. char buf[28];
  15266. //---Read the current system time---/
  15267. time(&now);
  15268. //---Convert the system time to GMT (now UTC)---/
  15269. gtime = gmtime(&now);
  15270. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15271. if(diff_f >= 0)
  15272. {
  15273. diff_i = (int)diff_f;
  15274. quotient = diff_i / 86400;//86400 seconds/day
  15275. remainder = diff_i % 86400;
  15276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15277. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15278. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  15280. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15281. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15282. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15283. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15284. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15285. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  15286. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15287. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15288. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15289. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15290. {
  15291. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15292. {
  15293. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15294. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15295. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15296. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15297. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15298. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15299. period = period + 1;
  15300. }
  15301. }
  15302. } //end of diff_f >= 0
  15303. }
  15304. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15305. {
  15306. //ChargePointMaxProfile
  15307. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  15308. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  15309. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15310. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  15311. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  15312. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15313. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15314. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  15315. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  15316. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  15317. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  15318. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  15319. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  15320. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  15321. {
  15322. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  15323. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  15324. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  15325. period = period + 1;
  15326. }
  15327. }
  15328. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  15329. {
  15330. //TxProfile Daily
  15331. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  15332. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  15333. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  15334. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  15335. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15336. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15337. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15338. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15339. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15340. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15341. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15342. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15343. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15344. for(int l=0; l< TxProfile.TotalPeriod; l++)
  15345. {
  15346. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  15347. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  15348. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  15349. }
  15350. }
  15351. confirmPeriods = period;
  15352. if(confirmPeriods != 0)
  15353. {
  15354. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  15355. DEBUG_INFO("\nchargingProfileId =%d, transactionId =%d\n, stackLevel =%d, chargingProfilePurpose=%s, chargingProfileKind=%s, recurrencyKind =%s, validFrom =%s, validTo =%s, duration=%d , startSchedule =%s, chargingRateUnit=%s, minChargingRate=%f,"
  15356. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  15357. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  15358. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  15359. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  15360. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  15361. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  15362. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  15363. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  15364. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  15365. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  15366. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  15367. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  15368. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  15369. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  15370. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  15371. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  15372. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  15373. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  15374. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  15375. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  15376. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  15377. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  15378. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  15379. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  15380. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  15381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  15382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  15383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  15384. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  15385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  15386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  15387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  15388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  15389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  15390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  15391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  15392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  15393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  15394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  15395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  15396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  15397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  15398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  15399. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  15400. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  15401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  15402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  15403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  15404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  15405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  15406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  15407. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  15408. }
  15409. }
  15410. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15411. void storeTempStopTransaction(int gun_index)
  15412. {
  15413. //int result = FAIL;
  15414. //char message[1500]={0};
  15415. char guid[37]={0};
  15416. int tempIndex = 0;
  15417. //char tempdata[65]={0};
  15418. //int idx_sample=0;
  15419. DEBUG_ERROR("sendStopTransactionRequest \n");
  15420. memset(queuedata, 0, sizeof(queuedata));
  15421. //ENERGY_ACTIVE_IMPORT_REGISTER
  15422. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15423. if(gunType[gun_index] == 'J')
  15424. {
  15425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15426. {
  15427. tempIndex = ((gun_index==2) ? 1: 0);
  15428. }
  15429. else
  15430. {
  15431. tempIndex = gun_index;
  15432. }
  15433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15434. {
  15435. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15436. {
  15437. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  15438. }
  15439. }// END OF CHAdeMO_QUANTITY
  15440. }
  15441. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15442. {
  15443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15444. {
  15445. tempIndex = ((gun_index==2) ? 1: 0);
  15446. }
  15447. else
  15448. {
  15449. tempIndex = gun_index;
  15450. }
  15451. for (int index = 0; index < CCS_QUANTITY; index++)
  15452. {
  15453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15454. {
  15455. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  15456. }
  15457. }// END OF CCS_QUANTITY
  15458. }
  15459. else if(gunType[gun_index] == 'G')
  15460. {
  15461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15462. {
  15463. tempIndex = ((gun_index==2) ? 1: 0);
  15464. }
  15465. else
  15466. {
  15467. tempIndex = gun_index;
  15468. }
  15469. for (int index = 0; index < GB_QUANTITY; index++)
  15470. {
  15471. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15472. {
  15473. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  15474. }
  15475. }// END OF GB_QUANTITY
  15476. }
  15477. else
  15478. {
  15479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15480. {
  15481. tempIndex = 2;
  15482. }
  15483. else
  15484. {
  15485. tempIndex = gun_index;
  15486. }
  15487. for (int index = 0; index < AC_QUANTITY; index++)
  15488. {
  15489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15490. {
  15491. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  15492. }
  15493. }// END OF AC_QUANTITY
  15494. }
  15495. //Stop Transaction Time
  15496. struct timeval tmnow;
  15497. struct tm *tm;
  15498. char buf[28];//, usec_buf[6];
  15499. gettimeofday(&tmnow, NULL);
  15500. time_t t;
  15501. t = time(NULL);
  15502. /*UTC time and date*/
  15503. tm = gmtime(&t);
  15504. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15506. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15508. random_uuid(guid);
  15509. /***********************************transactionData******************************************************/
  15510. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  15511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15512. //=================================
  15513. //1. Transaction_Begin
  15514. //=================================
  15515. // Energy.Active.Export.Interval
  15516. //idx_sample=0;
  15517. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  15518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  15521. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15522. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15523. {
  15524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15525. }
  15526. else
  15527. {
  15528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15529. }
  15530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15532. //=================================
  15533. //2. Transaction_End
  15534. //=================================
  15535. //2.1 Current.Export
  15536. //idx_sample=1;
  15537. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15538. if(gunType[gun_index] == 'J')
  15539. {
  15540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15541. {
  15542. tempIndex = ((gun_index==2) ? 1: 0);
  15543. }
  15544. else
  15545. {
  15546. tempIndex = gun_index;
  15547. }
  15548. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15549. {
  15550. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15551. {
  15552. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15553. }
  15554. }// End of for CHAdeMO_QUANTITY
  15555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15556. }
  15557. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15558. {
  15559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15560. {
  15561. tempIndex = ((gun_index==2) ? 1: 0);
  15562. }
  15563. else
  15564. {
  15565. tempIndex = gun_index;
  15566. }
  15567. for (int index = 0; index < CCS_QUANTITY; index++)
  15568. {
  15569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15570. {
  15571. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15572. }
  15573. }// End of for CCS_QUANTITY
  15574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15575. }
  15576. else if(gunType[gun_index] == 'G')
  15577. {
  15578. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15579. {
  15580. tempIndex = ((gun_index==2) ? 1: 0);
  15581. }
  15582. else
  15583. {
  15584. tempIndex = gun_index;
  15585. }
  15586. for (int index = 0; index < GB_QUANTITY; index++)
  15587. {
  15588. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15589. {
  15590. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15591. }
  15592. }// End of for GB_QUANTITY
  15593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15594. }
  15595. else
  15596. {
  15597. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15598. {
  15599. tempIndex = 2;
  15600. }
  15601. else
  15602. {
  15603. tempIndex = gun_index;
  15604. }
  15605. for (int index = 0; index < AC_QUANTITY; index++)
  15606. {
  15607. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15608. {
  15609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15610. }
  15611. }// End of for AC_QUANTITY
  15612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15613. }
  15614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15617. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15620. //2.2 Energy.Active.Export.Interval
  15621. //idx_sample=2;
  15622. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15623. if(gunType[gun_index] == 'J')
  15624. {
  15625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15626. {
  15627. tempIndex = ((gun_index==2) ? 1: 0);
  15628. }
  15629. else
  15630. {
  15631. tempIndex = gun_index;
  15632. }
  15633. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15634. {
  15635. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15636. {
  15637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15638. }
  15639. }// END OF CHAdeMO_QUANTITY
  15640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15641. }
  15642. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15643. {
  15644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15645. {
  15646. tempIndex = ((gun_index==2) ? 1: 0);
  15647. }
  15648. else
  15649. {
  15650. tempIndex = gun_index;
  15651. }
  15652. for (int index = 0; index < CCS_QUANTITY; index++)
  15653. {
  15654. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15655. {
  15656. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15657. }
  15658. }// END OF CCS_QUANTITY
  15659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15660. }
  15661. else if(gunType[gun_index] == 'G')
  15662. {
  15663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15664. {
  15665. tempIndex = ((gun_index==2) ? 1: 0);
  15666. }
  15667. else
  15668. {
  15669. tempIndex = gun_index;
  15670. }
  15671. for (int index = 0; index < GB_QUANTITY; index++)
  15672. {
  15673. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15674. {
  15675. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15676. }
  15677. }// END OF GB_QUANTITY
  15678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15679. }
  15680. else
  15681. {
  15682. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15683. {
  15684. tempIndex = 2;
  15685. }
  15686. else
  15687. {
  15688. tempIndex = gun_index;
  15689. }
  15690. for (int index = 0; index < AC_QUANTITY; index++)
  15691. {
  15692. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15693. {
  15694. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15695. }
  15696. }// END OF AC_QUANTITY
  15697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15698. }
  15699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15702. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15705. //2.3 Power.Active.Export
  15706. //idx_sample=3;
  15707. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15708. if(gunType[gun_index] == 'J')
  15709. {
  15710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15711. {
  15712. tempIndex = ((gun_index==2) ? 1: 0);
  15713. }
  15714. else
  15715. {
  15716. tempIndex = gun_index;
  15717. }
  15718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15719. {
  15720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15721. {
  15722. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15723. }
  15724. } // End for CHAdeMO_QUANTITY
  15725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15726. }
  15727. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15728. {
  15729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15730. {
  15731. tempIndex = ((gun_index==2) ? 1: 0);
  15732. }
  15733. else
  15734. {
  15735. tempIndex = gun_index;
  15736. }
  15737. for (int index = 0; index < CCS_QUANTITY; index++)
  15738. {
  15739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15740. {
  15741. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15742. }
  15743. } // END for CCS_QUANTITY
  15744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15745. }
  15746. else if(gunType[gun_index] == 'G')
  15747. {
  15748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15749. {
  15750. tempIndex = ((gun_index==2) ? 1: 0);
  15751. }
  15752. else
  15753. {
  15754. tempIndex = gun_index;
  15755. }
  15756. for (int index = 0; index < GB_QUANTITY; index++)
  15757. {
  15758. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15759. {
  15760. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15761. }
  15762. }// END for GB_QUANTITY
  15763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15764. }
  15765. else
  15766. {
  15767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15768. {
  15769. tempIndex = 2;
  15770. }
  15771. else
  15772. {
  15773. tempIndex = gun_index;
  15774. }
  15775. for (int index = 0; index < AC_QUANTITY; index++)
  15776. {
  15777. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15778. {
  15779. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15780. }
  15781. } // END for AC_QUANTITY
  15782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15783. }
  15784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15787. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15790. //2.4 Voltage
  15791. //idx_sample=4;
  15792. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15793. if(gunType[gun_index] == 'J')
  15794. {
  15795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15796. {
  15797. tempIndex = ((gun_index==2) ? 1: 0);
  15798. }
  15799. else
  15800. {
  15801. tempIndex = gun_index;
  15802. }
  15803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15804. {
  15805. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15806. {
  15807. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15808. }
  15809. } // END OF FOR CHAdeMO_QUANTITY
  15810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15811. }
  15812. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15813. {
  15814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15815. {
  15816. tempIndex = ((gun_index==2) ? 1: 0);
  15817. }
  15818. else
  15819. {
  15820. tempIndex = gun_index;
  15821. }
  15822. for (int index = 0; index < CCS_QUANTITY; index++)
  15823. {
  15824. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15825. {
  15826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15827. }
  15828. } // END OF FOR CCS_QUANTITY
  15829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15830. }
  15831. else if(gunType[gun_index] == 'G')
  15832. {
  15833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15834. {
  15835. tempIndex = ((gun_index==2) ? 1: 0);
  15836. }
  15837. else
  15838. {
  15839. tempIndex = gun_index;
  15840. }
  15841. for (int index = 0; index < GB_QUANTITY; index++)
  15842. {
  15843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15844. {
  15845. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15846. }
  15847. } // END OF FOR GB_QUANTITY
  15848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15849. }
  15850. else
  15851. {
  15852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15853. {
  15854. tempIndex = 2;
  15855. }
  15856. else
  15857. {
  15858. tempIndex = gun_index;
  15859. }
  15860. for (int index = 0; index < AC_QUANTITY; index++)
  15861. {
  15862. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15863. {
  15864. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15865. }
  15866. } // END OF FOR AC_QUANTITY
  15867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15868. }
  15869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15872. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15875. //2.5 SoC
  15876. //idx_sample=5;
  15877. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15878. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15879. {
  15880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15881. {
  15882. tempIndex = ((gun_index==2) ? 1: 0);
  15883. }
  15884. else
  15885. {
  15886. tempIndex = gun_index;
  15887. }
  15888. if(gunType[gun_index] == 'J')
  15889. {
  15890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15891. {
  15892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15893. {
  15894. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15895. }
  15896. }
  15897. }
  15898. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15899. {
  15900. for (int index = 0; index < CCS_QUANTITY; index++)
  15901. {
  15902. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15903. {
  15904. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15905. }
  15906. }
  15907. }
  15908. else if(gunType[gun_index] == 'G')
  15909. {
  15910. for (int index = 0; index < GB_QUANTITY; index++)
  15911. {
  15912. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15913. {
  15914. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15915. }
  15916. }
  15917. }
  15918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15922. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  15923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15924. } // END FOR DC CASE
  15925. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15926. {
  15927. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  15928. ,MESSAGE_TYPE_CALL
  15929. ,guid
  15930. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15931. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15932. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15934. ,"PowerLoss"
  15935. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  15972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  15973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  15974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  15975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  15976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  15977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  15978. );
  15979. }
  15980. else
  15981. {
  15982. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  15983. ,MESSAGE_TYPE_CALL
  15984. ,guid
  15985. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15986. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15987. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15989. ,"PowerLoss"
  15990. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  16000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  16001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  16002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  16003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  16004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  16005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  16006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  16007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  16008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  16009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  16010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  16011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  16012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  16013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  16014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  16015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  16016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  16017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  16018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  16019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  16020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  16021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  16022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  16023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  16024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  16025. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  16026. );
  16027. }
  16028. // Check File "TempStopTransaction" Exist
  16029. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  16030. {
  16031. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16032. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  16033. }
  16034. else
  16035. {
  16036. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16037. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  16038. if(log == NULL)
  16039. {
  16040. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16041. return ;
  16042. }
  16043. else
  16044. {
  16045. fclose(log);
  16046. }
  16047. }
  16048. //Add TempStopTransaction | Update TempStopTransaction
  16049. // open file for writing
  16050. FILE *outfile;
  16051. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  16052. DEBUG_INFO("data=%s\n",queuedata);
  16053. fputs(queuedata, outfile);
  16054. fputs("\n", outfile);
  16055. fclose (outfile);
  16056. }
  16057. void checkTempStopTransaction(int gun_index)
  16058. {
  16059. FILE *fptr1;
  16060. char ch;
  16061. char str[1200]={0};
  16062. char guid[37]={0};
  16063. char tempdata[65]={0};
  16064. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  16065. if (!fptr1)
  16066. {
  16067. //printf(" File not found or unable to open the input file!!\n");
  16068. return ;
  16069. }
  16070. ch=fgetc(fptr1);
  16071. //printf(" Now the content of the file %s is : \n",fname);
  16072. rewind(fptr1);
  16073. if(ch!=EOF)
  16074. {
  16075. // copy all contents to the temporary file except the specific line
  16076. while (fgets(str, 1200, fptr1) != NULL)
  16077. {
  16078. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16079. if(str[0]=='\0')
  16080. {
  16081. break;
  16082. }
  16083. random_uuid(guid);
  16084. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16085. if(hashmap_operation(0, guid, tempdata) == 1)
  16086. {
  16087. DEBUG_INFO("StopTransaction mapitem pass\n");
  16088. }
  16089. queue_operation(4, guid, str );//addq(guid, queuedata); ---> remove temporally
  16090. memset(str,0,sizeof str);
  16091. }
  16092. }
  16093. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16094. fclose(fptr1);
  16095. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  16096. }
  16097. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16098. {
  16099. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16100. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16101. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16102. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16103. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16104. }
  16105. int GetWebSocketPingInterval(void)
  16106. {
  16107. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16108. }
  16109. int GetServerSign(void)
  16110. {
  16111. return server_sign;
  16112. }
  16113. void SetServerSign(int value)
  16114. {
  16115. server_sign = value;
  16116. }
  16117. int GetBootNotificationInterval(void)
  16118. {
  16119. return BootNotificationInterval;
  16120. }
  16121. int GetInternetConn(void)
  16122. {
  16123. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16124. }
  16125. void InitialSystemValue(void)
  16126. {
  16127. int connectorIndex = 0;
  16128. //int valueASCII = 0;
  16129. server_cycle_Status = 120;
  16130. gunTotalNumber=0;
  16131. SystemInitial = 0;
  16132. localversion=0;
  16133. BootNotificationInterval = 0;
  16134. authorizeRetryTimes = 0;
  16135. GunStatusInterval = 10;
  16136. TransactionMessageAttemptsValue = 0;
  16137. TransactionMessageRetryIntervalValue = 0;
  16138. //Hear Beat
  16139. HeartBeatWithNOResponse = 0;
  16140. HeartBeatCountPerHour = 0;
  16141. HeartBeatWaitTime = 10;
  16142. FirstHeartBeat = 0;
  16143. FirmwareStatusNotificationStatus = 3; // Idle
  16144. DiagnosticsStatusNotificationStatus = 0; // Idle
  16145. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  16146. memset(statusModeChage, 0, sizeof(statusModeChage));
  16147. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  16148. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  16149. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  16150. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  16151. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  16152. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  16153. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  16154. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  16155. memset(gunType, 0, sizeof(gunType));
  16156. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16157. {
  16158. //check connector / socket type (index: 8, 9, 10)
  16159. for(int index=7; index <10 ; index++)
  16160. {
  16161. if(index != 8)
  16162. {
  16163. // DC Connector
  16164. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  16165. {
  16166. SystemInitial = SystemInitial + 1;
  16167. gunTotalNumber = gunTotalNumber + 1;
  16168. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16169. connectorIndex = connectorIndex + 1;
  16170. }
  16171. }
  16172. else
  16173. {
  16174. // AC Connector
  16175. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16176. {
  16177. SystemInitial = SystemInitial + 1;
  16178. gunTotalNumber = gunTotalNumber + 1;
  16179. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16180. connectorIndex = connectorIndex + 1;
  16181. }
  16182. }
  16183. }
  16184. //DEBUG_INFO("DC ...\n");
  16185. }
  16186. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16187. {
  16188. //check connector / socket type (index: 8, 9, 10)
  16189. for(int index=7; index <10 ; index++)
  16190. {
  16191. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16192. {
  16193. SystemInitial = SystemInitial + 1;
  16194. gunTotalNumber = gunTotalNumber + 1;
  16195. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16196. connectorIndex = connectorIndex + 1;
  16197. DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16198. }
  16199. }
  16200. DEBUG_INFO("gunTotalNumber: %d\n", gunTotalNumber);
  16201. DEBUG_INFO("connectorIndex: %d\n", connectorIndex);
  16202. DEBUG_INFO("SystemInitial: %d\n", SystemInitial);
  16203. //DEBUG_INFO("AC ...\n");
  16204. }
  16205. //Status && ConnectorPlugIn Setting
  16206. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16207. {
  16208. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16209. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16210. }
  16211. for (int index = 0; index < CCS_QUANTITY; index++)
  16212. {
  16213. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16214. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16215. }
  16216. for (int index = 0; index < GB_QUANTITY; index++)
  16217. {
  16218. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16219. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16220. }
  16221. for (int index = 0; index < AC_QUANTITY; index++)
  16222. {
  16223. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16224. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16225. }
  16226. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16227. {
  16228. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16229. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16230. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16231. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  16232. }
  16233. // Charger PRE_SYS_MODE
  16234. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  16235. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16236. clientTime.Heartbeat=time((time_t*)NULL);
  16237. sleep(1);
  16238. }
  16239. void LWS_Send(char * str)
  16240. {
  16241. //=====================================================
  16242. // Check InternetConn 0: disconnected, 1: connected
  16243. //====================================================
  16244. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  16245. {
  16246. DEBUG_INFO("\n offline now !!!\n");
  16247. return;
  16248. }
  16249. pthread_mutex_lock(&lock);
  16250. memset(SendBuffer,0,SendBufLen);
  16251. sprintf((char *)SendBuffer, "%s", str);
  16252. pthread_mutex_unlock(&lock);
  16253. lws_callback_on_writable(wsi_client);
  16254. lws_service(context, 10000);//timeout_ms
  16255. }