MessageHandler.c 670 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657
  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. static int OcppPort=0;
  113. //===============================
  114. // OCPP sign variable
  115. //===============================
  116. static int server_sign = FALSE;
  117. int server_pending = FALSE;
  118. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  119. static int BootNotificationInterval = 0;
  120. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  121. //===============================
  122. // OCPP auth variable
  123. //===============================
  124. static int authorizeRetryTimes = 0; //number of Retry times
  125. //===============================
  126. // OCPP StartTransaction transactionId variables
  127. //===============================
  128. //static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  129. //===============================
  130. // OCPP other variables
  131. //===============================
  132. //int isUpdateRequest = FALSE;
  133. static int HeartBeatWaitTime = 10;
  134. static int FirstHeartBeat = 0;
  135. static int FirmwareStatusNotificationStatus = 3; // Idle
  136. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  137. static char CurrentChargingProfileScheduleStr[30]={0};
  138. //========================================
  139. // OCPP status/previous related variables
  140. //========================================
  141. static int GunStatusInterval = 10;
  142. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  143. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  144. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  145. static int GbPreviousSystemStatus[GB_QUANTITY];
  146. static int AcPreviousSystemStatus[AC_QUANTITY];
  147. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  148. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  149. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  150. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  151. static int TransactionMessageAttemptsValue = 0;
  152. static int TransactionMessageRetryIntervalValue = 0;
  153. static struct OCPPAuthLocalElemet
  154. {
  155. int listVersionInt;
  156. char idTagstr[20];
  157. char parentIdTag[20];
  158. char expiryDate[30];
  159. char idTagstatus[16];
  160. }idTagQuery;
  161. //=============================================
  162. // OCPP HeartBeat Response Not Receive Counts
  163. //============================================
  164. static int HeartBeatWithNOResponse = 0;
  165. static int HeartBeatCountPerHour = 0;
  166. extern struct lws *wsi_client;
  167. extern struct lws_context *context;
  168. extern unsigned char SendBuffer[4096];
  169. extern int SendBufLen;
  170. extern char *random_uuid( char buf[37] );
  171. extern void split(char **arr, char *str, const char *del);
  172. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  173. extern int GetTransactionQueueNum(void);
  174. extern pthread_mutex_t mutex1;
  175. extern struct Charger_Info Charger;
  176. extern sqlite3 *db;
  177. int TransactionMessageAttemptsGet(void);
  178. int TransactionMessageRetryIntervalGet(void);
  179. int GetOcppConnStatus(void);
  180. void SetOcppConnStatus(uint8_t status);
  181. int updateSetting(char *key, char *value);
  182. int setKeyValue(char *key, char *value);
  183. void OCPP_get_TableAuthlocalAllData(void);
  184. void processUnkownKey(void);
  185. struct StructOCPPMeterValue
  186. {
  187. unsigned char TimeStamp[28];
  188. struct StructSampledValue SampledValue[10];
  189. };
  190. struct ClientTime
  191. {
  192. unsigned int Heartbeat;
  193. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  194. unsigned int StartTransaction;
  195. unsigned int StopTransaction;
  196. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  197. }clientTime;
  198. typedef union
  199. {
  200. //Operations Initiated by Central System
  201. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  202. struct
  203. {
  204. //CsMsgValue[0]
  205. unsigned char StatusNotificationReq :1; //bit 0,
  206. unsigned char StatusNotificationConf :1; //bit 0,
  207. unsigned char :6; //bit 2~7
  208. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  209. }CpinitiateMsg;
  210. CpinitiateMsg cpinitateMsg;
  211. //==========================================
  212. // Init all Enumeration & Mapping String
  213. //==========================================
  214. /*ChargePointErrorCode*/
  215. typedef enum {
  216. ConnectorLockFailure,
  217. EVCommunicationError,
  218. GroundFailure,
  219. HighTemperature,
  220. InternalError,
  221. LocalListConflict,
  222. NoError,
  223. OtherError,
  224. OverCurrentFailure,
  225. OverVoltage,
  226. PowerMeterFailure,
  227. PowerSwitchFailure,
  228. ReaderFailure,
  229. ResetFailure,
  230. UnderVoltage,
  231. WeakSignal
  232. } ChargePointErrorCode;
  233. #if 0
  234. static char *ChargePointErrorCodeStr[] = {
  235. MACROSTR(ConnectorLockFailure),
  236. MACROSTR(EVCommunicationError),
  237. MACROSTR(GroundFailure),
  238. MACROSTR(HighTemperature),
  239. MACROSTR(InternalError),
  240. MACROSTR(LocalListConflict),
  241. MACROSTR(NoError),
  242. MACROSTR(OtherError),
  243. MACROSTR(OverCurrentFailure),
  244. MACROSTR(OverVoltage),
  245. MACROSTR(PowerMeterFailure),
  246. MACROSTR(PowerSwitchFailure),
  247. MACROSTR(ReaderFailure),
  248. MACROSTR(ResetFailure),
  249. MACROSTR(UnderVoltage),
  250. MACROSTR(WeakSignal)
  251. };
  252. #endif
  253. /*ChargePointStatus*/
  254. typedef enum {
  255. Available =0,
  256. Preparing,
  257. Charging,
  258. SuspendedEVSE,
  259. SuspendedEV,
  260. Finishing,
  261. Reserved,
  262. Unavailable,
  263. Faulted
  264. } ChargePointStatus;
  265. static char * ChargePointStatusStr[] = {
  266. MACROSTR(Available),
  267. MACROSTR(Preparing),
  268. MACROSTR(Charging),
  269. MACROSTR(SuspendedEVSE),
  270. MACROSTR(SuspendedEV),
  271. MACROSTR(Finishing),
  272. MACROSTR(Reserved),
  273. MACROSTR(Unavailable),
  274. MACROSTR(Faulted)
  275. };
  276. /*AvailabilityType*/
  277. typedef enum {
  278. RegistrationStatus_Accepted,
  279. RegistrationStatus_Pending,
  280. RegistrationStatus_Rejected
  281. } RegistrationStatus;
  282. static char *RegistrationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Pending),
  285. MACROSTR(Rejected)
  286. };
  287. /*AvailabilityType*/
  288. typedef enum {
  289. Inoperative,
  290. Operative
  291. } AvailabilityType;
  292. static char *AvailabilityTypeStr[] = {
  293. MACROSTR(Inoperative),
  294. MACROSTR(Operative)
  295. };
  296. /*AvailabilityStatus*/
  297. typedef enum {
  298. Accepted,
  299. Rejected,
  300. Scheduled
  301. } AvailabilityStatus;
  302. static char *AvailabilityStatusStr[] = {
  303. MACROSTR(Accepted),
  304. MACROSTR(Rejected),
  305. MACROSTR(Scheduled)
  306. };
  307. /*ConfigurationStatus*/
  308. typedef enum {
  309. ConfigurationStatus_Accepted,
  310. ConfigurationStatus_Rejected,
  311. RebootRequired,
  312. NotSupported
  313. } ConfigurationStatus;
  314. static char *ConfigurationStatusStr[] = {
  315. MACROSTR(Accepted),
  316. MACROSTR(Rejected),
  317. MACROSTR(RebootRequired),
  318. MACROSTR(NotSupported)
  319. };
  320. /*ClearCacheStatus*/
  321. typedef enum {
  322. ClearCacheStatus_Accepted,
  323. ClearCacheStatus_Rejected
  324. } ClearCacheStatus;
  325. static char *ClearCacheStatusStr[] = {
  326. MACROSTR(Accepted),
  327. MACROSTR(Rejected)
  328. };
  329. /*ChargingProfilePurposeType*/
  330. typedef enum {
  331. ChargePointMaxProfile,
  332. TxDefaultProfile,
  333. TxProfile
  334. } ChargingProfilePurposeType;
  335. static char *ChargingProfilePurposeTypeStr[] = {
  336. MACROSTR(ChargePointMaxProfile),
  337. MACROSTR(TxDefaultProfile),
  338. MACROSTR(TxProfile)
  339. };
  340. /*ChargingProfileStatus*/
  341. typedef enum {
  342. ChargingProfileStatus_Accepted,
  343. ChargingProfileStatus_Rejected,
  344. ChargingProfileStatus_NotSupported
  345. } ChargingProfileStatus;
  346. static char *ChargingProfileStatusStr[] = {
  347. MACROSTR(Accepted),
  348. MACROSTR(Rejected),
  349. MACROSTR(NotSupported)
  350. };
  351. /*ClearChargingProfileStatus*/
  352. typedef enum {
  353. ClearChargingProfileStatus_Accepted,
  354. ClearChargingProfileStatus_Unknown
  355. } ClearChargingProfileStatus;
  356. static char *ClearChargingProfileStatusStr[] = {
  357. MACROSTR(Accepted),
  358. MACROSTR(Unknown)
  359. };
  360. /*GetCompositeScheduleStatus*/
  361. typedef enum {
  362. GetCompositeScheduleStatus_Accepted,
  363. GetCompositeScheduleStatus_Rejected
  364. } GetCompositeScheduleStatus;
  365. static char *GetCompositeScheduleStatusStr[] = {
  366. MACROSTR(Accepted),
  367. MACROSTR(Rejected)
  368. };
  369. /*ChargingRateUnitType*/
  370. typedef enum {
  371. ChargingRateUnitType_W,
  372. ChargingRateUnitType_A
  373. } ChargingRateUnitType;
  374. /*AuthorizationStatus*/
  375. typedef enum {
  376. AuthorizationStatus_Accepted ,
  377. AuthorizationStatus_Blocked ,
  378. AuthorizationStatus_Expired ,
  379. AuthorizationStatus_Invalid ,
  380. AuthorizationStatus_ConcurrentTx
  381. } AuthorizationStatus;
  382. /*UpdateType*/
  383. typedef enum {
  384. Differential ,
  385. Full
  386. } UpdateType;
  387. static char *UpdateTypeStr[] = {
  388. MACROSTR(Differential),
  389. MACROSTR(Full)
  390. };
  391. /*UpdateStatus*/
  392. typedef enum {
  393. UpdateStatus_Accepted ,
  394. UpdateStatus_Failed ,
  395. UpdateStatus_NotSupported ,
  396. UpdateStatus_VersionMismatch
  397. } UpdateStatus;
  398. static char *UpdateStatusStr[] = {
  399. MACROSTR(Accepted),
  400. MACROSTR(Failed),
  401. MACROSTR(NotSupported),
  402. MACROSTR(VersionMismatch)
  403. };
  404. /*RemoteStartStopStatus*/
  405. typedef enum {
  406. RemoteStartStopStatus_Accepted,
  407. RemoteStartStopStatus_Rejected
  408. } RemoteStartStopStatus;
  409. static char *RemoteStartStopStatusStr[] = {
  410. MACROSTR(Accepted),
  411. MACROSTR(Rejected)
  412. };
  413. /*ReservationStatus*/
  414. typedef enum {
  415. ReservationStatus_Accepted,
  416. ReservationStatus_Faulted,
  417. ReservationStatus_Occupied,
  418. ReservationStatus_Rejected,
  419. ReservationStatus_Unavailable
  420. } ReservationStatus;
  421. static char *ReservationStatusStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Faulted),
  424. MACROSTR(Occupied),
  425. MACROSTR(Rejected),
  426. MACROSTR(Unavailable)
  427. };
  428. /*ResetType*/
  429. typedef enum {
  430. Hard,
  431. Soft
  432. } ResetType;
  433. static char *ResetTypeStr[] = {
  434. MACROSTR(Hard),
  435. MACROSTR(Soft)
  436. };
  437. /*ResetStatus*/
  438. typedef enum {
  439. ResetStatus_Accepted,
  440. ResetStatus_Rejected
  441. } ResetStatus;
  442. static char *ResetStatusStr[] = {
  443. MACROSTR(Accepted),
  444. MACROSTR(Rejected)
  445. };
  446. /*DiagnosticsStatus*/
  447. typedef enum {
  448. DiagnosticsStatus_Idle,
  449. DiagnosticsStatus_Uploaded,
  450. DiagnosticsStatus_UploadFailed,
  451. DiagnosticsStatus_Uploading
  452. } DiagnosticsStatus;
  453. static char * DiagnosticsStatusStr[] = {
  454. MACROSTR(Idle),
  455. MACROSTR(Uploaded),
  456. MACROSTR(UploadFailed),
  457. MACROSTR(Uploading)
  458. };
  459. /*FirmwareStatus*/
  460. typedef enum {
  461. FirmwareStatus_Downloaded,
  462. FirmwareStatus_DownloadFailed,
  463. FirmwareStatus_Downloading,
  464. FirmwareStatus_Idle,
  465. FirmwareStatus_InstallationFailed,
  466. FirmwareStatus_Installing,
  467. FirmwareStatus_Installed
  468. } FirmwareStatus;
  469. static char * FirmwareStatusStr[] = {
  470. MACROSTR(Downloaded),
  471. MACROSTR(DownloadFailed),
  472. MACROSTR(Downloading),
  473. MACROSTR(Idle),
  474. MACROSTR(InstallationFailed),
  475. MACROSTR(Installing),
  476. MACROSTR(Installed)
  477. };
  478. /*MessageTrigger*/
  479. typedef enum {
  480. BootNotification,
  481. DiagnosticsStatusNotification,
  482. FirmwareStatusNotification,
  483. Heartbeat,
  484. MeterValues,
  485. StatusNotification
  486. } MessageTrigger;
  487. static char * MessageTriggerStr[] = {
  488. MACROSTR(BootNotification),
  489. MACROSTR(DiagnosticsStatusNotification),
  490. MACROSTR(FirmwareStatusNotification),
  491. MACROSTR(Heartbeat),
  492. MACROSTR(MeterValues),
  493. MACROSTR(StatusNotification)
  494. };
  495. /*TriggerMessageStatus*/
  496. typedef enum {
  497. TriggerMessageStatus_Accepted ,
  498. TriggerMessageStatus_Rejected ,
  499. TriggerMessageStatus_NotImplemented
  500. } TriggerMessageStatus;
  501. static char * TriggerMessageStatusStr[] = {
  502. MACROSTR(Accepted),
  503. MACROSTR(Rejected),
  504. MACROSTR(NotImplemented)
  505. };
  506. /*UnlockStatus*/
  507. typedef enum {
  508. Unlocked,
  509. UnlockFailed,
  510. UnlockStatus_NotSupported
  511. } UnlockStatus;
  512. static char * UnlockStatusStr[] = {
  513. MACROSTR(Unlocked),
  514. MACROSTR(UnlockFailed),
  515. MACROSTR(NotSupported)
  516. };
  517. /*StopTransactionReason*/
  518. typedef enum {
  519. EmergencyStop,
  520. EVDisconnected,
  521. HardReset,
  522. Local,
  523. Other,
  524. PowerLoss,
  525. Reboot,
  526. Remote,
  527. SoftReset,
  528. UnlockCommand,
  529. DeAuthorized
  530. } StopTransactionReason;
  531. #if 0
  532. static char * StopTransactionReasonStr[] = {
  533. MACROSTR(EmergencyStop),
  534. MACROSTR(EVDisconnected),
  535. MACROSTR(HardReset),
  536. MACROSTR(Local),
  537. MACROSTR(Other),
  538. MACROSTR(PowerLoss),
  539. MACROSTR(Reboot),
  540. MACROSTR(Remote),
  541. MACROSTR(SoftReset),
  542. MACROSTR(UnlockCommand),
  543. MACROSTR(DeAuthorized)
  544. };
  545. #endif
  546. /*CancelReservationStatus*/
  547. typedef enum {
  548. CancelReservationStatus_Accepted,
  549. CancelReservationStatus_Rejected
  550. } CancelReservationStatus;
  551. static char * CancelReservationStatusStr[] = {
  552. MACROSTR(Accepted),
  553. MACROSTR(Rejected)
  554. };
  555. /*ReadingContext*/
  556. typedef enum {
  557. ReadingContext_Interruption_Begin,
  558. ReadingContext_Interruption_End,
  559. ReadingContext_Other,
  560. ReadingContext_Sample_Clock,
  561. ReadingContext_Sample_Periodic ,
  562. ReadingContext_Transaction_Begin ,
  563. ReadingContext_Transaction_End,
  564. ReadingContext_Trigger
  565. } ReadingContext;
  566. static char * ReadingContextStr[] = {
  567. MACROSTR(Interruption.Begin),
  568. MACROSTR(Interruption.End),
  569. MACROSTR(Other),
  570. MACROSTR(Sample.Clock),
  571. MACROSTR(Sample.Periodic),
  572. MACROSTR(Transaction.Begin),
  573. MACROSTR(Transaction.End),
  574. MACROSTR(Trigger)
  575. };
  576. /*ValueFormat*/
  577. typedef enum {
  578. Raw,
  579. SignedData
  580. } ValueFormat;
  581. static char * ValueFormatStr[] = {
  582. MACROSTR(Raw),
  583. MACROSTR(SignedData)
  584. };
  585. /*Measurand*/
  586. typedef enum {
  587. Current_Export ,
  588. Current_Import,
  589. Current_Offered,
  590. Energy_Active_Export_Register,
  591. Energy_Active_Import_Register,
  592. Energy_Reactive_Export_Register,
  593. Energy_Reactive_Import_Register,
  594. Energy_Active_Export_Interval,
  595. Energy_Active_Import_Interval,
  596. Energy_Reactive_Export_Interval,
  597. Energy_Reactive_Import_Interval,
  598. Frequency,
  599. Power_Active_Export ,
  600. Power_Active_Import,
  601. Power_Factor,
  602. Power_Offered,
  603. Power_Reactive_Export,
  604. Power_Reactive_Import,
  605. RPM,
  606. SoC,
  607. Temperature ,
  608. Voltage
  609. } Measurand;
  610. static char * MeasurandStr[] = {
  611. MACROSTR(Current.Export),
  612. MACROSTR(Current.Import),
  613. MACROSTR(Current.Offered),
  614. MACROSTR(Energy.Active.Export.Register),
  615. MACROSTR(Energy.Active.Import.Register),
  616. MACROSTR(Energy.Reactive.Export.Register),
  617. MACROSTR(Energy.Reactive.Import.Register),
  618. MACROSTR(Energy.Active.Export.Interval),
  619. MACROSTR(Energy.Active.Import.Interval),
  620. MACROSTR(Energy.Reactive.Export.Interval),
  621. MACROSTR(Energy.Reactive.Import.Interval),
  622. MACROSTR(Frequency),
  623. MACROSTR(Power.Active.Export),
  624. MACROSTR(Power.Active.Import),
  625. MACROSTR(Power.Factor),
  626. MACROSTR(Power.Offered),
  627. MACROSTR(Power.Reactive.ExportMACROSTR),
  628. MACROSTR(Power.Reactive.Import),
  629. MACROSTR(RPM),
  630. MACROSTR(SoC),
  631. MACROSTR(Temperature),
  632. MACROSTR(Voltage)
  633. };
  634. /*Location*/
  635. typedef enum {
  636. Location_Body,
  637. Location_Cable,
  638. Location_EV,
  639. Location_Inlet ,
  640. Location_Outlet
  641. } Location;
  642. static char * LocationStr[] = {
  643. MACROSTR(Body),
  644. MACROSTR(Cable),
  645. MACROSTR(EV),
  646. MACROSTR(Inlet),
  647. MACROSTR(Outlet)
  648. };
  649. /*Phase*/
  650. typedef enum {
  651. L1,
  652. L2,
  653. L3,
  654. N,
  655. L1_N,
  656. L2_N,
  657. L3_N,
  658. L1_L2,
  659. L2_L3,
  660. L3_L1
  661. } Phase;
  662. static char * PhaseStr[] = {
  663. MACROSTR(L1),
  664. MACROSTR(L2),
  665. MACROSTR(L3),
  666. MACROSTR(N),
  667. MACROSTR(L1-N),
  668. MACROSTR(L2-N),
  669. MACROSTR(L3-N),
  670. MACROSTR(L1-L2),
  671. MACROSTR(L2-L3),
  672. MACROSTR(L3-L1)
  673. };
  674. /*UnitOfMeasure*/
  675. typedef enum {
  676. UnitOfMeasure_Wh,
  677. UnitOfMeasure_kWh ,
  678. UnitOfMeasure_varh ,
  679. UnitOfMeasure_kvarh ,
  680. UnitOfMeasure_W ,
  681. UnitOfMeasure_kW ,
  682. UnitOfMeasure_VA ,
  683. UnitOfMeasure_kVA ,
  684. UnitOfMeasure_var ,
  685. UnitOfMeasure_kvar ,
  686. UnitOfMeasure_A ,
  687. UnitOfMeasure_V ,
  688. UnitOfMeasure_Celsius ,
  689. UnitOfMeasure_Fahrenheit ,
  690. UnitOfMeasure_K ,
  691. UnitOfMeasure_Percent
  692. } UnitOfMeasure;
  693. static char * UnitOfMeasureStr[] = {
  694. MACROSTR(Wh),
  695. MACROSTR(kWh),
  696. MACROSTR(varh),
  697. MACROSTR(kvarh),
  698. MACROSTR(W),
  699. MACROSTR(kW),
  700. MACROSTR(VA),
  701. MACROSTR(kVA),
  702. MACROSTR(var),
  703. MACROSTR(kvar),
  704. MACROSTR(A),
  705. MACROSTR(V),
  706. MACROSTR(Celsius),
  707. MACROSTR(Fahrenheit),
  708. MACROSTR(K),
  709. MACROSTR(Percent)
  710. };
  711. #if 0
  712. /*Configuration enum*/
  713. enum CoreProfile {
  714. AllowOfflineTxForUnknownId=0,
  715. AuthorizationCacheEnabled,
  716. AuthorizeRemoteTxRequests,
  717. BlinkRepeat,
  718. ClockAlignedDataInterval,
  719. ConnectionTimeOut,
  720. GetConfigurationMaxKeys,
  721. HeartbeatInterval,
  722. LightIntensity,
  723. LocalAuthorizeOffline,
  724. LocalPreAuthorize,
  725. MaxEnergyOnInvalidId,
  726. MeterValuesAlignedData,
  727. MeterValuesAlignedDataMaxLength,
  728. MeterValuesSampledData,
  729. MeterValuesSampledDataMaxLength,
  730. MeterValueSampleInterval,
  731. MinimumStatusDuration,
  732. NumberOfConnectors,
  733. ResetRetries,
  734. ConnectorPhaseRotation,
  735. ConnectorPhaseRotationMaxLength,
  736. StopTransactionOnEVSideDisconnect,
  737. StopTransactionOnInvalidId,
  738. StopTxnAlignedData,
  739. StopTxnAlignedDataMaxLength,
  740. StopTxnSampledData,
  741. StopTxnSampledDataMaxLength,
  742. SupportedFeatureProfiles,
  743. SupportedFeatureProfilesMaxLength,
  744. TransactionMessageAttempts,
  745. TransactionMessageRetryInterval,
  746. UnlockConnectorOnEVSideDisconnect,
  747. WebSocketPingInterval,
  748. _CoreProfile_CNT
  749. };
  750. #endif
  751. enum LocalAuthListManagementProfile{
  752. LocalAuthListEnabled=0,
  753. LocalAuthListMaxLength,
  754. SendLocalListMaxLength,
  755. _LocalAuthListManagementProfile_CNT
  756. };
  757. enum ReservationProfile{
  758. ReserveConnectorZeroSupported
  759. };
  760. enum SmartChargingProfile{
  761. ChargeProfileMaxStackLevel,
  762. ChargingScheduleAllowedChargingRateUnit,
  763. ChargingScheduleMaxPeriods,
  764. ConnectorSwitch3to1PhaseSupported,
  765. MaxChargingProfilesInstalled
  766. };
  767. enum ChargerSystemStatus{
  768. ChargerSystemStatus_Booting,
  769. ChargerSystemStatus_Idle,
  770. ChargerSystemStatus_Authorizing,
  771. ChargerSystemStatus_Preparing,
  772. ChargerSystemStatus_Charging,
  773. ChargerSystemStatus_Terminating,
  774. ChargerSystemStatus_Alarm,
  775. ChargerSystemStatus_Fault
  776. };
  777. enum GetConfigurationKey {
  778. GetConfiguration_AllowOfflineTxForUnknownId=0,
  779. GetConfiguration_AuthorizationCacheEnabled,
  780. GetConfiguration_AuthorizeRemoteTxRequests,
  781. GetConfiguration_BlinkRepeat,
  782. GetConfiguration_ClockAlignedDataInterval,
  783. GetConfiguration_ConnectionTimeOut,
  784. GetConfiguration_GetConfigurationMaxKeys,
  785. GetConfiguration_HeartbeatInterval,
  786. GetConfiguration_LightIntensity,
  787. GetConfiguration_LocalAuthorizeOffline,
  788. GetConfiguration_LocalPreAuthorize,
  789. GetConfiguration_MaxEnergyOnInvalidId,
  790. GetConfiguration_MeterValuesAlignedData,
  791. GetConfiguration_MeterValuesAlignedDataMaxLength,
  792. GetConfiguration_MeterValuesSampledData,
  793. GetConfiguration_MeterValuesSampledDataMaxLength,
  794. GetConfiguration_MeterValueSampleInterval,
  795. GetConfiguration_MinimumStatusDuration,
  796. GetConfiguration_NumberOfConnectors,
  797. GetConfiguration_ResetRetries,
  798. GetConfiguration_ConnectorPhaseRotation,
  799. GetConfiguration_ConnectorPhaseRotationMaxLength,
  800. GetConfiguration_StopTransactionOnEVSideDisconnect,
  801. GetConfiguration_StopTransactionOnInvalidId,
  802. GetConfiguration_StopTxnAlignedData,
  803. GetConfiguration_StopTxnAlignedDataMaxLength,
  804. GetConfiguration_StopTxnSampledData,
  805. GetConfiguration_StopTxnSampledDataMaxLength,
  806. GetConfiguration_SupportedFeatureProfiles,
  807. GetConfiguration_SupportedFeatureProfilesMaxLength,
  808. GetConfiguration_TransactionMessageAttempts,
  809. GetConfiguration_TransactionMessageRetryInterval,
  810. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  811. GetConfiguration_WebSocketPingInterval,
  812. GetConfiguration_LocalAuthListEnabled,
  813. GetConfiguration_LocalAuthListMaxLength,
  814. GetConfiguration_SendLocalListMaxLength,
  815. GetConfiguration_ReserveConnectorZeroSupported,
  816. GetConfiguration_ChargeProfileMaxStackLevel,
  817. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  818. GetConfiguration_ChargingScheduleMaxPeriods,
  819. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  820. GetConfiguration_MaxChargingProfilesInstalled,
  821. };
  822. //GetConfiguration Array
  823. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  824. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  825. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  826. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  827. //==========================================
  828. // Init all share memory
  829. //==========================================
  830. int InitShareMemory()
  831. {
  832. int result = PASS;
  833. int MeterSMId;
  834. //creat ShmSysConfigAndInfo
  835. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  836. {
  837. #ifdef SystemLogMessage
  838. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  839. #endif
  840. result = FAIL;
  841. }
  842. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  843. {
  844. #ifdef SystemLogMessage
  845. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  846. #endif
  847. result = FAIL;
  848. }
  849. else
  850. {}
  851. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmPsuData
  868. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmPsuData NG\n");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. //creat ShmOCPP16Data
  885. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  893. {
  894. #ifdef SystemLogMessage
  895. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  896. #endif
  897. result = FAIL;
  898. }
  899. else
  900. {}
  901. /****************************** For Initial Settings************************************************/
  902. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  903. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  904. // allocate Configuration memory address
  905. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  906. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  907. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  908. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  909. return result;
  910. }
  911. int ProcessShareMemory()
  912. {
  913. if(InitShareMemory() == FAIL)
  914. {
  915. #ifdef SystemLogMessage
  916. DEBUG_ERROR("InitShareMemory NG\n");
  917. #endif
  918. if(ShmStatusCodeData!=NULL)
  919. {
  920. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  921. }
  922. sleep(5);
  923. return FAIL;
  924. }
  925. return PASS;
  926. }
  927. //---------------------common routine---------------------------//
  928. char * stringtrim( char * s )
  929. {
  930. char * p1 = s;
  931. char * p2 = s;
  932. while(*p1 != '\0')
  933. {
  934. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  935. {
  936. if(*p1 != ',')
  937. {
  938. p1 ++;
  939. }
  940. else
  941. {
  942. break;
  943. }
  944. }
  945. if(*p1 != ',')
  946. {
  947. * p2 ++ = *p1 ++;
  948. //printf("p2=%s\n",p2);
  949. }
  950. else
  951. {
  952. break;
  953. }
  954. }
  955. *p2 = '\0';
  956. return (s);
  957. }
  958. char * stringtrimspace( char * s )
  959. {
  960. char * p1 = s;
  961. char * p2 = s;
  962. while(*p1 != '\0')
  963. {
  964. while(*p1 == ' ') //while(*p1 == ' ' || *p1 == '\t' || *p1 == '\n' || *p1 == '\r')
  965. {
  966. p1 ++;
  967. }
  968. * p2 ++ = *p1 ++;
  969. //printf("p2=%s\n",p2);
  970. }
  971. *p2 = '\0';
  972. return (s);
  973. }
  974. //---------------------------------------------
  975. // new:
  976. // enum SYSTEM_STATUS
  977. // {
  978. // SYS_MODE_BOOTING = 0,
  979. // SYS_MODE_IDLE = 1,
  980. // SYS_MODE_AUTHORIZING = 2,
  981. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  982. // SYS_MODE_REASSIGN = 4,
  983. // SYS_MODE_PREPARING = 5,
  984. // SYS_MODE_PREPARE_FOR_EV = 6,
  985. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  986. // SYS_MODE_CHARGING = 8,
  987. // SYS_MODE_TERMINATING = 9,
  988. // SYS_MODE_COMPLETE = 10,
  989. // SYS_MODE_ALARM = 11,
  990. // SYS_MODE_FAULT = 12,
  991. // SYS_MODE_RESERVATION = 13,
  992. // SYS_MODE_BOOKING = 14,
  993. // SYS_MODE_MAINTAIN = 15,
  994. // SYS_MODE_DEBUG = 16,
  995. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  996. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  997. // SYS_MODE_UPDATE = 19
  998. // };
  999. //
  1000. //
  1001. //-----------------------------------------
  1002. void CheckSystemValue(void)
  1003. {
  1004. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1005. //int IdleModeCnt = 0;
  1006. char filenmae[100]={0};
  1007. char str[100]={0};
  1008. //===============================
  1009. // send Heartbeat
  1010. //===============================
  1011. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1012. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1013. {
  1014. clientTime.Heartbeat=time((time_t*)NULL);
  1015. if(server_sign == TRUE)
  1016. {
  1017. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1018. }
  1019. else
  1020. {
  1021. HeartBeatWaitTime = 10;
  1022. }
  1023. }
  1024. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1025. {
  1026. DEBUG_INFO("Heartbeat !!!\n");
  1027. //parameter for test
  1028. sendHeartbeatRequest(0);
  1029. //==============================================
  1030. // Reset Waiting Time
  1031. //==============================================
  1032. clientTime.Heartbeat=time((time_t*)NULL);
  1033. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1034. }
  1035. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1036. {
  1037. //===============================
  1038. // CSU Trigger Reset Conf
  1039. //===============================
  1040. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1041. {
  1042. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1043. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1044. {
  1045. server_sign = FALSE;
  1046. }
  1047. }
  1048. //===============================
  1049. // CSU Trigger Authorize Request
  1050. //===============================
  1051. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1052. {
  1053. sendAuthorizeRequest(0);
  1054. authorizeRetryTimes = authorizeRetryTimes + 1;
  1055. if(authorizeRetryTimes < 3)
  1056. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1057. }
  1058. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1059. {
  1060. authorizeRetryTimes = 0;
  1061. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1062. server_sign = FALSE;
  1063. }
  1064. 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))
  1065. {
  1066. sendAuthorizeRequest(0);
  1067. }
  1068. //===============================
  1069. // CSU Trigger Smart Charging Profilw
  1070. //===============================
  1071. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1072. {
  1073. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1074. GetChargingProfileRequest(gun_index);
  1075. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1076. }
  1077. //==============================================
  1078. // Charger start transaction
  1079. //==============================================
  1080. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1081. {
  1082. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1083. sendStartTransactionRequest(gun_index);
  1084. clientTime.StartTransaction = time((time_t*)NULL);
  1085. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1086. }
  1087. //==============================================
  1088. // Charger stop transaction
  1089. //==============================================
  1090. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1091. {
  1092. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1093. sendStopTransactionRequest(gun_index);
  1094. clientTime.StopTransaction = time((time_t*)NULL);
  1095. }
  1096. //==============================================
  1097. // Charger status report
  1098. //==============================================
  1099. //--- Check Mode Change ---//
  1100. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1101. if(gunType[gun_index] == 'J')
  1102. {
  1103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1104. {
  1105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1106. {
  1107. 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]*/ )
  1108. {
  1109. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1110. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1111. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1112. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1113. statusModeChage[gun_index] = TRUE;
  1114. }
  1115. #if 1 // for TempStopTransaction
  1116. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1117. {
  1118. checkTempStopTransaction(gun_index);
  1119. }
  1120. #endif
  1121. }
  1122. }
  1123. }
  1124. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1125. {
  1126. for (int index = 0; index < CCS_QUANTITY; index++)
  1127. {
  1128. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1129. {
  1130. 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]*/ )
  1131. {
  1132. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1133. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1134. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1135. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1136. statusModeChage[gun_index] = TRUE;
  1137. }
  1138. #if 1 // for TempStopTransaction
  1139. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1140. {
  1141. checkTempStopTransaction(gun_index);
  1142. }
  1143. #endif
  1144. }
  1145. }
  1146. }
  1147. else if(gunType[gun_index] == 'G')
  1148. {
  1149. for (int index = 0; index < GB_QUANTITY; index++)
  1150. {
  1151. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1152. {
  1153. 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]*/ )
  1154. {
  1155. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1156. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1157. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1158. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1159. statusModeChage[gun_index] = TRUE;
  1160. }
  1161. #if 1 // for TempStopTransaction
  1162. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1163. {
  1164. checkTempStopTransaction(gun_index);
  1165. }
  1166. #endif
  1167. }
  1168. }
  1169. }
  1170. else
  1171. {
  1172. for (int index = 0; index < AC_QUANTITY; index++)
  1173. {
  1174. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1175. {
  1176. 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]*/ )
  1177. {
  1178. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1179. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1180. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1181. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1182. statusModeChage[gun_index] = TRUE;
  1183. }
  1184. #if 1 // for TempStopTransaction
  1185. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1186. {
  1187. checkTempStopTransaction(gun_index);
  1188. }
  1189. #endif
  1190. }
  1191. }// END
  1192. }
  1193. if(((SystemInitial > 0)&& (server_sign == TRUE))||
  1194. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1195. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1196. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1197. {
  1198. if(SystemInitial > 0)
  1199. SystemInitial = SystemInitial -1;
  1200. sendStatusNotificationRequest(gun_index);
  1201. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1202. statusModeChage[gun_index] = FALSE;
  1203. DEBUG_INFO("SystemInitial=%d !!!\n",SystemInitial);
  1204. //DEBUG_INFO("difftime(time((time_t*)NULL), clientTime.Heartbeat)=%d !!!\n",difftime(time((time_t*)NULL), clientTime.Heartbeat));
  1205. //DEBUG_INFO("HeartBeatWaitTime=%d !!!\n",HeartBeatWaitTime);
  1206. //DEBUG_INFO("ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval=%d !!!\n",ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  1207. }
  1208. //==============================================
  1209. // Meter report
  1210. //==============================================
  1211. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1212. {
  1213. //check Transaction active
  1214. if(gunType[gun_index] == 'J')
  1215. {
  1216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1217. {
  1218. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1219. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1220. {
  1221. meterValueSend[gun_index] =1;
  1222. }
  1223. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1224. {
  1225. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1226. if((access(filenmae,F_OK))!=-1)
  1227. {
  1228. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1229. sprintf(str,"rm -f %s",filenmae);
  1230. system(str);
  1231. }
  1232. }
  1233. }// End for CHAdeMO
  1234. }
  1235. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1236. {
  1237. for (int index = 0; index < CCS_QUANTITY; index++)
  1238. {
  1239. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1240. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1241. {
  1242. meterValueSend[gun_index] =1;
  1243. }
  1244. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1245. {
  1246. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1247. if((access(filenmae,F_OK))!=-1)
  1248. {
  1249. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1250. sprintf(str,"rm -f %s",filenmae);
  1251. system(str);
  1252. }
  1253. }
  1254. } // End for CCS
  1255. }
  1256. else if(gunType[gun_index] == 'G')
  1257. {
  1258. for (int index = 0; index < GB_QUANTITY; index++)
  1259. {
  1260. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1261. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1262. {
  1263. meterValueSend[gun_index] =1;
  1264. }
  1265. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1266. {
  1267. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1268. if((access(filenmae,F_OK))!=-1)
  1269. {
  1270. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1271. sprintf(str,"rm -f %s",filenmae);
  1272. system(str);
  1273. }
  1274. }
  1275. }// End for GB
  1276. }
  1277. else
  1278. {
  1279. for (int index = 0; index < AC_QUANTITY; index++)
  1280. {
  1281. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1282. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1283. {
  1284. meterValueSend[gun_index] =1;
  1285. }
  1286. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1287. {
  1288. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1289. if((access(filenmae,F_OK))!=-1)
  1290. {
  1291. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1292. sprintf(str,"rm -f %s",filenmae);
  1293. system(str);
  1294. }
  1295. }
  1296. }//End for AC
  1297. }
  1298. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1299. if(meterValueSend[gun_index] == 1)
  1300. {
  1301. sendMeterValuesRequest(gun_index);
  1302. #if 1 // for TempStopTransaction
  1303. storeTempStopTransaction(gun_index);
  1304. #endif
  1305. }
  1306. }
  1307. //==============================================
  1308. // Check Connector reserved
  1309. //==============================================
  1310. //===============================
  1311. // Check if Reserve is expired
  1312. //===============================
  1313. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1314. {
  1315. double diff_t;
  1316. struct tm tp;
  1317. // current time
  1318. time_t t = time(NULL);
  1319. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1320. tp.tm_isdst = -1;
  1321. time_t utc = mktime(&tp);
  1322. diff_t = difftime(utc, t);
  1323. if(diff_t <= 0)
  1324. {
  1325. DEBUG_INFO("reserve expired !!! \n");
  1326. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1327. }
  1328. }//END OF Check if Reserve is expired
  1329. //==========================================
  1330. // csu trigger FirmwareStatusNotificationReq
  1331. //==========================================
  1332. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1333. {
  1334. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1335. }
  1336. //==========================================
  1337. // csu trigger CancelReservationConf
  1338. //==========================================
  1339. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1340. {
  1341. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1342. }
  1343. //==========================================
  1344. // csu trigger ChangeAvailabilityConf
  1345. //==========================================
  1346. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1347. {
  1348. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1349. }
  1350. //==========================================
  1351. // csu trigger UnlockConnectorConf
  1352. //==========================================
  1353. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1354. {
  1355. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1356. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1357. }
  1358. //==========================================
  1359. // csu trigger ReserveNowConf
  1360. //==========================================
  1361. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1362. {
  1363. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1364. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1365. }
  1366. //==========================================
  1367. // csu trigger DataTransferReq
  1368. //==========================================
  1369. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1370. {
  1371. sendDataTransferRequest(gun_index);
  1372. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1373. }
  1374. }
  1375. }
  1376. //==========================================
  1377. // send request routine
  1378. //==========================================
  1379. int sendAuthorizeRequest(int gun_index)
  1380. {
  1381. mtrace();
  1382. int result = FAIL;
  1383. char message[100]={0};
  1384. char guid[37];
  1385. char tempdata[65]={0};
  1386. DEBUG_INFO("sendAuthorizeRequest \n");
  1387. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1388. //Local Authorize
  1389. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1390. {
  1391. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1392. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1395. result = PASS;
  1396. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1397. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1398. authorizeRetryTimes = 0;
  1399. return result;
  1400. }
  1401. 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))||
  1402. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1403. {
  1404. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1405. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1406. {
  1407. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1408. {
  1409. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1410. }
  1411. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1412. {
  1413. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1414. }
  1415. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1416. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1417. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1418. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1419. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1420. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1421. authorizeRetryTimes = 0;
  1422. return result;
  1423. }
  1424. else
  1425. {
  1426. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1427. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1428. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1429. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1430. result = PASS;
  1431. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1432. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1433. authorizeRetryTimes = 0;
  1434. return result;
  1435. }
  1436. }
  1437. //initailize struct Authorize
  1438. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1439. //get data from shared memory
  1440. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1441. random_uuid(guid);
  1442. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1443. LWS_Send(message);
  1444. sprintf(tempdata, "Authorize,%d", gun_index);
  1445. if(hashmap_operation(0, guid, tempdata) == 1)
  1446. {
  1447. result = PASS;
  1448. DEBUG_ERROR("Authorize mapItem pass\n");
  1449. }
  1450. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1451. return result;
  1452. }
  1453. int sendBootNotificationRequest(void)
  1454. {
  1455. mtrace();
  1456. int result = FAIL;
  1457. char message[500]={0}, payload[700]={0};
  1458. char guid[37]={0};
  1459. char tempdata[65]={0};
  1460. int IsGunCharging = FALSE;
  1461. //check Transaction active
  1462. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1463. {
  1464. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1465. {
  1466. IsGunCharging = TRUE;
  1467. }
  1468. }
  1469. for (int index = 0; index < CCS_QUANTITY; index++)
  1470. {
  1471. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1472. {
  1473. IsGunCharging = TRUE;
  1474. }
  1475. }
  1476. for (int index = 0; index < GB_QUANTITY; index++)
  1477. {
  1478. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1479. {
  1480. IsGunCharging = TRUE;
  1481. }
  1482. }
  1483. for (int index = 0; index < AC_QUANTITY; index++)
  1484. {
  1485. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1486. {
  1487. IsGunCharging = TRUE;
  1488. }
  1489. }
  1490. if(IsGunCharging == TRUE)
  1491. {
  1492. server_sign = TRUE;
  1493. return result;
  1494. }
  1495. // Fill BootNotification fields
  1496. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1497. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1498. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1499. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1500. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1501. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1502. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1503. #if 0
  1504. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1505. ShmOCPP16Data->ChargeBoxId
  1506. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1507. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1508. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1509. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1510. ,ShmOCPP16Data->BootNotification.CpIccid
  1511. ,ShmOCPP16Data->BootNotification.CpImsi
  1512. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1513. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1514. #endif
  1515. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1516. ShmOCPP16Data->ChargeBoxId
  1517. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1518. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1519. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1520. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1521. ,ShmOCPP16Data->BootNotification.CpIccid
  1522. ,ShmOCPP16Data->BootNotification.CpImsi);
  1523. random_uuid(guid);
  1524. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1525. LWS_Send(message);
  1526. sprintf(tempdata, "BootNotification,0");
  1527. 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*/)
  1528. {
  1529. result = PASS;
  1530. }
  1531. memset(queuedata, 0, sizeof(queuedata));
  1532. strcpy(queuedata,message);
  1533. return result;
  1534. }
  1535. int sendDataTransferRequest(int gun_index)
  1536. {
  1537. mtrace();
  1538. char message[1000]={0};
  1539. char guid[37]={0};
  1540. char tempdata[65]={0};
  1541. int result = FAIL;
  1542. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1543. random_uuid(guid);
  1544. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1545. MESSAGE_TYPE_CALL,
  1546. guid,
  1547. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1548. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1549. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1550. LWS_Send(message);
  1551. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1552. 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*/)
  1553. {
  1554. result = PASS;
  1555. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1556. }
  1557. return result;
  1558. }
  1559. int sendDiagnosticsStatusNotificationRequest(char *status)
  1560. {
  1561. mtrace();
  1562. int result = FAIL;
  1563. char message[110]={0};
  1564. char guid[37]={0};
  1565. char tempdata[65]={0};
  1566. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1567. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1568. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1569. random_uuid(guid);
  1570. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1571. LWS_Send(message);
  1572. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1573. if(hashmap_operation(0, guid, tempdata) == 1)
  1574. {
  1575. result = PASS;
  1576. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1577. }
  1578. //#ifdef SystemLogMessage
  1579. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1580. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1581. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1582. //#endif
  1583. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1584. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1585. //record status
  1586. if(strcmp(status,"Idle")==0)
  1587. {
  1588. DiagnosticsStatusNotificationStatus = 0;
  1589. }
  1590. else if(strcmp(status,"Uploaded")==0)
  1591. {
  1592. DiagnosticsStatusNotificationStatus = 1;
  1593. }
  1594. else if(strcmp(status,"UploadFailed")==0)
  1595. {
  1596. DiagnosticsStatusNotificationStatus = 2;
  1597. }
  1598. else if(strcmp(status,"Uploading")==0)
  1599. {
  1600. DiagnosticsStatusNotificationStatus = 3;
  1601. }
  1602. return result;
  1603. }
  1604. int sendFirmwareStatusNotificationRequest(char *status)
  1605. {
  1606. mtrace();
  1607. int result = FAIL;
  1608. char message[110]={0};
  1609. char guid[37]={0};
  1610. char tempdata[65]={0};
  1611. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1612. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1613. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1614. random_uuid(guid);
  1615. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1616. LWS_Send(message);
  1617. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1618. 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*/)
  1619. {
  1620. result = PASS;
  1621. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1622. }
  1623. //#ifdef SystemLogMessage
  1624. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1625. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1626. //#endif
  1627. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1628. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1629. //record status
  1630. if(strcmp(status,"Downloaded")==0)
  1631. {
  1632. FirmwareStatusNotificationStatus = 0;
  1633. }
  1634. else if(strcmp(status,"DownloadFailed")==0)
  1635. {
  1636. FirmwareStatusNotificationStatus = 1;
  1637. }
  1638. else if(strcmp(status,"Downloading")==0)
  1639. {
  1640. FirmwareStatusNotificationStatus = 2;
  1641. }
  1642. else if(strcmp(status,"Idle")==0)
  1643. {
  1644. FirmwareStatusNotificationStatus = 3;
  1645. }
  1646. else if(strcmp(status,"InstallationFailed")==0)
  1647. {
  1648. FirmwareStatusNotificationStatus = 4;
  1649. }
  1650. else if(strcmp(status,"Installing")==0)
  1651. {
  1652. FirmwareStatusNotificationStatus = 5;
  1653. }
  1654. else if(strcmp(status,"Installed")==0)
  1655. {
  1656. FirmwareStatusNotificationStatus = 6;
  1657. }
  1658. return result;
  1659. }
  1660. int sendHeartbeatRequest(int gun_index)
  1661. {
  1662. mtrace();
  1663. int result = FAIL;
  1664. char message[80]={0};
  1665. char guid[37]={0};
  1666. char tempdata[65]={0};
  1667. random_uuid(guid);
  1668. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1669. , MESSAGE_TYPE_CALL
  1670. , guid );
  1671. LWS_Send(message);
  1672. sprintf(tempdata, "Heartbeat,%d", 0);
  1673. 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*/)
  1674. {
  1675. result = PASS;
  1676. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1677. }
  1678. return result;
  1679. }
  1680. int sendStartTransactionRequest(int gun_index)
  1681. {
  1682. mtrace();
  1683. int result = FAIL;
  1684. char message[250]={0};
  1685. char guid[37]={0};
  1686. struct timeval tmnow;
  1687. struct tm *tm;
  1688. char buf[28];//, usec_buf[6];
  1689. char tempdata[65]={0};
  1690. int tempIndex = 0;
  1691. DEBUG_INFO("sendStartTransactionRequest...");
  1692. gettimeofday(&tmnow, NULL);
  1693. time_t t;
  1694. t = time(NULL);
  1695. /*UTC time and date*/
  1696. tm = gmtime(&t);
  1697. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1698. #if 0 // remove temporally
  1699. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1700. strcat(buf,".");
  1701. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1702. strcat(buf,usec_buf);
  1703. #endif
  1704. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1705. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1706. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1707. // clear StartTransaction Response
  1708. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1709. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1710. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1711. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1712. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1713. if(gunType[gun_index] == 'J')
  1714. {
  1715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1716. {
  1717. tempIndex = ((gun_index==2) ? 1: 0);
  1718. }
  1719. else
  1720. {
  1721. tempIndex = gun_index;
  1722. }
  1723. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1724. {
  1725. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  1726. {
  1727. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1728. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1729. }
  1730. }
  1731. }
  1732. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1733. {
  1734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1735. {
  1736. tempIndex = ((gun_index==2) ? 1: 0);
  1737. }
  1738. else
  1739. {
  1740. tempIndex = gun_index;
  1741. }
  1742. for (int index = 0; index < CCS_QUANTITY; index++)
  1743. {
  1744. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1745. {
  1746. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1747. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1748. }
  1749. }
  1750. }
  1751. else if(gunType[gun_index] == 'G')
  1752. {
  1753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1754. {
  1755. tempIndex = ((gun_index==2) ? 1: 0);
  1756. }
  1757. else
  1758. {
  1759. tempIndex = gun_index;
  1760. }
  1761. for (int index = 0; index < GB_QUANTITY; index++)
  1762. {
  1763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1764. {
  1765. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1766. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1767. }
  1768. }
  1769. }
  1770. else
  1771. {
  1772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1773. {
  1774. tempIndex = 2;
  1775. }
  1776. else
  1777. {
  1778. tempIndex = gun_index;
  1779. }
  1780. for (int index = 0; index < AC_QUANTITY; index++)
  1781. {
  1782. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1783. {
  1784. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  1785. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1786. }
  1787. }
  1788. }
  1789. random_uuid(guid);
  1790. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1791. , MESSAGE_TYPE_CALL
  1792. , guid
  1793. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1794. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1795. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1796. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1797. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1798. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1799. 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*/)
  1800. {
  1801. result = PASS;
  1802. }
  1803. strcpy(queuedata, message);
  1804. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1805. if(GetTransactionQueueNum() == 1)
  1806. {
  1807. LWS_Send(message);
  1808. }
  1809. return result;
  1810. }
  1811. int sendStatusNotificationRequest(int gun_index)
  1812. {
  1813. mtrace();
  1814. int result = FAIL;
  1815. char message[600]={0};
  1816. char guid[37];
  1817. int currentStatus = 0;
  1818. struct timeval tmnow;
  1819. struct tm *tm;
  1820. char buf[28];//, usec_buf[6];
  1821. char tempdata[65]={0};
  1822. int tempIndex = 0;
  1823. gettimeofday(&tmnow, NULL);
  1824. time_t t;
  1825. t = time(NULL);
  1826. /*UTC time and date*/
  1827. tm = gmtime(&t);
  1828. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1829. #if 0 // remove temporally
  1830. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1831. strcat(buf,".");
  1832. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1833. strcat(buf,usec_buf);
  1834. #endif
  1835. printf("%s",buf);
  1836. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1837. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1838. // it's option
  1839. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1840. /*
  1841. enum _SYSTEM_STATUS
  1842. {
  1843. S_BOOTING = 0,
  1844. S_IDLE, = 1
  1845. S_AUTHORIZING, =2
  1846. S_REASSIGN_CHECK, =3
  1847. S_REASSIGN, =4
  1848. S_PRECHARGE, =5
  1849. S_PREPARING_FOR_EV, =6
  1850. S_PREPARING_FOR_EVSE, =7
  1851. S_CHARGING, =8
  1852. S_TERMINATING, =9
  1853. S_COMPLETE, =10
  1854. S_ALARM, =11
  1855. S_FAULT =12
  1856. }
  1857. */
  1858. //check Transaction active
  1859. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1860. if(gunType[gun_index] == 'J')
  1861. {
  1862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1863. {
  1864. tempIndex = ((gun_index==2) ? 1: 0);
  1865. }
  1866. else
  1867. {
  1868. tempIndex = gun_index;
  1869. }
  1870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1871. {
  1872. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1873. {
  1874. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  1875. {
  1876. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1877. {
  1878. currentStatus = 1; //OCPP Status: Preparing
  1879. }
  1880. else
  1881. {
  1882. currentStatus = 0; //OCPP Status: Available
  1883. }
  1884. }
  1885. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1886. {
  1887. currentStatus = 1; //OCPP Status: Preparing
  1888. }
  1889. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1890. {
  1891. currentStatus = 2; //OCPP Status: Charging
  1892. }
  1893. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1894. {
  1895. currentStatus = 5; //OCPP Status: Finishing
  1896. }
  1897. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  1898. {
  1899. currentStatus = 4; //OCPP Status: SuspendedEV
  1900. }
  1901. 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
  1902. {
  1903. currentStatus = 7; //OCPP Status: Unavailable
  1904. }
  1905. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  1906. {
  1907. currentStatus = 8; //OCPP Status: Faulted
  1908. }
  1909. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1910. {
  1911. currentStatus = 6; //OCPP Status: Reserved
  1912. }
  1913. } //end of the same index
  1914. }//end of for CHAdeMO_QUANTITY
  1915. }
  1916. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1917. {
  1918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1919. {
  1920. tempIndex = ((gun_index==2) ? 1: 0);
  1921. }
  1922. else
  1923. {
  1924. tempIndex = gun_index;
  1925. }
  1926. for (int index = 0; index < CCS_QUANTITY; index++)
  1927. {
  1928. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1929. {
  1930. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1931. {
  1932. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1933. {
  1934. currentStatus = 1; //OCPP Status: Preparing
  1935. }
  1936. else
  1937. {
  1938. currentStatus = 0; //OCPP Status: Available
  1939. }
  1940. }
  1941. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1942. {
  1943. currentStatus = 1; //OCPP Status: Preparing
  1944. }
  1945. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1946. {
  1947. currentStatus = 2; //OCPP Status: Charging
  1948. }
  1949. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1950. {
  1951. currentStatus = 5; //OCPP Status: Finishing
  1952. }
  1953. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  1954. {
  1955. currentStatus = 4; //OCPP Status: SuspendedEV
  1956. }
  1957. 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
  1958. {
  1959. currentStatus = 7; //OCPP Status : Unavailable
  1960. }
  1961. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  1962. {
  1963. currentStatus = 8; //OCPP Status: Faulted
  1964. }
  1965. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1966. {
  1967. currentStatus = 6; //OCPP Status: Reserved
  1968. }
  1969. } //end of the same index
  1970. } // end of for CCS_QUANTITY
  1971. }
  1972. else if(gunType[gun_index] == 'G')
  1973. {
  1974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1975. {
  1976. tempIndex = ((gun_index==2) ? 1: 0);
  1977. }
  1978. else
  1979. {
  1980. tempIndex = gun_index;
  1981. }
  1982. for (int index = 0; index < GB_QUANTITY; index++)
  1983. {
  1984. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1985. {
  1986. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1987. {
  1988. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1989. {
  1990. currentStatus = 1; //OCPP Status: Preparing
  1991. }
  1992. else
  1993. {
  1994. currentStatus = 0; //OCPP Status: Available
  1995. }
  1996. }
  1997. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1998. {
  1999. currentStatus = 1; //OCPP Status: Preparing
  2000. }
  2001. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2002. {
  2003. currentStatus = 2; //OCPP Status: Charging
  2004. }
  2005. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2006. {
  2007. currentStatus = 5; //OCPP Status: Finishing
  2008. }
  2009. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2010. {
  2011. currentStatus = 4; //OCPP Status: SuspendedEV
  2012. }
  2013. 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
  2014. {
  2015. currentStatus = 7; //OCPP Status: Unavailable
  2016. }
  2017. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2018. {
  2019. currentStatus = 8; //OCPP Status: Faulted
  2020. }
  2021. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2022. {
  2023. currentStatus = 6; //OCPP Status: Reserved
  2024. }
  2025. } //end of the same index
  2026. } // end of for GB_QUANTITY
  2027. }
  2028. else
  2029. {
  2030. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2031. {
  2032. tempIndex = 2;
  2033. }
  2034. else
  2035. {
  2036. tempIndex = gun_index;
  2037. }
  2038. for (int index = 0; index < AC_QUANTITY; index++)
  2039. {
  2040. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2041. {
  2042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  2043. {
  2044. 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))
  2045. {
  2046. currentStatus = 1; //OCPP Status: Preparing
  2047. }
  2048. else
  2049. {
  2050. currentStatus = 0; //OCPP Status: Available
  2051. }
  2052. }
  2053. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  2054. {
  2055. currentStatus = 1; //OCPP Status: Preparing
  2056. }
  2057. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  2058. {
  2059. currentStatus = 2; //OCPP Status: Charging
  2060. }
  2061. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  2062. {
  2063. currentStatus = 5; //OCPP Status: Finishing
  2064. }
  2065. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2066. {
  2067. currentStatus = 4; //OCPP Status: SuspendedEV
  2068. }
  2069. 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
  2070. {
  2071. currentStatus = 7; //OCPP Status: Unavailable
  2072. }
  2073. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2074. {
  2075. currentStatus = 8; //OCPP Status: Faulted
  2076. }
  2077. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2078. {
  2079. currentStatus = 6; //OCPP Status: Reserved
  2080. }
  2081. }//end of the same index
  2082. }//end of for AC_QUANTITY
  2083. }
  2084. //it's option
  2085. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2086. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2087. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2088. random_uuid(guid);
  2089. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2090. , MESSAGE_TYPE_CALL
  2091. , guid
  2092. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2093. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2094. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2095. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2096. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2097. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2098. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2099. LWS_Send(message);
  2100. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2101. 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*/)
  2102. {
  2103. //DEBUG_ERROR("statusNotification mapitem pass");
  2104. result = PASS;
  2105. }
  2106. return result;
  2107. }
  2108. int sendStopTransactionRequest(int gun_index)
  2109. {
  2110. mtrace();
  2111. int result = FAIL;
  2112. //char message[1500]={0};
  2113. char guid[37]={0};
  2114. char tempdata[65]={0};
  2115. int tempIndex = 0;
  2116. //int idx_sample=0;
  2117. DEBUG_ERROR("sendStopTransactionRequest \n");
  2118. memset(queuedata, 0, sizeof(queuedata));
  2119. //ENERGY_ACTIVE_IMPORT_REGISTER
  2120. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2121. if(gunType[gun_index] == 'J')
  2122. {
  2123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2124. {
  2125. tempIndex = ((gun_index==2) ? 1: 0);
  2126. }
  2127. else
  2128. {
  2129. tempIndex = gun_index;
  2130. }
  2131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2134. {
  2135. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2136. }
  2137. }// END OF CHAdeMO_QUANTITY
  2138. }
  2139. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2140. {
  2141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2142. {
  2143. tempIndex = ((gun_index==2) ? 1: 0);
  2144. }
  2145. else
  2146. {
  2147. tempIndex = gun_index;
  2148. }
  2149. for (int index = 0; index < CCS_QUANTITY; index++)
  2150. {
  2151. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2152. {
  2153. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2154. }
  2155. }// END OF CCS_QUANTITY
  2156. }
  2157. else if(gunType[gun_index] == 'G')
  2158. {
  2159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2160. {
  2161. tempIndex = ((gun_index==2) ? 1: 0);
  2162. }
  2163. else
  2164. {
  2165. tempIndex = gun_index;
  2166. }
  2167. for (int index = 0; index < GB_QUANTITY; index++)
  2168. {
  2169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2170. {
  2171. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2172. }
  2173. }// END OF GB_QUANTITY
  2174. }
  2175. else
  2176. {
  2177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2178. {
  2179. tempIndex = 2;
  2180. }
  2181. else
  2182. {
  2183. tempIndex = gun_index;
  2184. }
  2185. for (int index = 0; index < AC_QUANTITY; index++)
  2186. {
  2187. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2188. {
  2189. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  2190. }
  2191. }// END OF AC_QUANTITY
  2192. }
  2193. //Stop Transaction Time
  2194. struct timeval tmnow;
  2195. struct tm *tm;
  2196. char buf[28];//, usec_buf[6];
  2197. gettimeofday(&tmnow, NULL);
  2198. time_t t;
  2199. t = time(NULL);
  2200. /*UTC time and date*/
  2201. tm = gmtime(&t);
  2202. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2204. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2205. random_uuid(guid);
  2206. /***********************************transactionData******************************************************/
  2207. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2209. //=================================
  2210. // Transaction_Begin
  2211. //=================================
  2212. // Energy.Active.Export.Interval
  2213. //idx_sample=0;
  2214. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  2215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2217. 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*/]);
  2218. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2219. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2220. {
  2221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2222. }
  2223. else
  2224. {
  2225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2226. }
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2229. //=================================
  2230. // Transaction_End
  2231. //=================================
  2232. //Current.Export
  2233. //idx_sample=1;
  2234. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  2235. if(gunType[gun_index] == 'J')
  2236. {
  2237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2238. {
  2239. tempIndex = ((gun_index==2) ? 1: 0);
  2240. }
  2241. else
  2242. {
  2243. tempIndex = gun_index;
  2244. }
  2245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2246. {
  2247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2248. {
  2249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2250. }
  2251. }// End of for CHAdeMO_QUANTITY
  2252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2253. }
  2254. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2255. {
  2256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2257. {
  2258. tempIndex = ((gun_index==2) ? 1: 0);
  2259. }
  2260. else
  2261. {
  2262. tempIndex = gun_index;
  2263. }
  2264. for (int index = 0; index < CCS_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2267. {
  2268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2269. }
  2270. }// End of for CCS_QUANTITY
  2271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2272. }
  2273. else if(gunType[gun_index] == 'G')
  2274. {
  2275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2276. {
  2277. tempIndex = ((gun_index==2) ? 1: 0);
  2278. }
  2279. else
  2280. {
  2281. tempIndex = gun_index;
  2282. }
  2283. for (int index = 0; index < GB_QUANTITY; index++)
  2284. {
  2285. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2286. {
  2287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2288. }
  2289. }// End of for GB_QUANTITY
  2290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2291. }
  2292. else
  2293. {
  2294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2295. {
  2296. tempIndex = 2;
  2297. }
  2298. else
  2299. {
  2300. tempIndex = gun_index;
  2301. }
  2302. for (int index = 0; index < AC_QUANTITY; index++)
  2303. {
  2304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2305. {
  2306. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2307. }
  2308. }// End of for AC_QUANTITY
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2310. }
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  2314. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2317. //Energy.Active.Export.Interval
  2318. //idx_sample=2;
  2319. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2320. if(gunType[gun_index] == 'J')
  2321. {
  2322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2323. {
  2324. tempIndex = ((gun_index==2) ? 1: 0);
  2325. }
  2326. else
  2327. {
  2328. tempIndex = gun_index;
  2329. }
  2330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2331. {
  2332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2333. {
  2334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2335. }
  2336. }// END OF CHAdeMO_QUANTITY
  2337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2338. }
  2339. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2340. {
  2341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2342. {
  2343. tempIndex = ((gun_index==2) ? 1: 0);
  2344. }
  2345. else
  2346. {
  2347. tempIndex = gun_index;
  2348. }
  2349. for (int index = 0; index < CCS_QUANTITY; index++)
  2350. {
  2351. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2352. {
  2353. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2354. }
  2355. }// END OF CCS_QUANTITY
  2356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2357. }
  2358. else if(gunType[gun_index] == 'G')
  2359. {
  2360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2361. {
  2362. tempIndex = ((gun_index==2) ? 1: 0);
  2363. }
  2364. else
  2365. {
  2366. tempIndex = gun_index;
  2367. }
  2368. for (int index = 0; index < GB_QUANTITY; index++)
  2369. {
  2370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2371. {
  2372. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2373. }
  2374. }// END OF GB_QUANTITY
  2375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2376. }
  2377. else
  2378. {
  2379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2380. {
  2381. tempIndex = 2;
  2382. }
  2383. else
  2384. {
  2385. tempIndex = gun_index;
  2386. }
  2387. for (int index = 0; index < AC_QUANTITY; index++)
  2388. {
  2389. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2390. {
  2391. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2392. }
  2393. }// END OF AC_QUANTITY
  2394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2395. }
  2396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  2399. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2402. //Power.Active.Export
  2403. //idx_sample=3;
  2404. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2405. if(gunType[gun_index] == 'J')
  2406. {
  2407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2408. {
  2409. tempIndex = ((gun_index==2) ? 1: 0);
  2410. }
  2411. else
  2412. {
  2413. tempIndex = gun_index;
  2414. }
  2415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2416. {
  2417. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2418. {
  2419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2420. }
  2421. } // End for CHAdeMO_QUANTITY
  2422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2423. }
  2424. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2425. {
  2426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2427. {
  2428. tempIndex = ((gun_index==2) ? 1: 0);
  2429. }
  2430. else
  2431. {
  2432. tempIndex = gun_index;
  2433. }
  2434. for (int index = 0; index < CCS_QUANTITY; index++)
  2435. {
  2436. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2437. {
  2438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2439. }
  2440. } // END for CCS_QUANTITY
  2441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2442. }
  2443. else if(gunType[gun_index] == 'G')
  2444. {
  2445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2446. {
  2447. tempIndex = ((gun_index==2) ? 1: 0);
  2448. }
  2449. else
  2450. {
  2451. tempIndex = gun_index;
  2452. }
  2453. for (int index = 0; index < GB_QUANTITY; index++)
  2454. {
  2455. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2456. {
  2457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2458. }
  2459. }// END for GB_QUANTITY
  2460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2461. }
  2462. else
  2463. {
  2464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2465. {
  2466. tempIndex = 2;
  2467. }
  2468. else
  2469. {
  2470. tempIndex = gun_index;
  2471. }
  2472. for (int index = 0; index < AC_QUANTITY; index++)
  2473. {
  2474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2475. {
  2476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2477. }
  2478. } // END for AC_QUANTITY
  2479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2480. }
  2481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  2484. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2487. //Voltage
  2488. //idx_sample=4;
  2489. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2490. if(gunType[gun_index] == 'J')
  2491. {
  2492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2493. {
  2494. tempIndex = ((gun_index==2) ? 1: 0);
  2495. }
  2496. else
  2497. {
  2498. tempIndex = gun_index;
  2499. }
  2500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2501. {
  2502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2503. {
  2504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2505. }
  2506. } // END OF FOR CHAdeMO_QUANTITY
  2507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2508. }
  2509. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2510. {
  2511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2512. {
  2513. tempIndex = ((gun_index==2) ? 1: 0);
  2514. }
  2515. else
  2516. {
  2517. tempIndex = gun_index;
  2518. }
  2519. for (int index = 0; index < CCS_QUANTITY; index++)
  2520. {
  2521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2522. {
  2523. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2524. }
  2525. } // END OF FOR CCS_QUANTITY
  2526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2527. }
  2528. else if(gunType[gun_index] == 'G')
  2529. {
  2530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2531. {
  2532. tempIndex = ((gun_index==2) ? 1: 0);
  2533. }
  2534. else
  2535. {
  2536. tempIndex = gun_index;
  2537. }
  2538. for (int index = 0; index < GB_QUANTITY; index++)
  2539. {
  2540. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2541. {
  2542. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2543. }
  2544. } // END OF FOR GB_QUANTITY
  2545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2546. }
  2547. else
  2548. {
  2549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2550. {
  2551. tempIndex = 2;
  2552. }
  2553. else
  2554. {
  2555. tempIndex = gun_index;
  2556. }
  2557. for (int index = 0; index < AC_QUANTITY; index++)
  2558. {
  2559. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2560. {
  2561. 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
  2562. }
  2563. } // END OF FOR AC_QUANTITY
  2564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2565. }
  2566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2569. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2572. //SoC
  2573. //idx_sample=5;
  2574. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2575. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2576. {
  2577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2578. {
  2579. tempIndex = ((gun_index==2) ? 1: 0);
  2580. }
  2581. else
  2582. {
  2583. tempIndex = gun_index;
  2584. }
  2585. if(gunType[gun_index] == 'J')
  2586. {
  2587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2588. {
  2589. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2590. {
  2591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2592. }
  2593. }
  2594. }
  2595. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2596. {
  2597. for (int index = 0; index < CCS_QUANTITY; index++)
  2598. {
  2599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2600. {
  2601. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2602. }
  2603. }
  2604. }
  2605. else if(gunType[gun_index] == 'G')
  2606. {
  2607. for (int index = 0; index < GB_QUANTITY; index++)
  2608. {
  2609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2610. {
  2611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2612. }
  2613. }
  2614. }
  2615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2621. } // END FOR DC CASE
  2622. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2623. {
  2624. 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\"}]}]}]"
  2625. ,MESSAGE_TYPE_CALL
  2626. ,guid
  2627. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2628. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2629. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2630. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2631. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2632. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2633. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2634. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2635. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2636. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2637. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2638. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2639. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2640. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2641. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2642. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2643. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2644. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2645. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2646. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2647. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2648. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2649. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2650. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2651. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2652. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2653. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2654. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2655. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2656. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2657. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2658. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2659. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2660. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2661. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2662. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2663. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2664. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2665. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2666. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2667. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2668. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2669. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2670. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2671. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2672. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2673. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2674. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2675. );
  2676. }
  2677. else
  2678. {
  2679. 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\"}]}]}]"
  2680. ,MESSAGE_TYPE_CALL
  2681. ,guid
  2682. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2683. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2684. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2686. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2687. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2699. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2700. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2701. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2702. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2703. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2704. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2705. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2706. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2707. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2708. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2709. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2710. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2711. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2712. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2722. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2723. );
  2724. }
  2725. #if 0 // for TempStopTransaction
  2726. //Delete TempStopTransaction
  2727. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  2728. {
  2729. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  2730. }
  2731. #endif
  2732. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2733. if(hashmap_operation(0, guid, tempdata) == 1)
  2734. {
  2735. result = PASS;
  2736. DEBUG_INFO("StopTransaction mapitem pass\n");
  2737. }
  2738. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2739. if(GetTransactionQueueNum() == 1)
  2740. {
  2741. LWS_Send(queuedata);
  2742. }
  2743. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2744. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2745. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2746. {
  2747. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2748. }
  2749. //for test
  2750. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2751. return result;
  2752. }
  2753. int sendMeterValuesRequest(int gun_index)
  2754. {
  2755. mtrace();
  2756. int result = FAIL;
  2757. // char message[1500]={0};
  2758. char guid[37]={0};
  2759. //int idx_sample=0;
  2760. //int length = 0;
  2761. char tempdata[65]={0};
  2762. int tempIndex = 0;
  2763. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2764. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2765. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2766. {
  2767. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2768. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2769. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2770. return result;
  2771. }
  2772. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2773. {
  2774. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2775. }
  2776. memset(queuedata, 0, sizeof(queuedata));
  2777. //set value
  2778. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2779. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2780. random_uuid(guid);
  2781. //UTC Date time
  2782. struct timeval tmnow;
  2783. struct tm *tm;
  2784. char buf[28];//, usec_buf[6];
  2785. gettimeofday(&tmnow, NULL);
  2786. time_t t;
  2787. t = time(NULL);
  2788. /*UTC time and date*/
  2789. tm = gmtime(&t);
  2790. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2792. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2793. //idx_sample=0;
  2794. //********************************(1)Current.Export************************************************/
  2795. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2796. if(gunType[gun_index] == 'J')
  2797. {
  2798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2799. {
  2800. tempIndex = ((gun_index==2) ? 1: 0);
  2801. }
  2802. else
  2803. {
  2804. tempIndex = gun_index;
  2805. }
  2806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2807. {
  2808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2809. {
  2810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2811. }
  2812. }
  2813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2814. }
  2815. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2816. {
  2817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2818. {
  2819. tempIndex = ((gun_index==2) ? 1: 0);
  2820. }
  2821. else
  2822. {
  2823. tempIndex = gun_index;
  2824. }
  2825. for (int index = 0; index < CCS_QUANTITY; index++)
  2826. {
  2827. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2828. {
  2829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2830. }
  2831. }
  2832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2833. }
  2834. else if(gunType[gun_index] == 'G')
  2835. {
  2836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2837. {
  2838. tempIndex = ((gun_index==2) ? 1: 0);
  2839. }
  2840. else
  2841. {
  2842. tempIndex = gun_index;
  2843. }
  2844. for (int index = 0; index < GB_QUANTITY; index++)
  2845. {
  2846. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2847. {
  2848. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2849. }
  2850. }
  2851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2852. }
  2853. else
  2854. {
  2855. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2856. {
  2857. tempIndex = 2;
  2858. }
  2859. else
  2860. {
  2861. tempIndex = gun_index;
  2862. }
  2863. for (int index = 0; index < AC_QUANTITY; index++)
  2864. {
  2865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2866. {
  2867. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2868. }
  2869. }
  2870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2871. }
  2872. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  2875. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2878. //idx_sample=1;
  2879. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2880. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2881. if(gunType[gun_index] == 'J')
  2882. {
  2883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2884. {
  2885. tempIndex = ((gun_index==2) ? 1: 0);
  2886. }
  2887. else
  2888. {
  2889. tempIndex = gun_index;
  2890. }
  2891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2892. {
  2893. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2894. {
  2895. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2896. }
  2897. } // END OF FOR CHAdeMO_QUANTITY
  2898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2899. }
  2900. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2901. {
  2902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2903. {
  2904. tempIndex = ((gun_index==2) ? 1: 0);
  2905. }
  2906. else
  2907. {
  2908. tempIndex = gun_index;
  2909. }
  2910. for (int index = 0; index < CCS_QUANTITY; index++)
  2911. {
  2912. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2913. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2914. {
  2915. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2916. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2917. }
  2918. } // END OF CCS_QUANTITY
  2919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2920. }
  2921. else if(gunType[gun_index] == 'G')
  2922. {
  2923. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2924. {
  2925. tempIndex = ((gun_index==2) ? 1: 0);
  2926. }
  2927. else
  2928. {
  2929. tempIndex = gun_index;
  2930. }
  2931. for (int index = 0; index < GB_QUANTITY; index++)
  2932. {
  2933. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2934. {
  2935. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2936. }
  2937. } // END OF GB_QUANTITY
  2938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2939. }
  2940. else
  2941. {
  2942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2943. {
  2944. tempIndex = 2;
  2945. }
  2946. else
  2947. {
  2948. tempIndex = gun_index;
  2949. }
  2950. for (int index = 0; index < AC_QUANTITY; index++)
  2951. {
  2952. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2953. {
  2954. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2955. }
  2956. }
  2957. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2958. }
  2959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2960. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2961. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  2962. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2965. //idx_sample=2;
  2966. //********************************(4)Power.Active.Export************************************************/
  2967. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2968. if(gunType[gun_index] == 'J')
  2969. {
  2970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2971. {
  2972. tempIndex = ((gun_index==2) ? 1: 0);
  2973. }
  2974. else
  2975. {
  2976. tempIndex = gun_index;
  2977. }
  2978. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2979. {
  2980. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2981. {
  2982. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2983. }
  2984. } // END OF FOR
  2985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2986. }
  2987. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2988. {
  2989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2990. {
  2991. tempIndex = ((gun_index==2) ? 1: 0);
  2992. }
  2993. else
  2994. {
  2995. tempIndex = gun_index;
  2996. }
  2997. for (int index = 0; index < CCS_QUANTITY; index++)
  2998. {
  2999. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3000. {
  3001. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  3002. }
  3003. }
  3004. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3005. }
  3006. else if(gunType[gun_index] == 'G')
  3007. {
  3008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3009. {
  3010. tempIndex = ((gun_index==2) ? 1: 0);
  3011. }
  3012. else
  3013. {
  3014. tempIndex = gun_index;
  3015. }
  3016. for (int index = 0; index < GB_QUANTITY; index++)
  3017. {
  3018. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3019. {
  3020. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  3021. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  3022. }
  3023. }
  3024. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3025. }
  3026. else
  3027. {
  3028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3029. {
  3030. tempIndex = 2;
  3031. }
  3032. else
  3033. {
  3034. tempIndex = gun_index;
  3035. }
  3036. for (int index = 0; index < AC_QUANTITY; index++)
  3037. {
  3038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3039. {
  3040. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  3041. }
  3042. }
  3043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3044. }
  3045. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3046. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  3047. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Import]);
  3048. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3049. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  3050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  3051. //idx_sample=3;
  3052. //***********************************************(5)VOLTAGE******************************************************/
  3053. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3054. if(gunType[gun_index] == 'J')
  3055. {
  3056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3057. {
  3058. tempIndex = ((gun_index==2) ? 1: 0);
  3059. }
  3060. else
  3061. {
  3062. tempIndex = gun_index;
  3063. }
  3064. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3065. {
  3066. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3067. {
  3068. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  3069. }
  3070. }
  3071. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3072. }
  3073. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3074. {
  3075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3076. {
  3077. tempIndex = ((gun_index==2) ? 1: 0);
  3078. }
  3079. else
  3080. {
  3081. tempIndex = gun_index;
  3082. }
  3083. for (int index = 0; index < CCS_QUANTITY; index++)
  3084. {
  3085. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3086. {
  3087. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  3088. }
  3089. }
  3090. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3091. }
  3092. else if(gunType[gun_index] == 'G')
  3093. {
  3094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3095. {
  3096. tempIndex = ((gun_index==2) ? 1: 0);
  3097. }
  3098. else
  3099. {
  3100. tempIndex = gun_index;
  3101. }
  3102. for (int index = 0; index < GB_QUANTITY; index++)
  3103. {
  3104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3105. {
  3106. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  3107. }
  3108. }
  3109. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3110. }
  3111. else
  3112. {
  3113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3114. {
  3115. tempIndex = 2;
  3116. }
  3117. else
  3118. {
  3119. tempIndex = gun_index;
  3120. }
  3121. for (int index = 0; index < AC_QUANTITY; index++)
  3122. {
  3123. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3124. {
  3125. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  3126. }
  3127. }
  3128. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3129. }
  3130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  3132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  3133. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  3135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3136. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3137. {
  3138. //idx_sample=4;
  3139. //sampledValue = NULL;
  3140. //***********************************************(6)SOC******************************************************/
  3141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3142. {
  3143. tempIndex = ((gun_index==2) ? 1: 0);
  3144. }
  3145. else
  3146. {
  3147. tempIndex = gun_index;
  3148. }
  3149. if(gunType[gun_index] == 'J')
  3150. {
  3151. //tempIndex = ((gun_index==2) ? 1: 0);
  3152. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3153. {
  3154. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3155. {
  3156. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  3157. }
  3158. }
  3159. }
  3160. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3161. {
  3162. //tempIndex = ((gun_index==2) ? 1: 0);
  3163. for (int index = 0; index < CCS_QUANTITY; index++)
  3164. {
  3165. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3166. {
  3167. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  3168. }
  3169. }
  3170. }
  3171. else if(gunType[gun_index] == 'G')
  3172. {
  3173. //tempIndex = ((gun_index==2) ? 1: 0);
  3174. for (int index = 0; index < GB_QUANTITY; index++)
  3175. {
  3176. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3177. {
  3178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  3179. }
  3180. }
  3181. }
  3182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  3184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  3185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  3187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  3188. }
  3189. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3190. {
  3191. 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\"}]}]}]"
  3192. ,MESSAGE_TYPE_CALL
  3193. ,guid
  3194. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3195. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3196. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3197. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3198. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3199. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3200. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3201. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3202. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3203. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3204. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3205. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3206. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3207. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3208. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3209. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3210. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3211. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3212. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3213. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3214. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3215. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3216. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3217. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3218. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3219. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3220. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3221. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3222. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3223. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3224. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3225. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  3226. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  3227. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  3228. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  3229. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  3230. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  3231. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  3232. );
  3233. }
  3234. else
  3235. {
  3236. 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\"}]}]}]"
  3237. ,MESSAGE_TYPE_CALL
  3238. ,guid
  3239. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3240. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3241. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3242. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3243. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3244. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3245. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3246. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3247. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3248. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3249. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3250. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3251. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3252. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3253. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3254. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3255. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3256. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3257. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3258. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3259. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3260. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3261. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3262. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3263. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3264. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3265. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3266. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3267. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3268. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3269. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3270. );
  3271. }
  3272. // Put request guid to hash map
  3273. sprintf(tempdata, "MeterValues,%d", (gun_index));
  3274. 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*/)
  3275. {
  3276. result = PASS;
  3277. DEBUG_INFO("MeterValues mapitem pass\n");
  3278. }
  3279. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3280. if(GetTransactionQueueNum() == 1)
  3281. {
  3282. LWS_Send(queuedata);
  3283. }
  3284. return result;
  3285. }
  3286. //==========================================
  3287. // send confirm routine
  3288. //==========================================
  3289. int sendCancelReservationConfirmation(char *uuid,char *payload)
  3290. {
  3291. mtrace();
  3292. int result = FAIL;
  3293. char message[100]={0};
  3294. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  3295. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3296. LWS_Send(message);
  3297. result = TRUE;
  3298. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  3299. return result;
  3300. }
  3301. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  3302. {
  3303. mtrace();
  3304. int result = FAIL;
  3305. char message[100]={0};
  3306. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  3307. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3308. LWS_Send(message);
  3309. result = TRUE;
  3310. return result;
  3311. }
  3312. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  3313. {
  3314. mtrace();
  3315. int result = FAIL;
  3316. char message[100]={0};
  3317. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  3318. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3319. LWS_Send(message);
  3320. result = TRUE;
  3321. return result;
  3322. }
  3323. int sendClearCacheConfirmation(char *uuid,char *payload)
  3324. {
  3325. mtrace();
  3326. int result = FAIL;
  3327. char message[500]={0};
  3328. // int count = 0;
  3329. // int gun_index = 0;
  3330. // char guid[37];
  3331. // [ 3, "1570592744204", { "status": "Accepted" } ]
  3332. DEBUG_ERROR("sendClearCacheConfirmation\n");
  3333. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3334. LWS_Send(message);
  3335. return result;
  3336. }
  3337. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  3338. {
  3339. mtrace();
  3340. int result = FAIL;
  3341. char message[500]={0};
  3342. // [ 3, "1571284268200", { "status": "Unknown" } ]
  3343. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  3344. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3345. LWS_Send(message);
  3346. return result;
  3347. }
  3348. int sendDataTransferConfirmation(char *uuid,char *payload)
  3349. {
  3350. mtrace();
  3351. char statusStr[20]={0};
  3352. char dataStr[10]={0};
  3353. char sstr[20]={0};
  3354. int c = 0;
  3355. char *loc;
  3356. int result = FAIL;
  3357. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3358. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3359. /**********************status**************************/
  3360. loc = strstr(payload, "status");
  3361. memset(sstr ,0, sizeof(sstr) );
  3362. c = 0;
  3363. while (loc[3+strlen("status")+c] != '\"')
  3364. {
  3365. sstr[c] = loc[3+strlen("status")+c];
  3366. c++;
  3367. }
  3368. sstr[c] = '\0';
  3369. strcpy(statusStr, sstr);
  3370. /**********************data**************************/
  3371. loc = strstr(payload, "data");
  3372. memset(sstr ,0, sizeof(sstr) );
  3373. c = 0;
  3374. while (loc[3+strlen("data")+c] != '\"')
  3375. {
  3376. sstr[c] = loc[3+strlen("data")+c];
  3377. c++;
  3378. }
  3379. sstr[c] = '\0';
  3380. strcpy(dataStr, sstr);
  3381. return result;
  3382. }
  3383. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3384. {
  3385. mtrace();
  3386. int result = FAIL;
  3387. char message[1000]={0};
  3388. double diff_f = 0.0;
  3389. int diff_i = 0;
  3390. int diffSeconds = 0;
  3391. struct tm tp;
  3392. int TimeZero = FALSE;
  3393. int CompositeScheduleIndex = 0;
  3394. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  3395. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  3396. {
  3397. TimeZero = TRUE;
  3398. }
  3399. else
  3400. {
  3401. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3402. }
  3403. if(TimeZero == FALSE)
  3404. {
  3405. tp.tm_isdst = -1;
  3406. time_t utc = mktime(&tp);
  3407. time_t t = time(NULL);
  3408. diff_f = difftime(t, utc);
  3409. diff_i = (int)diff_f;
  3410. diffSeconds = diff_i % 86400;//86400 seconds/day
  3411. }
  3412. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3413. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3414. #if 0 //remove temporally
  3415. 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}"
  3416. ,MESSAGE_TYPE_CALLRESULT
  3417. ,uuid
  3418. ,payload
  3419. ,connectorIdInt
  3420. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3421. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3422. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3423. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3424. #endif
  3425. if(nPeriod == 0)
  3426. {
  3427. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  3428. {
  3429. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  3430. ,MESSAGE_TYPE_CALLRESULT
  3431. ,uuid
  3432. ,payload
  3433. ,connectorIdInt);
  3434. }
  3435. else
  3436. {
  3437. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3438. ,MESSAGE_TYPE_CALLRESULT
  3439. ,uuid
  3440. ,payload
  3441. ,connectorIdInt
  3442. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3443. }
  3444. }
  3445. else
  3446. {
  3447. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3448. ,MESSAGE_TYPE_CALLRESULT
  3449. ,uuid
  3450. ,payload
  3451. ,connectorIdInt
  3452. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3453. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3454. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3455. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3456. int len = nPeriod;
  3457. //Last Period StartPriod is less than diffSeconds
  3458. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds) || (diffSeconds == 0))
  3459. {
  3460. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3461. , 0
  3462. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3463. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3464. }
  3465. else
  3466. {
  3467. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3468. {
  3469. 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)
  3470. {
  3471. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3472. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3473. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3474. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3475. }
  3476. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3477. {
  3478. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3479. , ((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*/))
  3480. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3481. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3482. }
  3483. }
  3484. }
  3485. sprintf(message + strlen(message), "]}}]");
  3486. }
  3487. LWS_Send(message);
  3488. result = TRUE;
  3489. return result;
  3490. }
  3491. int sendGetConfigurationConfirmation(char *uuid)
  3492. {
  3493. mtrace();
  3494. int result = FAIL;
  3495. int MaxKeySupported = 0;
  3496. int sentConfigurationNumber= 0;
  3497. int sentunConfigurationNumber= 0;
  3498. char message[4000]={0};
  3499. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3500. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3501. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3502. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3503. ,MESSAGE_TYPE_CALLRESULT
  3504. ,uuid );
  3505. //configuration key
  3506. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3507. {
  3508. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3509. {
  3510. if (sentConfigurationNumber == 0)
  3511. {
  3512. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3513. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3514. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3515. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3516. }
  3517. else
  3518. {
  3519. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3520. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3521. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3522. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3523. }
  3524. sentConfigurationNumber = sentConfigurationNumber + 1;
  3525. }
  3526. }
  3527. sprintf(message + strlen(message), "]");
  3528. if(UnknownKeynum != 0)
  3529. {
  3530. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3531. //unkown key
  3532. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3533. {
  3534. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3535. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3536. if(sentunConfigurationNumber == 0)
  3537. {
  3538. sprintf(message + strlen(message), "\"%s\""
  3539. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3540. }
  3541. else
  3542. {
  3543. sprintf(message + strlen(message), ",\"%s\""
  3544. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3545. }
  3546. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3547. }
  3548. sprintf(message + strlen(message), "]");
  3549. }
  3550. sprintf(message + strlen(message), "}]");
  3551. LWS_Send(message);
  3552. return result;
  3553. }
  3554. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3555. {
  3556. mtrace();
  3557. int result = FAIL;
  3558. char message[400]={0};
  3559. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3560. if(strcmp(payload,"")==0)
  3561. {
  3562. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3563. }
  3564. else
  3565. {
  3566. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3567. }
  3568. LWS_Send(message);
  3569. result = TRUE;
  3570. return result;
  3571. }
  3572. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3573. {
  3574. mtrace();
  3575. int result = FAIL;
  3576. char message[80]={0};
  3577. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3578. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3579. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3580. LWS_Send(message);
  3581. result = TRUE;
  3582. return result;
  3583. }
  3584. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3585. {
  3586. mtrace();
  3587. int result = FAIL;
  3588. char message[80]={0};
  3589. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3590. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3591. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3592. LWS_Send(message);
  3593. result = TRUE;
  3594. return result;
  3595. }
  3596. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3597. {
  3598. mtrace();
  3599. int result = FAIL;
  3600. char message[80]={0};
  3601. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3602. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3603. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3604. LWS_Send(message);
  3605. result = TRUE;
  3606. return result;
  3607. }
  3608. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3609. {
  3610. mtrace();
  3611. int result = FAIL;
  3612. char message[80]={0};
  3613. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3614. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3615. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3616. LWS_Send(message);
  3617. result = TRUE;
  3618. return result;
  3619. }
  3620. int sendResetConfirmation(char *uuid,char *payload)
  3621. {
  3622. mtrace();
  3623. int result = FAIL;
  3624. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3625. char message[80]={0};
  3626. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3627. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3628. LWS_Send(message);
  3629. result = TRUE;
  3630. return result;
  3631. }
  3632. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3633. {
  3634. mtrace();
  3635. int result = FAIL;
  3636. char message[500]={0};
  3637. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3638. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3639. LWS_Send(message);
  3640. result = TRUE;
  3641. return result;
  3642. }
  3643. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3644. {
  3645. mtrace();
  3646. int result = FAIL;
  3647. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3648. char message[80]={0};
  3649. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3650. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3651. LWS_Send(message);
  3652. result = TRUE;
  3653. return result;
  3654. }
  3655. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3656. {
  3657. mtrace();
  3658. int result = FAIL;
  3659. char message[80]={0};
  3660. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3661. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3662. LWS_Send(message);
  3663. result = TRUE;
  3664. return result;
  3665. }
  3666. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3667. {
  3668. mtrace();
  3669. int result = FAIL;
  3670. char message[80]={0};
  3671. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3672. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3673. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3674. LWS_Send(message);
  3675. result = TRUE;
  3676. return result;
  3677. }
  3678. int sendUpdateFirmwareConfirmation(char *uuid)
  3679. {
  3680. mtrace();
  3681. int result = FAIL;
  3682. char message[60]={0};
  3683. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3684. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3685. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3686. LWS_Send(message);
  3687. result = TRUE;
  3688. return result;
  3689. }
  3690. //==========================================
  3691. // send CallError routine
  3692. //==========================================
  3693. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3694. {
  3695. mtrace();
  3696. //int result = FAIL;
  3697. char message[220]={0};
  3698. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3699. #ifdef SystemLogMessage
  3700. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3701. uniqueId, action, errorCode, errorDescription);
  3702. #endif
  3703. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3704. LWS_Send(message);
  3705. //result = TRUE;
  3706. }
  3707. //==========================================
  3708. // Handle server request routine Start
  3709. //==========================================
  3710. #define GUN_NUM 1
  3711. int handleCancelReservationRequest(char *uuid, char *payload)
  3712. {
  3713. mtrace();
  3714. int result = FAIL;
  3715. int gunNO = 0;
  3716. int reservationIdInt =0;
  3717. char comfirmstr[20];
  3718. int c = 0;
  3719. int copyTo = 0;
  3720. char *loc;
  3721. char sstr[100]={0};
  3722. DEBUG_INFO("handle CancelReservationRequest\n");
  3723. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3724. c = 0;
  3725. copyTo = 0;
  3726. loc = strstr(payload, "reservationId");
  3727. memset(sstr ,0, sizeof(sstr) );
  3728. while (loc[strlen("reservationId")+2+c] != '}')
  3729. {
  3730. if(loc[strlen("interval")+2+c] != ' ')
  3731. {
  3732. sstr[copyTo] = loc[strlen("reservationId")+2+c];
  3733. copyTo = copyTo + 1;
  3734. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3735. }
  3736. c++;
  3737. }
  3738. sstr[copyTo] = '\0';
  3739. reservationIdInt = atoi(sstr);
  3740. memset(comfirmstr, 0, sizeof comfirmstr);
  3741. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3742. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3743. //check Transaction active
  3744. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3745. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3746. {
  3747. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3748. {
  3749. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3750. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3751. if(gunType[2] == 'J')
  3752. {
  3753. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  3754. }
  3755. else
  3756. {
  3757. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3758. }
  3759. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3760. goto end;
  3761. }
  3762. }
  3763. for (int index = 0; index < CCS_QUANTITY; index++)
  3764. {
  3765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3766. {
  3767. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3768. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3769. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  3770. {
  3771. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  3772. }
  3773. else
  3774. {
  3775. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3776. }
  3777. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3778. goto end;
  3779. }
  3780. }
  3781. for (int index = 0; index < GB_QUANTITY; index++)
  3782. {
  3783. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3784. {
  3785. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3786. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3787. if(gunType[2] == 'G')
  3788. {
  3789. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  3790. }
  3791. else
  3792. {
  3793. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3794. }
  3795. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3796. goto end;
  3797. }
  3798. }
  3799. for (int index = 0; index < AC_QUANTITY; index++)
  3800. {
  3801. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3802. {
  3803. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3804. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3806. {
  3807. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  3808. }
  3809. else
  3810. {
  3811. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3812. }
  3813. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3814. goto end;
  3815. }
  3816. }
  3817. //The reservationId does NOT match the reservationId
  3818. sendCancelReservationConfirmation(uuid, comfirmstr);
  3819. end:
  3820. // Fill in ocpp packet uuid
  3821. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3822. return result;
  3823. }
  3824. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3825. {
  3826. mtrace();
  3827. int result = FAIL;
  3828. int gunIndex = 0;
  3829. char sstr[90]={0},sstrtemp[50]={ 0 };
  3830. char typeStr[16]={0};
  3831. char comfirmstr[20];
  3832. int specificId = FALSE;
  3833. char *loc;
  3834. //int intervalInt = 0;
  3835. int c = 0;
  3836. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3837. strcpy(sstrtemp, stringtrimspace(payload));
  3838. /*** connectorId ****/
  3839. loc = strstr(sstrtemp, "connectorId");
  3840. memset(sstr ,0, sizeof(sstr) );
  3841. c = 0;
  3842. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') ) // 2: ":
  3843. {
  3844. sstr[c] = loc[strlen("connectorId")+2+c];
  3845. c++;
  3846. }
  3847. sstr[c] = '\0';
  3848. gunIndex = atoi(sstr);
  3849. /***type ****/
  3850. loc = strstr(sstrtemp, "type");
  3851. memset(sstr ,0, sizeof(sstr) );
  3852. c = 0;
  3853. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3854. {
  3855. sstr[c] = loc[3+strlen("type")+c];
  3856. c++;
  3857. }
  3858. sstr[c] = '\0';
  3859. strcpy(typeStr, sstr);
  3860. if(gunIndex != 0)
  3861. {
  3862. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3863. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3864. }
  3865. else
  3866. {
  3867. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3868. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3869. }
  3870. memset(comfirmstr, 0, sizeof comfirmstr);
  3871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3872. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3873. {
  3874. specificId = TRUE;
  3875. }
  3876. if(specificId == FALSE)
  3877. goto end;
  3878. if(gunIndex != 0)
  3879. {
  3880. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3881. }
  3882. else
  3883. {
  3884. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3885. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3886. }
  3887. /*
  3888. enum SYSTEM_STATUS
  3889. {
  3890. SYS_MODE_BOOTING = 0,
  3891. SYS_MODE_IDLE = 1,
  3892. SYS_MODE_AUTHORIZING = 2,
  3893. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3894. SYS_MODE_REASSIGN = 4,
  3895. SYS_MODE_PREPARING = 5,
  3896. SYS_MODE_PREPARE_FOR_EV = 6,
  3897. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3898. SYS_MODE_CHARGING = 8,
  3899. SYS_MODE_TERMINATING = 9,
  3900. SYS_MODE_COMPLETE = 10,
  3901. SYS_MODE_ALARM = 11,
  3902. SYS_MODE_FAULT = 12,
  3903. SYS_MODE_RESERVATION = 13,
  3904. SYS_MODE_BOOKING = 14,
  3905. SYS_MODE_MAINTAIN = 15,
  3906. SYS_MODE_DEBUG = 16,
  3907. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3908. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3909. SYS_MODE_UPDATE = 19
  3910. };
  3911. */
  3912. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3913. {
  3914. //check Transaction active
  3915. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3916. {
  3917. if ((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')))
  3918. {
  3919. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3920. {
  3921. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3922. }
  3923. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3924. {
  3925. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3926. }
  3927. else
  3928. {
  3929. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3930. }
  3931. goto end;
  3932. }
  3933. }//END FOR CHAdeMO_QUANTITY
  3934. for (int index = 0; index < CCS_QUANTITY; index++)
  3935. {
  3936. if ((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))))
  3937. {
  3938. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3939. {
  3940. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3941. }
  3942. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3943. {
  3944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3945. }
  3946. else
  3947. {
  3948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3949. }
  3950. goto end;
  3951. }
  3952. }//END FOR CCS_QUANTITY
  3953. for (int index = 0; index < GB_QUANTITY; index++)
  3954. {
  3955. if ((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))
  3956. {
  3957. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3958. {
  3959. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3960. }
  3961. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3962. {
  3963. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3964. }
  3965. else
  3966. {
  3967. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3968. }
  3969. goto end;
  3970. }
  3971. }// END FOR GB_QUANTITY
  3972. for (int index = 0; index < AC_QUANTITY; index++)
  3973. {
  3974. if ((gunIndex == 0) || ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))))
  3975. {
  3976. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3977. {
  3978. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3979. }
  3980. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3981. {
  3982. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3983. }
  3984. else
  3985. {
  3986. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3987. }
  3988. goto end;
  3989. }
  3990. }//END FOR AC_QUANTITY
  3991. }//END FOR AvailabilityTypeStr[Inoperative]
  3992. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3993. {
  3994. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3995. //check Transaction active
  3996. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3997. {
  3998. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3999. {
  4000. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4001. goto end;
  4002. }
  4003. }//END FOR CHAdeMO_QUANTITY
  4004. for (int index = 0; index < CCS_QUANTITY; index++)
  4005. {
  4006. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4007. {
  4008. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4009. goto end;
  4010. }
  4011. }//END FOR CCS_QUANTITY
  4012. for (int index = 0; index < GB_QUANTITY; index++)
  4013. {
  4014. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4015. {
  4016. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  4017. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4018. goto end;
  4019. }
  4020. }// END FOR GB_QUANTITY
  4021. for (int index = 0; index < AC_QUANTITY; index++)
  4022. {
  4023. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4024. {
  4025. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4026. goto end;
  4027. }
  4028. }//END FOR CHAdeMO_QUANTITY
  4029. }//END FOR AvailabilityTypeStr[Operative]
  4030. end:
  4031. if(gunIndex != 0)
  4032. {
  4033. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  4034. }
  4035. else
  4036. {
  4037. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  4038. }
  4039. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  4040. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  4041. return result;
  4042. }
  4043. int handleChangeConfigurationRequest(char *uuid, char *payload)
  4044. {
  4045. mtrace();
  4046. int result = FAIL;
  4047. char sstr[100]={0},sstrtemp[160]={ 0 };
  4048. char keystr[40]={0};
  4049. char valuestr[100]={0};
  4050. char *loc;
  4051. int c = 0;
  4052. char comfirmstr[20]={0};
  4053. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  4054. strcpy(sstrtemp, stringtrimspace(payload));
  4055. /***key ****/
  4056. loc = strstr(sstrtemp, "key");
  4057. memset(sstr ,0, sizeof(sstr) );
  4058. c = 0;
  4059. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  4060. {
  4061. sstr[c] = loc[3+strlen("key")+c];
  4062. c++;
  4063. }
  4064. sstr[c] = '\0';
  4065. strcpy(keystr, sstr);
  4066. //DEBUG_INFO( "keystr=%s\n",keystr);
  4067. /***value ****/
  4068. loc = strstr(sstrtemp, "value");
  4069. memset(sstr ,0, sizeof(sstr) );
  4070. c = 0;
  4071. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  4072. {
  4073. sstr[c] = loc[3+strlen("value")+c];
  4074. c++;
  4075. }
  4076. sstr[c] = '\0';
  4077. strcpy(valuestr, sstr);
  4078. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  4079. if((uuid==NULL) || (payload ==NULL) )
  4080. {
  4081. #ifdef Debug
  4082. DEBUG_INFO("payload is null\n");
  4083. #endif
  4084. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4085. }
  4086. else
  4087. {
  4088. int status = setKeyValue(keystr, valuestr);
  4089. switch(status)
  4090. {
  4091. case ConfigurationStatus_Accepted:
  4092. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  4093. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  4094. StoreConfigurationTable();
  4095. break;
  4096. case ConfigurationStatus_Rejected:
  4097. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4098. break;
  4099. case RebootRequired:
  4100. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  4101. StoreConfigurationTable();
  4102. break;
  4103. case NotSupported:
  4104. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  4105. break;
  4106. default:
  4107. break;
  4108. }
  4109. }
  4110. //confirmation.setStatus(ConfigurationStatus.Rejected);
  4111. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  4112. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  4113. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  4114. {
  4115. ChageWebSocketPingInterval(atoi(valuestr));
  4116. }
  4117. return result;
  4118. }
  4119. int handleClearCacheRequest(char *uuid, char *payload)
  4120. {
  4121. mtrace();
  4122. int result = FAIL;
  4123. char comfirmstr[20];
  4124. int fd;
  4125. char rmFileCmd[100]={0};
  4126. struct stat stats;
  4127. DEBUG_INFO("handle ClearCacheRequest\n");
  4128. stat("/Storage/OCPP", &stats);
  4129. // Check for directory existence
  4130. if (S_ISDIR(stats.st_mode) == 1)
  4131. {
  4132. //DEBUG_ERROR("\n OCPP directory exist \n");
  4133. }
  4134. else
  4135. {
  4136. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  4137. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  4138. system(rmFileCmd);
  4139. }
  4140. memset(rmFileCmd, 0, sizeof rmFileCmd);
  4141. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  4142. {
  4143. DEBUG_INFO("AuthorizationCache file exist.\n");
  4144. }
  4145. else
  4146. {
  4147. DEBUG_INFO("AuthorizationCache file not exist\n");
  4148. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  4149. if(log == NULL)
  4150. {
  4151. DEBUG_INFO("AuthorizationCache file is NULL\n");
  4152. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4153. goto end;
  4154. }
  4155. else
  4156. {
  4157. fclose(log);
  4158. }
  4159. }
  4160. fd = open(AuthorizationCache_JSON,O_RDWR);
  4161. if(fd < 0)
  4162. {
  4163. DEBUG_INFO("open AuthorizationCache file failed\n");
  4164. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4165. }
  4166. else
  4167. {
  4168. DEBUG_INFO("open AuthorizationCache file successful\n");
  4169. //* 清空? 件 */
  4170. ftruncate(fd,0);
  4171. //* ? 新设置? 件? 移??*/
  4172. lseek(fd,0,SEEK_SET);
  4173. close(fd);
  4174. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  4175. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  4176. }
  4177. end:
  4178. sendClearCacheConfirmation(uuid, comfirmstr);
  4179. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  4180. return result;
  4181. }
  4182. int handleClearChargingProfileRequest(char *uuid, char *payload)
  4183. {
  4184. mtrace();
  4185. int result = FAIL;
  4186. int resultRename;
  4187. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  4188. char chargingProfilePurposeStr[26]={0};
  4189. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  4190. char tempchargingProfilePurposeStr[26]={0};
  4191. char sstr[160]={0},sstrtemp[160]={ 0 };//sstr[200]={ 0 };
  4192. char str[100]={0};
  4193. int c = 0;
  4194. //int i = 0;
  4195. //char * pch;
  4196. char *loc;
  4197. char fname[200]={0};
  4198. char comfirmstr[20]={0};
  4199. char word[1600]={0};
  4200. int clearflag = FALSE;
  4201. int chargingProfileIdIsNULL = FALSE;
  4202. int connectorIsNULL = FALSE;
  4203. int chargingProfilePurposeIsNULL = FALSE;
  4204. int stackLevelIsNULL = FALSE;
  4205. //int GotoEnd = FALSE;
  4206. FILE *fptr1, *fptr2;
  4207. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  4208. int n_chargingProfile=0;
  4209. int isEmptyFile = FALSE;
  4210. char sLineWord[1600]={0};
  4211. char chargingProfiles[10][100]={0};
  4212. int ChargeProfileCount = 0;
  4213. char ch;
  4214. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  4215. strcpy(sstrtemp, stringtrimspace(payload));
  4216. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  4217. //***id ****/
  4218. c = 0;
  4219. loc = strstr(sstrtemp, "id");
  4220. memset(sstr ,0, sizeof(sstr) );
  4221. if(loc == NULL)
  4222. {
  4223. chargingProfileIdIsNULL = TRUE;
  4224. }
  4225. else
  4226. {
  4227. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  4228. {
  4229. sstr[c] = loc[strlen("id")+2+c];
  4230. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4231. c++;
  4232. }
  4233. sstr[c] = '\0';
  4234. chargingProfileIdInt = atoi(sstr);
  4235. }
  4236. //***connectorId ****/
  4237. c=0;
  4238. loc = strstr(sstrtemp, "connectorId");
  4239. memset(sstr ,0, sizeof(sstr) );
  4240. if(loc == NULL)
  4241. {
  4242. connectorIsNULL = TRUE;
  4243. }
  4244. else
  4245. {
  4246. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  4247. {
  4248. sstr[c] = loc[strlen("connectorId")+2+c];
  4249. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4250. c++;
  4251. }
  4252. sstr[c] = '\0';
  4253. connectorIdInt = atoi(sstr);
  4254. }
  4255. //***chargingProfilePurpose ****/
  4256. loc = strstr(sstrtemp, "chargingProfilePurpose");
  4257. memset(sstr ,0, sizeof(sstr) );
  4258. c = 0;
  4259. if(loc == NULL)
  4260. {
  4261. chargingProfilePurposeIsNULL = TRUE;
  4262. }
  4263. else
  4264. {
  4265. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  4266. {
  4267. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4268. c++;
  4269. }
  4270. sstr[c] = '\0';
  4271. strcpy(chargingProfilePurposeStr, sstr);
  4272. }
  4273. //***stackLevel ****/
  4274. c=0;
  4275. loc = strstr(sstrtemp, "stackLevel");
  4276. memset(sstr ,0, sizeof(sstr) );
  4277. if(loc == NULL)
  4278. {
  4279. stackLevelIsNULL = TRUE;
  4280. }
  4281. else
  4282. {
  4283. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  4284. {
  4285. sstr[c] = loc[strlen("stackLevel")+2+c];
  4286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4287. c++;
  4288. }
  4289. sstr[c] = '\0';
  4290. stackLevelInt = atoi(sstr);
  4291. }
  4292. if(connectorIsNULL == FALSE)
  4293. {
  4294. switch(connectorIdInt)
  4295. {
  4296. case 0:
  4297. if(chargingProfilePurposeIsNULL == TRUE)
  4298. {
  4299. int l = 0;
  4300. strcpy(fname, ChargePointMaxProfile_JSON);
  4301. if((access(fname,F_OK))!=-1)
  4302. {
  4303. strcpy(chargingProfiles[l], fname);
  4304. l = l + 1;
  4305. }
  4306. strcpy(fname, TxDefaultProfile_0_JSON);
  4307. if((access(fname,F_OK))!=-1)
  4308. {
  4309. strcpy(chargingProfiles[l], fname);
  4310. l = l + 1;
  4311. }
  4312. ChargeProfileCount = l;
  4313. }
  4314. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  4315. {
  4316. strcpy(fname, ChargePointMaxProfile_JSON);
  4317. if((access(fname,F_OK))!=-1)
  4318. {
  4319. strcpy(chargingProfiles[0], fname);
  4320. ChargeProfileCount = 1;
  4321. }
  4322. }
  4323. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4324. {
  4325. strcpy(fname, TxDefaultProfile_0_JSON);
  4326. if((access(fname,F_OK))!=-1)
  4327. {
  4328. strcpy(chargingProfiles[0], fname);
  4329. ChargeProfileCount = 1;
  4330. }
  4331. }
  4332. break;
  4333. default:
  4334. if(chargingProfilePurposeIsNULL == TRUE)
  4335. {
  4336. int m = 0;
  4337. memset(fname, 0, sizeof fname);
  4338. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4339. if((access(fname,F_OK))!=-1)
  4340. {
  4341. strcpy(chargingProfiles[m], fname);
  4342. m = m + 1;
  4343. }
  4344. memset(fname, 0, sizeof fname);
  4345. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4346. if((access(fname,F_OK))!=-1)
  4347. {
  4348. strcpy(chargingProfiles[m], fname);
  4349. m = m + 1;
  4350. }
  4351. ChargeProfileCount = m;
  4352. }
  4353. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4354. {
  4355. //strcpy(fname, TxDefaultProfile_1_JSON);
  4356. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4357. if((access(fname,F_OK))!=-1)
  4358. {
  4359. strcpy(chargingProfiles[0], fname);
  4360. ChargeProfileCount = 1;
  4361. }
  4362. }
  4363. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  4364. {
  4365. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4366. if((access(fname,F_OK))!=-1)
  4367. {
  4368. strcpy(chargingProfiles[0], fname);
  4369. ChargeProfileCount = 1;
  4370. }
  4371. //strcpy(fname, TxProfile_1_JSON);
  4372. }
  4373. //strcpy(fname, ChargePointMaxProfile_JSON );
  4374. break;
  4375. }
  4376. }
  4377. else // Check all Charging Profiles
  4378. {
  4379. int i = 0;
  4380. char fnametemp[200]={0};
  4381. ChargeProfileCount = 0;
  4382. //Check ChargePointMaxProfile.json exit
  4383. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  4384. {
  4385. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  4386. i = i + 1;
  4387. }
  4388. //Check TxDefaultProfile_0.json exit
  4389. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  4390. {
  4391. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  4392. i = i + 1;
  4393. }
  4394. //Check TxDefaultProfile_%d.json
  4395. for(int j=1; j <= gunTotalNumber; j++)
  4396. {
  4397. memset(fnametemp, 0, sizeof fnametemp);
  4398. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  4399. if((access(fnametemp,F_OK))!=-1)
  4400. {
  4401. strcpy(chargingProfiles[i], fnametemp);
  4402. i = i + 1;
  4403. }
  4404. }
  4405. //Check TxProfile_%d.json
  4406. for(int j=1; j <= gunTotalNumber; j++)
  4407. {
  4408. memset(fnametemp, 0, sizeof fnametemp);
  4409. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  4410. if((access(fnametemp,F_OK))!=-1)
  4411. {
  4412. strcpy(chargingProfiles[i], fnametemp);
  4413. i = i + 1;
  4414. }
  4415. }
  4416. ChargeProfileCount = i;
  4417. }// End connectorIsNULL is TRUE
  4418. if(ChargeProfileCount == 0)
  4419. {
  4420. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4421. goto end;
  4422. }
  4423. #if 0
  4424. fptr1 = fopen(fname, "r");
  4425. if (!fptr1)
  4426. {
  4427. //file not exist
  4428. DEBUG_INFO("Unable to open the input file!!\n");
  4429. fptr1 = fopen(fname, "w+");
  4430. }
  4431. fclose(fptr1);
  4432. #endif
  4433. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  4434. {
  4435. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4436. goto end;
  4437. }
  4438. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  4439. {
  4440. memset(str, 0, sizeof str);
  4441. // clear temp file
  4442. sprintf(str,"rm -f %s",temp);
  4443. system(str);
  4444. for(int k=0; k < ChargeProfileCount; k++)
  4445. {
  4446. memset(str, 0, sizeof str);
  4447. //clear file in C
  4448. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4449. system(str);
  4450. }
  4451. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4452. goto end;
  4453. }
  4454. else if(connectorIsNULL == TRUE)
  4455. {
  4456. for(int k=0; k < ChargeProfileCount; k++)
  4457. {
  4458. fptr1 = fopen(chargingProfiles[k], "r");
  4459. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  4460. //Check Charging Profile Count
  4461. while(fscanf(fptr1, "%s", word) != EOF)
  4462. {
  4463. //DEBUG_INFO("word=%s\n",word);
  4464. if(strstr(word, "chargingProfileId")!= NULL)
  4465. {
  4466. //DEBUG_INFO("test chargingProfileId \n");
  4467. n_chargingProfile = n_chargingProfile + 1;
  4468. //DEBUG_INFO("chargingProfileId Found\n");
  4469. }
  4470. }
  4471. rewind(fptr1);
  4472. //search Charging Profile Element
  4473. //int i= 0;
  4474. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4475. {
  4476. //------------------------tempconnectorIdInt------------------------//
  4477. loc = strstr(sLineWord, "connectorId");
  4478. c = 0;
  4479. memset(sstr ,0, sizeof(sstr) );
  4480. while (loc[strlen("connectorId")+2+c] != ',')
  4481. {
  4482. sstr[c] = loc[strlen("connectorId")+2+c];
  4483. c++;
  4484. }
  4485. sstr[c] = '\0';
  4486. tempconnectorIdInt = atoi(sstr);
  4487. printf("file's gun number is %d\n", tempconnectorIdInt);
  4488. //--------------------------chargingProfileId--------------------//
  4489. c = 0;
  4490. loc = strstr(sLineWord, "chargingProfileId");
  4491. memset(sstr ,0, sizeof(sstr) );
  4492. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4493. {
  4494. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4495. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4496. c++;
  4497. }
  4498. sstr[c] = '\0';
  4499. tempchargingProfileIdInt = atoi(sstr);
  4500. //stackLevel
  4501. c = 0;
  4502. loc = strstr(sLineWord, "stackLevel");
  4503. memset(sstr ,0, sizeof(sstr) );
  4504. while (loc[strlen("stackLevel")+2+c] != ',')
  4505. {
  4506. sstr[c] = loc[strlen("stackLevel")+2+c];
  4507. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4508. c++;
  4509. }
  4510. sstr[c] = '\0';
  4511. tempstackLevelInt = atoi(sstr);
  4512. c = 0;
  4513. loc = strstr(sLineWord, "chargingProfilePurpose");
  4514. memset(sstr ,0, sizeof(sstr) );
  4515. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4516. {
  4517. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4518. c++;
  4519. }
  4520. sstr[c] = '\0';
  4521. strcpy(tempchargingProfilePurposeStr, sstr);
  4522. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4523. {
  4524. //------- not write to fptr2-------//
  4525. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4526. //clearflag = TRUE;
  4527. }
  4528. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4529. {
  4530. //------- not write to fptr2-------//
  4531. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4532. }
  4533. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4534. {
  4535. //------- not write to fptr2-------//
  4536. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4537. }
  4538. else
  4539. {
  4540. fprintf(fptr2, sLineWord);//writing data into file
  4541. }
  4542. memset(sLineWord, 0, sizeof sLineWord);
  4543. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4544. if(clearflag == TRUE)
  4545. {
  4546. fclose(fptr1);
  4547. fclose(fptr2);
  4548. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4549. system(str);
  4550. // clear temp file
  4551. sprintf(str,"rm -f %s",temp);
  4552. system(str);
  4553. }
  4554. else
  4555. {
  4556. fclose(fptr1);
  4557. fclose(fptr2);
  4558. memset(str, 0, sizeof str);
  4559. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4560. system(str);
  4561. resultRename = rename(temp, chargingProfiles[k]);
  4562. if(resultRename == 0)
  4563. {
  4564. DEBUG_INFO("File ChargingProfile renamed successfully");
  4565. }
  4566. else
  4567. {
  4568. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4569. }
  4570. if(comfirmstr[0]== 0)
  4571. {
  4572. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4573. }
  4574. //Check chargingProfile is empty file
  4575. /*------ Read the file ----------------*/
  4576. fptr1=fopen(chargingProfiles[k],"r");
  4577. ch=fgetc(fptr1);
  4578. rewind(fptr1);
  4579. memset(sLineWord, 0, sizeof sLineWord);
  4580. if(ch!=EOF)
  4581. {
  4582. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4583. {
  4584. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4585. if(sLineWord[0]=='\0')
  4586. {
  4587. isEmptyFile = TRUE;
  4588. break;
  4589. }
  4590. else
  4591. {
  4592. isEmptyFile = FALSE;
  4593. break;
  4594. }
  4595. }
  4596. }
  4597. fclose(fptr1);
  4598. if(isEmptyFile == TRUE)
  4599. {
  4600. memset(str, 0, sizeof str);
  4601. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4602. system(str);
  4603. }
  4604. }
  4605. }// End of while(int k=0; k < ChargePointCount; k++)
  4606. }
  4607. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4608. {
  4609. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4610. for(int k=0; k < ChargeProfileCount; k++)
  4611. {
  4612. fptr1 = fopen(chargingProfiles[k], "r");
  4613. fptr2 = fopen(temp, "w+");
  4614. //Check Charging Profile Count
  4615. while(fscanf(fptr1, "%s", word) != EOF)
  4616. {
  4617. //DEBUG_INFO("word=%s\n",word);
  4618. if(strstr(word, "chargingProfileId")!= NULL)
  4619. {
  4620. //DEBUG_INFO("test chargingProfileId \n");
  4621. n_chargingProfile = n_chargingProfile + 1;
  4622. //DEBUG_INFO("chargingProfileId Found\n");
  4623. }
  4624. }
  4625. rewind(fptr1);
  4626. //search Charging Profile Element
  4627. //int i= 0;
  4628. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4629. {
  4630. //*************************tempconnectorIdInt*********************************/
  4631. loc = strstr(sLineWord, "connectorId");
  4632. c = 0;
  4633. memset(sstr ,0, sizeof(sstr) );
  4634. while (loc[strlen("connectorId")+2+c] != ',')
  4635. {
  4636. sstr[c] = loc[strlen("connectorId")+2+c];
  4637. c++;
  4638. }
  4639. sstr[c] = '\0';
  4640. tempconnectorIdInt = atoi(sstr);
  4641. //chargingProfileId
  4642. c = 0;
  4643. loc = strstr(sLineWord, "chargingProfileId");
  4644. memset(sstr ,0, sizeof(sstr) );
  4645. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4646. {
  4647. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4648. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4649. c++;
  4650. }
  4651. sstr[c] = '\0';
  4652. tempchargingProfileIdInt = atoi(sstr);
  4653. //stackLevel
  4654. c = 0;
  4655. loc = strstr(sLineWord, "stackLevel");
  4656. memset(sstr ,0, sizeof(sstr) );
  4657. while (loc[strlen("stackLevel")+2+c] != ',')
  4658. {
  4659. sstr[c] = loc[strlen("stackLevel")+2+c];
  4660. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4661. c++;
  4662. }
  4663. sstr[c] = '\0';
  4664. tempstackLevelInt = atoi(sstr);
  4665. c = 0;
  4666. loc = strstr(sLineWord, "chargingProfilePurpose");
  4667. memset(sstr ,0, sizeof(sstr) );
  4668. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4669. {
  4670. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4671. c++;
  4672. }
  4673. sstr[c] = '\0';
  4674. strcpy(tempchargingProfilePurposeStr, sstr);
  4675. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4676. {
  4677. //------- not write to fptr2-------//
  4678. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4679. //clearflag = TRUE;
  4680. }
  4681. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4682. {
  4683. //------- not write to fptr2-------//
  4684. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4685. }
  4686. else if(stackLevelIsNULL == TRUE)
  4687. {
  4688. //Clear Whole File
  4689. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4690. clearflag = TRUE;
  4691. break;
  4692. }
  4693. else
  4694. {
  4695. fprintf(fptr2, sLineWord);//writing data into file
  4696. }
  4697. memset(sLineWord, 0, sizeof sLineWord);
  4698. }
  4699. if(clearflag == TRUE)
  4700. {
  4701. fclose(fptr1);
  4702. fclose(fptr2);
  4703. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4704. system(str);
  4705. // clear temp file
  4706. sprintf(str,"rm -f %s",temp);
  4707. system(str);
  4708. }
  4709. else
  4710. {
  4711. fclose(fptr1);
  4712. fclose(fptr2);
  4713. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4714. system(str);
  4715. resultRename = rename(temp, chargingProfiles[k]);
  4716. if(resultRename == 0)
  4717. {
  4718. DEBUG_INFO("File ChargingProfile renamed successfully");
  4719. }
  4720. else
  4721. {
  4722. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4723. }
  4724. if(comfirmstr[0]== 0)
  4725. {
  4726. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4727. }
  4728. //Check chargingProfile is empty file
  4729. /*------ Read the file ----------------*/
  4730. fptr1=fopen(chargingProfiles[k],"r");
  4731. ch=fgetc(fptr1);
  4732. rewind(fptr1);
  4733. memset(sLineWord, 0, sizeof sLineWord);
  4734. if(ch!=EOF)
  4735. {
  4736. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4737. {
  4738. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4739. if(sLineWord[0]=='\0')
  4740. {
  4741. isEmptyFile = TRUE;
  4742. break;
  4743. }
  4744. else
  4745. {
  4746. isEmptyFile = FALSE;
  4747. break;
  4748. }
  4749. }
  4750. }
  4751. fclose(fptr1);
  4752. if(isEmptyFile == TRUE)
  4753. {
  4754. memset(str, 0, sizeof str);
  4755. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4756. system(str);
  4757. }
  4758. /*------- End of reading ---------------*/
  4759. }
  4760. } // while(int k=0; k < ChargeProfileCount; k++)
  4761. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4762. end:
  4763. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4764. return result;
  4765. }
  4766. int handleDataTransferRequest(char *uuid, char *payload)
  4767. {
  4768. mtrace();
  4769. int result = FAIL;
  4770. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4771. char tempvendorId[255]={0};
  4772. char tempmessageId[50]={0};
  4773. char tempdata[50]={0};
  4774. char sstr[160]={0};//sstr[200]={ 0 };
  4775. char message[80]={0};
  4776. int c = 0;
  4777. char *loc;
  4778. DEBUG_INFO("handle DataTransferRequest\n");
  4779. if((uuid != NULL) && (payload != NULL))
  4780. {
  4781. //===============================
  4782. // vendorId
  4783. //===============================
  4784. c = 0;
  4785. loc = strstr(payload, "vendorId");
  4786. while (loc[strlen("vendorId")+3+c] != '\"')
  4787. {
  4788. sstr[c] = loc[strlen("vendorId")+3+c];
  4789. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4790. c++;
  4791. }
  4792. sstr[c] = '\0';
  4793. strcpy(tempvendorId,sstr);
  4794. //===============================
  4795. // messageId
  4796. //===============================
  4797. memset(sstr ,0, sizeof(sstr) );
  4798. c = 0;
  4799. loc = strstr(payload, "messageId");
  4800. while (loc[strlen("messageId")+3+c] != '\"')
  4801. {
  4802. sstr[c] = loc[strlen("messageId")+3+c];
  4803. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4804. c++;
  4805. }
  4806. sstr[c] = '\0';
  4807. strcpy(tempmessageId,sstr);
  4808. //===============================
  4809. // data
  4810. //===============================
  4811. memset(sstr ,0, sizeof(sstr) );
  4812. c = 0;
  4813. loc = strstr(payload, "data");
  4814. printf("loc=%s\n",loc);
  4815. while (loc[strlen("data")+3+c] != '\"')
  4816. {
  4817. sstr[c] = loc[strlen("data")+3+c];
  4818. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4819. c++;
  4820. }
  4821. sstr[c] = '\0';
  4822. strcpy(tempdata,sstr);
  4823. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4824. }
  4825. else
  4826. {
  4827. char guid[37]={0};
  4828. random_uuid(guid);
  4829. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4830. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4831. }
  4832. LWS_Send(message);
  4833. return result;
  4834. }
  4835. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4836. {
  4837. mtrace();
  4838. int result = FAIL;
  4839. int connectorIdInt, durationInt;
  4840. char chargingRateUnitStr[4]={0};
  4841. //int tempconnectorIdInt,
  4842. int tempdurationInt;
  4843. float tempminChargingRateFloat = 0.0;
  4844. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4845. int tempStartPeriodInt=0;
  4846. float tempLimitInt=0.0;//0.1;
  4847. int tempNumberPhasesInt=0;
  4848. char fname[200];
  4849. char comfirmstr[20];
  4850. //float totallimit =0.0;
  4851. float MinChargingRate =0.0;
  4852. //double diff_t;
  4853. //struct tm tp;
  4854. FILE *fptr1;
  4855. int c = 0;
  4856. //int i = 0;
  4857. char * pch;
  4858. char *loc;
  4859. char sstr[200]={ 0 },sstrtemp[50]={ 0 };
  4860. int n_chargingProfile = 0;
  4861. int n_SchedulePeriods = 0;
  4862. char SchedulePeriodList[10][200]={0};
  4863. char sLineWord[1600]={0};
  4864. //int n_periods = 0;
  4865. char word[1000]={0};
  4866. int confirmPeriods = 0;
  4867. struct StructProfile ChargePointMaxProfile;
  4868. struct StructProfile TxDefaultProfile;
  4869. struct StructProfile TxProfile;
  4870. struct StructProfile TxDefaultProfiletemp[2]={0};
  4871. int TxDefaultProfileFileIsNull=FALSE;
  4872. int ChargePointMaxProfileIsNull=FALSE;
  4873. int TxProfileIsNull=FALSE;
  4874. int CompositeSceduleIndex = 0;
  4875. char ChargePointMaxProfileScheduleStr[30]={0};
  4876. char TxDefaultProfileScheduleStr[30]={0};
  4877. char TxProfileScheduleStr[30]={0};
  4878. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4879. strcpy(sstrtemp, stringtrimspace(payload));
  4880. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4881. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4882. memset(&TxProfile,0,sizeof(struct StructProfile));
  4883. c=0;
  4884. loc = strstr(sstrtemp, "connectorId");
  4885. memset(sstr ,0, sizeof(sstr) );
  4886. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4887. {
  4888. sstr[c] = loc[strlen("connectorId")+2+c];
  4889. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4890. c++;
  4891. }
  4892. sstr[c] = '\0';
  4893. connectorIdInt = atoi(sstr);
  4894. c=0;
  4895. loc = strstr(sstrtemp, "duration");
  4896. memset(sstr ,0, sizeof(sstr) );
  4897. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4898. {
  4899. sstr[c] = loc[strlen("duration")+2+c];
  4900. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4901. c++;
  4902. }
  4903. sstr[c] = '\0';
  4904. durationInt = atoi(sstr);
  4905. c = 0;
  4906. loc = strstr(sstrtemp, "chargingRateUnit");
  4907. memset(sstr ,0, sizeof(sstr) );
  4908. if(loc == NULL)
  4909. {
  4910. }
  4911. else
  4912. {
  4913. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4914. {
  4915. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4916. c++;
  4917. }
  4918. sstr[c] = '\0';
  4919. strcpy(chargingRateUnitStr, sstr);
  4920. }
  4921. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4922. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4923. if(connectorIdInt==0) // connectorId is 0
  4924. {
  4925. //******************************ChargePointMaxProfile*****************************************************/
  4926. strcpy(fname, ChargePointMaxProfile_JSON );
  4927. char word[30]={0};
  4928. char sLineWord[1060]={0};
  4929. int n_chargingProfile=0;
  4930. ChargePointMaxProfileIsNull=TRUE;
  4931. if((access(fname,F_OK))!=-1)
  4932. {
  4933. fptr1 = fopen(fname, "r");
  4934. int c;
  4935. c = fgetc(fptr1);
  4936. //DEBUG_INFO("c:%d\n",c);
  4937. rewind(fptr1);
  4938. if(c == EOF)
  4939. {
  4940. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4941. ChargePointMaxProfileIsNull=TRUE;
  4942. fclose(fptr1);
  4943. }
  4944. else
  4945. {
  4946. ChargePointMaxProfileIsNull=FALSE;
  4947. while(fscanf(fptr1, "%s", word) != EOF)
  4948. {
  4949. if(strcmp(word, "chargingProfileId") == 0)
  4950. {
  4951. n_chargingProfile = n_chargingProfile + 1;
  4952. printf("Found\n");
  4953. }
  4954. }
  4955. rewind(fptr1);
  4956. //search Charging Profile Element
  4957. int i= 0;
  4958. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4959. #if 0
  4960. /***********connectorId****************/
  4961. c = 0;
  4962. loc = strstr(sLineWord, "connectorId");
  4963. // printf("loc=%s\n",loc);
  4964. memset(sstr ,0, sizeof(sstr) );
  4965. while (loc[strlen("connectorId")+2+c] != ',')
  4966. {
  4967. sstr[c] = loc[strlen("connectorId")+2+c];
  4968. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4969. c++;
  4970. }
  4971. sstr[c] = '\0';
  4972. tempconnectorIdInt = atoi(sstr);
  4973. #endif
  4974. //***********validFrom**************/
  4975. c = 0;
  4976. loc = strstr(sLineWord, "validFrom");
  4977. //DEBUG_INFO("loc=%s\n",loc);
  4978. memset(sstr ,0, sizeof(sstr) );
  4979. if(loc != NULL)
  4980. {
  4981. while (loc[3+strlen("validFrom")+c] != '\"')
  4982. {
  4983. sstr[c] = loc[3+strlen("validFrom")+c];
  4984. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4985. c++;
  4986. }
  4987. sstr[c] = '\0';
  4988. DEBUG_INFO("validFrom=%s\n",sstr);
  4989. strcpy(tempvalidFromStr,sstr);
  4990. }
  4991. else
  4992. {
  4993. strcpy(tempvalidFromStr,"");
  4994. }
  4995. //**********startSchedule**********/
  4996. c = 0;
  4997. loc = strstr(sLineWord, "startSchedule");
  4998. //DEBUG_INFO("loc=%s\n",loc);
  4999. memset(sstr ,0, sizeof(sstr) );
  5000. if(loc != NULL)
  5001. {
  5002. while (loc[3+strlen("startSchedule")+c] != '\"')
  5003. {
  5004. sstr[c] = loc[3+strlen("startSchedule")+c];
  5005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5006. c++;
  5007. }
  5008. sstr[c] = '\0';
  5009. strcpy(tempstartScheduleStr, sstr);
  5010. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5011. }
  5012. else
  5013. {
  5014. strcpy(tempstartScheduleStr, "");
  5015. strcpy(ChargePointMaxProfileScheduleStr, "");
  5016. }
  5017. //**********chargingRateUnit**********/
  5018. c = 0;
  5019. loc = strstr(sLineWord, "chargingRateUnit");
  5020. memset(sstr ,0, sizeof(sstr) );
  5021. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5022. {
  5023. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5024. c++;
  5025. }
  5026. sstr[c] = '\0';
  5027. strcpy(tempchargingRateUnitStr, sstr);
  5028. //**********minChargingRate*******/
  5029. c = 0;
  5030. loc = strstr(sLineWord, "minChargingRate");
  5031. //printf("loc=%s\n",loc);
  5032. if(loc != NULL)
  5033. {
  5034. memset(sstr ,0, sizeof(sstr) );
  5035. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5036. {
  5037. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5038. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5039. c++;
  5040. }
  5041. sstr[c] = '\0';
  5042. tempminChargingRateFloat = atof(sstr);
  5043. }
  5044. else
  5045. {
  5046. tempminChargingRateFloat = 0.0;
  5047. }
  5048. //
  5049. #if 0
  5050. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5051. tp.tm_isdst = -1;
  5052. time_t utc = mktime(&tp);
  5053. // current time
  5054. time_t t = time(NULL);
  5055. #endif
  5056. //diff_t = difftime(t, utc);
  5057. //parsing strings to words
  5058. i = 0;
  5059. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5060. loc = loc+3+strlen("chargingSchedulePeriod");
  5061. pch = strtok(loc ,"{");
  5062. while (pch != NULL)
  5063. {
  5064. strcpy(SchedulePeriodList[i], pch);
  5065. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5066. //printf ("%s\n",pch);
  5067. pch = strtok (NULL, "{");
  5068. i = i + 1;
  5069. }
  5070. n_SchedulePeriods = i;
  5071. for(int i=0;i<n_SchedulePeriods;i++)
  5072. {
  5073. //*************startPeriod****************/
  5074. c = 0;
  5075. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5076. memset(sstr ,0, sizeof(sstr) );
  5077. while (loc[strlen("startPeriod")+2+c] != ',')
  5078. {
  5079. sstr[c] = loc[strlen("startPeriod")+2+c];
  5080. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5081. c++;
  5082. }
  5083. sstr[c] = '\0';
  5084. tempStartPeriodInt = atoi(sstr);
  5085. //*************limit****************/
  5086. c = 0;
  5087. loc = strstr(SchedulePeriodList[i], "limit");
  5088. memset(sstr ,0, sizeof(sstr) );
  5089. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5090. {
  5091. sstr[c] = loc[strlen("limit")+2+c];
  5092. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5093. c++;
  5094. }
  5095. sstr[c] = '\0';
  5096. tempLimitInt = atof(sstr);
  5097. //*************numberPhases****************/
  5098. c = 0;
  5099. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5100. memset(sstr ,0, sizeof(sstr) );
  5101. if(loc != NULL)
  5102. {
  5103. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5104. {
  5105. sstr[c] = loc[strlen("numberPhases")+2+c];
  5106. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5107. c++;
  5108. }
  5109. sstr[c] = '\0';
  5110. tempNumberPhasesInt = atoi(sstr);
  5111. }
  5112. else
  5113. {
  5114. tempNumberPhasesInt = 0;
  5115. }
  5116. ChargePointMaxProfile.Duration = durationInt;
  5117. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5118. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5119. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5120. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5121. }
  5122. if(MinChargingRate < tempminChargingRateFloat)
  5123. MinChargingRate = tempminChargingRateFloat;
  5124. }
  5125. }// End of file ChargingProfile
  5126. } //THE END OF ACCESS ChargePointMaxProfile
  5127. //******************************TxDefaultProfile***********************************************/
  5128. strcpy(fname, TxDefaultProfile_0_JSON);
  5129. memset(word, 0, 30);
  5130. memset(sLineWord, 0, 1060);
  5131. //char word[30]={0};
  5132. //char sLineWord[1060]={0};
  5133. n_chargingProfile=0;
  5134. TxDefaultProfileFileIsNull=TRUE;
  5135. if((access(fname,F_OK))!=-1)
  5136. {
  5137. fptr1 = fopen(fname, "r");
  5138. c = 0;
  5139. c = fgetc(fptr1);
  5140. //DEBUG_INFO("c:%d\n",c);
  5141. rewind(fptr1);
  5142. if(c == EOF)
  5143. {
  5144. DEBUG_INFO("\n End of file ChargingProfile reached.");
  5145. TxDefaultProfileFileIsNull=TRUE;
  5146. fclose(fptr1);
  5147. }
  5148. else
  5149. {
  5150. TxDefaultProfileFileIsNull=FALSE;
  5151. while(fscanf(fptr1, "%s", word) != EOF)
  5152. {
  5153. if(strcmp(word, "chargingProfileId") == 0)
  5154. {
  5155. n_chargingProfile = n_chargingProfile + 1;
  5156. printf("Found\n");
  5157. }
  5158. }
  5159. rewind(fptr1);
  5160. //search Charging Profile Element
  5161. int i= 0;
  5162. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5163. #if 0
  5164. /***********connectorId****************/
  5165. c = 0;
  5166. loc = strstr(sLineWord, "connectorId");
  5167. // printf("loc=%s\n",loc);
  5168. memset(sstr ,0, sizeof(sstr) );
  5169. while (loc[strlen("connectorId")+2+c] != ',')
  5170. {
  5171. sstr[c] = loc[strlen("connectorId")+2+c];
  5172. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5173. c++;
  5174. }
  5175. sstr[c] = '\0';
  5176. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  5177. tempconnectorIdInt = atoi(sstr);
  5178. #endif
  5179. //***********validFrom**************/
  5180. c = 0;
  5181. loc = strstr(sLineWord, "validFrom");
  5182. //DEBUG_INFO("loc=%s\n",loc);
  5183. memset(sstr ,0, sizeof(sstr) );
  5184. if(loc != NULL)
  5185. {
  5186. while (loc[3+strlen("validFrom")+c] != '\"')
  5187. {
  5188. sstr[c] = loc[3+strlen("validFrom")+c];
  5189. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5190. c++;
  5191. }
  5192. sstr[c] = '\0';
  5193. DEBUG_INFO("validFrom=%s\n",sstr);
  5194. strcpy(tempvalidFromStr,sstr);
  5195. }
  5196. else
  5197. {
  5198. strcpy(tempvalidFromStr,"");
  5199. }
  5200. //**********startSchedule**********/
  5201. c = 0;
  5202. loc = strstr(sLineWord, "startSchedule");
  5203. //DEBUG_INFO("loc=%s\n",loc);
  5204. memset(sstr ,0, sizeof(sstr) );
  5205. if(loc != NULL)
  5206. {
  5207. while (loc[3+strlen("startSchedule")+c] != '\"')
  5208. {
  5209. sstr[c] = loc[3+strlen("startSchedule")+c];
  5210. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5211. c++;
  5212. }
  5213. sstr[c] = '\0';
  5214. strcpy(tempstartScheduleStr, sstr);
  5215. strcpy(TxDefaultProfileScheduleStr, sstr);
  5216. }
  5217. else
  5218. {
  5219. strcpy(tempstartScheduleStr, "");
  5220. strcpy(TxDefaultProfileScheduleStr, "");
  5221. }
  5222. //**********chargingRateUnit**********/
  5223. c = 0;
  5224. loc = strstr(sLineWord, "chargingRateUnit");
  5225. memset(sstr ,0, sizeof(sstr) );
  5226. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5227. {
  5228. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5229. c++;
  5230. }
  5231. sstr[c] = '\0';
  5232. strcpy(tempchargingRateUnitStr, sstr);
  5233. //**********minChargingRate*******/
  5234. c = 0;
  5235. loc = strstr(sLineWord, "minChargingRate");
  5236. //printf("loc=%s\n",loc);
  5237. if(loc != NULL)
  5238. {
  5239. memset(sstr ,0, sizeof(sstr) );
  5240. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5241. {
  5242. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5243. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5244. c++;
  5245. }
  5246. sstr[c] = '\0';
  5247. tempminChargingRateFloat = atof(sstr);
  5248. }
  5249. else
  5250. {
  5251. tempminChargingRateFloat = 0.0;
  5252. }
  5253. #if 0
  5254. //
  5255. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5256. tp.tm_isdst = -1;
  5257. time_t utc = mktime(&tp);
  5258. // current time
  5259. time_t t = time(NULL);
  5260. //diff_t = difftime(t, utc);
  5261. #endif
  5262. //parsing strings to words
  5263. i = 0;
  5264. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5265. loc = loc+3+strlen("chargingSchedulePeriod");
  5266. pch = strtok(loc ,"{");
  5267. while (pch != NULL)
  5268. {
  5269. strcpy(SchedulePeriodList[i], pch);
  5270. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5271. //printf ("%s\n",pch);
  5272. pch = strtok (NULL, "{");
  5273. i = i + 1;
  5274. }
  5275. n_SchedulePeriods = i;
  5276. for(int i=0;i<n_SchedulePeriods;i++)
  5277. {
  5278. //*************startPeriod****************/
  5279. c = 0;
  5280. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5281. memset(sstr ,0, sizeof(sstr) );
  5282. while (loc[strlen("startPeriod")+2+c] != ',')
  5283. {
  5284. sstr[c] = loc[strlen("startPeriod")+2+c];
  5285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5286. c++;
  5287. }
  5288. sstr[c] = '\0';
  5289. tempStartPeriodInt = atoi(sstr);
  5290. //*************limit****************/
  5291. c = 0;
  5292. loc = strstr(SchedulePeriodList[i], "limit");
  5293. memset(sstr ,0, sizeof(sstr) );
  5294. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5295. {
  5296. sstr[c] = loc[strlen("limit")+2+c];
  5297. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5298. c++;
  5299. }
  5300. sstr[c] = '\0';
  5301. tempLimitInt = atof(sstr);
  5302. //*************numberPhases****************/
  5303. c = 0;
  5304. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5305. memset(sstr ,0, sizeof(sstr) );
  5306. if(loc != NULL)
  5307. {
  5308. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5309. {
  5310. sstr[c] = loc[strlen("numberPhases")+2+c];
  5311. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5312. c++;
  5313. }
  5314. sstr[c] = '\0';
  5315. tempNumberPhasesInt = atoi(sstr);
  5316. }
  5317. else
  5318. {
  5319. tempNumberPhasesInt = 0;
  5320. }
  5321. TxDefaultProfile.Duration = durationInt;
  5322. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5323. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5324. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5325. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5326. }
  5327. if(MinChargingRate < tempminChargingRateFloat)
  5328. MinChargingRate = tempminChargingRateFloat;
  5329. }
  5330. }
  5331. }// the end of ACCESS TxDefaultProfile
  5332. //--------------------- Composite Schedule-----------------------------//
  5333. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  5334. {
  5335. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5336. struct tm tp;
  5337. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5338. tp.tm_isdst = -1;
  5339. time_t utc = mktime(&tp);
  5340. time_t t = time(NULL);
  5341. double diff_f = difftime(t, utc);
  5342. int diff_i; //= (int)diff_f;
  5343. int quotient; //= diff_i / 86400;//86400 seconds/day
  5344. int period = 0;
  5345. if(diff_f >= 0)
  5346. {
  5347. diff_i = (int)diff_f;
  5348. quotient = diff_i / 86400;
  5349. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5350. {
  5351. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5352. {
  5353. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  5354. {
  5355. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5356. }
  5357. else
  5358. {
  5359. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5360. }
  5361. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5362. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5363. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5364. period = period + 1;
  5365. }
  5366. }
  5367. }
  5368. confirmPeriods = period;
  5369. }
  5370. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  5371. {
  5372. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5373. struct tm tp;
  5374. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5375. tp.tm_isdst = -1;
  5376. time_t utc = mktime(&tp);
  5377. time_t t = time(NULL);
  5378. double diff_f = difftime(t, utc);
  5379. int diff_i; // = (int)diff_f;
  5380. int quotient; // = diff_i / 86400;//86400 seconds/day
  5381. int period = 0;
  5382. if(diff_f >= 0)
  5383. {
  5384. diff_i = (int)diff_f;
  5385. quotient = diff_i / 86400;//86400 seconds/day
  5386. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5387. {
  5388. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5389. {
  5390. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5391. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5392. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5393. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5394. period = period + 1;
  5395. }
  5396. }
  5397. }
  5398. confirmPeriods = period;
  5399. }
  5400. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  5401. {
  5402. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  5403. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  5404. {
  5405. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  5406. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  5407. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  5408. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5409. }
  5410. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  5411. }
  5412. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  5413. {
  5414. confirmPeriods = 0;
  5415. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5416. //goto end;
  5417. }
  5418. //* Define temporary variables */
  5419. struct tm *gtime;
  5420. time_t now;
  5421. char buf[28];
  5422. /* Read the current system time */
  5423. time(&now);
  5424. /* Convert the system time to GMT (now UTC) */
  5425. gtime = gmtime(&now);
  5426. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5427. // make .conf
  5428. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5429. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5430. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5431. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5432. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5433. }
  5434. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  5435. {
  5436. //*****************************ChargePointMaxProfile******************************************/
  5437. strcpy(fname, ChargePointMaxProfile_JSON);
  5438. ChargePointMaxProfileIsNull=TRUE;
  5439. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  5440. {
  5441. fptr1 = fopen(fname, "r");
  5442. int c;
  5443. c = fgetc(fptr1);
  5444. //DEBUG_INFO("c:%d\n",c);
  5445. rewind(fptr1);
  5446. if(c == EOF)
  5447. {
  5448. DEBUG_INFO("\n End of file reached.");
  5449. ChargePointMaxProfileIsNull=TRUE;
  5450. fclose(fptr1);
  5451. }
  5452. else
  5453. {
  5454. ChargePointMaxProfileIsNull=FALSE;
  5455. while(fscanf(fptr1, "%s", word) != EOF)
  5456. {
  5457. if(strcmp(word, "chargingProfileId") == 0)
  5458. {
  5459. n_chargingProfile = n_chargingProfile + 1;
  5460. }
  5461. }
  5462. rewind(fptr1);
  5463. //search Charging Profile Element
  5464. int i = 0;
  5465. int j = 0;
  5466. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5467. #if 0
  5468. /***********connectorId****************/
  5469. c = 0;
  5470. loc = strstr(sLineWord, "connectorId");
  5471. memset(sstr ,0, sizeof(sstr) );
  5472. while (loc[strlen("connectorId")+2+c] != ',')
  5473. {
  5474. sstr[c] = loc[strlen("connectorId")+2+c];
  5475. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5476. c++;
  5477. }
  5478. sstr[c] = '\0';
  5479. tempconnectorIdInt = atoi(sstr);
  5480. #endif
  5481. //***********validFrom**************/
  5482. c = 0;
  5483. loc = strstr(sLineWord, "validFrom");
  5484. if(loc != NULL)
  5485. {
  5486. memset(sstr ,0, sizeof(sstr) );
  5487. while (loc[3+strlen("validFrom")+c] != '\"')
  5488. {
  5489. sstr[c] = loc[3+strlen("validFrom")+c];
  5490. c++;
  5491. }
  5492. sstr[c] = '\0';
  5493. strcpy(tempvalidFromStr,sstr);
  5494. }
  5495. else
  5496. {
  5497. strcpy(tempvalidFromStr,"");
  5498. }
  5499. //***********validFrom**************/
  5500. c = 0;
  5501. loc = strstr(sLineWord, "duration");
  5502. if(loc != NULL)
  5503. {
  5504. memset(sstr ,0, sizeof(sstr) );
  5505. while (loc[2+strlen("duration")+c] != ',')
  5506. {
  5507. sstr[c] = loc[2+strlen("duration")+c];
  5508. c++;
  5509. }
  5510. sstr[c] = '\0';
  5511. tempdurationInt = atoi(sstr);
  5512. }
  5513. else
  5514. {
  5515. tempdurationInt = 0;
  5516. }
  5517. //**********startSchedule**********/
  5518. c = 0;
  5519. loc = strstr(sLineWord, "startSchedule");
  5520. memset(sstr ,0, sizeof(sstr) );
  5521. if(loc != NULL)
  5522. {
  5523. while (loc[3+strlen("startSchedule")+c] != '\"')
  5524. {
  5525. sstr[c] = loc[3+strlen("startSchedule")+c];
  5526. c++;
  5527. }
  5528. sstr[c] = '\0';
  5529. strcpy(tempstartScheduleStr, sstr);
  5530. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5531. }
  5532. else
  5533. {
  5534. strcpy(tempstartScheduleStr, "");
  5535. strcpy(ChargePointMaxProfileScheduleStr, "");
  5536. }
  5537. //**********chargingRateUnit**********/
  5538. c = 0;
  5539. loc = strstr(sLineWord, "chargingRateUnit");
  5540. memset(sstr ,0, sizeof(sstr) );
  5541. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5542. {
  5543. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5544. c++;
  5545. }
  5546. sstr[c] = '\0';
  5547. strcpy(tempchargingRateUnitStr, sstr);
  5548. //**********minChargingRate*******/
  5549. c = 0;
  5550. loc = strstr(sLineWord, "minChargingRate");
  5551. if(loc != NULL)
  5552. {
  5553. memset(sstr ,0, sizeof(sstr) );
  5554. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5555. {
  5556. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5557. c++;
  5558. }
  5559. sstr[c] = '\0';
  5560. tempminChargingRateFloat = atof(sstr);
  5561. }
  5562. else
  5563. {
  5564. tempminChargingRateFloat = 0.0;
  5565. }
  5566. #if 0
  5567. //
  5568. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5569. tp.tm_isdst = -1;
  5570. time_t utc = mktime(&tp);
  5571. time_t t = time(NULL);
  5572. //diff_t = difftime(t, utc);
  5573. #endif
  5574. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5575. //DEBUG_INFO(" debug 5 -1\n");
  5576. //parsing strings to words
  5577. i = 0;
  5578. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5579. loc = loc+3+strlen("chargingSchedulePeriod");
  5580. pch = strtok(loc ,"{");
  5581. while (pch != NULL)
  5582. {
  5583. strcpy(SchedulePeriodList[i], pch);
  5584. pch = strtok (NULL, "{");
  5585. i = i + 1;
  5586. }
  5587. n_SchedulePeriods = i;
  5588. for(int i=0;i<n_SchedulePeriods;i++)
  5589. {
  5590. //*************startPeriod****************/
  5591. c = 0;
  5592. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5593. memset(sstr ,0, sizeof(sstr) );
  5594. while (loc[strlen("startPeriod")+2+c] != ',')
  5595. {
  5596. sstr[c] = loc[strlen("startPeriod")+2+c];
  5597. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5598. c++;
  5599. }
  5600. sstr[c] = '\0';
  5601. tempStartPeriodInt = atoi(sstr);
  5602. //*************limit****************/
  5603. c = 0;
  5604. loc = strstr(SchedulePeriodList[i], "limit");
  5605. memset(sstr ,0, sizeof(sstr) );
  5606. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5607. {
  5608. sstr[c] = loc[strlen("limit")+2+c];
  5609. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5610. c++;
  5611. }
  5612. sstr[c] = '\0';
  5613. tempLimitInt = atof(sstr);
  5614. //*************numberPhases****************/
  5615. c = 0;
  5616. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5617. memset(sstr ,0, sizeof(sstr) );
  5618. if(loc != NULL)
  5619. {
  5620. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5621. {
  5622. sstr[c] = loc[strlen("numberPhases")+2+c];
  5623. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5624. c++;
  5625. }
  5626. sstr[c] = '\0';
  5627. tempNumberPhasesInt = atoi(sstr);
  5628. }
  5629. else
  5630. {
  5631. tempNumberPhasesInt = 0;
  5632. }
  5633. if(j == 0)
  5634. {
  5635. ChargePointMaxProfile.Duration = tempdurationInt;
  5636. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5637. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5638. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5639. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5640. }
  5641. }
  5642. if(MinChargingRate < tempminChargingRateFloat)
  5643. {
  5644. MinChargingRate = tempminChargingRateFloat;
  5645. }
  5646. if(confirmPeriods < n_SchedulePeriods)
  5647. {
  5648. confirmPeriods = n_SchedulePeriods;
  5649. }
  5650. j = j + 1;
  5651. }
  5652. fclose(fptr1);
  5653. }
  5654. }// the end of access file ChargePointMaxProfile
  5655. //****************************TxDefaultProfile************************************************/
  5656. memset(fname, 0, sizeof fname);
  5657. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5658. TxDefaultProfileFileIsNull=TRUE;
  5659. if((access(fname,F_OK))!=-1)
  5660. {
  5661. fptr1 = fopen(fname, "r");
  5662. c = 0;
  5663. c = fgetc(fptr1);
  5664. //DEBUG_INFO("c:%d\n",c);
  5665. rewind(fptr1);
  5666. if(c == EOF)
  5667. {
  5668. DEBUG_INFO("\n End of file reached.");
  5669. TxDefaultProfileFileIsNull=TRUE;
  5670. fclose(fptr1);
  5671. }
  5672. else
  5673. {
  5674. TxDefaultProfileFileIsNull=FALSE;
  5675. while(fscanf(fptr1, "%s", word) != EOF)
  5676. {
  5677. if(strcmp(word, "chargingProfileId") == 0)
  5678. {
  5679. n_chargingProfile = n_chargingProfile + 1;
  5680. }
  5681. }
  5682. rewind(fptr1);
  5683. //search Charging Profile Element
  5684. int i = 0;
  5685. int j = 0;
  5686. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5687. //DEBUG_INFO(" 1-1\n");
  5688. #if 0
  5689. /***********connectorId****************/
  5690. c = 0;
  5691. loc = strstr(sLineWord, "connectorId");
  5692. memset(sstr ,0, sizeof(sstr) );
  5693. while (loc[strlen("connectorId")+2+c] != ',')
  5694. {
  5695. sstr[c] = loc[strlen("connectorId")+2+c];
  5696. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5697. c++;
  5698. }
  5699. sstr[c] = '\0';
  5700. tempconnectorIdInt = atoi(sstr);
  5701. #endif
  5702. //***********validFrom**************/
  5703. c = 0;
  5704. loc = strstr(sLineWord, "validFrom");
  5705. if(loc != NULL)
  5706. {
  5707. memset(sstr ,0, sizeof(sstr) );
  5708. while (loc[3+strlen("validFrom")+c] != '\"')
  5709. {
  5710. sstr[c] = loc[3+strlen("validFrom")+c];
  5711. c++;
  5712. }
  5713. sstr[c] = '\0';
  5714. strcpy(tempvalidFromStr,sstr);
  5715. }
  5716. else
  5717. {
  5718. strcpy(tempvalidFromStr,"");
  5719. }
  5720. //***********duration**************/
  5721. c = 0;
  5722. loc = strstr(sLineWord, "duration");
  5723. if(loc != NULL)
  5724. {
  5725. memset(sstr ,0, sizeof(sstr) );
  5726. while (loc[2+strlen("duration")+c] != ',')
  5727. {
  5728. sstr[c] = loc[2+strlen("duration")+c];
  5729. c++;
  5730. }
  5731. sstr[c] = '\0';
  5732. tempdurationInt = atoi(sstr);
  5733. }
  5734. else
  5735. {
  5736. tempdurationInt = 0;
  5737. }
  5738. //**********startSchedule**********/
  5739. c = 0;
  5740. loc = strstr(sLineWord, "startSchedule");
  5741. memset(sstr ,0, sizeof(sstr) );
  5742. if(loc != NULL)
  5743. {
  5744. while (loc[3+strlen("startSchedule")+c] != '\"')
  5745. {
  5746. sstr[c] = loc[3+strlen("startSchedule")+c];
  5747. c++;
  5748. }
  5749. sstr[c] = '\0';
  5750. strcpy(tempstartScheduleStr, sstr);
  5751. strcpy(TxDefaultProfileScheduleStr, sstr);
  5752. }
  5753. else
  5754. {
  5755. strcpy(tempstartScheduleStr, "");
  5756. strcpy(TxDefaultProfileScheduleStr, "");
  5757. }
  5758. //**********chargingRateUnit**********/
  5759. c = 0;
  5760. loc = strstr(sLineWord, "chargingRateUnit");
  5761. memset(sstr ,0, sizeof(sstr) );
  5762. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5763. {
  5764. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5765. c++;
  5766. }
  5767. sstr[c] = '\0';
  5768. strcpy(tempchargingRateUnitStr, sstr);
  5769. //**********minChargingRate*******/
  5770. c = 0;
  5771. loc = strstr(sLineWord, "minChargingRate");
  5772. if(loc != NULL)
  5773. {
  5774. memset(sstr ,0, sizeof(sstr) );
  5775. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5776. {
  5777. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5778. c++;
  5779. }
  5780. sstr[c] = '\0';
  5781. tempminChargingRateFloat = atof(sstr);
  5782. }
  5783. else
  5784. {
  5785. tempminChargingRateFloat = 0.0;
  5786. }
  5787. #if 0
  5788. //
  5789. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5790. tp.tm_isdst = -1;
  5791. time_t utc = mktime(&tp);
  5792. time_t t = time(NULL);
  5793. //diff_t = difftime(t, utc);
  5794. #endif
  5795. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5796. //parsing strings to words
  5797. i = 0;
  5798. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5799. loc = loc+3+strlen("chargingSchedulePeriod");
  5800. pch = strtok(loc ,"{");
  5801. while (pch != NULL)
  5802. {
  5803. strcpy(SchedulePeriodList[i], pch);
  5804. pch = strtok (NULL, "{");
  5805. i = i + 1;
  5806. }
  5807. n_SchedulePeriods = i;
  5808. for(int i=0;i<n_SchedulePeriods;i++)
  5809. {
  5810. //*************startPeriod****************/
  5811. c = 0;
  5812. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5813. memset(sstr ,0, sizeof(sstr) );
  5814. while (loc[strlen("startPeriod")+2+c] != ',')
  5815. {
  5816. sstr[c] = loc[strlen("startPeriod")+2+c];
  5817. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5818. c++;
  5819. }
  5820. sstr[c] = '\0';
  5821. tempStartPeriodInt = atoi(sstr);
  5822. //*************limit****************/
  5823. c = 0;
  5824. loc = strstr(SchedulePeriodList[i], "limit");
  5825. memset(sstr ,0, sizeof(sstr) );
  5826. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5827. {
  5828. sstr[c] = loc[strlen("limit")+2+c];
  5829. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5830. c++;
  5831. }
  5832. sstr[c] = '\0';
  5833. tempLimitInt = atof(sstr);
  5834. //*************numberPhases****************/
  5835. c = 0;
  5836. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5837. memset(sstr ,0, sizeof(sstr) );
  5838. if(loc != NULL)
  5839. {
  5840. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5841. {
  5842. sstr[c] = loc[strlen("numberPhases")+2+c];
  5843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5844. c++;
  5845. }
  5846. sstr[c] = '\0';
  5847. tempNumberPhasesInt = atoi(sstr);
  5848. }
  5849. else
  5850. {
  5851. tempNumberPhasesInt = 0;
  5852. }
  5853. if(j == 0)
  5854. {
  5855. TxDefaultProfile.Duration = tempdurationInt;
  5856. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5857. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5858. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5859. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5860. }
  5861. else
  5862. {
  5863. //other stack level charging Profile
  5864. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5865. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5866. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5867. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5868. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5869. }
  5870. }
  5871. if(MinChargingRate < tempminChargingRateFloat)
  5872. MinChargingRate = tempminChargingRateFloat;
  5873. if(confirmPeriods < n_SchedulePeriods)
  5874. confirmPeriods = n_SchedulePeriods;
  5875. j = j + 1;
  5876. //DEBUG_INFO(" 1-2\n");
  5877. }
  5878. fclose(fptr1);
  5879. //Stacking Charging Profiles
  5880. for(int l=0; l <(j-1) ;l++)
  5881. {
  5882. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5883. {
  5884. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5885. {
  5886. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5887. {
  5888. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5889. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5890. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5891. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5892. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5893. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5894. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5895. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5896. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5897. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5898. }
  5899. else
  5900. {
  5901. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5902. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5903. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5904. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5905. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5906. }
  5907. }
  5908. }
  5909. }
  5910. //end of Stacking Charging Profiles
  5911. }
  5912. }// the end of ACCESS TxDefaultProfile
  5913. //****************************TxProfile************************************************/
  5914. memset(fname, 0, sizeof fname);
  5915. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5916. TxProfileIsNull=TRUE;
  5917. if((access(fname,F_OK))!=-1)
  5918. {
  5919. fptr1 = fopen(fname, "r");
  5920. c = 0;
  5921. c = fgetc(fptr1);
  5922. //DEBUG_INFO("c:%d\n",c);
  5923. rewind(fptr1);
  5924. if(c == EOF)
  5925. {
  5926. DEBUG_INFO("\n End of file reached.");
  5927. TxProfileIsNull=TRUE;
  5928. fclose(fptr1);
  5929. }
  5930. else
  5931. {
  5932. TxProfileIsNull=FALSE;
  5933. while(fscanf(fptr1, "%s", word) != EOF)
  5934. {
  5935. if(strcmp(word, "chargingProfileId") == 0)
  5936. {
  5937. n_chargingProfile = n_chargingProfile + 1;
  5938. }
  5939. }
  5940. rewind(fptr1);
  5941. //search Charging Profile Element
  5942. int i= 0;
  5943. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5944. #if 0
  5945. /***********connectorId****************/
  5946. c = 0;
  5947. loc = strstr(sLineWord, "connectorId");
  5948. memset(sstr ,0, sizeof(sstr) );
  5949. while (loc[strlen("connectorId")+2+c] != ',')
  5950. {
  5951. sstr[c] = loc[strlen("connectorId")+2+c];
  5952. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5953. c++;
  5954. }
  5955. sstr[c] = '\0';
  5956. tempconnectorIdInt = atoi(sstr);
  5957. #endif
  5958. //***********validFrom**************/
  5959. c = 0;
  5960. loc = strstr(sLineWord, "validFrom");
  5961. if(loc != NULL)
  5962. {
  5963. memset(sstr ,0, sizeof(sstr) );
  5964. while (loc[3+strlen("validFrom")+c] != '\"')
  5965. {
  5966. sstr[c] = loc[3+strlen("validFrom")+c];
  5967. c++;
  5968. }
  5969. sstr[c] = '\0';
  5970. strcpy(tempvalidFromStr,sstr);
  5971. }
  5972. else
  5973. {
  5974. strcpy(tempvalidFromStr,"");
  5975. }
  5976. //**********startSchedule**********/
  5977. c = 0;
  5978. loc = strstr(sLineWord, "startSchedule");
  5979. memset(sstr ,0, sizeof(sstr) );
  5980. if(loc != NULL)
  5981. {
  5982. while (loc[3+strlen("startSchedule")+c] != '\"')
  5983. {
  5984. sstr[c] = loc[3+strlen("startSchedule")+c];
  5985. c++;
  5986. }
  5987. sstr[c] = '\0';
  5988. strcpy(tempstartScheduleStr, sstr);
  5989. strcpy(TxProfileScheduleStr, sstr);
  5990. }
  5991. else
  5992. {
  5993. strcpy(tempstartScheduleStr, "");
  5994. strcpy(TxProfileScheduleStr, "");
  5995. }
  5996. //**********chargingRateUnit**********/
  5997. c = 0;
  5998. loc = strstr(sLineWord, "chargingRateUnit");
  5999. memset(sstr ,0, sizeof(sstr) );
  6000. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6001. {
  6002. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6003. c++;
  6004. }
  6005. sstr[c] = '\0';
  6006. strcpy(tempchargingRateUnitStr, sstr);
  6007. //**********minChargingRate*******/
  6008. c = 0;
  6009. loc = strstr(sLineWord, "minChargingRate");
  6010. if(loc != NULL)
  6011. {
  6012. memset(sstr ,0, sizeof(sstr) );
  6013. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  6014. {
  6015. sstr[c] = loc[2+strlen("minChargingRate")+c];
  6016. c++;
  6017. }
  6018. sstr[c] = '\0';
  6019. tempminChargingRateFloat = atof(sstr);
  6020. }
  6021. else
  6022. {
  6023. tempminChargingRateFloat = 0.0;
  6024. }
  6025. #if 0
  6026. //
  6027. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6028. tp.tm_isdst = -1;
  6029. time_t utc = mktime(&tp);
  6030. time_t t = time(NULL);
  6031. //diff_t = difftime(t, utc);
  6032. #endif
  6033. //DEBUG_INFO("diff_t=%f\n",diff_t);
  6034. //parsing strings to words
  6035. i = 0;
  6036. loc = strstr(sLineWord, "chargingSchedulePeriod");
  6037. loc = loc+3+strlen("chargingSchedulePeriod");
  6038. pch = strtok(loc ,"{");
  6039. while (pch != NULL)
  6040. {
  6041. strcpy(SchedulePeriodList[i], pch);
  6042. pch = strtok (NULL, "{");
  6043. i = i + 1;
  6044. }
  6045. n_SchedulePeriods = i;
  6046. for(int i=0;i<n_SchedulePeriods;i++)
  6047. {
  6048. //*************startPeriod****************/
  6049. c = 0;
  6050. loc = strstr(SchedulePeriodList[i], "startPeriod");
  6051. memset(sstr ,0, sizeof(sstr) );
  6052. while (loc[strlen("startPeriod")+2+c] != ',')
  6053. {
  6054. sstr[c] = loc[strlen("startPeriod")+2+c];
  6055. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6056. c++;
  6057. }
  6058. sstr[c] = '\0';
  6059. tempStartPeriodInt = atoi(sstr);
  6060. //*************limit****************/
  6061. c = 0;
  6062. loc = strstr(SchedulePeriodList[i], "limit");
  6063. memset(sstr ,0, sizeof(sstr) );
  6064. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  6065. {
  6066. sstr[c] = loc[strlen("limit")+2+c];
  6067. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6068. c++;
  6069. }
  6070. sstr[c] = '\0';
  6071. tempLimitInt = atof(sstr);
  6072. //*************numberPhases****************/
  6073. c = 0;
  6074. loc = strstr(SchedulePeriodList[i], "numberPhases");
  6075. memset(sstr ,0, sizeof(sstr) );
  6076. if(loc != NULL)
  6077. {
  6078. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  6079. {
  6080. sstr[c] = loc[strlen("numberPhases")+2+c];
  6081. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6082. c++;
  6083. }
  6084. sstr[c] = '\0';
  6085. tempNumberPhasesInt = atoi(sstr);
  6086. }
  6087. else
  6088. {
  6089. tempNumberPhasesInt = 0;
  6090. }
  6091. TxProfile.Duration = durationInt;
  6092. TxProfile.TotalPeriod = n_SchedulePeriods;
  6093. TxProfile.Period[i].Limit = tempLimitInt;
  6094. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  6095. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  6096. }
  6097. if(MinChargingRate < tempminChargingRateFloat)
  6098. MinChargingRate = tempminChargingRateFloat;
  6099. if(confirmPeriods < n_SchedulePeriods)
  6100. confirmPeriods = n_SchedulePeriods;
  6101. }
  6102. fclose(fptr1);
  6103. }
  6104. }// the end of ACCESS TxProfile
  6105. //CompositeSchedule
  6106. int period=0;
  6107. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  6108. {
  6109. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  6110. struct tm tp;
  6111. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6112. tp.tm_isdst = -1;
  6113. time_t utc = mktime(&tp);
  6114. time_t t = time(NULL);
  6115. double diff_f = difftime(t, utc);
  6116. int diff_i; // = (int)diff_f;
  6117. int quotient; // = diff_i / 86400;//86400 seconds/day
  6118. //int remainder = diff_i % 86400;
  6119. for(int k=0; k < TxProfile.TotalPeriod;k++)
  6120. {
  6121. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  6122. {
  6123. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  6124. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6125. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6126. period = period + 1;
  6127. }
  6128. else
  6129. {
  6130. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  6131. {
  6132. }
  6133. else
  6134. {
  6135. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6136. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6137. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6138. period = period + 1;
  6139. }
  6140. }
  6141. }
  6142. if( diff_f >= 0)
  6143. {
  6144. diff_i = (int)diff_f;
  6145. quotient = diff_i / 86400;//86400 seconds/day
  6146. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6147. {
  6148. 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))
  6149. {
  6150. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6151. {
  6152. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6153. }
  6154. else
  6155. {
  6156. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6157. }
  6158. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6159. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  6160. period = period + 1;
  6161. }
  6162. }
  6163. // Check Last Period
  6164. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  6165. {
  6166. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6167. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  6168. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  6169. period = period + 1;
  6170. }
  6171. } // diff_f >= 0
  6172. }
  6173. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  6174. {
  6175. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6176. struct tm tp;
  6177. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6178. tp.tm_isdst = -1;
  6179. time_t utc = mktime(&tp);
  6180. time_t t = time(NULL);
  6181. double diff_f = difftime(t, utc);
  6182. int diff_i;// = (int)diff_f;
  6183. int quotient; // = diff_i / 86400;//86400 seconds/day
  6184. //int remainder = diff_i % 86400;
  6185. if(diff_f >= 0)
  6186. {
  6187. diff_i = (int)diff_f;
  6188. quotient = diff_i / 86400;//86400 seconds/day
  6189. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6190. {
  6191. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6192. {
  6193. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6194. {
  6195. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6196. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6197. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6198. period = period + 1;
  6199. }
  6200. else
  6201. {
  6202. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6203. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6204. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6205. period = period + 1;
  6206. }
  6207. }
  6208. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6209. {
  6210. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6211. {
  6212. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6213. {
  6214. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6215. {
  6216. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6217. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6218. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6219. period = period + 1;
  6220. }
  6221. else
  6222. {
  6223. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6224. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6225. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6226. period = period + 1;
  6227. }
  6228. }
  6229. }
  6230. }
  6231. }
  6232. } // end diff_f >= 0
  6233. }
  6234. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  6235. {
  6236. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6237. struct tm tp;
  6238. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6239. tp.tm_isdst = -1;
  6240. time_t utc = mktime(&tp);
  6241. time_t t = time(NULL);
  6242. double diff_f = difftime(t, utc);
  6243. int diff_i; // = (int)diff_f;
  6244. int quotient; // = diff_i / 86400;//86400 seconds/day
  6245. //int remainder = diff_i % 86400;
  6246. if(diff_f >= 0)
  6247. {
  6248. diff_i = (int)diff_f;
  6249. quotient = diff_i / 86400;//86400 seconds/day
  6250. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6251. {
  6252. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6253. {
  6254. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6255. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6256. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6257. period = period + 1;
  6258. }
  6259. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6260. {
  6261. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6262. {
  6263. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6264. {
  6265. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6266. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6267. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6268. period = period + 1;
  6269. }
  6270. }
  6271. }
  6272. }
  6273. } // diff_f >= 0
  6274. }
  6275. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  6276. {
  6277. confirmPeriods = 0;
  6278. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6279. //goto end;
  6280. }
  6281. confirmPeriods = period;
  6282. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  6283. //---- Define StartSchedule----/
  6284. struct tm *gtime;
  6285. time_t now;
  6286. char buf[28];
  6287. //---Read the current system time---/
  6288. time(&now);
  6289. //---Convert the system time to GMT (now UTC)---/
  6290. gtime = gmtime(&now);
  6291. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  6292. // make .conf
  6293. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  6294. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  6295. //DEBUG_INFO(" debug 11\n");
  6296. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  6297. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  6298. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6299. }
  6300. else
  6301. {
  6302. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6303. }
  6304. //end:
  6305. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  6306. return result;
  6307. }
  6308. int handleGetConfigurationRequest(char *uuid, char *payload)
  6309. {
  6310. mtrace();
  6311. int result = FAIL;
  6312. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  6313. //struct json_object *jsonitem;
  6314. int MaxKeySupported = 0;
  6315. int n_keys = 0;
  6316. char requestKey[43][50]={0};
  6317. char search[]="[";
  6318. char sstr[500]={ 0 },sstrtemp[60]={ 0 };
  6319. //int pos;
  6320. int l, c = 0;
  6321. int i = 0;
  6322. char *delim = "\",\"";
  6323. char * pch;
  6324. strcpy(sstrtemp, stringtrimspace(payload));
  6325. char *loc = strstr(sstrtemp, search);
  6326. //********************* Parsing String ***********************************/
  6327. if(loc == NULL) {
  6328. DEBUG_INFO("no key match in Configuration \n");
  6329. }
  6330. else {
  6331. //pos = loc - payload;
  6332. l = strlen(loc)-4;
  6333. while (c < l)
  6334. {
  6335. sstr[c] = loc[c+2];
  6336. c++;
  6337. }
  6338. sstr[c] = '\0';
  6339. //parsing strings to words
  6340. pch = strtok(sstr,delim);
  6341. if(pch == NULL)
  6342. {
  6343. strcpy(requestKey[0], sstr);
  6344. }
  6345. else
  6346. {
  6347. while (pch != NULL)
  6348. {
  6349. strcpy(requestKey[i], pch);
  6350. pch = strtok (NULL, delim);
  6351. i = i + 1;
  6352. }
  6353. n_keys = i;
  6354. }
  6355. }
  6356. UnknownKeynum = 0;
  6357. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  6358. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  6359. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6360. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6361. if(n_keys != 0)
  6362. {
  6363. for(int i=0;i<n_keys;i++)
  6364. {
  6365. getKeyValue(requestKey[i]);
  6366. //json_object_put(jsonitem);
  6367. }
  6368. }
  6369. else
  6370. {
  6371. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6372. getKeyValue("");
  6373. }
  6374. processUnkownKey();
  6375. sendGetConfigurationConfirmation(uuid);
  6376. return result;
  6377. }
  6378. static char fnamePlusPath[100]={0};
  6379. static char fnamePWithNoPath[60]={0};
  6380. void checkUploadLog(void)
  6381. {
  6382. FILE *fp;
  6383. /* Open the command for reading. */
  6384. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6385. if (fp == NULL) {
  6386. printf("Failed to run command\n" );
  6387. exit(1);
  6388. }
  6389. int ftppathlen = 0;
  6390. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6391. int i = 0;
  6392. /* Read the output a line at a time - output it. */
  6393. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6394. if(i==0)
  6395. {
  6396. ftppathlen = strlen(fnamePlusPath);
  6397. printf("%s\n", fnamePlusPath);
  6398. fnamePlusPath[ftppathlen]='\0';
  6399. break;
  6400. }
  6401. i= i+1;
  6402. }
  6403. /* close */
  6404. pclose(fp);
  6405. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6406. {
  6407. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6408. {
  6409. fnamePlusPath[k]='\0';
  6410. }
  6411. }
  6412. i=1;
  6413. //char fname[60]={0};
  6414. while(i < ftppathlen)
  6415. {
  6416. int len=ftppathlen-i;
  6417. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6418. {
  6419. printf("compare '/' all right\n");
  6420. break;
  6421. }
  6422. i=i+1;
  6423. }
  6424. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6425. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6426. fnamePWithNoPath[i+1] = '\0';
  6427. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6428. {
  6429. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6430. {
  6431. fnamePWithNoPath[j]='\0';
  6432. }
  6433. }
  6434. FILE* fp1 = fopen(fnamePlusPath, "r");
  6435. if (fp1)
  6436. {
  6437. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6438. // file exists
  6439. fclose(fp1);
  6440. }
  6441. else
  6442. {
  6443. // file doesn't exist
  6444. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6445. }
  6446. }
  6447. static char GetDiagnosticspayloadData[300]={0};
  6448. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6449. {
  6450. mtrace();
  6451. int result = FAIL;
  6452. pthread_t t; // pthread 變數
  6453. system("exec /root/logPackTools 'log' 6");
  6454. #if 0
  6455. //char buffer [128];
  6456. time (&rawtime);
  6457. //printf("%ld\n", rawtime);
  6458. timeinfo = localtime (&rawtime);
  6459. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6460. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6461. if((access(fnamePlusPath,F_OK))!=-1)
  6462. {
  6463. DEBUG_INFO("fnamePlusPath exist.\n");
  6464. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6465. }
  6466. else
  6467. {
  6468. DEBUG_INFO("fnamePlusPath not exist!\n");
  6469. }
  6470. #endif
  6471. checkUploadLog();
  6472. memset(GetDiagnosticspayloadData, 0, 300);
  6473. strcpy(GetDiagnosticspayloadData, stringtrimspace(payload));
  6474. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  6475. pthread_create(&t, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6476. return result;
  6477. }
  6478. void* GetDiagnosticsProcess(void* data)
  6479. {
  6480. pthread_detach(pthread_self());
  6481. mtrace();
  6482. int retriesInt=0, retryIntervalInt=0;
  6483. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6484. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6485. 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};
  6486. int port=0;
  6487. char sstr[260]={ 0 };//sstr[200]={ 0 };
  6488. int c = 0;
  6489. char *loc;
  6490. int isSuccess = FALSE;
  6491. char ftpbuf[200]={0};
  6492. //char temp[100]={0};
  6493. char * pch;
  6494. // [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"}]
  6495. char str[300]={ 0 };
  6496. strcpy(str,(const char*)GetDiagnosticspayloadData);
  6497. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6498. DEBUG_INFO("GetDiagnosticsProcess\n");
  6499. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6500. //****************location*******************/
  6501. c = 0;
  6502. memset(sstr ,0, sizeof(sstr) );
  6503. loc = strstr(str, "location");
  6504. while (loc[3+strlen("location")+c] != '\"')
  6505. {
  6506. sstr[c] = loc[3+strlen("location")+c];
  6507. c++;
  6508. }
  6509. sstr[c] = '\0';
  6510. strcpy(locationstr,sstr);
  6511. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6512. if(strcmp(locationstr,"")==0)
  6513. {
  6514. DEBUG_INFO("location is <Empty>!\n");
  6515. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6516. goto end;
  6517. }
  6518. //****************retries*******************/
  6519. c = 0;
  6520. loc = strstr(str, "retries");
  6521. if(loc == NULL)
  6522. {
  6523. retriesIsNULL = TRUE;
  6524. }
  6525. else
  6526. {
  6527. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6528. {
  6529. sstr[c] = loc[strlen("retries")+2+c];
  6530. c++;
  6531. }
  6532. sstr[c] = '\0';
  6533. retriesInt = atoi(sstr);
  6534. }
  6535. if(retriesIsNULL == TRUE)
  6536. {
  6537. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6538. }
  6539. //****************retryInterval*******************/
  6540. c = 0;
  6541. loc = strstr(str, "retryInterval");
  6542. if(loc == NULL)
  6543. {
  6544. retryIntervalIsNULL = TRUE;
  6545. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6546. }
  6547. else
  6548. {
  6549. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6550. {
  6551. sstr[c] = loc[strlen("retryInterval")+2+c];
  6552. c++;
  6553. }
  6554. sstr[c] = '\0';
  6555. retryIntervalInt = atoi(sstr);
  6556. }
  6557. //****************startTime*******************/
  6558. c = 0;
  6559. memset(sstr ,0, sizeof(sstr) );
  6560. loc = strstr(str, "startTime");
  6561. if(loc == NULL)
  6562. {
  6563. startTimeIsNULL = TRUE;
  6564. }
  6565. else
  6566. {
  6567. while (loc[3+strlen("startTime")+c] != '\"')
  6568. {
  6569. sstr[c] = loc[3+strlen("startTime")+c];
  6570. c++;
  6571. }
  6572. sstr[c] = '\0';
  6573. strcpy(startTimestr,sstr);
  6574. }
  6575. //****************stopTime*******************/
  6576. c = 0;
  6577. memset(sstr ,0, sizeof(sstr) );
  6578. loc = strstr(str, "stopTime");
  6579. if(loc == NULL)
  6580. {
  6581. stopTimeIsNULL = TRUE;
  6582. }
  6583. else
  6584. {
  6585. while (loc[3+strlen("stopTime")+c] != '\"')
  6586. {
  6587. sstr[c] = loc[3+strlen("stopTime")+c];
  6588. c++;
  6589. }
  6590. sstr[c] = '\0';
  6591. strcpy(stopTimestr,sstr);
  6592. }
  6593. memset(protocol, 0, sizeof(protocol));
  6594. memset(user, 0, sizeof(user) );
  6595. memset(password, 0, sizeof(password));
  6596. memset(host, 0, sizeof(host));
  6597. memset(path, 0, sizeof(path));
  6598. memset(ftppath, 0, sizeof(ftppath));
  6599. memset(host1, 0, sizeof(host1));
  6600. memset(path1, 0, sizeof(path1));
  6601. /*location: ftp://user:password@host:port/path*/
  6602. #if 0
  6603. time_t rawtime;
  6604. struct tm * timeinfo;
  6605. //char buffer [128];
  6606. time (&rawtime);
  6607. //printf("%ld\n", rawtime);
  6608. timeinfo = localtime (&rawtime);
  6609. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6610. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6611. #endif
  6612. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6613. if((access(fnamePlusPath,F_OK))!=-1)
  6614. {
  6615. DEBUG_INFO("fnamePlusPath exist.\n");
  6616. }
  6617. else
  6618. {
  6619. DEBUG_INFO("fnamePlusPath not exist!\n");
  6620. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6621. goto end;
  6622. }
  6623. pch=strchr(locationstr,'@');
  6624. if(pch==NULL)
  6625. {
  6626. sscanf(locationstr,
  6627. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6628. protocol, host, &port, path);
  6629. strcpy(user,"anonymous");
  6630. strcpy(password,"");
  6631. }
  6632. else
  6633. {
  6634. //DEBUG_INFO("pch=%s\n", pch);
  6635. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6636. protocol, user, password, host, &port, path);
  6637. }
  6638. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6639. {
  6640. DEBUG_INFO("protocol is not ftp/http ! \n");
  6641. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6642. goto end;
  6643. }
  6644. if(strncmp(locationstr,"http", 4) == 0)
  6645. {
  6646. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6647. sprintf(ftppath,"/%s", path);
  6648. do{
  6649. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6650. sleep(retryIntervalInt);
  6651. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6652. if(!isSuccess)
  6653. {
  6654. DEBUG_INFO("Diagnostics fail.\n");
  6655. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6656. }
  6657. else
  6658. {
  6659. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6660. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6661. }
  6662. }
  6663. else
  6664. {
  6665. sscanf(host,"%[^/]%s",host1, path1);
  6666. sprintf(ftppath,"%s", path1);
  6667. int ftppathlen=strlen(ftppath);
  6668. int i=1;
  6669. char filenametemp[50];
  6670. while(i < ftppathlen)
  6671. {
  6672. int len=ftppathlen-i;
  6673. if(ftppath[len]== 47) // '/' ascll code: 47
  6674. {
  6675. DEBUG_INFO("find '/' all right\n");
  6676. break;
  6677. }
  6678. i=i+1;
  6679. }
  6680. memset(filenametemp, 0, sizeof(filenametemp));
  6681. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6682. filenametemp[i+1] = 0;
  6683. memset(ftpbuf, 0, sizeof(ftpbuf));
  6684. if(port == 0)
  6685. port = 21;
  6686. do{
  6687. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6688. sleep(retryIntervalInt);
  6689. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6690. if(!isSuccess)
  6691. {
  6692. DEBUG_INFO("Diagnostics fail.\n");
  6693. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6694. }
  6695. else
  6696. {
  6697. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6698. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6699. }
  6700. }
  6701. end:
  6702. DiagnosticsStatusNotificationStatus = 0; //Idle
  6703. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6704. }
  6705. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6706. {
  6707. mtrace();
  6708. int result = FAIL;
  6709. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6710. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6711. {
  6712. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6713. localversion = -1;
  6714. }
  6715. else
  6716. {
  6717. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6718. OCPP_getListVerion();
  6719. }
  6720. //from db.OCPP_getListVerion
  6721. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6722. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6723. sendGetLocalListVersionConfirmation(uuid,"");
  6724. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6725. return result;
  6726. }
  6727. int handleRemoteStartRequest(char *uuid, char *payload)
  6728. {
  6729. mtrace();
  6730. int result = FAIL;
  6731. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6732. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6733. int tempIndex = 0;
  6734. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6735. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6736. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6737. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6738. int chargingSchedulePeriodCount = 0;
  6739. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6740. int c = 0;
  6741. char *loc;
  6742. char comfirmstr[20]={0};
  6743. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6744. if(server_pending == TRUE)
  6745. {
  6746. return 0;
  6747. }
  6748. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6749. strcpy(sstrtemp, stringtrimspace(payload));
  6750. //**********connectorId****************/
  6751. c = 0;
  6752. memset(sstr ,0, sizeof(sstr) );
  6753. loc = strstr(sstrtemp, "connectorId");
  6754. if(loc == NULL)
  6755. {
  6756. connectorIdIsNULL = TRUE;
  6757. }
  6758. else
  6759. {
  6760. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6761. {
  6762. sstr[c] = loc[strlen("connectorId")+2+c];
  6763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6764. c++;
  6765. }
  6766. sstr[c] = '\0';
  6767. connectorIdInt = atoi(sstr);
  6768. }
  6769. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6770. {
  6771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6772. goto end;
  6773. }
  6774. //****************idTag*******************/
  6775. c = 0;
  6776. memset(sstr ,0, sizeof(sstr) );
  6777. loc = strstr(sstrtemp, "idTag");
  6778. while (loc[3+strlen("idTag")+c] != '\"')
  6779. {
  6780. sstr[c] = loc[3+strlen("idTag")+c];
  6781. c++;
  6782. }
  6783. sstr[c] = '\0';
  6784. strcpy(idTagstr,sstr);
  6785. //****************chargingProfile*******************/
  6786. c = 0;
  6787. memset(sstr ,0, sizeof(sstr) );
  6788. loc = strstr(sstrtemp, "chargingProfile");
  6789. if(loc == NULL)
  6790. {
  6791. chargingProfileIsNULL = TRUE;
  6792. }
  6793. else
  6794. {
  6795. //****************chargingProfileId*******************/
  6796. c=0;
  6797. loc = strstr(sstrtemp, "chargingProfileId");
  6798. memset(sstr ,0, sizeof(sstr) );
  6799. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6800. {
  6801. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6802. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6803. c++;
  6804. }
  6805. sstr[c] = '\0';
  6806. chargingProfileIdInt = atoi(sstr);
  6807. //****************transactionId*******************/
  6808. loc = strstr(sstrtemp, "transactionId");
  6809. if(loc == NULL)
  6810. {
  6811. transactionIdIsNULL = TRUE;
  6812. }
  6813. else
  6814. {
  6815. c=0;
  6816. memset(sstr ,0, sizeof(sstr) );
  6817. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6818. {
  6819. sstr[c] = loc[strlen("transactionId")+2+c];
  6820. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6821. c++;
  6822. }
  6823. sstr[c] = '\0';
  6824. transactionIdInt = atoi(sstr);
  6825. }
  6826. //****************stackLevel*******************/
  6827. c=0;
  6828. loc = strstr(sstrtemp, "stackLevel");
  6829. memset(sstr ,0, sizeof(sstr) );
  6830. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6831. {
  6832. sstr[c] = loc[strlen("stackLevel")+2+c];
  6833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6834. c++;
  6835. }
  6836. sstr[c] = '\0';
  6837. stackLevelInt = atoi(sstr);
  6838. //****************chargingProfilePurpose*******************/
  6839. c = 0;
  6840. memset(sstr ,0, sizeof(sstr) );
  6841. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6842. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6843. {
  6844. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6845. c++;
  6846. }
  6847. sstr[c] = '\0';
  6848. strcpy(chargingProfilePurposestr,sstr);
  6849. //****************chargingProfileKind*******************/
  6850. c = 0;
  6851. memset(sstr ,0, sizeof(sstr) );
  6852. loc = strstr(sstrtemp, "chargingProfileKind");
  6853. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6854. {
  6855. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6856. c++;
  6857. }
  6858. sstr[c] = '\0';
  6859. strcpy(chargingProfileKindstr,sstr);
  6860. //****************recurrencyKind*******************/
  6861. loc = strstr(sstrtemp, "recurrencyKind");
  6862. if(loc == NULL)
  6863. {
  6864. recurrencyKindIsNULL = TRUE;
  6865. }
  6866. else
  6867. {
  6868. c = 0;
  6869. memset(sstr ,0, sizeof(sstr) );
  6870. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6871. {
  6872. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6873. c++;
  6874. }
  6875. sstr[c] = '\0';
  6876. strcpy(recurrencyKindstr,sstr);
  6877. }
  6878. //****************validFrom*******************/
  6879. loc = strstr(sstrtemp, "validFrom");
  6880. if(loc == NULL)
  6881. {
  6882. validFromIsNULL = TRUE;
  6883. }
  6884. else
  6885. {
  6886. c = 0;
  6887. memset(sstr ,0, sizeof(sstr) );
  6888. while (loc[3+strlen("validFrom")+c] != '\"')
  6889. {
  6890. sstr[c] = loc[3+strlen("validFrom")+c];
  6891. c++;
  6892. }
  6893. sstr[c] = '\0';
  6894. strcpy(validFromstr,sstr);
  6895. }
  6896. //****************validTo*******************/
  6897. loc = strstr(sstrtemp, "validTo");
  6898. if(loc == NULL)
  6899. {
  6900. validToIsNULL = TRUE;
  6901. }
  6902. else
  6903. {
  6904. c = 0;
  6905. memset(sstr ,0, sizeof(sstr) );
  6906. while (loc[3+strlen("validTo")+c] != '\"')
  6907. {
  6908. sstr[c] = loc[3+strlen("validTo")+c];
  6909. c++;
  6910. }
  6911. sstr[c] = '\0';
  6912. strcpy(validTostr,sstr);
  6913. }
  6914. //****************chargingSchedule*******************/
  6915. loc = strstr(sstrtemp, "chargingSchedule");
  6916. if(loc != NULL)
  6917. {
  6918. //****************duration*******************/
  6919. loc = strstr(sstrtemp, "duration");
  6920. if(loc == NULL)
  6921. {
  6922. durationIsNULL = TRUE;
  6923. }
  6924. else
  6925. {
  6926. c=0;
  6927. memset(sstr ,0, sizeof(sstr) );
  6928. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6929. {
  6930. sstr[c] = loc[strlen("duration")+2+c];
  6931. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6932. c++;
  6933. }
  6934. sstr[c] = '\0';
  6935. durationInt = atoi(sstr);
  6936. }
  6937. //****************startSchedule******************/
  6938. loc = strstr(sstrtemp, "startSchedule");
  6939. if(loc == NULL)
  6940. {
  6941. startScheduleIsNULL = TRUE;
  6942. }
  6943. else
  6944. {
  6945. c = 0;
  6946. memset(sstr ,0, sizeof(sstr) );
  6947. while (loc[3+strlen("startSchedule")+c] != '\"')
  6948. {
  6949. sstr[c] = loc[3+strlen("startSchedule")+c];
  6950. c++;
  6951. }
  6952. sstr[c] = '\0';
  6953. strcpy(startSchedulestr,sstr);
  6954. }
  6955. //****************chargingRateUnit*******************/
  6956. c = 0;
  6957. memset(sstr ,0, sizeof(sstr) );
  6958. loc = strstr(sstrtemp, "chargingRateUnit");
  6959. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6960. {
  6961. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6962. c++;
  6963. }
  6964. sstr[c] = '\0';
  6965. strcpy(chargingRateUnitstr,sstr);
  6966. //****************minChargingRate*******************/
  6967. loc = strstr(sstrtemp, "minChargingRate");
  6968. if(loc == NULL)
  6969. {
  6970. minChargingRateIsNULL = TRUE;
  6971. }
  6972. else
  6973. {
  6974. c=0;
  6975. memset(sstr ,0, sizeof(sstr) );
  6976. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6977. {
  6978. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6979. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6980. c++;
  6981. }
  6982. sstr[c] = '\0';
  6983. minChargingRateflaot = atof(sstr);
  6984. }
  6985. //****************chargingSchedulePeriod count*******************/
  6986. int what_len = strlen("startPeriod");
  6987. char *where = sstrtemp;
  6988. while ((where = strstr(where, "startPeriod"))) {
  6989. where += what_len;
  6990. chargingSchedulePeriodCount++;
  6991. }
  6992. where = sstrtemp;
  6993. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6994. {
  6995. //****************startPeriod*******************/
  6996. c=0;
  6997. loc = strstr(where, "startPeriod");
  6998. memset(sstr ,0, sizeof(sstr) );
  6999. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7000. {
  7001. sstr[c] = loc[strlen("startPeriod")+2+c];
  7002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7003. c++;
  7004. }
  7005. sstr[c] = '\0';
  7006. startPeriodInt[periodNums] = atoi(sstr);
  7007. //****************limit*******************/
  7008. c=0;
  7009. loc = strstr(where, "limit");
  7010. memset(sstr ,0, sizeof(sstr) );
  7011. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7012. {
  7013. sstr[c] = loc[strlen("limit")+2+c];
  7014. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7015. c++;
  7016. }
  7017. sstr[c] = '\0';
  7018. limitflaot[periodNums] = atof(sstr);
  7019. //****************numberPhases*******************/
  7020. loc = strstr(where, "numberPhases");
  7021. if(loc == NULL)
  7022. {
  7023. numberPhasesIsNULL = TRUE;
  7024. }
  7025. else
  7026. {
  7027. c=0;
  7028. memset(sstr ,0, sizeof(sstr) );
  7029. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7030. {
  7031. sstr[c] = loc[strlen("numberPhases")+2+c];
  7032. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7033. c++;
  7034. }
  7035. sstr[c] = '\0';
  7036. numberPhasesInt[periodNums] = atoi(sstr);
  7037. }
  7038. where = loc;
  7039. } // END FOR chargingSchedulePeriodCount
  7040. }// END IF chargingSchedule
  7041. } // END chargingProfile
  7042. /*
  7043. enum _SYSTEM_STATUS
  7044. {
  7045. S_BOOTING = 0,
  7046. S_IDLE, = 1
  7047. S_AUTHORIZING, =2
  7048. S_REASSIGN_CHECK, =3
  7049. S_REASSIGN, =4
  7050. S_PRECHARGE, =5
  7051. S_PREPARING_FOR_EV, =6
  7052. S_PREPARING_FOR_EVSE, =7
  7053. S_CHARGING, =8
  7054. S_TERMINATING, =9
  7055. S_COMPLETE, =10
  7056. S_ALARM, =11
  7057. S_FAULT =12
  7058. }
  7059. */
  7060. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7061. {
  7062. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7063. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7064. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7065. //check Transaction active
  7066. if(gunType[connectorIdInt -1] == 'J')
  7067. {
  7068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7069. {
  7070. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7071. }
  7072. else
  7073. {
  7074. tempIndex = connectorIdInt -1;
  7075. }
  7076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7077. {
  7078. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7079. {
  7080. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7081. {
  7082. //Reserved
  7083. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7084. }
  7085. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7086. {
  7087. //Reserved
  7088. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7090. goto end;
  7091. }
  7092. else
  7093. {
  7094. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7095. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7096. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7097. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7098. {
  7099. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7100. goto end;
  7101. }
  7102. }//END FOR ELSE
  7103. }
  7104. }// END FOR CHAdeMO_QUANTITY
  7105. }
  7106. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7107. {
  7108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7109. {
  7110. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7111. }
  7112. else
  7113. {
  7114. tempIndex = connectorIdInt -1;
  7115. }
  7116. for (int index = 0; index < CCS_QUANTITY; index++)
  7117. {
  7118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7119. {
  7120. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7121. {
  7122. //Reserved
  7123. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7124. }
  7125. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7126. {
  7127. //Reserved
  7128. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7129. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7130. goto end;
  7131. }
  7132. else
  7133. {
  7134. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7135. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7136. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7137. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7138. {
  7139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7140. goto end;
  7141. }
  7142. }// END FOR ELSE
  7143. }
  7144. }// END FOR CCS_QUANTITY
  7145. }
  7146. else if(gunType[connectorIdInt -1] == 'G')
  7147. {
  7148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7149. {
  7150. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7151. }
  7152. else
  7153. {
  7154. tempIndex = connectorIdInt -1;
  7155. }
  7156. for (int index = 0; index < GB_QUANTITY; index++)
  7157. {
  7158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7159. {
  7160. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7161. {
  7162. //Reserved
  7163. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7164. }
  7165. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7166. {
  7167. //Reserved
  7168. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7169. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7170. goto end;
  7171. }
  7172. else
  7173. {
  7174. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7175. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7176. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7177. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7178. {
  7179. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7180. goto end;
  7181. }
  7182. }// END FOR ELSE
  7183. }
  7184. } // END FOR GB_QUANTITY
  7185. }
  7186. else
  7187. {
  7188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7189. {
  7190. tempIndex = 2;
  7191. }
  7192. else
  7193. {
  7194. tempIndex = connectorIdInt -1;
  7195. }
  7196. for (int index = 0; index < AC_QUANTITY; index++)
  7197. {
  7198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7199. {
  7200. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7201. {
  7202. //Reserved
  7203. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7204. }
  7205. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7206. {
  7207. //Reserved
  7208. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7210. goto end;
  7211. }
  7212. else
  7213. {
  7214. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7215. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7216. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7217. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7218. {
  7219. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7220. goto end;
  7221. }
  7222. }//END FOR ELSE
  7223. }
  7224. }// END FOR AC_QUANTITY
  7225. }
  7226. if(chargingProfileIsNULL == FALSE)
  7227. {
  7228. //ChargingProfile
  7229. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7230. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7231. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7232. if(recurrencyKindIsNULL == FALSE) //OPTION
  7233. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7234. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7235. if(transactionIdIsNULL == FALSE) // OPTION
  7236. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7237. if(validFromIsNULL == FALSE) // OPTION
  7238. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7239. if(validToIsNULL == FALSE) //OPTION
  7240. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7241. //ChargingSchedule
  7242. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7243. if(durationIsNULL == FALSE) //OPTION
  7244. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7245. if(minChargingRateIsNULL == FALSE) //OPTION
  7246. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7247. if(startScheduleIsNULL == FALSE) //OPTION
  7248. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7249. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7250. {
  7251. //ChargingSchedulePeriod
  7252. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7253. if(numberPhasesIsNULL == FALSE)
  7254. {
  7255. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7256. }
  7257. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7258. }
  7259. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7260. {
  7261. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7263. //memset idTag
  7264. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7265. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7266. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7267. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7268. }
  7269. else
  7270. {
  7271. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7272. }
  7273. }
  7274. else
  7275. {
  7276. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7277. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7278. //memset idTag
  7279. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7280. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7281. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7282. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7283. }
  7284. }
  7285. else
  7286. {
  7287. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7288. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7289. }
  7290. end:
  7291. if(connectorIdIsNULL == FALSE)
  7292. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7293. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7294. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7295. //OCPP send RemoteStartConfirmation by first.
  7296. sendRemoteStartConfirmation(uuid, comfirmstr);
  7297. return result;
  7298. }
  7299. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7300. {
  7301. mtrace();
  7302. int result = FAIL;
  7303. int match = FALSE;
  7304. int GunNO = 0;
  7305. int tempIndex = 0;
  7306. int transactionIdInt=0;
  7307. int transactionIdIsNULL= FALSE;
  7308. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7309. int c = 0;
  7310. char *loc;
  7311. char comfirmstr[20];
  7312. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7313. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7314. if(server_pending == TRUE)
  7315. {
  7316. return 0;
  7317. }
  7318. strcpy(sstrtemp, stringtrimspace(payload));
  7319. c=0;
  7320. loc = strstr(sstrtemp, "transactionId");
  7321. if(loc == NULL)
  7322. {
  7323. transactionIdIsNULL= TRUE;
  7324. }
  7325. else
  7326. {
  7327. memset(sstr ,0, sizeof(sstr) );
  7328. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7329. {
  7330. sstr[c] = loc[strlen("transactionId")+2+c];
  7331. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7332. c++;
  7333. }
  7334. sstr[c] = '\0';
  7335. transactionIdInt = atoi(sstr);
  7336. }
  7337. if(transactionIdIsNULL == FALSE)
  7338. {
  7339. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7340. {
  7341. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7342. {
  7343. //check Transaction active
  7344. if(gunType[gun_index] == 'J')
  7345. {
  7346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7347. {
  7348. tempIndex = ((gun_index==2) ? 1: 0);
  7349. }
  7350. else
  7351. {
  7352. tempIndex = gun_index;
  7353. }
  7354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7355. {
  7356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7357. {
  7358. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7359. {
  7360. match = TRUE;
  7361. GunNO = gun_index;
  7362. }
  7363. }
  7364. }// END FOR CHAdeMO_QUANTITY
  7365. }
  7366. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7367. {
  7368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7369. {
  7370. tempIndex = ((gun_index==2) ? 1: 0);
  7371. }
  7372. else
  7373. {
  7374. tempIndex = gun_index;
  7375. }
  7376. for (int index = 0; index < CCS_QUANTITY; index++)
  7377. {
  7378. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7379. {
  7380. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7381. {
  7382. match = TRUE;
  7383. GunNO = gun_index;
  7384. }
  7385. }
  7386. }// END FOR CCS_QUANTITY
  7387. }
  7388. else if(gunType[gun_index] == 'G')
  7389. {
  7390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7391. {
  7392. tempIndex = ((gun_index==2) ? 1: 0);
  7393. }
  7394. else
  7395. {
  7396. tempIndex = gun_index;
  7397. }
  7398. for (int index = 0; index < GB_QUANTITY; index++)
  7399. {
  7400. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7401. {
  7402. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7403. {
  7404. match = TRUE;
  7405. GunNO = gun_index;
  7406. }
  7407. }
  7408. }// END FOR GB_QUANTITY
  7409. }
  7410. else
  7411. {
  7412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7413. {
  7414. tempIndex = 2;
  7415. }
  7416. else
  7417. {
  7418. tempIndex = gun_index;
  7419. }
  7420. for (int index = 0; index < AC_QUANTITY; index++)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7423. {
  7424. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7425. {
  7426. match = TRUE;
  7427. GunNO = gun_index;
  7428. }
  7429. }
  7430. }// END FOR CHAdeMO_QUANTITY
  7431. } // END FOR AC ELSE
  7432. }// CHECK IF ResponseTransactionId == transactionIdInt
  7433. }//END FOR
  7434. if( match == TRUE)
  7435. {
  7436. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7437. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7438. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7439. }
  7440. else
  7441. {
  7442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7443. }
  7444. }
  7445. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7446. return result;
  7447. }
  7448. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7449. {
  7450. mtrace();
  7451. int result = FAIL;
  7452. int connectorIdInt=0, reservationIdInt=0;
  7453. int tempIndex = 0;
  7454. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7455. char comfirmstr[20]={0};
  7456. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7457. int c = 0;
  7458. char *loc;
  7459. //char *ptr;
  7460. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  7461. strcpy(sstrtemp, stringtrimspace(payload));
  7462. //***(1)connectorId ****/
  7463. c=0;
  7464. loc = strstr(sstrtemp, "connectorId");
  7465. memset(sstr ,0, sizeof(sstr) );
  7466. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7467. {
  7468. sstr[c] = loc[strlen("connectorId")+2+c];
  7469. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7470. c++;
  7471. }
  7472. sstr[c] = '\0';
  7473. connectorIdInt = atoi(sstr);
  7474. //***(2)expiryDate ****/
  7475. loc = strstr(sstrtemp, "expiryDate");
  7476. memset(sstr ,0, sizeof(sstr) );
  7477. c = 0;
  7478. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7479. {
  7480. sstr[c] = loc[3+strlen("expiryDate")+c];
  7481. c++;
  7482. }
  7483. sstr[c] = '\0';
  7484. strcpy(expiryDatestr, sstr);
  7485. //***(3)idTag ****/
  7486. loc = strstr(sstrtemp, "idTag");
  7487. memset(sstr ,0, sizeof(sstr) );
  7488. c = 0;
  7489. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7490. {
  7491. sstr[c] = loc[3+strlen("idTag")+c];
  7492. c++;
  7493. }
  7494. sstr[c] = '\0';
  7495. strcpy(idTagstr, sstr);
  7496. //***(4)parentIdTag ****/
  7497. loc = strstr(sstrtemp, "parentIdTag");
  7498. memset(sstr ,0, sizeof(sstr) );
  7499. c = 0;
  7500. if(loc == NULL)
  7501. {
  7502. strcpy(parentIdTagstr, "");
  7503. }
  7504. else
  7505. {
  7506. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7507. {
  7508. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7509. c++;
  7510. }
  7511. sstr[c] = '\0';
  7512. strcpy(parentIdTagstr, sstr);
  7513. }
  7514. //***(5)reservationId ****/
  7515. c=0;
  7516. loc = strstr(sstrtemp, "reservationId");
  7517. memset(sstr ,0, sizeof(sstr) );
  7518. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7519. {
  7520. sstr[c] = loc[strlen("reservationId")+2+c];
  7521. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7522. c++;
  7523. }
  7524. sstr[c] = '\0';
  7525. reservationIdInt = atoi(sstr);
  7526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7527. /*
  7528. enum SYSTEM_STATUS
  7529. {
  7530. SYS_MODE_BOOTING = 0,
  7531. SYS_MODE_IDLE = 1,
  7532. SYS_MODE_AUTHORIZING = 2,
  7533. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7534. SYS_MODE_REASSIGN = 4,
  7535. SYS_MODE_PREPARING = 5,
  7536. SYS_MODE_PREPARE_FOR_EV = 6,
  7537. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7538. SYS_MODE_CHARGING = 8,
  7539. SYS_MODE_TERMINATING = 9,
  7540. SYS_MODE_COMPLETE = 10,
  7541. SYS_MODE_ALARM = 11,
  7542. SYS_MODE_FAULT = 12,
  7543. SYS_MODE_RESERVATION = 13,
  7544. SYS_MODE_BOOKING = 14,
  7545. SYS_MODE_MAINTAIN = 15,
  7546. SYS_MODE_DEBUG = 16,
  7547. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7548. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7549. SYS_MODE_UPDATE = 19
  7550. };
  7551. */
  7552. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7553. {
  7554. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7555. goto end;
  7556. }
  7557. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7558. {
  7559. //check Transaction active
  7560. if(gunType[connectorIdInt -1] == 'J')
  7561. {
  7562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7563. {
  7564. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7565. }
  7566. else
  7567. {
  7568. tempIndex = connectorIdInt -1;
  7569. }
  7570. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7571. {
  7572. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7573. {
  7574. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7575. {
  7576. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7577. {
  7578. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7579. {
  7580. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7582. }
  7583. 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'))
  7584. {
  7585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7586. }
  7587. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7588. {
  7589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7590. }
  7591. else
  7592. {
  7593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7594. }
  7595. }
  7596. 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
  7597. {
  7598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7599. }
  7600. }
  7601. else
  7602. {
  7603. //replace reservation
  7604. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7606. }
  7607. }
  7608. } // END FOR CHAdeMO_QUANTITY
  7609. }
  7610. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7611. {
  7612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7613. {
  7614. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7615. }
  7616. else
  7617. {
  7618. tempIndex = connectorIdInt -1;
  7619. }
  7620. for (int index = 0; index < CCS_QUANTITY; index++)
  7621. {
  7622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7623. {
  7624. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7625. {
  7626. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7627. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7628. {
  7629. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7630. {
  7631. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7633. }
  7634. 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'))
  7635. {
  7636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7637. }
  7638. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7639. {
  7640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7641. }
  7642. else
  7643. {
  7644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7645. }
  7646. }
  7647. 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
  7648. {
  7649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7650. }
  7651. }
  7652. else
  7653. {
  7654. //replace reservation
  7655. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7657. }
  7658. }
  7659. } // END FOR CCS_QUANTITY
  7660. }
  7661. else if(gunType[connectorIdInt -1] == 'G')
  7662. {
  7663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7664. {
  7665. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7666. }
  7667. else
  7668. {
  7669. tempIndex = connectorIdInt -1;
  7670. }
  7671. for (int index = 0; index < GB_QUANTITY; index++)
  7672. {
  7673. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7674. {
  7675. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7676. {
  7677. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7678. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7679. {
  7680. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7681. {
  7682. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7684. }
  7685. 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'))
  7686. {
  7687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7688. }
  7689. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7690. {
  7691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7692. }
  7693. else
  7694. {
  7695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7696. }
  7697. }
  7698. 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
  7699. {
  7700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7701. }
  7702. }
  7703. else
  7704. {
  7705. //replace reservation
  7706. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7708. }
  7709. }
  7710. }// END FOR GB_QUANTITY
  7711. }
  7712. else
  7713. {
  7714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7715. {
  7716. tempIndex = 2;
  7717. }
  7718. else
  7719. {
  7720. tempIndex = (connectorIdInt -1);
  7721. }
  7722. for (int index = 0; index < AC_QUANTITY; index++)
  7723. {
  7724. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7725. {
  7726. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7727. {
  7728. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7729. {
  7730. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7731. {
  7732. 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))
  7733. {
  7734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7735. }
  7736. else
  7737. {
  7738. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7740. }
  7741. }
  7742. 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'))
  7743. {
  7744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7745. }
  7746. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7747. {
  7748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7749. }
  7750. else
  7751. {
  7752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7753. }
  7754. }
  7755. 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
  7756. {
  7757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7758. }
  7759. }
  7760. else
  7761. {
  7762. //replace reservation
  7763. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7765. }
  7766. }
  7767. } // END FOR AC_QUANTITY
  7768. }
  7769. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7770. }
  7771. else if(connectorIdInt == 0)
  7772. {
  7773. //check Transaction active
  7774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7775. {
  7776. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7777. {
  7778. 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'))
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7781. goto end;
  7782. }
  7783. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7784. {
  7785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7786. goto end;
  7787. }
  7788. 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
  7789. {
  7790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7791. goto end;
  7792. }
  7793. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7794. {
  7795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7796. goto end;
  7797. }
  7798. }
  7799. }// END FOR CHAdeMO_QUANTITY
  7800. for (int index = 0; index < CCS_QUANTITY; index++)
  7801. {
  7802. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7803. {
  7804. 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'))
  7805. {
  7806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7807. goto end;
  7808. }
  7809. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7810. {
  7811. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7812. goto end;
  7813. }
  7814. 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
  7815. {
  7816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7817. goto end;
  7818. }
  7819. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7820. {
  7821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7822. goto end;
  7823. }
  7824. }
  7825. } // END FOR CCS_QUANTITY
  7826. for (int index = 0; index < GB_QUANTITY; index++)
  7827. {
  7828. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7829. {
  7830. 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'))
  7831. {
  7832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7833. goto end;
  7834. }
  7835. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7836. {
  7837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7838. goto end;
  7839. }
  7840. 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
  7841. {
  7842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7843. goto end;
  7844. }
  7845. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7846. {
  7847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7848. goto end;
  7849. }
  7850. }
  7851. } // END FOR GB_QUANTITY
  7852. for (int index = 0; index < AC_QUANTITY; index++)
  7853. {
  7854. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7855. {
  7856. 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'))
  7857. {
  7858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7859. goto end;
  7860. }
  7861. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7862. {
  7863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7864. goto end;
  7865. }
  7866. 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
  7867. {
  7868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7869. goto end;
  7870. }
  7871. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7872. {
  7873. 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))
  7874. {
  7875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7876. goto end;
  7877. }
  7878. }
  7879. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7880. {
  7881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7882. goto end;
  7883. }
  7884. }
  7885. }// END FOR AC_QUANTITY
  7886. //The connectorId is 0
  7887. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7889. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7890. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7891. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7892. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7893. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7894. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7895. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7896. result = TRUE;
  7897. return result;
  7898. }
  7899. else
  7900. {
  7901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7902. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7903. }
  7904. if(strcmp(comfirmstr,"Accepted") == 0)
  7905. {
  7906. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7907. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7908. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7909. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7910. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7911. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7912. result = TRUE;
  7913. return result;
  7914. }
  7915. end:
  7916. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7917. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7918. return result;
  7919. }
  7920. int handleResetRequest(char *uuid, char *payload)
  7921. {
  7922. mtrace();
  7923. int result = FAIL;
  7924. char sstr[10]={0},sstrtemp[30]={ 0 };
  7925. char typestr[10]={0};
  7926. char comfirmstr[20]={0};
  7927. int c = 0;
  7928. char *loc;
  7929. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7930. DEBUG_INFO("handleResetRequest ...\n");
  7931. strcpy(sstrtemp, stringtrimspace(payload));
  7932. loc = strstr(sstrtemp, "type");
  7933. memset(sstr ,0, sizeof(sstr) );
  7934. c = 0;
  7935. while (loc[3+strlen("type")+c] != '\"')
  7936. {
  7937. sstr[c] = loc[3+strlen("type")+c];
  7938. c++;
  7939. }
  7940. sstr[c] = '\0';
  7941. strcpy(typestr,sstr);
  7942. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7943. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7944. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7945. {
  7946. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7947. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7948. result = TRUE;
  7949. return result;
  7950. }
  7951. else
  7952. {
  7953. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7954. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7955. goto errorend;
  7956. }
  7957. errorend:
  7958. sendResetConfirmation(uuid, comfirmstr);
  7959. return result;
  7960. }
  7961. int handleSendLocalListRequest(char *uuid, char *payload)
  7962. {
  7963. mtrace();
  7964. int result = FAIL;
  7965. int listVersionInt;
  7966. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7967. char listsearch[]="listVersion";
  7968. char updateTypesearch[]="updateType";
  7969. char localAuthorizationListsearch[]="localAuthorizationList";
  7970. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7971. char CardList[500][160]={0};
  7972. char updateTypestr[15]={0};
  7973. char idTagstr[20]={0};
  7974. char parentIdTag[20]={0};
  7975. char expiryDate[30]={0};
  7976. char idTagstatus[16]={0};
  7977. int c = 0;
  7978. int i = 0;
  7979. char *delim1 = "}";
  7980. char * pch;
  7981. char *loc;
  7982. //char *ptr;
  7983. char comfirmstr[20];
  7984. //int n_localAuthorizations = 0;
  7985. int checkState_Faulted = FALSE;
  7986. DEBUG_INFO("handleSendLocalListRequest\n");
  7987. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7988. {
  7989. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7990. goto end;
  7991. }
  7992. //check Charge Point state
  7993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7994. {
  7995. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7996. {
  7997. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7998. }
  7999. }
  8000. for (int index = 0; index < CCS_QUANTITY; index++)
  8001. {
  8002. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8003. {
  8004. checkState_Faulted = TRUE; //OCPP Status
  8005. }
  8006. }
  8007. for (int index = 0; index < GB_QUANTITY; index++)
  8008. {
  8009. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8010. {
  8011. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8012. }
  8013. }
  8014. //check Charge Point state
  8015. for (int index = 0; index < AC_QUANTITY; index++)
  8016. {
  8017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8018. {
  8019. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8020. }
  8021. }
  8022. if(checkState_Faulted == TRUE)
  8023. {
  8024. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8025. goto end;
  8026. }
  8027. //Filter payload space
  8028. strcpy(sstrtemp, stringtrimspace(payload));
  8029. //listVersion
  8030. c = 0;
  8031. loc = strstr(sstrtemp, listsearch);
  8032. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8033. {
  8034. sstr[c] = loc[strlen("listVersion")+2+c];
  8035. c++;
  8036. }
  8037. sstr[c] = '\0';
  8038. listVersionInt = atoi(sstr);
  8039. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8040. //updateType
  8041. loc = strstr(sstrtemp, updateTypesearch);
  8042. c = 0;
  8043. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8044. {
  8045. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8046. c++;
  8047. }
  8048. sstr[c] = '\0';
  8049. strcpy(updateTypestr, sstr);
  8050. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8051. //localAuthorizationList
  8052. memset(sstr ,0, sizeof(sstr) );
  8053. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8054. if(loc != NULL) // localAuthorizationList is not NULL
  8055. {
  8056. //Check UpdateType
  8057. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8058. {
  8059. //Local list full update
  8060. printf("Local list full update.\n");
  8061. OCPP_getListVerion();
  8062. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8063. {
  8064. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8065. goto end;
  8066. }
  8067. OCPP_cleanLocalList();
  8068. }
  8069. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8070. {
  8071. //Local list different update
  8072. printf("Local list different update.\n");
  8073. OCPP_getListVerion();
  8074. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8075. {
  8076. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8077. goto end;
  8078. }
  8079. }
  8080. else
  8081. {
  8082. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8083. goto end;
  8084. }
  8085. c = 0;
  8086. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8087. {
  8088. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8089. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8090. c++;
  8091. }
  8092. sstr[c] = '\0';
  8093. //DEBUG_INFO("sstr=%s\n", sstr);
  8094. //parsing strings to words
  8095. i = 0;
  8096. pch = strtok(sstr,delim1);
  8097. while (pch != NULL)
  8098. {
  8099. strcpy(CardList[i], pch);
  8100. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8101. pch = strtok (NULL, delim1);
  8102. i = i + 1;
  8103. }
  8104. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8105. //local Authorizations List Numbers
  8106. //n_localAuthorizations = i;
  8107. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8108. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8109. c= 0;
  8110. while(c < i) // i is CardList Number
  8111. {
  8112. //Search "IdToken"
  8113. memset(sstr ,0, sizeof(sstr) );
  8114. loc = strstr(CardList[c], "idTag");
  8115. int j = 0;
  8116. while (loc[3+strlen("idTag")+j] != '\"')
  8117. {
  8118. sstr[j] = loc[3+strlen("idTag")+j];
  8119. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8120. j++;
  8121. }
  8122. sstr[j] = '\0';
  8123. strcpy(idTagstr, sstr);
  8124. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8125. //Search "expiryDate"
  8126. memset(sstr ,0, sizeof(sstr) );
  8127. loc = strstr(CardList[c], "expiryDate");
  8128. j = 0;
  8129. if(loc != NULL)
  8130. {
  8131. while (loc[3+strlen("expiryDate")+j] != '\"')
  8132. {
  8133. sstr[j] = loc[3+strlen("expiryDate")+j];
  8134. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8135. j++;
  8136. }
  8137. sstr[j] = '\0';
  8138. strcpy(expiryDate, sstr);
  8139. }
  8140. else
  8141. {
  8142. strcpy(expiryDate, "");
  8143. }
  8144. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8145. //Search "parentIdTag"
  8146. memset(sstr ,0, sizeof(sstr) );
  8147. loc = strstr(CardList[c], "parentIdTag");
  8148. j = 0;
  8149. if(loc != NULL)
  8150. {
  8151. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8152. {
  8153. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8154. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8155. j++;
  8156. }
  8157. sstr[j] = '\0';
  8158. strcpy(parentIdTag, sstr);
  8159. }
  8160. else
  8161. {
  8162. strcpy(parentIdTag, "");
  8163. }
  8164. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8165. //Search "status"
  8166. memset(sstr ,0, sizeof(sstr) );
  8167. loc = strstr(CardList[c], "status");
  8168. j = 0;
  8169. while (loc[3+strlen("status")+j] != '\"')
  8170. {
  8171. sstr[j] = loc[3+strlen("status")+j];
  8172. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8173. j++;
  8174. }
  8175. sstr[j] = '\0';
  8176. strcpy(idTagstatus, sstr);
  8177. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8178. OCPP_getIdTag(idTagstr);
  8179. //OCPP_getIdTag("test"); For Test
  8180. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8181. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8182. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8183. {
  8184. //Local list full update
  8185. DEBUG_INFO("Local list full update.\n");
  8186. // update list
  8187. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8188. //DEBUG_INFO("Local list full update. 1\n");
  8189. //OCPP_get_TableAuthlocalAllData();
  8190. //DEBUG_INFO("Local list full update. 2\n");
  8191. }
  8192. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8193. {
  8194. #if 0
  8195. if(strcmp(idTagstr, idTagAuthorization) == 0)
  8196. {
  8197. //OCPP_deleteIdTag(idTagstr);
  8198. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  8199. }
  8200. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  8201. {
  8202. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  8203. }
  8204. #endif
  8205. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8206. }
  8207. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8208. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8209. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8210. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8211. c++;
  8212. }
  8213. }
  8214. else
  8215. {
  8216. //Check UpdateType
  8217. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8218. {
  8219. //Local list full update
  8220. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8221. OCPP_cleanLocalList();
  8222. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8223. goto end;
  8224. }
  8225. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8226. {
  8227. //Local list different update
  8228. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8229. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8230. goto end;
  8231. }
  8232. }
  8233. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8234. end:
  8235. sendSendLocalListConfirmation(uuid, comfirmstr);
  8236. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8237. return result;
  8238. }
  8239. #define MAX 200
  8240. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8241. {
  8242. mtrace();
  8243. int result = FAIL;
  8244. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8245. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8246. char chargingProfilePurposeStr[30]={0};
  8247. char chargingProfileKindStr[16]={0};
  8248. char recurrencyKindStr[10]={0};
  8249. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8250. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8251. int chargingSchedulePeriodCount = 0;
  8252. //int updateflag = FALSE;
  8253. char comfirmstr[20]={0};
  8254. int meet= FALSE;
  8255. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8256. int c = 0;
  8257. char *loc;
  8258. FILE *fptr1;//, *fptr2;
  8259. //int lno=0;//, linectr = 0;
  8260. //int modifyflag = FALSE;
  8261. char filename[MAX]={0};
  8262. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8263. //int resultRename=0;
  8264. char rmFileCmd[50]={0};
  8265. char tempchargingProfilePurposeStr[30]={0};
  8266. char word[1600]={0};
  8267. int n_chargingProfile = 0;
  8268. //[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}}}]
  8269. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8270. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8271. //Filter string space
  8272. strcpy(sstrtemp, stringtrimspace(payload));
  8273. //*********************connectorId***************************/
  8274. loc = strstr(sstrtemp, "connectorId");
  8275. c = 0;
  8276. memset(sstr ,0, sizeof(sstr) );
  8277. while (loc[strlen("connectorId")+2+c] != ',')
  8278. {
  8279. sstr[c] = loc[strlen("connectorId")+2+c];
  8280. c++;
  8281. }
  8282. sstr[c] = '\0';
  8283. connectorIdInt = atoi(sstr);
  8284. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8285. {
  8286. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8287. }
  8288. else
  8289. {
  8290. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8291. }
  8292. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8293. //*********************chargingProfileId***************************/
  8294. loc = strstr(sstrtemp, "chargingProfileId");
  8295. c = 0;
  8296. memset(sstr ,0, sizeof(sstr) );
  8297. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8298. {
  8299. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8300. c++;
  8301. }
  8302. sstr[c] = '\0';
  8303. chargingProfileIdInt = atoi(sstr);
  8304. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8305. {
  8306. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8307. }
  8308. else
  8309. {
  8310. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8311. }
  8312. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8313. //*********************transactionId***************************/
  8314. loc = strstr(sstrtemp, "transactionId");
  8315. if(loc != NULL)
  8316. {
  8317. c = 0;
  8318. memset(sstr ,0, sizeof(sstr) );
  8319. while (loc[strlen("transactionId")+2+c] != ',')
  8320. {
  8321. sstr[c] = loc[strlen("transactionId")+2+c];
  8322. c++;
  8323. }
  8324. sstr[c] = '\0';
  8325. transactionIdInt = atoi(sstr);
  8326. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8327. {
  8328. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8329. }
  8330. else
  8331. {
  8332. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8333. }
  8334. }
  8335. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8336. //*********************stackLevel***************************/
  8337. loc = strstr(sstrtemp, "stackLevel");
  8338. c = 0;
  8339. memset(sstr ,0, sizeof(sstr) );
  8340. while (loc[strlen("stackLevel")+2+c] != ',')
  8341. {
  8342. sstr[c] = loc[strlen("stackLevel")+2+c];
  8343. c++;
  8344. }
  8345. sstr[c] = '\0';
  8346. stackLevelInt = atoi(sstr);
  8347. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8348. {
  8349. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8350. }
  8351. else
  8352. {
  8353. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8354. }
  8355. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8356. //*********************chargingProfilePurpose***************************/
  8357. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8358. c = 0;
  8359. memset(sstr ,0, sizeof(sstr) );
  8360. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8361. {
  8362. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8363. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8364. c++;
  8365. }
  8366. sstr[c] = '\0';
  8367. strcpy(chargingProfilePurposeStr,sstr);
  8368. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8369. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8370. {
  8371. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8372. }
  8373. else
  8374. {
  8375. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8376. }
  8377. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8378. //*********************chargingProfileKind***************************/
  8379. loc = strstr(sstrtemp, "chargingProfileKind");
  8380. c = 0;
  8381. memset(sstr ,0, sizeof(sstr) );
  8382. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8383. {
  8384. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8385. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8386. c++;
  8387. }
  8388. sstr[c] = '\0';
  8389. strcpy(chargingProfileKindStr,sstr);
  8390. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8391. {
  8392. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8393. }
  8394. else
  8395. {
  8396. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8397. }
  8398. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8399. //*********************recurrencyKind***************************/
  8400. loc = strstr(sstrtemp, "recurrencyKind");
  8401. if(loc != NULL)
  8402. {
  8403. c = 0;
  8404. memset(sstr ,0, sizeof(sstr) );
  8405. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8406. {
  8407. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8408. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8409. c++;
  8410. }
  8411. sstr[c] = '\0';
  8412. strcpy(recurrencyKindStr,sstr);
  8413. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8414. {
  8415. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8416. }
  8417. else
  8418. {
  8419. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8420. }
  8421. }
  8422. else
  8423. {
  8424. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8425. {
  8426. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8427. }
  8428. else
  8429. {
  8430. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8431. }
  8432. }
  8433. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8434. //*********************validFrom***************************/
  8435. loc = strstr(sstrtemp, "validFrom");
  8436. if(loc != NULL)
  8437. {
  8438. c = 0;
  8439. memset(sstr ,0, sizeof(sstr) );
  8440. while (loc[3+strlen("validFrom")+c] != '\"')
  8441. {
  8442. sstr[c] = loc[3+strlen("validFrom")+c];
  8443. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8444. c++;
  8445. }
  8446. sstr[c] = '\0';
  8447. strcpy(validFromStr,sstr);
  8448. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8449. {
  8450. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8451. }
  8452. else
  8453. {
  8454. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8455. }
  8456. }
  8457. else
  8458. {
  8459. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8460. {
  8461. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8462. }
  8463. else
  8464. {
  8465. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8466. }
  8467. }
  8468. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8469. //*********************validTo***************************/
  8470. loc = strstr(sstrtemp, "validTo");
  8471. if(loc != NULL)
  8472. {
  8473. c = 0;
  8474. memset(sstr ,0, sizeof(sstr) );
  8475. while (loc[3+strlen("validTo")+c] != '\"')
  8476. {
  8477. sstr[c] = loc[3+strlen("validTo")+c];
  8478. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8479. c++;
  8480. }
  8481. sstr[c] = '\0';
  8482. strcpy(validToStr,sstr);
  8483. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8484. {
  8485. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8486. }
  8487. else
  8488. {
  8489. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8490. }
  8491. }
  8492. else
  8493. {
  8494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8495. {
  8496. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8497. }
  8498. else
  8499. {
  8500. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8501. }
  8502. }
  8503. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8504. //*********************duration***************************/
  8505. loc = strstr(sstrtemp, "duration");
  8506. if(loc != NULL)
  8507. {
  8508. c = 0;
  8509. memset(sstr ,0, sizeof(sstr) );
  8510. while (loc[strlen("duration")+2+c] != ',')
  8511. {
  8512. sstr[c] = loc[strlen("duration")+2+c];
  8513. c++;
  8514. }
  8515. sstr[c] = '\0';
  8516. durationInt = atoi(sstr);
  8517. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8518. {
  8519. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8520. }
  8521. else
  8522. {
  8523. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8524. }
  8525. }
  8526. else
  8527. {
  8528. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8529. {
  8530. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8531. }
  8532. else
  8533. {
  8534. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8535. }
  8536. }
  8537. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8538. //*********************startSchedule***************************/
  8539. loc = strstr(sstrtemp, "startSchedule");
  8540. if(loc != NULL)
  8541. {
  8542. c = 0;
  8543. memset(sstr ,0, sizeof(sstr) );
  8544. while (loc[3+strlen("startSchedule")+c] != '\"')
  8545. {
  8546. sstr[c] = loc[3+strlen("startSchedule")+c];
  8547. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8548. c++;
  8549. }
  8550. sstr[c] = '\0';
  8551. strcpy(startScheduleStr,sstr);
  8552. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8553. {
  8554. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8555. }
  8556. else
  8557. {
  8558. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8559. }
  8560. }
  8561. else
  8562. {
  8563. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8564. {
  8565. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8566. }
  8567. else
  8568. {
  8569. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8570. }
  8571. }
  8572. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8573. //*********************chargingRateUnit***************************/
  8574. loc = strstr(sstrtemp, "chargingRateUnit");
  8575. if(loc != NULL)
  8576. {
  8577. c = 0;
  8578. memset(sstr ,0, sizeof(sstr) );
  8579. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8580. {
  8581. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8582. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8583. c++;
  8584. }
  8585. sstr[c] = '\0';
  8586. strcpy(chargingRateUnitStr,sstr);
  8587. #if 0
  8588. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8589. {
  8590. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8591. goto end;
  8592. }
  8593. #endif
  8594. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8595. {
  8596. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8597. }
  8598. else
  8599. {
  8600. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8601. }
  8602. }
  8603. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8604. //****************chargingSchedulePeriod count start*******************/
  8605. int what_len = strlen("startPeriod");
  8606. char tempChargingProfile[1600]={0};
  8607. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8608. char *where = tempChargingProfile;
  8609. if (what_len)
  8610. {
  8611. while ((where = strstr(where, "startPeriod"))) {
  8612. where += what_len;
  8613. chargingSchedulePeriodCount++;
  8614. }
  8615. }
  8616. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8617. {
  8618. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8619. goto end;
  8620. }
  8621. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8622. //where = payload;
  8623. int templength = 0;
  8624. //int searchstart = 0;
  8625. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8626. {
  8627. //****************startPeriod*******************/
  8628. c=0;
  8629. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8630. memset(sstr ,0, sizeof(sstr) );
  8631. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8632. {
  8633. sstr[c] = loc[strlen("startPeriod")+2+c];
  8634. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8635. c++;
  8636. }
  8637. sstr[c] = '\0';
  8638. startPeriodInt[periodNums] = atoi(sstr);
  8639. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8640. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8641. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8642. {
  8643. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8644. }
  8645. else
  8646. {
  8647. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8648. }
  8649. templength = strlen("startPeriod")+2+c;
  8650. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8651. //****************limit*******************/
  8652. c=0;
  8653. loc = strstr(tempChargingProfile + templength, "limit");
  8654. memset(sstr ,0, sizeof(sstr) );
  8655. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8656. {
  8657. sstr[c] = loc[strlen("limit")+2+c];
  8658. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8659. c++;
  8660. }
  8661. sstr[c] = '\0';
  8662. limitflaot[periodNums] = atof(sstr);
  8663. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8664. {
  8665. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8666. }
  8667. else
  8668. {
  8669. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8670. }
  8671. templength = templength + strlen("limit")+2+c;
  8672. //****************numberPhases*******************/
  8673. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8674. if(loc != NULL)
  8675. {
  8676. c=0;
  8677. memset(sstr ,0, sizeof(sstr) );
  8678. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8679. {
  8680. sstr[c] = loc[strlen("numberPhases")+2+c];
  8681. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8682. c++;
  8683. }
  8684. sstr[c] = '\0';
  8685. numberPhasesInt[periodNums] = atoi(sstr);
  8686. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8687. {
  8688. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8689. }
  8690. else
  8691. {
  8692. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8693. }
  8694. templength = templength + strlen("numberPhases")+2+c;
  8695. }
  8696. //where = loc;
  8697. }
  8698. //****************chargingSchedulePeriod count end*******************/
  8699. //*********************minChargingRate***************************/
  8700. loc = strstr(sstrtemp, "minChargingRate");
  8701. if(loc != NULL)
  8702. {
  8703. c = 0;
  8704. memset(sstr ,0, sizeof(sstr) );
  8705. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8706. {
  8707. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8708. c++;
  8709. }
  8710. sstr[c] = '\0';
  8711. minChargingRateFloat = atof(sstr);
  8712. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8713. {
  8714. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8715. }
  8716. else
  8717. {
  8718. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8719. }
  8720. }
  8721. else
  8722. {
  8723. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8724. {
  8725. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8726. }
  8727. else
  8728. {
  8729. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8730. }
  8731. }
  8732. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8733. {
  8734. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8735. if(connectorIdInt != 0)
  8736. {
  8737. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8738. goto end;
  8739. }
  8740. strcpy(filename, ChargePointMaxProfile_JSON );
  8741. fptr1 = fopen(filename, "r");
  8742. if (!fptr1)
  8743. {
  8744. //file not exist
  8745. DEBUG_INFO("Unable to open the input file!!\n");
  8746. fptr1 = fopen(filename, "w+");
  8747. }
  8748. else
  8749. {
  8750. //Check Charging Profile Count
  8751. while(fscanf(fptr1, "%s", word) != EOF)
  8752. {
  8753. //DEBUG_INFO("word=%s\n",word);
  8754. if(strstr(word, "chargingProfileId")!= NULL)
  8755. {
  8756. //DEBUG_INFO("test chargingProfileId \n");
  8757. n_chargingProfile = n_chargingProfile + 1;
  8758. //DEBUG_INFO("chargingProfileId Found\n");
  8759. }
  8760. }
  8761. }
  8762. fclose(fptr1);
  8763. }
  8764. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8765. {
  8766. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8767. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8768. {
  8769. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8770. goto end;
  8771. }
  8772. memset(filename, 0, sizeof filename);
  8773. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8774. fptr1 = fopen(filename, "r");
  8775. if (!fptr1)
  8776. {
  8777. //file not exist
  8778. //DEBUG_INFO("Unable to open the input file!!\n");
  8779. fptr1 = fopen(filename, "w+");
  8780. }
  8781. else
  8782. {
  8783. //Check Charging Profile Count
  8784. while(fscanf(fptr1, "%s", word) != EOF)
  8785. {
  8786. //DEBUG_INFO("word=%s\n",word);
  8787. if(strstr(word, "chargingProfileId")!= NULL)
  8788. {
  8789. //DEBUG_INFO("test chargingProfileId \n");
  8790. n_chargingProfile = n_chargingProfile + 1;
  8791. //DEBUG_INFO("chargingProfileId Found\n");
  8792. }
  8793. }
  8794. }
  8795. fclose(fptr1);
  8796. }
  8797. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8798. {
  8799. //printf("set chargingProfile 1-4\n");
  8800. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8801. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8802. if(connectorIdInt == 0)
  8803. {
  8804. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8805. goto end;
  8806. }
  8807. int tempIndex = 0;
  8808. //check Transaction active
  8809. if(gunType[connectorIdInt -1] == 'J')
  8810. {
  8811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8812. {
  8813. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8814. }
  8815. else
  8816. {
  8817. tempIndex = connectorIdInt -1;
  8818. }
  8819. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8820. {
  8821. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8822. {
  8823. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8824. {
  8825. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8826. {
  8827. meet = TRUE;
  8828. break;
  8829. }
  8830. }
  8831. }
  8832. }
  8833. }
  8834. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8835. {
  8836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8837. {
  8838. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8839. }
  8840. else
  8841. {
  8842. tempIndex = connectorIdInt -1;
  8843. }
  8844. for (int index = 0; index < CCS_QUANTITY; index++)
  8845. {
  8846. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8847. {
  8848. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8849. {
  8850. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8851. {
  8852. meet = TRUE;
  8853. break;
  8854. }
  8855. }
  8856. }
  8857. }
  8858. }
  8859. else if(gunType[connectorIdInt -1] == 'G')
  8860. {
  8861. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8862. {
  8863. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8864. }
  8865. else
  8866. {
  8867. tempIndex = connectorIdInt -1;
  8868. }
  8869. for (int index = 0; index < GB_QUANTITY; index++)
  8870. {
  8871. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8872. {
  8873. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8874. {
  8875. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8876. {
  8877. meet = TRUE;
  8878. break;
  8879. }
  8880. }
  8881. }
  8882. }
  8883. }
  8884. else
  8885. {
  8886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8887. {
  8888. tempIndex = 2;
  8889. }
  8890. else
  8891. {
  8892. tempIndex = (connectorIdInt -1);
  8893. }
  8894. for (int index = 0; index < AC_QUANTITY; index++)
  8895. {
  8896. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8897. {
  8898. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8899. {
  8900. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8901. {
  8902. meet = TRUE;
  8903. break;
  8904. }
  8905. }
  8906. }
  8907. }
  8908. }
  8909. //check Transaction active
  8910. if(meet == FALSE)
  8911. {
  8912. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8913. goto end;
  8914. }
  8915. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8916. {
  8917. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8918. goto end;
  8919. }
  8920. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8921. fptr1 = fopen(filename, "r");
  8922. if (!fptr1)
  8923. {
  8924. //file not exist
  8925. DEBUG_INFO("Unable to open the input file!!\n");
  8926. fptr1 = fopen(filename, "w+");
  8927. }
  8928. else
  8929. {
  8930. //Check Charging Profile Count
  8931. while(fscanf(fptr1, "%s", word) != EOF)
  8932. {
  8933. //DEBUG_INFO("word=%s\n",word);
  8934. if(strstr(word, "chargingProfileId")!= NULL)
  8935. {
  8936. //DEBUG_INFO("test chargingProfileId \n");
  8937. n_chargingProfile = n_chargingProfile + 1;
  8938. //DEBUG_INFO("chargingProfileId Found\n");
  8939. }
  8940. }
  8941. }
  8942. fclose(fptr1);
  8943. }
  8944. // Check ChargeProfileMaxStackLevel
  8945. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8946. {
  8947. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8948. goto end;
  8949. }
  8950. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8951. {
  8952. int i = 0;
  8953. char fnametemp[200]={0};
  8954. n_chargingProfile = 0;
  8955. //Check ChargePointMaxProfile.json exit
  8956. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8957. {
  8958. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8959. //Check Charging Profile Count
  8960. while(fscanf(fptr1, "%s", word) != EOF)
  8961. {
  8962. //DEBUG_INFO("word=%s\n",word);
  8963. if(strstr(word, "chargingProfileId")!= NULL)
  8964. {
  8965. //DEBUG_INFO("test chargingProfileId \n");
  8966. n_chargingProfile = n_chargingProfile + 1;
  8967. i = i + 1;
  8968. //DEBUG_INFO("chargingProfileId Found\n");
  8969. }
  8970. memset(word, 0, sizeof word);
  8971. }
  8972. fclose(fptr1);
  8973. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8974. }
  8975. //Check TxDefaultProfile_0.json exit
  8976. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8977. {
  8978. i = 0;
  8979. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8980. //Check Charging Profile Count
  8981. while(fscanf(fptr1, "%s", word) != EOF)
  8982. {
  8983. //DEBUG_INFO("word=%s\n",word);
  8984. if(strstr(word, "chargingProfileId")!= NULL)
  8985. {
  8986. //DEBUG_INFO("test chargingProfileId \n");
  8987. n_chargingProfile = n_chargingProfile + 1;
  8988. i = i + 1;
  8989. //DEBUG_INFO("chargingProfileId Found\n");
  8990. }
  8991. memset(word, 0, sizeof word);
  8992. }
  8993. fclose(fptr1);
  8994. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8995. }
  8996. //Check TxDefaultProfile_%d.json
  8997. for(int j=1; j <= gunTotalNumber; j++)
  8998. {
  8999. memset(fnametemp, 0, sizeof fnametemp);
  9000. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9001. if((access(fnametemp,F_OK))!=-1)
  9002. {
  9003. i = 0;
  9004. fptr1 = fopen(fnametemp, "r");
  9005. //Check Charging Profile Count
  9006. while(fscanf(fptr1, "%s", word) != EOF)
  9007. {
  9008. //DEBUG_INFO("word=%s\n",word);
  9009. if(strstr(word, "chargingProfileId")!= NULL)
  9010. {
  9011. //DEBUG_INFO("test chargingProfileId \n");
  9012. n_chargingProfile = n_chargingProfile + 1;
  9013. i = i + 1;
  9014. //DEBUG_INFO("chargingProfileId Found\n");
  9015. }
  9016. memset(word, 0, sizeof word);
  9017. }
  9018. fclose(fptr1);
  9019. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9020. }
  9021. }
  9022. //Check TxProfile_%d.json
  9023. for(int j=1; j <= gunTotalNumber; j++)
  9024. {
  9025. memset(fnametemp, 0, sizeof fnametemp);
  9026. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9027. if((access(fnametemp,F_OK))!=-1)
  9028. {
  9029. i = 0;
  9030. fptr1 = fopen(fnametemp, "r");
  9031. //Check Charging Profile Count
  9032. while(fscanf(fptr1, "%s", word) != EOF)
  9033. {
  9034. //DEBUG_INFO("word=%s\n",word);
  9035. if(strstr(word, "chargingProfileId")!= NULL)
  9036. {
  9037. //DEBUG_INFO("test chargingProfileId \n");
  9038. n_chargingProfile = n_chargingProfile + 1;
  9039. i = i + 1;
  9040. //DEBUG_INFO("chargingProfileId Found\n");
  9041. }
  9042. memset(word, 0, sizeof word);
  9043. }
  9044. fclose(fptr1);
  9045. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9046. }
  9047. }
  9048. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9049. {
  9050. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9051. goto end;
  9052. }
  9053. }
  9054. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9055. //**********************************Write to File********************************************************/
  9056. FILE *infile;
  9057. FILE *outfile;
  9058. // open file for writing
  9059. infile = fopen (filename, "r");
  9060. outfile = fopen (tempfile, "w");
  9061. int d =0;
  9062. d = fgetc(infile);
  9063. //DEBUG_INFO("d:%d\n",d);
  9064. rewind(infile);
  9065. //*检测到文件结束标识返回1,否则返回0。*/
  9066. if(d == EOF)
  9067. {
  9068. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9069. fprintf(outfile,"%s\n",payload);
  9070. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9071. fclose(infile);
  9072. fclose(outfile);
  9073. sprintf(rmFileCmd,"rm -f %s",filename);
  9074. system(rmFileCmd);
  9075. rename(tempfile, filename);
  9076. sleep(1);
  9077. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9078. //system(rmFileCmd);
  9079. }
  9080. else
  9081. {
  9082. char buf[1000]={0};
  9083. int ChargingProfileAdded = FALSE;
  9084. while (fgets(buf, sizeof(buf), infile) != NULL)
  9085. {
  9086. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9087. //*************************tempconnectorIdInt*********************************/
  9088. loc = strstr(buf, "connectorId");
  9089. c = 0;
  9090. memset(sstr ,0, sizeof(sstr) );
  9091. while (loc[strlen("connectorId")+2+c] != ',')
  9092. {
  9093. sstr[c] = loc[strlen("connectorId")+2+c];
  9094. c++;
  9095. }
  9096. sstr[c] = '\0';
  9097. tempconnectorIdInt = atoi(sstr);
  9098. //*************************tempchargingProfileIdInt*********************************/
  9099. loc = strstr(buf, "chargingProfileId");
  9100. c = 0;
  9101. memset(sstr ,0, sizeof(sstr) );
  9102. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9103. {
  9104. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9105. c++;
  9106. }
  9107. sstr[c] = '\0';
  9108. tempchargingProfileIdInt = atoi(sstr);
  9109. //*************************tempstackLevelInt*********************************/
  9110. loc = strstr(buf, "stackLevel");
  9111. c = 0;
  9112. memset(sstr ,0, sizeof(sstr) );
  9113. while (loc[strlen("stackLevel")+2+c] != ',')
  9114. {
  9115. sstr[c] = loc[strlen("stackLevel")+2+c];
  9116. c++;
  9117. }
  9118. sstr[c] = '\0';
  9119. tempstackLevelInt = atoi(sstr);
  9120. //*************************tempchargingProfilePurposeStr*********************************/
  9121. loc = strstr(payload, "chargingProfilePurpose");
  9122. c = 0;
  9123. memset(sstr ,0, sizeof(sstr) );
  9124. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9125. {
  9126. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9127. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9128. c++;
  9129. }
  9130. sstr[c] = '\0';
  9131. strcpy(tempchargingProfilePurposeStr,sstr);
  9132. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9133. {
  9134. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9135. {
  9136. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9137. if(ChargingProfileAdded == FALSE)
  9138. {
  9139. fprintf(outfile,"%s\n",payload);
  9140. ChargingProfileAdded = TRUE;
  9141. }
  9142. }
  9143. else
  9144. {
  9145. if(tempstackLevelInt < stackLevelInt)
  9146. {
  9147. if(ChargingProfileAdded == FALSE)
  9148. {
  9149. fprintf(outfile,"%s\n",payload);
  9150. ChargingProfileAdded = TRUE;
  9151. fprintf(outfile,"%s\n",buf);
  9152. }
  9153. else
  9154. {
  9155. fprintf(outfile,"%s\n",buf);
  9156. }
  9157. }
  9158. else
  9159. {
  9160. if(ChargingProfileAdded == FALSE)
  9161. {
  9162. fprintf(outfile,"%s\n",buf);
  9163. fprintf(outfile,"%s\n",payload);
  9164. ChargingProfileAdded = TRUE;
  9165. }
  9166. else
  9167. {
  9168. fprintf(outfile,"%s\n",buf);
  9169. }
  9170. }
  9171. }
  9172. }
  9173. else
  9174. {
  9175. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9176. {
  9177. if(ChargingProfileAdded == FALSE)
  9178. {
  9179. fprintf(outfile,"%s\n",payload);
  9180. ChargingProfileAdded = TRUE;
  9181. fprintf(outfile,"%s\n",buf);
  9182. }
  9183. else
  9184. {
  9185. fprintf(outfile,"%s\n",buf);
  9186. }
  9187. }
  9188. else if(tempstackLevelInt < stackLevelInt)
  9189. {
  9190. if(ChargingProfileAdded == FALSE)
  9191. {
  9192. fprintf(outfile,"%s\n",payload);
  9193. ChargingProfileAdded = TRUE;
  9194. fprintf(outfile,"%s\n",buf);
  9195. }
  9196. else
  9197. {
  9198. fprintf(outfile,"%s\n",buf);
  9199. }
  9200. }
  9201. else
  9202. {
  9203. if(ChargingProfileAdded == FALSE)
  9204. {
  9205. fprintf(outfile,"%s\n",buf);
  9206. fprintf(outfile,"%s\n",payload);
  9207. ChargingProfileAdded = TRUE;
  9208. }
  9209. else
  9210. {
  9211. fprintf(outfile,"%s\n",buf);
  9212. }
  9213. }
  9214. }
  9215. } // end of while loop
  9216. fclose(infile);
  9217. fclose(outfile);
  9218. sprintf(rmFileCmd,"rm -f %s",filename);
  9219. system(rmFileCmd);
  9220. rename(tempfile, filename);
  9221. sleep(1);
  9222. result = TRUE;
  9223. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9224. }
  9225. end:
  9226. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9227. return result;
  9228. return result;
  9229. }
  9230. int handleTriggerMessageRequest(char *uuid, char *payload)
  9231. {
  9232. mtrace();
  9233. int result = FAIL;
  9234. int connectorIdIsNULL = FALSE;
  9235. int connectorIdInt =0;
  9236. char sstr[40]={0},sstrtemp[100]={ 0 };
  9237. char requestedMessagestr[40]={0};
  9238. char comfirmstr[20]={0};
  9239. int c = 0;
  9240. char *loc;
  9241. DEBUG_INFO("handleTriggerMessageRequest\n");
  9242. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9243. strcpy(sstrtemp, stringtrimspace(payload));
  9244. c = 0;
  9245. loc = strstr(sstrtemp, "requestedMessage");
  9246. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9247. {
  9248. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9249. c++;
  9250. }
  9251. sstr[c] = '\0';
  9252. strcpy(requestedMessagestr, sstr);
  9253. c = 0;
  9254. loc = strstr(sstrtemp, "connectorId");
  9255. if(loc == NULL)
  9256. {
  9257. connectorIdIsNULL = TRUE;
  9258. }
  9259. else
  9260. {
  9261. memset(sstr ,0, sizeof(sstr) );
  9262. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9263. {
  9264. sstr[c] = loc[strlen("connectorId")+2+c];
  9265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9266. c++;
  9267. }
  9268. sstr[c] = '\0';
  9269. connectorIdInt = atoi(sstr);
  9270. }
  9271. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9272. {
  9273. //connectorIdInt = json_object_get_int(connectorId);
  9274. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9275. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9276. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9277. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9278. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9279. }
  9280. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9281. {
  9282. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9283. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9284. return TRUE;
  9285. }
  9286. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9287. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9288. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9289. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9290. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9291. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9292. {
  9293. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9294. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9295. return TRUE;
  9296. }
  9297. else
  9298. {
  9299. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9300. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9301. }
  9302. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9303. {
  9304. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  9305. {
  9306. FirmwareStatusNotificationStatus = 3;
  9307. }
  9308. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9309. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9310. }
  9311. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9312. {
  9313. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9314. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9315. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9316. }
  9317. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9318. {
  9319. sendBootNotificationRequest();
  9320. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9321. }
  9322. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9323. {
  9324. sendHeartbeatRequest(connectorIdInt);
  9325. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9326. }
  9327. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9328. {
  9329. if(connectorIdIsNULL == FALSE)
  9330. {
  9331. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9332. {
  9333. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9334. sendMeterValuesRequest(connectorIdInt -1);
  9335. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9336. }
  9337. }
  9338. else
  9339. {
  9340. for(int idx=0;idx< gunTotalNumber;idx++)
  9341. {
  9342. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9343. sendMeterValuesRequest(idx);
  9344. }
  9345. }
  9346. }
  9347. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9348. {
  9349. if(connectorIdIsNULL == FALSE)
  9350. {
  9351. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9352. {
  9353. sendStatusNotificationRequest(connectorIdInt -1);
  9354. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9355. }
  9356. }
  9357. else
  9358. {
  9359. for(int idx=0;idx< gunTotalNumber;idx++)
  9360. sendStatusNotificationRequest(idx);
  9361. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9362. }
  9363. }
  9364. return result;
  9365. }
  9366. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9367. {
  9368. mtrace();
  9369. int result = FAIL;
  9370. char sstr[6]={0},sstrtemp[50]={ 0 };
  9371. int connectorIdInt =0;
  9372. char comfirmstr[20]={0};
  9373. int c = 0;
  9374. int tempIndex = 0;
  9375. char *loc;
  9376. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9377. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9378. strcpy(sstrtemp, stringtrimspace(payload));
  9379. c = 0;
  9380. loc = strstr(sstrtemp, "connectorId");
  9381. memset(sstr ,0, sizeof(sstr) );
  9382. while (loc[strlen("connectorId")+2+c] != '}')
  9383. {
  9384. sstr[c] = loc[strlen("connectorId")+2+c];
  9385. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9386. c++;
  9387. }
  9388. sstr[c] = '\0';
  9389. connectorIdInt = atoi(sstr);
  9390. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9391. if(gunTotalNumber == 0)
  9392. {
  9393. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9394. goto end;
  9395. }
  9396. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9397. {
  9398. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9399. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9400. goto end;
  9401. }
  9402. else
  9403. {
  9404. //check Transaction active
  9405. if(gunType[connectorIdInt-1] == 'J')
  9406. {
  9407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9408. {
  9409. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9410. }
  9411. else
  9412. {
  9413. tempIndex = connectorIdInt -1;
  9414. }
  9415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9416. {
  9417. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9418. {
  9419. //stop Transaction
  9420. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9421. }
  9422. }
  9423. }
  9424. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9425. {
  9426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9427. {
  9428. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9429. }
  9430. else
  9431. {
  9432. tempIndex = connectorIdInt -1;
  9433. }
  9434. for (int index = 0; index < CCS_QUANTITY; index++)
  9435. {
  9436. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9437. {
  9438. //stop Transaction
  9439. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9440. }
  9441. }
  9442. }
  9443. else if(gunType[connectorIdInt-1] == 'G')
  9444. {
  9445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9446. {
  9447. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9448. }
  9449. else
  9450. {
  9451. tempIndex = connectorIdInt -1;
  9452. }
  9453. for (int index = 0; index < GB_QUANTITY; index++)
  9454. {
  9455. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9456. {
  9457. //stop Transaction
  9458. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9459. }
  9460. }
  9461. }
  9462. else
  9463. {
  9464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9465. {
  9466. tempIndex = 2;
  9467. }
  9468. else
  9469. {
  9470. tempIndex = connectorIdInt-1;
  9471. }
  9472. for (int index = 0; index < AC_QUANTITY; index++)
  9473. {
  9474. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9475. {
  9476. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9477. }
  9478. }
  9479. }
  9480. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9481. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9482. result = TRUE;
  9483. return result;
  9484. }
  9485. end:
  9486. //json_object_put(obj); --- remove temporally
  9487. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9488. return result;
  9489. }
  9490. static char UpdateFirmwarepayloadData[300]={0};
  9491. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9492. {
  9493. mtrace();
  9494. int result = FAIL;
  9495. pthread_t t;
  9496. sendUpdateFirmwareConfirmation(uuid);
  9497. memset(UpdateFirmwarepayloadData, 0, 300);
  9498. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9499. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9500. ////pthread_join(t, NULL); //
  9501. //pthread_detach(t);
  9502. //sendUpdateFirmwareConfirmation(uuid);
  9503. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9504. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9505. return result;
  9506. }
  9507. void *UpdateFirmwareProcess(void *data)
  9508. {
  9509. pthread_detach(pthread_self());
  9510. mtrace();
  9511. int retriesInt =0, retryIntervalInt=0;
  9512. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9513. int port=0;
  9514. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9515. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9516. //char comfirmstr[20];
  9517. int isSuccess = 0;
  9518. char ftpbuf[200];
  9519. char temp[100];
  9520. char * pch;
  9521. int retriesISNULL=FALSE;
  9522. int retryInterval=FALSE;
  9523. int c = 0;
  9524. //int i = 0;
  9525. char *loc;
  9526. char sstr[300]={ 0 };
  9527. char str[300]={ 0 };
  9528. //char *str = (char*) data; // ? ?輸入資 ?
  9529. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9530. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9531. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9532. //***************location **************/
  9533. loc = strstr(str, "location");
  9534. memset(sstr ,0, sizeof(sstr) );
  9535. c = 0;
  9536. while (loc[3+strlen("location")+c] != '\"')
  9537. {
  9538. sstr[c] = loc[3+strlen("location")+c];
  9539. c++;
  9540. }
  9541. sstr[c] = '\0';
  9542. strcpy(locationstr, sstr);
  9543. //***************retries**************/
  9544. c = 0;
  9545. loc = strstr(str, "retries");
  9546. if(loc == NULL)
  9547. {
  9548. retriesISNULL=TRUE;
  9549. }
  9550. else
  9551. {
  9552. memset(sstr ,0, sizeof(sstr) );
  9553. while (loc[strlen("retries")+2+c] != ',')
  9554. {
  9555. sstr[c] = loc[strlen("retries")+2+c];
  9556. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9557. c++;
  9558. }
  9559. sstr[c] = '\0';
  9560. }
  9561. if(retriesISNULL == FALSE)
  9562. {
  9563. retriesInt = atoi(sstr);
  9564. }
  9565. //***************retrieveDate **************/
  9566. loc = strstr(str, "retrieveDate");
  9567. memset(sstr ,0, sizeof(sstr) );
  9568. c = 0;
  9569. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9570. {
  9571. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9572. c++;
  9573. }
  9574. sstr[c] = '\0';
  9575. strcpy(retrieveDatestr, sstr);
  9576. //***************retryInterval **************/
  9577. c = 0;
  9578. loc = strstr(str, "retryInterval");
  9579. memset(sstr ,0, sizeof(sstr) );
  9580. if(loc == NULL)
  9581. {
  9582. retryInterval=TRUE;
  9583. }
  9584. else
  9585. {
  9586. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9587. {
  9588. sstr[c] = loc[strlen("retryInterval")+2+c];
  9589. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9590. c++;
  9591. }
  9592. sstr[c] = '\0';
  9593. }
  9594. if(retryInterval==FALSE)
  9595. {
  9596. retryIntervalInt = atoi(sstr);
  9597. }
  9598. memset(ftppath, 0, sizeof(ftppath));
  9599. memset(path, 0, sizeof(path));
  9600. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9601. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9602. if(strncmp(locationstr,"http", 4) == 0)
  9603. {
  9604. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9605. protocol, host, path);
  9606. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9607. // protocol, user, password, host, path);
  9608. sprintf(ftppath,"/%s", path);
  9609. //DEBUG_INFO("protocol =%s\n",protocol);
  9610. //DEBUG_INFO("host =%s\n",host);
  9611. //DEBUG_INFO("path =%s\n",path);
  9612. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9613. int ftppathlen=strlen(ftppath);
  9614. int i=1;
  9615. char filenametemp[50];
  9616. while(i < ftppathlen)
  9617. {
  9618. int len=ftppathlen-i;
  9619. if(ftppath[len]== 47) // '/' ascll code: 47
  9620. {
  9621. DEBUG_INFO("compare '/' all right\n");
  9622. break;
  9623. }
  9624. i=i+1;
  9625. }
  9626. memset(filenametemp, 0, sizeof(filenametemp));
  9627. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9628. filenametemp[i+1] = 0;
  9629. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9630. do{
  9631. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9632. sleep(retryIntervalInt);
  9633. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9634. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9635. if(!isSuccess)
  9636. {
  9637. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9638. }
  9639. else
  9640. {
  9641. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9642. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9643. //isUpdateRequest = TRUE;
  9644. }
  9645. }
  9646. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9647. {
  9648. memset(ftpbuf, 0, sizeof(ftpbuf));
  9649. memset(temp, 0, sizeof(temp));
  9650. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9651. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9652. int ftppathlen=strlen(ftpbuf);
  9653. int i=1;
  9654. char filenametemp[50];
  9655. while(i < ftppathlen)
  9656. {
  9657. int len=ftppathlen-i;
  9658. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9659. {
  9660. DEBUG_INFO(" compare '/' all right\n");
  9661. break;
  9662. }
  9663. i=i+1;
  9664. }
  9665. memset(filenametemp, 0, sizeof(filenametemp));
  9666. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9667. filenametemp[i+1] = 0;
  9668. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9669. pch=strchr(temp,'@');
  9670. if(pch==NULL)
  9671. {
  9672. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9673. protocol, host, &port, path);
  9674. strcpy(user,"anonymous");
  9675. strcpy(password,"");
  9676. }
  9677. else
  9678. {
  9679. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9680. protocol, user, password, host, &port, path);
  9681. }
  9682. sscanf(host,"%[^/]%s",host1, path1);
  9683. sprintf(ftppath,"%s", path1);
  9684. //DEBUG_INFO("protocol =%s\n",protocol);
  9685. //DEBUG_INFO("user =%s\n",user);
  9686. //DEBUG_INFO("password =%s\n",password);
  9687. //DEBUG_INFO("host1 =%s\n",host1);
  9688. //DEBUG_INFO("port =%d\n",port);
  9689. //DEBUG_INFO("path1 =%s\n",path1);
  9690. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9691. //ftpFile(host, user, password, port, ftppath, fname);
  9692. //download firmware pthred
  9693. if(port == 0)
  9694. {
  9695. port = 21;
  9696. }
  9697. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9698. do{
  9699. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9700. sleep(retryIntervalInt);
  9701. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9702. if(!isSuccess)
  9703. {
  9704. //BulldogUtil.sleepMs(interval*1000);
  9705. DEBUG_INFO("Update firmware request and download file fail.\n");
  9706. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9707. }
  9708. else
  9709. {
  9710. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9711. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9712. //isUpdateRequest = TRUE;
  9713. }
  9714. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9715. }
  9716. else
  9717. {
  9718. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9719. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9720. }
  9721. pthread_exit(NULL);
  9722. }
  9723. //==========================================
  9724. // Handle server response routine
  9725. //==========================================
  9726. void handleAuthorizeResponse(char *payload, int gun_index)
  9727. {
  9728. mtrace();
  9729. char expiryDatestr[30]={0};
  9730. char parentIdTagstr[20]={0};
  9731. char statusstr[20]={0};
  9732. char expiryDatestrtemp[30]={0};
  9733. char parentIdTagstrtemp[20]={0};
  9734. char IdTagstrtemp[20]={0};
  9735. char statusstrtemp[20]={0};
  9736. int expiryDateISNULL=FALSE;
  9737. int parentIdTagISNULL=FALSE;
  9738. char sstr[160]={0},sstrtemp[160]={0};
  9739. char* filename = AuthorizationCache_JSON;
  9740. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9741. int c = 0;
  9742. char *loc;
  9743. int resultRename=0;
  9744. int responseIdTagInfoAsZero= 0;
  9745. char rmFileCmd[50]={0};
  9746. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9747. strcpy(sstrtemp, stringtrimspace(payload));
  9748. //***********expiryDate*************/
  9749. loc = strstr(sstrtemp, "expiryDate");
  9750. memset(sstr ,0, sizeof(sstr) );
  9751. c = 0;
  9752. if(loc == NULL)
  9753. {
  9754. expiryDateISNULL = TRUE;
  9755. }
  9756. else
  9757. {
  9758. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9759. {
  9760. sstr[c] = loc[3+strlen("expiryDate")+c];
  9761. c++;
  9762. }
  9763. sstr[c] = '\0';
  9764. strcpy(expiryDatestr, sstr);
  9765. }
  9766. //***********parentIdTag*************/
  9767. loc = strstr(sstrtemp, "parentIdTag");
  9768. memset(sstr ,0, sizeof(sstr) );
  9769. c = 0;
  9770. if(loc == NULL)
  9771. {
  9772. parentIdTagISNULL = TRUE;
  9773. }
  9774. else
  9775. {
  9776. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9777. {
  9778. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9779. c++;
  9780. }
  9781. sstr[c] = '\0';
  9782. strcpy(parentIdTagstr, sstr);
  9783. }
  9784. //***********status*************/
  9785. loc = strstr(sstrtemp, "status");
  9786. memset(sstr ,0, sizeof(sstr) );
  9787. c = 0;
  9788. while (loc[3+strlen("status")+c] != '\"')
  9789. {
  9790. sstr[c] = loc[3+strlen("status")+c];
  9791. c++;
  9792. }
  9793. sstr[c] = '\0';
  9794. strcpy(statusstr, sstr);
  9795. if(expiryDateISNULL == FALSE)
  9796. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9797. if(parentIdTagISNULL == FALSE)
  9798. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9799. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9800. //Update idTag information to authorization cache if supproted
  9801. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9802. {
  9803. if((access(filename,F_OK))!=-1)
  9804. {
  9805. printf("AuthorizationCache exist.\n");
  9806. }
  9807. else
  9808. {
  9809. printf("AuthorizationCache not exist\n");
  9810. FILE *log = fopen(filename, "w+");
  9811. if(log == NULL)
  9812. {
  9813. printf("log is NULL\n");
  9814. goto out;
  9815. }
  9816. else
  9817. {
  9818. fclose(log);
  9819. }
  9820. }
  9821. FILE *infile;
  9822. FILE *outfile;
  9823. // open file for writing
  9824. infile = fopen (filename, "r");
  9825. outfile = fopen (tempfile, "w");
  9826. //*检测到文件结束标识返回1,否则返回0。*/
  9827. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9828. int c;
  9829. c = fgetc(infile);
  9830. //DEBUG_INFO("c:%d\n",c);
  9831. rewind(infile);
  9832. if(c == EOF)
  9833. {
  9834. DEBUG_INFO("Orignal File is NULL\n");
  9835. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9836. {
  9837. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9838. }
  9839. else
  9840. {
  9841. strcpy(expiryDatestrtemp, "");
  9842. }
  9843. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9844. {
  9845. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9846. }
  9847. else
  9848. {
  9849. //write Authorize IdTag
  9850. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9851. }
  9852. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9853. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9854. fclose(infile);
  9855. fclose(outfile);
  9856. sprintf(rmFileCmd,"rm -f %s",filename);
  9857. system(rmFileCmd);
  9858. resultRename = rename(tempfile, filename);
  9859. if(resultRename == 0)
  9860. {
  9861. printf("File renamed successfully");
  9862. }
  9863. else
  9864. {
  9865. printf("Error: unable to rename the file");
  9866. }
  9867. }
  9868. else
  9869. {
  9870. char buf[160]={0};
  9871. while (fgets(buf, sizeof(buf), infile) != NULL)
  9872. {
  9873. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9874. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9875. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9876. memset(statusstr, 0, sizeof(statusstrtemp));
  9877. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9878. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9879. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9880. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9881. //------------------IdTag-----------------------
  9882. loc = strstr(buf, "idTag");
  9883. memset(sstr ,0, sizeof(sstr) );
  9884. c = 0;
  9885. while (loc[3+strlen("idTag")+c] != '\"')
  9886. {
  9887. sstr[c] = loc[3+strlen("idTag")+c];
  9888. c++;
  9889. }
  9890. sstr[c] = '\0';
  9891. strcpy(IdTagstrtemp,sstr);
  9892. //*********************expiryDate***************/
  9893. loc = strstr(buf, "expiryDate");
  9894. memset(sstr ,0, sizeof(sstr) );
  9895. c = 0;
  9896. while (loc[3+strlen("expiryDate")+c] != '\"')
  9897. {
  9898. sstr[c] = loc[3+strlen("expiryDate")+c];
  9899. c++;
  9900. }
  9901. sstr[c] = '\0';
  9902. strcpy(expiryDatestr,sstr);
  9903. //*********************parentIdTag***************/
  9904. loc = strstr(buf, "parentIdTag");
  9905. memset(sstr ,0, sizeof(sstr) );
  9906. c = 0;
  9907. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9908. {
  9909. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9910. c++;
  9911. }
  9912. sstr[c] = '\0';
  9913. strcpy(parentIdTagstr,sstr);
  9914. //*********************status***************/
  9915. loc = strstr(buf, "status");
  9916. memset(sstr ,0, sizeof(sstr) );
  9917. c = 0;
  9918. while (loc[3+strlen("status")+c] != '\"')
  9919. {
  9920. sstr[c] = loc[3+strlen("status")+c];
  9921. c++;
  9922. }
  9923. sstr[c] = '\0';
  9924. strcpy(statusstr,sstr);
  9925. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9926. {
  9927. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9928. responseIdTagInfoAsZero = 1;
  9929. }
  9930. else
  9931. {
  9932. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9933. }
  9934. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9935. {
  9936. //modify item
  9937. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9938. {
  9939. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9940. }
  9941. else
  9942. {
  9943. strcpy(expiryDatestrtemp, "");
  9944. }
  9945. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9946. {
  9947. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9948. }
  9949. else
  9950. {
  9951. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9952. }
  9953. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9954. }
  9955. else
  9956. {
  9957. //wrie original item
  9958. strcpy(expiryDatestrtemp, expiryDatestr);
  9959. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9960. strcpy(statusstrtemp, statusstr);
  9961. }
  9962. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9963. }
  9964. fclose(infile);
  9965. fclose(outfile);
  9966. sprintf(rmFileCmd,"rm -f %s",filename);
  9967. system(rmFileCmd);
  9968. resultRename = rename(tempfile, filename);
  9969. if(resultRename == 0)
  9970. {
  9971. DEBUG_INFO("File renamed successfully");
  9972. }
  9973. else
  9974. {
  9975. DEBUG_INFO("Error: unable to rename the file");
  9976. }
  9977. }
  9978. }
  9979. out:
  9980. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9981. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9982. authorizeRetryTimes = 0;
  9983. }
  9984. char * strtrimc( char * s )
  9985. {
  9986. char * p1 = s;
  9987. char * p2 = s;
  9988. while(*p1 != '\0')
  9989. {
  9990. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9991. {
  9992. if(*p1 != ',')
  9993. {
  9994. p1 ++;
  9995. }
  9996. else
  9997. {
  9998. break;
  9999. }
  10000. }
  10001. if(*p1 != ',')
  10002. {
  10003. * p2 ++ = *p1 ++;
  10004. //printf("p2=%s\n",p2);
  10005. }
  10006. else
  10007. {
  10008. break;
  10009. }
  10010. }
  10011. *p2 = '\0';
  10012. return (s);
  10013. }
  10014. void handleBootNotificationResponse(char *payload, int gun_index)
  10015. {
  10016. mtrace();
  10017. char sstr[140]={0}, sstrtemp[140]={0};//sstr[200]={ 0 };
  10018. char statusStr[12]={0};
  10019. char currentTimeStr[30]={0};
  10020. char *loc;
  10021. int intervalInt = 0;
  10022. int c = 0;
  10023. //double diff_t;
  10024. struct tm tp;
  10025. char buf[28]={0};
  10026. char timebuf[50]={0};
  10027. DEBUG_INFO("handleBootNotificationResponse ...\n");
  10028. //Filter string space
  10029. strcpy(sstrtemp, stringtrimspace(payload));
  10030. //*** interval ****/
  10031. c = 0;
  10032. loc = strstr(sstrtemp, "interval");
  10033. //printf("loc=%s\n",loc);
  10034. memset(sstr ,0, sizeof(sstr) );
  10035. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  10036. {
  10037. sstr[c] = loc[strlen("interval")+2+c];
  10038. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10039. c++;
  10040. }
  10041. sstr[c] = '\0';
  10042. //DEBUG_INFO("id=%d\n",atoi(sstr));
  10043. intervalInt = atoi(sstr);
  10044. //***status ****/
  10045. loc = strstr(sstrtemp, "status");
  10046. memset(sstr ,0, sizeof(sstr) );
  10047. c = 0;
  10048. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  10049. {
  10050. sstr[c] = loc[3+strlen("status")+c];
  10051. c++;
  10052. }
  10053. sstr[c] = '\0';
  10054. strcpy(statusStr, sstr);
  10055. //***currentTime ****/
  10056. loc = strstr(sstrtemp, "currentTime");
  10057. //printf("loc=%s\n",loc);
  10058. memset(sstr ,0, sizeof(sstr) );
  10059. c = 0;
  10060. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  10061. {
  10062. sstr[c] = loc[3+strlen("currentTime")+c];
  10063. c++;
  10064. }
  10065. sstr[c] = '\0';
  10066. strcpy(currentTimeStr, sstr);
  10067. //BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10068. //HeartBeatWaitTime = BootNotificationInterval;
  10069. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10070. BootNotificationInterval = intervalInt;
  10071. HeartBeatWaitTime = intervalInt;
  10072. clientTime.Heartbeat=time((time_t*)NULL);
  10073. //write back to ShmOCPP16Data->BootNotification
  10074. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10075. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10076. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10077. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  10078. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  10079. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  10080. {
  10081. server_sign = TRUE;
  10082. server_pending =FALSE;
  10083. }
  10084. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10085. {
  10086. server_pending = TRUE;
  10087. }
  10088. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10089. tp.tm_isdst = -1;
  10090. //time_t utc = mktime(&tp);
  10091. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10092. memset(timebuf, 0, sizeof timebuf);
  10093. sprintf(timebuf,"date -s '%s'",buf);
  10094. //DEBUG_INFO("timebuf=%s\n",timebuf);
  10095. system(timebuf);
  10096. //==============================================
  10097. // RTC sync
  10098. //==============================================
  10099. system("/sbin/hwclock -w --systohc");
  10100. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10101. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10102. }
  10103. void handleDataTransferResponse(char *payload, int gun_index)
  10104. {
  10105. char sstr[160]={0};//sstr[200]={ 0 };
  10106. int c = 0;
  10107. char *loc;
  10108. DEBUG_INFO("handleDataTransferResponse ...\n");
  10109. loc = strstr(payload, "status");
  10110. printf("loc=%s\n",loc);
  10111. c = 0;
  10112. while (loc[3+strlen("status")+c] != '\"')
  10113. {
  10114. sstr[c] = loc[3+strlen("status")+c];
  10115. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10116. c++;
  10117. }
  10118. sstr[c] = '\0';
  10119. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10120. }
  10121. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10122. {
  10123. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10124. //struct json_object *obj;
  10125. // obj = json_tokener_parse(payload);
  10126. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10127. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10128. //No fields are defined.
  10129. }
  10130. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10131. {
  10132. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10133. //struct json_object *obj;
  10134. // obj = json_tokener_parse(payload);
  10135. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10136. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10137. //No fields are defined.
  10138. }
  10139. void handleHeartbeatResponse(char *payload, int gun_index)
  10140. {
  10141. mtrace();
  10142. //double diff_t;
  10143. struct tm tp;
  10144. char buf[28]={0};
  10145. char timebuf[50]={0},sstrtemp[100]={0};
  10146. char sstr[30]={ 0 };
  10147. int c = 0;
  10148. char *loc;
  10149. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  10150. if(FirstHeartBeat == 0)
  10151. {
  10152. FirstHeartBeat = 1;
  10153. DEBUG_INFO("FirstHeartBeat \n");
  10154. }
  10155. HeartBeatWithNOResponse = 0;
  10156. strcpy(sstrtemp, stringtrimspace(payload));
  10157. c = 0;
  10158. loc = strstr(sstrtemp, "currentTime");
  10159. memset(sstr ,0, sizeof(sstr) );
  10160. while (loc[3+strlen("currentTime")+c] != '\"')
  10161. {
  10162. sstr[c] = loc[3+strlen("currentTime")+c];
  10163. c++;
  10164. }
  10165. sstr[c] = '\0';
  10166. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  10167. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10168. tp.tm_isdst = -1;
  10169. //time_t utc = mktime(&tp);
  10170. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10171. memset(timebuf, 0, sizeof timebuf);
  10172. sprintf(timebuf,"date -s '%s'",buf);
  10173. system(timebuf);
  10174. //==============================================
  10175. // RTC sync
  10176. //==============================================
  10177. system("/sbin/hwclock -w --systohc");
  10178. //===============================================
  10179. //Print Out HeartBeat log
  10180. //===============================================
  10181. {
  10182. double diff_t;
  10183. struct tm tp,tp1;
  10184. // BootNotification Receive Time
  10185. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10186. tp.tm_isdst = -1;
  10187. time_t BootNotificationReceiveTime = mktime(&tp);
  10188. //HeartBeat Receive Time
  10189. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10190. tp1.tm_isdst = -1;
  10191. time_t HeartBeatReceiveTime = mktime(&tp1);
  10192. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10193. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10194. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10195. {
  10196. HeartBeatCountPerHour = (int)diff_t / 3600;
  10197. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10198. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10199. }
  10200. }
  10201. }
  10202. void handleMeterValuesResponse(char *payload, int gun_index)
  10203. {
  10204. mtrace();
  10205. //struct json_object *obj;
  10206. DEBUG_INFO("handleMeterValuesResponse ...\n");
  10207. //No fields are defined.
  10208. }
  10209. void handleStartTransactionResponse(char *payload, int gun_index)
  10210. {
  10211. mtrace();
  10212. char sstr[28]={ 0 },sstrtemp[200]={ 0 };
  10213. int c = 0;
  10214. int copyTo = 0;
  10215. char *loc;
  10216. //int transactionIdInt = 0;
  10217. FILE *outfile;
  10218. char data[100]={0};
  10219. //char *delim = ":";
  10220. //char requestKey[2][50]={0};
  10221. //char * pch;
  10222. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  10223. DEBUG_INFO("handleStartTransactionResponse\n");
  10224. //****************expiryDate********************/
  10225. strcpy(sstrtemp, stringtrimspace(payload));
  10226. loc = strstr(sstrtemp, "expiryDate");
  10227. if(loc == NULL)
  10228. {
  10229. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  10230. }
  10231. else
  10232. {
  10233. #if 0
  10234. c = 0;
  10235. memset(sstr ,0, sizeof(sstr) );
  10236. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10237. memset(requestKey ,0, sizeof(requestKey) );
  10238. strcpy(sstrtemp,loc+strlen("expiryDate")+2); // 2: ":
  10239. //printf("sstrtemp=%s\n",sstrtemp);
  10240. //parsing strings to words
  10241. pch = strtok(sstrtemp,",");
  10242. while (pch != NULL)
  10243. {
  10244. strcpy(requestKey[c], pch);
  10245. pch = strtok (NULL, ",");
  10246. c = c + 1;
  10247. }
  10248. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10249. //strcpy(currentTimeStr, strtrimc(requestKey[0]));
  10250. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", stringtrim(requestKey[0]));
  10251. #endif
  10252. #if 1
  10253. c = 0;
  10254. memset(sstr ,0, sizeof(sstr) );
  10255. while (loc[3+strlen("expiryDate")+c] != '\"')
  10256. {
  10257. sstr[c] = loc[3+strlen("expiryDate")+c];
  10258. c++;
  10259. }
  10260. sstr[c] = '\0';
  10261. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10262. #endif
  10263. }
  10264. //****************parentIdTag********************/
  10265. loc = strstr(sstrtemp, "parentIdTag");
  10266. if(loc == NULL)
  10267. {
  10268. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  10269. }
  10270. else
  10271. {
  10272. #if 0
  10273. c = 0;
  10274. memset(sstr ,0, sizeof(sstr) );
  10275. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10276. memset(requestKey ,0, sizeof(requestKey) );
  10277. strcpy(sstrtemp,loc);
  10278. //printf("sstrtemp=%s\n",sstrtemp);
  10279. //parsing strings to words
  10280. pch = strtok(sstrtemp,delim);
  10281. while (pch != NULL)
  10282. {
  10283. strcpy(requestKey[c], pch);
  10284. pch = strtok (NULL, delim);
  10285. c = c + 1;
  10286. }
  10287. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10288. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", strtrimc(requestKey[1]));
  10289. #endif
  10290. #if 1
  10291. c = 0;
  10292. memset(sstr ,0, sizeof(sstr) );
  10293. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10294. {
  10295. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10296. c++;
  10297. }
  10298. sstr[c] = '\0';
  10299. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10300. #endif
  10301. }
  10302. //****************status********************/
  10303. loc = strstr(sstrtemp, "status");
  10304. if(loc == NULL)
  10305. {
  10306. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  10307. }
  10308. else
  10309. {
  10310. #if 0
  10311. c = 0;
  10312. memset(sstr ,0, sizeof(sstr) );
  10313. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10314. memset(requestKey ,0, sizeof(requestKey) );
  10315. strcpy(sstrtemp,loc);
  10316. //printf("sstrtemp=%s\n",sstrtemp);
  10317. //parsing strings to words
  10318. pch = strtok(sstrtemp,delim);
  10319. while (pch != NULL)
  10320. {
  10321. strcpy(requestKey[c], pch);
  10322. pch = strtok (NULL, delim);
  10323. c = c + 1;
  10324. }
  10325. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10326. //strcpy(statusStr, strtrimc(requestKey[1]));
  10327. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", strtrimc(requestKey[1]));
  10328. #endif
  10329. #if 1
  10330. c = 0;
  10331. memset(sstr ,0, sizeof(sstr) );
  10332. while (loc[3+strlen("status")+c] != '\"')
  10333. {
  10334. sstr[c] = loc[3+strlen("status")+c];
  10335. c++;
  10336. }
  10337. sstr[c] = '\0';
  10338. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10339. #endif
  10340. }
  10341. //****************transactionId********************/
  10342. c=0;
  10343. copyTo = 0;
  10344. loc = strstr(sstrtemp, "transactionId");
  10345. memset(sstr ,0, sizeof(sstr) );
  10346. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  10347. {
  10348. if(loc[strlen("transactionId")+2+c] != ' ')
  10349. {
  10350. sstr[copyTo] = loc[strlen("transactionId")+2+c];
  10351. copyTo = copyTo + 1;
  10352. }
  10353. c++;
  10354. }
  10355. sstr[copyTo] = '\0';
  10356. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  10357. //transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  10358. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10359. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10360. //-----------Start : write to the Queue TransactionId file -----------------//
  10361. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10362. {
  10363. //DEBUG_INFO("QueueTransactionId exist.\n");
  10364. }
  10365. else
  10366. {
  10367. //DEBUG_INFO("QueueTransactionId not exist\n");
  10368. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10369. if(log == NULL)
  10370. {
  10371. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10372. return ;
  10373. }
  10374. else
  10375. {
  10376. fclose(log);
  10377. }
  10378. }
  10379. // open file for writing
  10380. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10381. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10382. {
  10383. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10384. //DEBUG_INFO("data=%s\n",data);
  10385. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10386. fputs(data, outfile);
  10387. //fputs("\n", outfile);
  10388. fclose (outfile);
  10389. }
  10390. //-------------End: write to the Queue TransactionId file------------------------------------------//
  10391. //TransactionId[gun_index] = transactionIdInt;
  10392. //DEBUG_INFO("gun_index: %d\n", gun_index);
  10393. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  10394. #ifdef SystemLogMessage
  10395. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10396. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10397. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10398. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10399. #endif
  10400. }
  10401. void handleStatusNotificationResponse(char *payload, int gun_index)
  10402. {
  10403. mtrace();
  10404. printf("handleStatusNotificationResponse\n");
  10405. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10406. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10407. }
  10408. void handleStopTransactionnResponse(char *payload, int gun_index)
  10409. {
  10410. mtrace();
  10411. char sstr[30]={ 0 },sstrtemp[140]={ 0 };
  10412. int c = 0;
  10413. char *loc;
  10414. //char *delim = ":";
  10415. //char requestKey[3][50]={0};
  10416. //char * pch;
  10417. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  10418. strcpy(sstrtemp, stringtrimspace(payload));
  10419. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10420. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10421. loc = strstr(sstrtemp, "idTagInfo");
  10422. //***********************idTagInfo************************/
  10423. if(loc != NULL)
  10424. {
  10425. //***********************expiryDate************************/
  10426. loc = strstr(sstrtemp, "expiryDate");
  10427. if(loc != NULL)
  10428. {
  10429. memset(sstr ,0, sizeof(sstr) );
  10430. c = 0;
  10431. while (loc[3+strlen("expiryDate")+c] != '\"')
  10432. {
  10433. sstr[c] = loc[3+strlen("expiryDate")+c];
  10434. c++;
  10435. }
  10436. sstr[c] = '\0';
  10437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10438. }
  10439. //***********************parentIdTag************************/
  10440. loc = strstr(sstrtemp, "parentIdTag");
  10441. if(loc != NULL)
  10442. {
  10443. memset(sstr ,0, sizeof(sstr) );
  10444. c = 0;
  10445. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10446. {
  10447. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10448. c++;
  10449. }
  10450. sstr[c] = '\0';
  10451. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10452. }
  10453. //***********************status************************/
  10454. loc = strstr(sstrtemp, "status");
  10455. memset(sstr ,0, sizeof(sstr) );
  10456. c = 0;
  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->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10464. }
  10465. #ifdef SystemLogMessage
  10466. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10467. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10468. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10469. #endif
  10470. }
  10471. //==========================================
  10472. // Handle Error routine
  10473. //==========================================
  10474. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10475. {
  10476. mtrace();
  10477. #ifdef SystemLogMessage
  10478. DEBUG_INFO("errorCode: %s\n", errorCode);
  10479. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10480. DEBUG_INFO("errorDetails: %s\n", payload);
  10481. #endif
  10482. }
  10483. //===============================================
  10484. // Common routine
  10485. //===============================================
  10486. int initialConfigurationTable(void)
  10487. {
  10488. //clock_t start_t, end_t, total_t;
  10489. FILE *fp;
  10490. FILE *outfile;
  10491. char str[200]={0};
  10492. char sstr[100]={0};
  10493. int c = 0;
  10494. char *loc;
  10495. printf("initialConfigurationTable \n");
  10496. //start_t = clock();
  10497. //printf("Starting of the program, start_t = %ld\n", start_t);
  10498. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10499. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10500. {
  10501. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10502. if(outfile == NULL) {
  10503. DEBUG_INFO("Error opening file");
  10504. return FALSE;
  10505. }
  10506. /*Core Profile*/
  10507. //AllowOfflineTxForUnknownId
  10508. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10509. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10513. //AuthorizationCacheEnabled
  10514. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10518. //AuthorizeRemoteTxRequests
  10519. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10523. //BlinkRepeat
  10524. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10528. //ClockAlignedDataInterval
  10529. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10533. //ConnectionTimeOut
  10534. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10538. //GetConfigurationMaxKeys
  10539. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10543. // HeartbeatInterval
  10544. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10548. // LightIntensity
  10549. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10553. // LocalAuthorizeOffline
  10554. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10558. // LocalPreAuthorize
  10559. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10563. // MaxEnergyOnInvalidId
  10564. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10567. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10569. // MeterValuesAlignedData
  10570. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10574. // MeterValuesAlignedDataMaxLength
  10575. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10579. // MeterValuesSampledData
  10580. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10584. // MeterValuesSampledDataMaxLength
  10585. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  10589. // MeterValueSampleInterval
  10590. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10594. // MinimumStatusDuration
  10595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10598. server_cycle_Status = 120; //StatusNotification cycle
  10599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10600. // NumberOfConnectors
  10601. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10604. {
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10606. }
  10607. else
  10608. {
  10609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10610. }
  10611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10612. // ResetRetries
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10617. // ConnectorPhaseRotation
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10622. // ConnectorPhaseRotationMaxLength
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10627. // StopTransactionOnEVSideDisconnect
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10632. // StopTransactionOnInvalidId
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10637. // StopTxnAlignedData
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10642. // StopTxnAlignedDataMaxLength
  10643. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10647. // StopTxnSampledData
  10648. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10652. // StopTxnSampledDataMaxLength
  10653. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10656. {
  10657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10658. }
  10659. else
  10660. {
  10661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10662. }
  10663. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10665. // SupportedFeatureProfiles
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10670. // SupportedFeatureProfilesMaxLength
  10671. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10675. // TransactionMessageAttempts
  10676. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10679. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10681. // TransactionMessageRetryInterval
  10682. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10685. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10687. // UnlockConnectorOnEVSideDisconnect
  10688. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10692. // WebSocketPingInterval
  10693. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10697. //* Local Auth List Management Profile*/
  10698. #if 0
  10699. //For OCTT Test Case
  10700. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10703. #endif
  10704. #if 1
  10705. //LocalAuthListEnabled
  10706. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10710. #endif
  10711. //LocalAuthListMaxLength
  10712. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10716. //SendLocalListMaxLength
  10717. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10721. //ReserveConnectorZeroSupported
  10722. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10726. //* Smart Charging Profile */
  10727. //ChargeProfileMaxStackLevel
  10728. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10732. // ChargingScheduleAllowedChargingRateUnit
  10733. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10737. // ChargingScheduleMaxPeriods
  10738. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10742. // ConnectorSwitch3to1PhaseSupported
  10743. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10747. // MaxChargingProfilesInstalled
  10748. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10752. fclose(outfile);
  10753. }
  10754. else
  10755. {
  10756. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10757. char keystr[60]={0};
  10758. char readonlystr[10]={0};
  10759. char valuestr[100]={0};
  10760. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10761. if(fp == NULL) {
  10762. DEBUG_INFO("Error opening file");
  10763. return FALSE;
  10764. }
  10765. while( fgets (str, sizeof(str), fp)!=NULL )
  10766. {
  10767. //DEBUG_INFO("Get Configuration \n");
  10768. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10769. //*************************key*********************************/
  10770. loc = strstr(str, "key");
  10771. c = 0;
  10772. memset(sstr ,0, sizeof(sstr) );
  10773. while (loc[strlen("key")+3+c] != '\"')
  10774. {
  10775. sstr[c] = loc[strlen("key")+3+c];
  10776. c++;
  10777. }
  10778. sstr[c] = '\0';
  10779. strcpy(keystr,sstr);
  10780. //*************************readonly*********************************/
  10781. loc = strstr(str, "readonly");
  10782. c = 0;
  10783. memset(sstr ,0, sizeof(sstr) );
  10784. while (loc[strlen("readonly")+2+c] != ',')
  10785. {
  10786. sstr[c] = loc[strlen("readonly")+2+c];
  10787. c++;
  10788. }
  10789. sstr[c] = '\0';
  10790. strcpy(readonlystr,sstr);
  10791. //*************************value*********************************/
  10792. loc = strstr(str, "value");
  10793. c = 0;
  10794. memset(sstr ,0, sizeof(sstr) );
  10795. while (loc[strlen("value")+3+c] != '\"')
  10796. {
  10797. sstr[c] = loc[strlen("value")+3+c];
  10798. c++;
  10799. }
  10800. sstr[c] = '\0';
  10801. strcpy(valuestr,sstr);
  10802. // DEBUG_INFO("keystr=%s\n",keystr);
  10803. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10804. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10805. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10806. {
  10807. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10808. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10810. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10811. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10812. }
  10813. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10814. {
  10815. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10816. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10818. }
  10819. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10820. {
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10823. }
  10824. if(strcmp(keystr, "BlinkRepeat") == 0)
  10825. {
  10826. //Charger.BlinkRepeat = Integer.parseInt(value);
  10827. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10829. }
  10830. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10831. {
  10832. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10834. }
  10835. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10836. {
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10839. }
  10840. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10841. {
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10844. }
  10845. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10846. {
  10847. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10849. HeartBeatWaitTime = atoi(valuestr);
  10850. }
  10851. if(strcmp(keystr, "LightIntensity") == 0)
  10852. {
  10853. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10855. }
  10856. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10857. {
  10858. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10860. }
  10861. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10862. {
  10863. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10865. }
  10866. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10867. {
  10868. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10870. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10871. }
  10872. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10873. {
  10874. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10876. }
  10877. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10878. {
  10879. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10881. }
  10882. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10883. {
  10884. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10886. }
  10887. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10888. {
  10889. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10891. }
  10892. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10893. {
  10894. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10896. }
  10897. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10898. {
  10899. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10901. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10902. }
  10903. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10904. {
  10905. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10907. }
  10908. if(strcmp(keystr, "ResetRetries") == 0)
  10909. {
  10910. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10912. }
  10913. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10914. {
  10915. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10917. }
  10918. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10919. {
  10920. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10922. }
  10923. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10924. {
  10925. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10927. }
  10928. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10929. {
  10930. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10932. }
  10933. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10934. {
  10935. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10937. }
  10938. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10939. {
  10940. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10942. }
  10943. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10944. {
  10945. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10947. }
  10948. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10949. {
  10950. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10952. }
  10953. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10954. {
  10955. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10957. }
  10958. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10959. {
  10960. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10962. }
  10963. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10964. {
  10965. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10967. TransactionMessageAttemptsValue = atoi(valuestr);
  10968. }
  10969. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10970. {
  10971. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10973. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10974. }
  10975. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10976. {
  10977. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10979. }
  10980. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10981. {
  10982. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10984. }
  10985. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10986. {
  10987. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10989. }
  10990. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10991. {
  10992. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10994. }
  10995. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10996. {
  10997. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10999. }
  11000. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11001. {
  11002. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11004. }
  11005. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11006. {
  11007. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11009. }
  11010. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11011. {
  11012. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11014. }
  11015. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11016. {
  11017. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11019. }
  11020. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11021. {
  11022. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11024. }
  11025. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11026. {
  11027. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11029. }
  11030. }
  11031. fclose(fp);
  11032. }
  11033. //end_t = clock();
  11034. //printf("End of the big loop, end_t = %ld\n", end_t);
  11035. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  11036. //printf("Total time taken by CPU: %f\n", total_t );
  11037. return 0;
  11038. }
  11039. void StoreConfigurationTable(void)
  11040. {
  11041. FILE *outfile;
  11042. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11043. if(outfile == NULL)
  11044. {
  11045. DEBUG_INFO("Error opening file");
  11046. return ;
  11047. }
  11048. /*Core Profile*/
  11049. //AllowOfflineTxForUnknownId
  11050. /*
  11051. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11052. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11055. */
  11056. //DEBUG_INFO("data=%s\n",data);
  11057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11058. //AuthorizationCacheEnabled
  11059. /*
  11060. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11063. */
  11064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11065. //AuthorizeRemoteTxRequests
  11066. /*
  11067. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11070. */
  11071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11072. //BlinkRepeat
  11073. /*
  11074. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11077. */
  11078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11079. //ClockAlignedDataInterval
  11080. /*
  11081. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11084. */
  11085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11086. //ConnectionTimeOut
  11087. /*
  11088. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11091. */
  11092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11093. //GetConfigurationMaxKeys
  11094. /*
  11095. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11098. */
  11099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11100. // HeartbeatInterval
  11101. /*
  11102. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11105. */
  11106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11107. // LightIntensity
  11108. /*
  11109. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11112. */
  11113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11114. // LocalAuthorizeOffline
  11115. /*
  11116. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11119. */
  11120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11121. // LocalPreAuthorize
  11122. /*
  11123. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11126. */
  11127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11128. // MaxEnergyOnInvalidId
  11129. /*
  11130. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11133. */
  11134. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11136. // MeterValuesAlignedData
  11137. /*
  11138. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11141. */
  11142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11143. // MeterValuesAlignedDataMaxLength
  11144. /*
  11145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11148. */
  11149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11150. // MeterValuesSampledData
  11151. /*
  11152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11155. */
  11156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11157. // MeterValuesSampledDataMaxLength
  11158. /*
  11159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11162. */
  11163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11164. // MeterValueSampleInterval
  11165. /*
  11166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11169. */
  11170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11171. // MinimumStatusDuration
  11172. /*
  11173. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11176. */
  11177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11178. // NumberOfConnectors
  11179. /*
  11180. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11183. {
  11184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11185. }
  11186. else
  11187. {
  11188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11189. }
  11190. */
  11191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11192. // ResetRetries
  11193. /*
  11194. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11197. */
  11198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11199. // ConnectorPhaseRotation
  11200. /*
  11201. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11204. */
  11205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11206. // ConnectorPhaseRotationMaxLength
  11207. /*
  11208. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11211. */
  11212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11213. // StopTransactionOnEVSideDisconnect
  11214. /*
  11215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11218. */
  11219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11220. // StopTransactionOnInvalidId
  11221. /*
  11222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11225. */
  11226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11227. // StopTxnAlignedData
  11228. /*
  11229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11232. */
  11233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11234. // StopTxnAlignedDataMaxLength
  11235. /*
  11236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11239. */
  11240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11241. // StopTxnSampledData
  11242. /*
  11243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11246. */
  11247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11248. // StopTxnSampledDataMaxLength
  11249. /*
  11250. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11253. */
  11254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11255. // SupportedFeatureProfiles
  11256. /*
  11257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11260. */
  11261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11262. // SupportedFeatureProfilesMaxLength
  11263. /*
  11264. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11267. */
  11268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11269. // TransactionMessageAttempts
  11270. /*
  11271. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11274. */
  11275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11276. // TransactionMessageRetryInterval
  11277. /*
  11278. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11281. */
  11282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11283. // UnlockConnectorOnEVSideDisconnect
  11284. /*
  11285. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11288. */
  11289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11290. // WebSocketPingInterval
  11291. /*
  11292. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11295. */
  11296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11297. //* Local Auth List Management Profile*/
  11298. //LocalAuthListEnabled
  11299. /*
  11300. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11303. */
  11304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11305. //LocalAuthListMaxLength
  11306. /*
  11307. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11310. */
  11311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11312. //SendLocalListMaxLength
  11313. /*
  11314. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11317. */
  11318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11319. //ReserveConnectorZeroSupported
  11320. /*
  11321. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11324. */
  11325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11326. //* Smart Charging Profile */
  11327. //ChargeProfileMaxStackLevel
  11328. /*
  11329. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11332. */
  11333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11334. // ChargingScheduleAllowedChargingRateUnit
  11335. /*
  11336. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11339. */
  11340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11341. // ChargingScheduleMaxPeriods
  11342. /*
  11343. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11346. */
  11347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11348. // ConnectorSwitch3to1PhaseSupported
  11349. /*
  11350. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11353. */
  11354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11355. // MaxChargingProfilesInstalled
  11356. /*
  11357. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11360. */
  11361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11362. fclose(outfile);
  11363. }
  11364. void getKeyValue(char *keyReq)
  11365. {
  11366. int isEmpty = FALSE;
  11367. int isKnowKey = FALSE;
  11368. //int unKnowIndex = 0;
  11369. DEBUG_INFO("getKeyValue \n");
  11370. DEBUG_INFO("keyReq=%s \n",keyReq);
  11371. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11372. isEmpty = TRUE;
  11373. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11374. {
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11378. {
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11380. }
  11381. else
  11382. {
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11384. }
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11386. isKnowKey = TRUE;
  11387. }
  11388. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11389. {
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11395. }
  11396. else
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11399. }
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11401. isKnowKey = TRUE;
  11402. }
  11403. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11404. {
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11410. }
  11411. else
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11414. }
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11416. isKnowKey = TRUE;
  11417. }
  11418. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11419. {
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11425. }
  11426. else
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11429. }
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11431. isKnowKey = TRUE;
  11432. }
  11433. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11434. {
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11440. }
  11441. else
  11442. {
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11444. }
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11446. isKnowKey = TRUE;
  11447. }
  11448. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11449. {
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11453. {
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11455. }
  11456. else
  11457. {
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11459. }
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11461. isKnowKey = TRUE;
  11462. }
  11463. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11470. }
  11471. else
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11474. }
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11476. isKnowKey = TRUE;
  11477. }
  11478. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11479. {
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11483. {
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11485. }
  11486. else
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11489. }
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11491. isKnowKey = TRUE;
  11492. }
  11493. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11494. {
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11498. {
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11500. }
  11501. else
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11504. }
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11506. isKnowKey = TRUE;
  11507. }
  11508. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11509. {
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11513. {
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11515. }
  11516. else
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11519. }
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11521. isKnowKey = TRUE;
  11522. }
  11523. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11524. {
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11528. {
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11530. }
  11531. else
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11534. }
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11536. isKnowKey = TRUE;
  11537. }
  11538. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11539. {
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11545. }
  11546. else
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11549. }
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11551. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11552. isKnowKey = TRUE;
  11553. }
  11554. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11561. }
  11562. else
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11565. }
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11567. isKnowKey = TRUE;
  11568. }
  11569. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11570. {
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11576. }
  11577. else
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11580. }
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11582. isKnowKey = TRUE;
  11583. }
  11584. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11585. {
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11591. }
  11592. else
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11595. }
  11596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11597. isKnowKey = TRUE;
  11598. }
  11599. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11600. {
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11606. }
  11607. else
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11610. }
  11611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11612. isKnowKey = TRUE;
  11613. }
  11614. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11615. {
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11619. {
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11621. }
  11622. else
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11625. }
  11626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11627. isKnowKey = TRUE;
  11628. }
  11629. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11630. {
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11634. {
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11636. }
  11637. else
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11640. }
  11641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11642. isKnowKey = TRUE;
  11643. }
  11644. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11645. {
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11649. {
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11651. }
  11652. else
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11655. }
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11657. isKnowKey = TRUE;
  11658. }
  11659. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11660. {
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11666. }
  11667. else
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11670. }
  11671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11672. isKnowKey = TRUE;
  11673. }
  11674. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11675. {
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11679. {
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11681. }
  11682. else
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11685. }
  11686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11687. isKnowKey = TRUE;
  11688. }
  11689. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11690. {
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11694. {
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11696. }
  11697. else
  11698. {
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11700. }
  11701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11702. isKnowKey = TRUE;
  11703. }
  11704. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11705. {
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11709. {
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11711. }
  11712. else
  11713. {
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11715. }
  11716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11717. isKnowKey = TRUE;
  11718. }
  11719. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11720. {
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11724. {
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11726. }
  11727. else
  11728. {
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11730. }
  11731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11732. isKnowKey = TRUE;
  11733. }
  11734. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11735. {
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11739. {
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11741. }
  11742. else
  11743. {
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11745. }
  11746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11747. isKnowKey = TRUE;
  11748. }
  11749. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11750. {
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11754. {
  11755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11756. }
  11757. else
  11758. {
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11760. }
  11761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11762. isKnowKey = TRUE;
  11763. }
  11764. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11765. {
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11769. {
  11770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11771. }
  11772. else
  11773. {
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11775. }
  11776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11777. isKnowKey = TRUE;
  11778. }
  11779. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11780. {
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11783. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11784. {
  11785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11786. }
  11787. else
  11788. {
  11789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11790. }
  11791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11792. isKnowKey = TRUE;
  11793. }
  11794. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11795. {
  11796. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11798. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11799. {
  11800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11801. }
  11802. else
  11803. {
  11804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11805. }
  11806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11807. isKnowKey = TRUE;
  11808. }
  11809. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11810. {
  11811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11814. {
  11815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11816. }
  11817. else
  11818. {
  11819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11820. }
  11821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11822. isKnowKey = TRUE;
  11823. }
  11824. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11825. {
  11826. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11829. {
  11830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11831. }
  11832. else
  11833. {
  11834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11835. }
  11836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11837. isKnowKey = TRUE;
  11838. }
  11839. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11840. {
  11841. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11844. {
  11845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11846. }
  11847. else
  11848. {
  11849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11850. }
  11851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11852. isKnowKey = TRUE;
  11853. }
  11854. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11855. {
  11856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11859. {
  11860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11861. }
  11862. else
  11863. {
  11864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11865. }
  11866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11867. isKnowKey = TRUE;
  11868. }
  11869. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11870. {
  11871. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11874. {
  11875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11876. }
  11877. else
  11878. {
  11879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11880. }
  11881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11882. isKnowKey = TRUE;
  11883. }
  11884. #if 0
  11885. //For OCTT Test Case
  11886. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11887. {
  11888. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11890. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11891. {
  11892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11893. }
  11894. else
  11895. {
  11896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11897. }
  11898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11899. isKnowKey = TRUE;
  11900. }
  11901. #endif
  11902. #if 1
  11903. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11904. {
  11905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11907. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11908. {
  11909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11910. }
  11911. else
  11912. {
  11913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11914. }
  11915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11916. isKnowKey = TRUE;
  11917. }
  11918. #endif
  11919. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11920. {
  11921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11923. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11924. {
  11925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11926. }
  11927. else
  11928. {
  11929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11930. }
  11931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11932. isKnowKey = TRUE;
  11933. }
  11934. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11935. {
  11936. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11938. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11939. {
  11940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11941. }
  11942. else
  11943. {
  11944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11945. }
  11946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11947. isKnowKey = TRUE;
  11948. }
  11949. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11950. {
  11951. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11953. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11954. {
  11955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11956. }
  11957. else
  11958. {
  11959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11960. }
  11961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11962. isKnowKey = TRUE;
  11963. }
  11964. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11965. {
  11966. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11968. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11969. {
  11970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11971. }
  11972. else
  11973. {
  11974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11975. }
  11976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11977. isKnowKey = TRUE;
  11978. }
  11979. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11980. {
  11981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11983. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11984. {
  11985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11986. }
  11987. else
  11988. {
  11989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11990. }
  11991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11992. isKnowKey = TRUE;
  11993. }
  11994. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11995. {
  11996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11998. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11999. {
  12000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12001. }
  12002. else
  12003. {
  12004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12005. }
  12006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12007. isKnowKey = TRUE;
  12008. }
  12009. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12010. {
  12011. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12013. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12014. {
  12015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12016. }
  12017. else
  12018. {
  12019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12020. }
  12021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12022. isKnowKey = TRUE;
  12023. }
  12024. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12025. {
  12026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12028. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12029. {
  12030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12031. }
  12032. else
  12033. {
  12034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12035. }
  12036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12037. isKnowKey = TRUE;
  12038. }
  12039. //=========================================================
  12040. if(!isEmpty && !isKnowKey)
  12041. {
  12042. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12043. strcpy(unknownkey[UnknownKeynum], keyReq);
  12044. UnknownKeynum = UnknownKeynum + 1;
  12045. }
  12046. }
  12047. void processUnkownKey(void)
  12048. {
  12049. DEBUG_INFO("processUnkownKey\n");
  12050. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12051. for(int index=0; index < UnknownKeynum; index++)
  12052. {
  12053. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12054. {
  12055. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12056. }
  12057. }
  12058. }
  12059. int setKeyValue(char *key, char *value)
  12060. {
  12061. int isSuccess = NotSupported;
  12062. int check_ascii=0;
  12063. char str[10]={0};
  12064. #ifdef Debug
  12065. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  12066. #endif
  12067. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12068. {
  12069. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12071. {
  12072. strcpy(str, (const char*)value);
  12073. for(int i = 0; str[i]; i++){
  12074. str[i] = tolower(str[i]);
  12075. }
  12076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12077. isSuccess = ConfigurationStatus_Accepted;
  12078. }
  12079. else
  12080. {
  12081. isSuccess = ConfigurationStatus_Rejected;
  12082. }
  12083. }
  12084. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12085. {
  12086. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12088. {
  12089. strcpy(str, (const char*)value);
  12090. for(int i = 0; str[i]; i++){
  12091. str[i] = tolower(str[i]);
  12092. }
  12093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12094. isSuccess = ConfigurationStatus_Accepted;
  12095. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  12096. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12097. }
  12098. else
  12099. {
  12100. isSuccess = ConfigurationStatus_Rejected;
  12101. }
  12102. }
  12103. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12104. {
  12105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12106. {
  12107. strcpy(str, (const char*)value);
  12108. for(int i = 0; str[i]; i++)
  12109. {
  12110. str[i] = tolower(str[i]);
  12111. }
  12112. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12114. isSuccess = ConfigurationStatus_Accepted;
  12115. }
  12116. else
  12117. {
  12118. isSuccess = ConfigurationStatus_Rejected;
  12119. }
  12120. }
  12121. if(strcmp(key, "BlinkRepeat") == 0)
  12122. {
  12123. //Charger.BlinkRepeat = Integer.parseInt(value);
  12124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12125. {
  12126. check_ascii = value[0];
  12127. if( (check_ascii < 48) || (check_ascii > 57) )
  12128. {
  12129. isSuccess = ConfigurationStatus_Rejected;
  12130. }
  12131. else
  12132. {
  12133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12134. isSuccess = ConfigurationStatus_Accepted;
  12135. }
  12136. }
  12137. else
  12138. {
  12139. isSuccess = ConfigurationStatus_Rejected;
  12140. }
  12141. }
  12142. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12143. {
  12144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12145. {
  12146. check_ascii = value[0];
  12147. if( (check_ascii < 48) || (check_ascii > 57) )
  12148. {
  12149. isSuccess = ConfigurationStatus_Rejected;
  12150. }
  12151. else
  12152. {
  12153. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12155. isSuccess = ConfigurationStatus_Accepted;
  12156. }
  12157. }
  12158. else
  12159. {
  12160. isSuccess = ConfigurationStatus_Rejected;
  12161. }
  12162. }
  12163. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12164. {
  12165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12166. {
  12167. check_ascii = value[0];
  12168. if( (check_ascii < 48) || (check_ascii > 57) )
  12169. {
  12170. isSuccess = ConfigurationStatus_Rejected;
  12171. }
  12172. else
  12173. {
  12174. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12176. isSuccess = ConfigurationStatus_Accepted;
  12177. }
  12178. }
  12179. else
  12180. {
  12181. isSuccess = ConfigurationStatus_Rejected;
  12182. }
  12183. }
  12184. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12185. {
  12186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12187. {
  12188. check_ascii = value[0];
  12189. if( (check_ascii < 48) || (check_ascii > 57) )
  12190. {
  12191. isSuccess = ConfigurationStatus_Rejected;
  12192. }
  12193. else
  12194. {
  12195. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12197. isSuccess = ConfigurationStatus_Accepted;
  12198. }
  12199. }
  12200. else
  12201. {
  12202. isSuccess = ConfigurationStatus_Rejected;
  12203. }
  12204. }
  12205. if(strcmp(key, "HeartbeatInterval") == 0)
  12206. {
  12207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12208. {
  12209. check_ascii = value[0];
  12210. if( (check_ascii < 48) || (check_ascii > 57) )
  12211. {
  12212. isSuccess = ConfigurationStatus_Rejected;
  12213. }
  12214. else
  12215. {
  12216. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12218. HeartBeatWaitTime = atoi(value);
  12219. isSuccess = ConfigurationStatus_Accepted;
  12220. }
  12221. }
  12222. else
  12223. {
  12224. isSuccess = ConfigurationStatus_Rejected;
  12225. }
  12226. }
  12227. if(strcmp(key, "LightIntensity") == 0)
  12228. {
  12229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12230. {
  12231. check_ascii = value[0];
  12232. if( (check_ascii < 48) || (check_ascii > 57) )
  12233. {
  12234. isSuccess = ConfigurationStatus_Rejected;
  12235. }
  12236. else
  12237. {
  12238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12239. isSuccess = ConfigurationStatus_Accepted;
  12240. }
  12241. }
  12242. else
  12243. {
  12244. isSuccess = ConfigurationStatus_Rejected;
  12245. }
  12246. }
  12247. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12248. {
  12249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12250. {
  12251. strcpy(str, (const char*)value);
  12252. for(int i = 0; str[i]; i++)
  12253. {
  12254. str[i] = tolower(str[i]);
  12255. }
  12256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12257. isSuccess = ConfigurationStatus_Accepted;
  12258. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12259. }
  12260. else
  12261. {
  12262. isSuccess = ConfigurationStatus_Rejected;
  12263. }
  12264. }
  12265. if(strcmp(key, "LocalPreAuthorize") == 0)
  12266. {
  12267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12268. {
  12269. strcpy(str, (const char*)value);
  12270. for(int i = 0; str[i]; i++)
  12271. {
  12272. str[i] = tolower(str[i]);
  12273. }
  12274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12275. isSuccess = ConfigurationStatus_Accepted;
  12276. }
  12277. else
  12278. {
  12279. isSuccess = ConfigurationStatus_Rejected;
  12280. }
  12281. }
  12282. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12283. {
  12284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12285. {
  12286. check_ascii = value[0];
  12287. if( (check_ascii < 48) || (check_ascii > 57) )
  12288. {
  12289. isSuccess = ConfigurationStatus_Rejected;
  12290. }
  12291. else
  12292. {
  12293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12294. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12295. isSuccess = ConfigurationStatus_Accepted;
  12296. }
  12297. }
  12298. else
  12299. {
  12300. isSuccess = ConfigurationStatus_Rejected;
  12301. }
  12302. }
  12303. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12304. {
  12305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12306. {
  12307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12308. isSuccess = ConfigurationStatus_Accepted;
  12309. }
  12310. else
  12311. {
  12312. isSuccess = ConfigurationStatus_Rejected;
  12313. }
  12314. }
  12315. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12316. {
  12317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12318. {
  12319. check_ascii = value[0];
  12320. if( (check_ascii < 48) || (check_ascii > 57) )
  12321. {
  12322. isSuccess = ConfigurationStatus_Rejected;
  12323. }
  12324. else
  12325. {
  12326. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12328. isSuccess = ConfigurationStatus_Accepted;
  12329. }
  12330. }
  12331. else
  12332. {
  12333. isSuccess = ConfigurationStatus_Rejected;
  12334. }
  12335. }
  12336. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12337. {
  12338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12339. {
  12340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12341. isSuccess = ConfigurationStatus_Accepted;
  12342. }
  12343. else
  12344. {
  12345. isSuccess = ConfigurationStatus_Rejected;
  12346. }
  12347. }
  12348. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12349. {
  12350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12351. {
  12352. check_ascii = value[0];
  12353. if( (check_ascii < 48) || (check_ascii > 57) )
  12354. {
  12355. isSuccess = ConfigurationStatus_Rejected;
  12356. }
  12357. else
  12358. {
  12359. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12361. isSuccess = ConfigurationStatus_Accepted;
  12362. }
  12363. }
  12364. else
  12365. {
  12366. isSuccess = ConfigurationStatus_Rejected;
  12367. }
  12368. }
  12369. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12370. {
  12371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12372. {
  12373. check_ascii = value[0];
  12374. if( (check_ascii < 48) || (check_ascii > 57) )
  12375. {
  12376. isSuccess = ConfigurationStatus_Rejected;
  12377. }
  12378. else
  12379. {
  12380. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12382. isSuccess = ConfigurationStatus_Accepted;
  12383. }
  12384. }
  12385. else
  12386. {
  12387. isSuccess = ConfigurationStatus_Rejected;
  12388. }
  12389. }
  12390. if(strcmp(key, "MinimumStatusDuration") == 0)
  12391. {
  12392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12393. {
  12394. check_ascii = value[0];
  12395. if( (check_ascii < 48) || (check_ascii > 57) )
  12396. {
  12397. isSuccess = ConfigurationStatus_Rejected;
  12398. }
  12399. else
  12400. {
  12401. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12402. {
  12403. isSuccess = ConfigurationStatus_Rejected;
  12404. }
  12405. else
  12406. {
  12407. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12409. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12410. isSuccess = ConfigurationStatus_Accepted;
  12411. }
  12412. }
  12413. }
  12414. else
  12415. {
  12416. isSuccess = ConfigurationStatus_Rejected;
  12417. }
  12418. }
  12419. if(strcmp(key, "NumberOfConnectors") == 0)
  12420. {
  12421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12422. {
  12423. check_ascii = value[0];
  12424. if( (check_ascii < 48) || (check_ascii > 57) )
  12425. {
  12426. isSuccess = ConfigurationStatus_Rejected;
  12427. }
  12428. else
  12429. {
  12430. //Charger.ResetRetries = Integer.parseInt(value);
  12431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12432. isSuccess = ConfigurationStatus_Accepted;
  12433. }
  12434. }
  12435. else
  12436. {
  12437. isSuccess = ConfigurationStatus_Rejected;
  12438. }
  12439. }
  12440. if(strcmp(key, "ResetRetries") == 0)
  12441. {
  12442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].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.ResetRetries = Integer.parseInt(value);
  12452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12453. isSuccess = ConfigurationStatus_Accepted;
  12454. }
  12455. }
  12456. else
  12457. {
  12458. isSuccess = ConfigurationStatus_Rejected;
  12459. }
  12460. }
  12461. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12462. {
  12463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12464. {
  12465. strcpy(str, (const char*)value);
  12466. for(int i = 0; str[i]; i++)
  12467. {
  12468. str[i] = tolower(str[i]);
  12469. }
  12470. if(strcmp(str, "notapplicable")== 0)
  12471. {
  12472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12473. isSuccess = ConfigurationStatus_Accepted;
  12474. }
  12475. else if(strcmp(str, "unknown")== 0)
  12476. {
  12477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12478. isSuccess = ConfigurationStatus_Accepted;
  12479. }
  12480. else if(strcmp(str, "rst")== 0)
  12481. {
  12482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12483. isSuccess = ConfigurationStatus_Accepted;
  12484. }
  12485. else if(strcmp(str, "rts")== 0)
  12486. {
  12487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12488. isSuccess = ConfigurationStatus_Accepted;
  12489. }
  12490. else if(strcmp(str, "srt")== 0)
  12491. {
  12492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12493. isSuccess = ConfigurationStatus_Accepted;
  12494. }
  12495. else if(strcmp(str, "str")== 0)
  12496. {
  12497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12498. isSuccess = ConfigurationStatus_Accepted;
  12499. }
  12500. else if(strcmp(str, "trs")== 0)
  12501. {
  12502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12503. isSuccess = ConfigurationStatus_Accepted;
  12504. }
  12505. else if(strcmp(str, "tsr")== 0)
  12506. {
  12507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12508. isSuccess = ConfigurationStatus_Accepted;
  12509. }
  12510. else
  12511. {
  12512. isSuccess = ConfigurationStatus_Rejected;
  12513. }
  12514. }
  12515. else
  12516. {
  12517. isSuccess = ConfigurationStatus_Rejected;
  12518. }
  12519. }
  12520. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12521. {
  12522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12523. {
  12524. check_ascii = value[0];
  12525. if( (check_ascii < 48) || (check_ascii > 57) )
  12526. {
  12527. isSuccess = ConfigurationStatus_Rejected;
  12528. }
  12529. else
  12530. {
  12531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12532. isSuccess = ConfigurationStatus_Accepted;
  12533. }
  12534. }
  12535. else
  12536. {
  12537. isSuccess = ConfigurationStatus_Rejected;
  12538. }
  12539. }
  12540. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12541. {
  12542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12543. {
  12544. strcpy(str, (const char*)value);
  12545. for(int i = 0; str[i]; i++)
  12546. {
  12547. str[i] = tolower(str[i]);
  12548. }
  12549. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12551. isSuccess = ConfigurationStatus_Accepted;
  12552. }
  12553. else
  12554. {
  12555. isSuccess = ConfigurationStatus_Rejected;
  12556. }
  12557. }
  12558. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12559. {
  12560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12561. {
  12562. strcpy(str, (const char*)value);
  12563. for(int i = 0; str[i]; i++)
  12564. {
  12565. str[i] = tolower(str[i]);
  12566. }
  12567. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12569. isSuccess = ConfigurationStatus_Accepted;
  12570. }
  12571. else
  12572. {
  12573. isSuccess = ConfigurationStatus_Rejected;
  12574. }
  12575. }
  12576. if(strcmp(key, "StopTxnAlignedData") == 0)
  12577. {
  12578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12579. {
  12580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12581. isSuccess = ConfigurationStatus_Accepted;
  12582. }
  12583. else
  12584. {
  12585. isSuccess = ConfigurationStatus_Rejected;
  12586. }
  12587. }
  12588. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12589. {
  12590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12591. {
  12592. check_ascii = value[0];
  12593. if( (check_ascii < 48) || (check_ascii > 57) )
  12594. {
  12595. isSuccess = ConfigurationStatus_Rejected;
  12596. }
  12597. else
  12598. {
  12599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12600. isSuccess = ConfigurationStatus_Accepted;
  12601. }
  12602. }
  12603. else
  12604. {
  12605. isSuccess = ConfigurationStatus_Rejected;
  12606. }
  12607. }
  12608. if(strcmp(key, "StopTxnSampledData") == 0)
  12609. {
  12610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12611. {
  12612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12613. isSuccess = ConfigurationStatus_Accepted;
  12614. }
  12615. else
  12616. {
  12617. isSuccess = ConfigurationStatus_Rejected;
  12618. }
  12619. }
  12620. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12621. {
  12622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12623. {
  12624. check_ascii = value[0];
  12625. if( (check_ascii < 48) || (check_ascii > 57) )
  12626. {
  12627. isSuccess = ConfigurationStatus_Rejected;
  12628. }
  12629. else
  12630. {
  12631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12632. isSuccess = ConfigurationStatus_Accepted;
  12633. }
  12634. }
  12635. else
  12636. {
  12637. isSuccess = ConfigurationStatus_Rejected;
  12638. }
  12639. }
  12640. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12641. {
  12642. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12643. {
  12644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12645. isSuccess = ConfigurationStatus_Accepted;
  12646. }
  12647. else
  12648. {
  12649. isSuccess = ConfigurationStatus_Rejected;
  12650. }
  12651. }
  12652. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12653. {
  12654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12655. {
  12656. check_ascii = value[0];
  12657. if( (check_ascii < 48) || (check_ascii > 57) )
  12658. {
  12659. isSuccess = ConfigurationStatus_Rejected;
  12660. }
  12661. else
  12662. {
  12663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12664. isSuccess = ConfigurationStatus_Accepted;
  12665. }
  12666. }
  12667. else
  12668. {
  12669. isSuccess = ConfigurationStatus_Rejected;
  12670. }
  12671. }
  12672. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12673. {
  12674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12675. {
  12676. check_ascii = value[0];
  12677. if( (check_ascii < 48) || (check_ascii > 57) )
  12678. {
  12679. isSuccess = ConfigurationStatus_Rejected;
  12680. }
  12681. else
  12682. {
  12683. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12685. TransactionMessageAttemptsValue = atoi(value);
  12686. isSuccess = ConfigurationStatus_Accepted;
  12687. }
  12688. }
  12689. else
  12690. {
  12691. isSuccess = ConfigurationStatus_Rejected;
  12692. }
  12693. }
  12694. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12695. {
  12696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12697. {
  12698. check_ascii = value[0];
  12699. if( (check_ascii < 48) || (check_ascii > 57) )
  12700. {
  12701. isSuccess = ConfigurationStatus_Rejected;
  12702. }
  12703. else
  12704. {
  12705. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12707. TransactionMessageRetryIntervalValue = atoi(value);
  12708. isSuccess = ConfigurationStatus_Accepted;
  12709. }
  12710. }
  12711. else
  12712. {
  12713. isSuccess = ConfigurationStatus_Rejected;
  12714. }
  12715. }
  12716. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12717. {
  12718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12719. {
  12720. strcpy(str, (const char*)value);
  12721. for(int i = 0; str[i]; i++)
  12722. {
  12723. str[i] = tolower(str[i]);
  12724. }
  12725. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12727. isSuccess = ConfigurationStatus_Accepted;
  12728. }
  12729. else
  12730. {
  12731. isSuccess = ConfigurationStatus_Rejected;
  12732. }
  12733. }
  12734. if(strcmp(key, "WebSocketPingInterval") == 0)
  12735. {
  12736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12737. {
  12738. check_ascii = value[0];
  12739. if( (check_ascii < 48) || (check_ascii > 57) )
  12740. {
  12741. isSuccess = ConfigurationStatus_Rejected;
  12742. }
  12743. else
  12744. {
  12745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12746. isSuccess = ConfigurationStatus_Accepted;
  12747. }
  12748. }
  12749. else
  12750. {
  12751. isSuccess = ConfigurationStatus_Rejected;
  12752. }
  12753. }
  12754. #if 0
  12755. //For OCPP Test Case
  12756. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12757. {
  12758. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12759. {
  12760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12761. isSuccess = ConfigurationStatus_Accepted;
  12762. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12763. }
  12764. else
  12765. {
  12766. isSuccess = ConfigurationStatus_Rejected;
  12767. }
  12768. }
  12769. #endif
  12770. #if 1
  12771. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12772. {
  12773. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12774. {
  12775. strcpy(str, (const char*)value);
  12776. for(int i = 0; str[i]; i++)
  12777. {
  12778. str[i] = tolower(str[i]);
  12779. }
  12780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12781. isSuccess = ConfigurationStatus_Accepted;
  12782. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12783. }
  12784. else
  12785. {
  12786. isSuccess = ConfigurationStatus_Rejected;
  12787. }
  12788. }
  12789. #endif
  12790. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12791. {
  12792. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12793. {
  12794. check_ascii = value[0];
  12795. if( (check_ascii < 48) || (check_ascii > 57) )
  12796. {
  12797. isSuccess = ConfigurationStatus_Rejected;
  12798. }
  12799. else
  12800. {
  12801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12802. isSuccess = ConfigurationStatus_Accepted;
  12803. }
  12804. }
  12805. else
  12806. {
  12807. isSuccess = ConfigurationStatus_Rejected;
  12808. }
  12809. }
  12810. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12811. {
  12812. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12813. {
  12814. check_ascii = value[0];
  12815. if( (check_ascii < 48) || (check_ascii > 57) )
  12816. {
  12817. isSuccess = ConfigurationStatus_Rejected;
  12818. }
  12819. else
  12820. {
  12821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12822. isSuccess = ConfigurationStatus_Accepted;
  12823. }
  12824. }
  12825. else
  12826. {
  12827. isSuccess = ConfigurationStatus_Rejected;
  12828. }
  12829. }
  12830. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12831. {
  12832. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12833. {
  12834. strcpy(str, (const char*)value);
  12835. for(int i = 0; str[i]; i++)
  12836. {
  12837. str[i] = tolower(str[i]);
  12838. }
  12839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12840. isSuccess = ConfigurationStatus_Accepted;
  12841. }
  12842. else
  12843. {
  12844. isSuccess = ConfigurationStatus_Rejected;
  12845. }
  12846. }
  12847. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12848. {
  12849. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12850. {
  12851. check_ascii = value[0];
  12852. if( (check_ascii < 48) || (check_ascii > 57) )
  12853. {
  12854. isSuccess = ConfigurationStatus_Rejected;
  12855. }
  12856. else
  12857. {
  12858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12859. isSuccess = ConfigurationStatus_Accepted;
  12860. }
  12861. }
  12862. else
  12863. {
  12864. isSuccess = ConfigurationStatus_Rejected;
  12865. }
  12866. }
  12867. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12868. {
  12869. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12870. {
  12871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12872. isSuccess = ConfigurationStatus_Accepted;
  12873. }
  12874. else
  12875. {
  12876. isSuccess = ConfigurationStatus_Rejected;
  12877. }
  12878. }
  12879. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12880. {
  12881. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12882. {
  12883. check_ascii = value[0];
  12884. if( (check_ascii < 48) || (check_ascii > 57) )
  12885. {
  12886. isSuccess = ConfigurationStatus_Rejected;
  12887. }
  12888. else
  12889. {
  12890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12891. isSuccess = ConfigurationStatus_Accepted;
  12892. }
  12893. }
  12894. else
  12895. {
  12896. isSuccess = ConfigurationStatus_Rejected;
  12897. }
  12898. }
  12899. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12900. {
  12901. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12902. {
  12903. strcpy(str, (const char*)value);
  12904. for(int i = 0; str[i]; i++)
  12905. {
  12906. str[i] = tolower(str[i]);
  12907. }
  12908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12909. isSuccess = ConfigurationStatus_Accepted;
  12910. }
  12911. else
  12912. {
  12913. isSuccess = ConfigurationStatus_Rejected;
  12914. }
  12915. }
  12916. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12917. {
  12918. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12919. {
  12920. check_ascii = value[0];
  12921. if( (check_ascii < 48) || (check_ascii > 57) )
  12922. {
  12923. isSuccess = ConfigurationStatus_Rejected;
  12924. }
  12925. else
  12926. {
  12927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12928. isSuccess = ConfigurationStatus_Accepted;
  12929. }
  12930. }
  12931. else
  12932. {
  12933. isSuccess = ConfigurationStatus_Rejected;
  12934. }
  12935. }
  12936. return isSuccess;
  12937. }
  12938. int updateSetting(char *key, char *value)
  12939. {
  12940. mtrace();
  12941. int isSuccess = FALSE;
  12942. char string[1000]={0}, buffer[1000]={0};
  12943. char strtemp[50]={0};
  12944. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12945. int pos, c = 0;
  12946. char *loc;
  12947. int pos1=0;
  12948. FILE *f = fopen("/var/www/settings1", "r");
  12949. if(f == NULL)
  12950. {
  12951. #ifdef Debug
  12952. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12953. #endif
  12954. return isSuccess;
  12955. }
  12956. fseek(f, 0, SEEK_END);
  12957. long fsize = ftell(f);
  12958. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12959. fread(string, 1, fsize, f);
  12960. fclose(f);
  12961. string[fsize] = 0;
  12962. loc = strstr(string, key);
  12963. if(loc != NULL)
  12964. {
  12965. DEBUG_INFO("key exist!\n");
  12966. pos = loc - string-1;
  12967. f = fopen("/var/www/settings1", "w");
  12968. strncpy(buffer, string, pos);
  12969. fprintf(f, "%s", buffer);
  12970. memset(sstr ,0, sizeof(sstr) );
  12971. c = 0;
  12972. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12973. {
  12974. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12975. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12976. c++;
  12977. }
  12978. sstr[c] = '\0';
  12979. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12980. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12981. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12982. memset(buffer ,0, sizeof(buffer) );
  12983. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12984. //printf("buffer=%s",buffer);
  12985. fprintf(f, "%s", buffer);
  12986. fclose(f);
  12987. }
  12988. else
  12989. {
  12990. printf("key not exist!\n");
  12991. f = fopen("/var/www/settings1", "w+");
  12992. fputs(string, f);
  12993. fseek(f, -1, SEEK_CUR);
  12994. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12995. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12996. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12997. fclose(f);
  12998. }
  12999. isSuccess = TRUE;
  13000. return isSuccess;
  13001. }
  13002. int TransactionMessageAttemptsGet(void)
  13003. {
  13004. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13005. }
  13006. int FirstHeartBeatResponse(void)
  13007. {
  13008. return FirstHeartBeat;
  13009. }
  13010. int TransactionMessageRetryIntervalGet(void)
  13011. {
  13012. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13013. }
  13014. #define SA struct sockaddr
  13015. #define MAXBUF 1024
  13016. //static int m_socket_data;
  13017. //static int sockfd;
  13018. int ReadHttpStatus(int sock){
  13019. //char c;
  13020. char buff[1024]="",*ptr=buff+1;
  13021. int bytes_received, status;
  13022. DEBUG_INFO("Begin Response ..\n");
  13023. while((bytes_received = recv(sock, ptr, 1, 0))){
  13024. if(bytes_received==-1){
  13025. perror("ReadHttpStatus");
  13026. exit(1);
  13027. }
  13028. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13029. ptr++;
  13030. }
  13031. *ptr=0;
  13032. ptr=buff+1;
  13033. sscanf(ptr,"%*s %d ", &status);
  13034. DEBUG_INFO("%s\n",ptr);
  13035. DEBUG_INFO("status=%d\n",status);
  13036. DEBUG_INFO("End Response ..\n");
  13037. return (bytes_received>0)?status:0;
  13038. }
  13039. //the only filed that it parsed is 'Content-Length'
  13040. int ParseHeader(int sock){
  13041. //char c;
  13042. char buff[1024]="",*ptr=buff+4;
  13043. int bytes_received;
  13044. DEBUG_INFO("Begin HEADER ..\n");
  13045. while((bytes_received = recv(sock, ptr, 1, 0))){
  13046. if(bytes_received==-1){
  13047. perror("Parse Header");
  13048. exit(1);
  13049. }
  13050. if(
  13051. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13052. (ptr[-1]=='\r') && (*ptr=='\n' )
  13053. ) break;
  13054. ptr++;
  13055. }
  13056. *ptr=0;
  13057. ptr=buff+4;
  13058. //printf("%s",ptr);
  13059. if(bytes_received){
  13060. ptr=strstr(ptr,"Content-Length:");
  13061. if(ptr){
  13062. sscanf(ptr,"%*s %d",&bytes_received);
  13063. }else
  13064. bytes_received=-1; //unknown size
  13065. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13066. }
  13067. DEBUG_INFO("End HEADER ..\n");
  13068. return bytes_received ;
  13069. }
  13070. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13071. {
  13072. char rmFileCmd[100]={0};
  13073. char FilePath[100]={0};
  13074. char ftpbuf[200];
  13075. int systemresult;
  13076. //DEBUG_INFO("filename=%s\n",filename);
  13077. //DEBUG_INFO("url=%s\n",url);
  13078. sprintf(FilePath,"/mnt/%s",filename);
  13079. if((access(FilePath,F_OK))!=-1)
  13080. {
  13081. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13082. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13083. system(rmFileCmd);
  13084. }
  13085. memset(ftpbuf, 0, sizeof(ftpbuf));
  13086. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13087. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13088. systemresult = system(ftpbuf);
  13089. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13090. if(systemresult != 0)
  13091. {
  13092. DEBUG_INFO("http DownLoad error!\n");
  13093. return FALSE;
  13094. }
  13095. return TRUE;
  13096. }
  13097. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13098. {
  13099. char rmFileCmd[100]={0};
  13100. char FilePath[100]={0};
  13101. char ftpbuf[200];
  13102. int systemresult;
  13103. //char temp[100];
  13104. #if 0
  13105. struct hostent* server;
  13106. char *IPbuffer;
  13107. server = gethostbyname(location);
  13108. // To convert an Internet network
  13109. // address into ASCII string
  13110. IPbuffer = inet_ntoa(*((struct in_addr*)
  13111. server->h_addr_list[0]));
  13112. #endif
  13113. sprintf(FilePath,"/mnt/%s",filename);
  13114. if((access(FilePath,F_OK))!=-1)
  13115. {
  13116. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13117. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13118. system(rmFileCmd);
  13119. }
  13120. memset(ftpbuf, 0, sizeof(ftpbuf));
  13121. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13122. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13123. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13124. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13125. systemresult = system(ftpbuf);
  13126. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13127. if(systemresult != 0)
  13128. {
  13129. printf("wget error!\n");
  13130. return FALSE;
  13131. }
  13132. return TRUE;
  13133. }
  13134. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13135. {
  13136. char rmFileCmd[100]={0};
  13137. char FilePath[100]={0};
  13138. char ftpbuf[200];
  13139. char filenametemp[60]={0};
  13140. int systemresult;
  13141. //DEBUG_INFO("filename=%s\n",filename);
  13142. //DEBUG_INFO("url=%s\n",url);
  13143. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13144. if((access(FilePath,F_OK))!=-1)
  13145. {
  13146. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13147. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13148. system(rmFileCmd);
  13149. }
  13150. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13151. if(fp == NULL)
  13152. {
  13153. DEBUG_INFO("log is NULL\n");
  13154. return FALSE;
  13155. }
  13156. else
  13157. {
  13158. fprintf(fp, "%s\n", url);
  13159. sscanf(filename, "%*2[.]%s", filenametemp);
  13160. fprintf(fp, "%s\n", filenametemp);
  13161. fclose(fp);
  13162. }
  13163. memset(ftpbuf, 0, sizeof(ftpbuf));
  13164. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13165. systemresult = system(ftpbuf);
  13166. DEBUG_INFO("systemresult=%d\n",systemresult);
  13167. if(systemresult != 0)
  13168. {
  13169. DEBUG_INFO("http upload error!\n");
  13170. return FALSE;
  13171. }
  13172. return TRUE;
  13173. }
  13174. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13175. {
  13176. struct hostent* server;
  13177. char *IPbuffer;
  13178. char ftpbuf[200];
  13179. int systemresult;
  13180. // To retrieve host information
  13181. server = gethostbyname(location);
  13182. // To convert an Internet network
  13183. // address into ASCII string
  13184. IPbuffer = inet_ntoa(*((struct in_addr*)
  13185. server->h_addr_list[0]));
  13186. memset(ftpbuf, 0, sizeof(ftpbuf));
  13187. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13188. /* format : ftpput -u username -p passwd IP target source*/
  13189. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13190. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13191. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13192. systemresult = system(ftpbuf);
  13193. DEBUG_INFO("systemresult=%d\n",systemresult);
  13194. if(systemresult != 0)
  13195. {
  13196. DEBUG_INFO("ftpput error!\n");
  13197. return FALSE;
  13198. }
  13199. return TRUE;
  13200. }
  13201. int SettingChargingRecord(int target, int transactionId)
  13202. {
  13203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13204. {
  13205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13206. {
  13207. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13208. {
  13209. addBuff(target, transactionId, 0);
  13210. return TRUE;
  13211. }
  13212. }
  13213. for (int index = 0; index < CCS_QUANTITY; index++)
  13214. {
  13215. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13216. {
  13217. addBuff(target, transactionId, 0);
  13218. return TRUE;
  13219. }
  13220. }
  13221. for (int index = 0; index < GB_QUANTITY; index++)
  13222. {
  13223. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13224. {
  13225. addBuff(target, transactionId, 0);
  13226. return TRUE;
  13227. }
  13228. }
  13229. }
  13230. else
  13231. {
  13232. for (int index = 0; index < AC_QUANTITY; index++)
  13233. {
  13234. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13235. {
  13236. addBuff(target, transactionId, 0);
  13237. return TRUE;
  13238. }
  13239. }
  13240. }
  13241. return FALSE;
  13242. }
  13243. int addBuff(int gun_idx, int user_id, int cmd_sn)
  13244. {
  13245. int isSuccess = FALSE;
  13246. //char *query = NULL;
  13247. sqlite3_stmt *stmt;
  13248. int rc; // return code
  13249. char str[20];
  13250. sprintf(str,"%d",user_id);
  13251. 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 */
  13252. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  13253. rc = sqlite3_step(stmt); /* 3 */
  13254. if (rc != SQLITE_DONE) {
  13255. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  13256. goto out;
  13257. }
  13258. sqlite3_finalize(stmt);
  13259. // free(query);
  13260. out:
  13261. //----------------------
  13262. // close SQLite database
  13263. //----------------------
  13264. sqlite3_close(db);
  13265. printf("database closed.\n");
  13266. return isSuccess;
  13267. }
  13268. /**
  13269. * Place the contents of the specified file into a memory buffer
  13270. *
  13271. * @param[in] filename The path and name of the file to read
  13272. * @param[out] filebuffer A pointer to the contents in memory
  13273. * @return status 0 success, 1 on failure
  13274. */
  13275. int get_file_contents(const char* filename, char** outbuffer) {
  13276. FILE* file = NULL;
  13277. long filesize;
  13278. const int blocksize = 1;
  13279. size_t readsize;
  13280. char* filebuffer;
  13281. // Open the file
  13282. file = fopen(filename, "r");
  13283. if (NULL == file)
  13284. {
  13285. printf("'%s' not opened\n", filename);
  13286. exit(EXIT_FAILURE);
  13287. }
  13288. // Determine the file size
  13289. fseek(file, 0, SEEK_END);
  13290. filesize = ftell(file);
  13291. rewind (file);
  13292. // Allocate memory for the file contents
  13293. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13294. *outbuffer = filebuffer;
  13295. if (filebuffer == NULL)
  13296. {
  13297. fputs ("malloc out-of-memory", stderr);
  13298. exit(EXIT_FAILURE);
  13299. }
  13300. // Read in the file
  13301. readsize = fread(filebuffer, blocksize, filesize, file);
  13302. if (readsize != filesize)
  13303. {
  13304. fputs ("didn't read file completely",stderr);
  13305. exit(EXIT_FAILURE);
  13306. }
  13307. // Clean exit
  13308. fclose(file);
  13309. return EXIT_SUCCESS;
  13310. }
  13311. static int selectSqlCount = 0;
  13312. static int callback(void *data, int argc, char **argv, char **azColName){
  13313. int i;
  13314. //printf("%s: ", (const char*)data);
  13315. selectSqlCount = argc;
  13316. for(i = 0; i<argc; i++){
  13317. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13318. }
  13319. //printf("\n");
  13320. return 0;
  13321. }
  13322. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13323. //int i;
  13324. //printf("%s:\n", (const char*)data);
  13325. localversion = argv[5] ? atoi(argv[5]) : 0;
  13326. //printf("localversion=%d\n", localversion);
  13327. return 0;
  13328. }
  13329. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13330. //int i;
  13331. //printf("%s:\n", (const char*)data);
  13332. //idTag
  13333. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13334. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13335. //parentIdTag
  13336. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13337. //expir_date
  13338. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13339. //status
  13340. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13341. //version
  13342. idTagQuery.listVersionInt = atoi(argv[5]);
  13343. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13344. return 0;
  13345. }
  13346. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  13347. #if 0
  13348. int i;
  13349. //printf("%s:\n", (const char*)data);
  13350. for(i=0; i<argc; i++){
  13351. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  13352. }
  13353. //printf("");
  13354. #endif
  13355. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13356. // printf("localversion=%d\n", localversion);
  13357. return 0;
  13358. }
  13359. /** sqlite3_exec的回调。
  13360. *
  13361. * 向控制台打印查询的结果。
  13362. *
  13363. * @param in data 传递给回调函数的数据。
  13364. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  13365. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  13366. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  13367. * @return 状态码。
  13368. */
  13369. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13370. {
  13371. for (int i = 0; i < n_columns; i++)
  13372. {
  13373. DEBUG_INFO("%s/t", col_values[i]);
  13374. }
  13375. DEBUG_INFO("/n");
  13376. return 0;
  13377. }
  13378. void OCPP_getListVerion()
  13379. {
  13380. int rc = 0;
  13381. // const char* data = "Callback function called";
  13382. char sql[100];
  13383. char zErrMsg[100];
  13384. memset(sql, 0, 100);
  13385. memset(zErrMsg, 0, 100);
  13386. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  13387. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13388. /* Execute SQL statement */
  13389. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13390. DEBUG_INFO("rc=%d\n",rc);
  13391. if( rc != SQLITE_OK ){
  13392. DEBUG_INFO("SQL error: %s", zErrMsg);
  13393. //sqlite3_free(zErrMsg);
  13394. }
  13395. }
  13396. void OCPP_getIdTag(char idTag[])
  13397. {
  13398. int rc = 0;
  13399. // const char* data = "Callback function called";
  13400. char sql[100];
  13401. char zErrMsg[100];
  13402. memset(sql, 0, 100);
  13403. memset(zErrMsg, 0, 100);
  13404. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  13405. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13406. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13407. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13408. /* Execute SQL statement */
  13409. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13410. if( rc != SQLITE_OK ){
  13411. DEBUG_INFO("SQL error: %s", zErrMsg);
  13412. //sqlite3_free(zErrMsg);
  13413. }
  13414. //return ver;
  13415. }
  13416. void OCPP_get_TableAuthlocalAllData(void)
  13417. {
  13418. int rc = 0;
  13419. // const char* data = "Callback function called";
  13420. char sql[100];
  13421. char zErrMsg[100];
  13422. memset(sql, 0, 100);
  13423. memset(zErrMsg, 0, 100);
  13424. sprintf(sql,"select * from ocpp_auth_local ");
  13425. /* Execute SQL statement */
  13426. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13427. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  13428. if( rc != SQLITE_OK ){
  13429. DEBUG_INFO("SQL error: %s", zErrMsg);
  13430. //sqlite3_free(zErrMsg);
  13431. }
  13432. //return ver;
  13433. }
  13434. int OCPP_cleanLocalList()
  13435. {
  13436. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13437. char *errMsg = 0;
  13438. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13439. if (SQLITE_OK != rc)
  13440. {
  13441. DEBUG_INFO("%s\n",errMsg);
  13442. return FALSE;
  13443. }
  13444. else
  13445. {
  13446. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  13447. }
  13448. return TRUE;
  13449. }
  13450. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13451. {
  13452. int isSuccess = FALSE;
  13453. int ret = 0;
  13454. //const char* data = "Callback function called";
  13455. char sql[300];
  13456. char zErrMsg[200];
  13457. memset(sql, 0, 300);
  13458. memset(zErrMsg, 0, 200);
  13459. 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);
  13460. //* Execute SQL statement */
  13461. //zErrMsg = 0;
  13462. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13463. if( ret != SQLITE_OK ){
  13464. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13465. // free(zErrMsg);
  13466. // free(sql);
  13467. return isSuccess;
  13468. }
  13469. memset(sql, 0, 300);
  13470. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13471. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13472. if( ret != SQLITE_OK ){
  13473. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13474. // free(zErrMsg);
  13475. // free(sql);
  13476. return isSuccess;
  13477. }
  13478. // DEBUG_INFO("successfully Insert records created\n");
  13479. isSuccess = TRUE;
  13480. return isSuccess;
  13481. }
  13482. void OCPP_deleteIdTag(char idTag[])
  13483. {
  13484. //int ver = 0;
  13485. //int isSuccess = FALSE;
  13486. int rc = 0;
  13487. char sql[100];
  13488. char zErrMsg[100];
  13489. memset(sql, 0, 100);
  13490. memset(zErrMsg, 0, 100);
  13491. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13492. //* Execute SQL statement */
  13493. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13494. if( rc != SQLITE_OK ){
  13495. DEBUG_INFO("SQL error: %s", zErrMsg);
  13496. //sqlite3_free(zErrMsg);
  13497. }
  13498. }
  13499. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13500. {
  13501. int isSuccess = FALSE;
  13502. int ret = 0;
  13503. const char* data = "Callback function called";
  13504. char sql[200];
  13505. char zErrMsg[100];
  13506. memset(sql, 0, 200);
  13507. memset(zErrMsg, 0, 100);
  13508. //* selectFromTable */
  13509. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  13510. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13511. //* Execute SQL statement */
  13512. selectSqlCount = 0;
  13513. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13514. if( ret != SQLITE_OK ){
  13515. printf("Error SQL: %s\n", zErrMsg);
  13516. }
  13517. printf("successfully select operation done\n");
  13518. memset(sql, 0, 200);
  13519. memset(zErrMsg, 0, 100);
  13520. if(selectSqlCount == 0)
  13521. {
  13522. //Insert
  13523. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  13524. 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);
  13525. DEBUG_INFO("sql:%s\n", sql);
  13526. //* Execute SQL statement */
  13527. //zErrMsg = 0;
  13528. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  13529. if( ret != SQLITE_OK ){
  13530. printf("SQL error: %s\n", zErrMsg);
  13531. return isSuccess;
  13532. }
  13533. DEBUG_INFO("successfully Insert records created\n");
  13534. isSuccess = TRUE;
  13535. }
  13536. else
  13537. {
  13538. //Update
  13539. //* Create merged SQL statement */
  13540. 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);
  13541. /* Execute SQL statement */
  13542. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13543. if( ret != SQLITE_OK ){
  13544. printf("SQL error: %s\n", zErrMsg);
  13545. //sqlite3_free(zErrMsg);
  13546. //sqlite3_free(sql);
  13547. return isSuccess;
  13548. }
  13549. DEBUG_INFO("Successfully operation done \n");
  13550. isSuccess = TRUE;
  13551. }
  13552. return isSuccess;
  13553. }
  13554. int GetOcppServerURL()
  13555. {
  13556. int result = FALSE;
  13557. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  13558. memset(OcppHost, 0, sizeof(OcppHost));
  13559. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  13560. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13561. {
  13562. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  13563. #if 1
  13564. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13565. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13566. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13567. #endif
  13568. #if 0
  13569. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13570. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  13571. OcppProtocol, OcppHost, OcppTempPath);
  13572. OcppPort = 443;
  13573. #endif
  13574. result = TRUE;
  13575. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13576. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13577. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13578. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13579. goto End;
  13580. }
  13581. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13582. {
  13583. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  13584. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13585. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13586. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13587. result = TRUE;
  13588. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13589. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13590. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13591. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13592. goto End;
  13593. }
  13594. else
  13595. {
  13596. strcpy(OcppHost,"");
  13597. }
  13598. End:
  13599. return result;
  13600. }
  13601. int GetOcppPath()
  13602. {
  13603. int result = FALSE;
  13604. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13605. {
  13606. if(OcppTempPath == NULL)
  13607. {
  13608. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13609. }
  13610. else
  13611. {
  13612. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13613. }
  13614. result = TRUE;
  13615. goto End;
  13616. }
  13617. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13618. {
  13619. if(OcppTempPath == NULL)
  13620. {
  13621. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13622. }
  13623. else
  13624. {
  13625. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13626. }
  13627. result = TRUE;
  13628. goto End;
  13629. }
  13630. else
  13631. {
  13632. strcpy(OcppPath,"");
  13633. }
  13634. End:
  13635. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  13636. return result;
  13637. }
  13638. int GetOcppPort()
  13639. {
  13640. return OcppPort;
  13641. }
  13642. int GetOcppConnStatus(void)
  13643. {
  13644. return ShmOCPP16Data->OcppConnStatus;
  13645. }
  13646. void SetOcppConnStatus(uint8_t status)
  13647. {
  13648. ShmOCPP16Data->OcppConnStatus = status;
  13649. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13650. }
  13651. int GetHeartBeatWithNOResponse(void)
  13652. {
  13653. return HeartBeatWithNOResponse;
  13654. }
  13655. void SetHeartBeatWithNOResponse(void)
  13656. {
  13657. HeartBeatWithNOResponse = 0;
  13658. }
  13659. void splitstring(char *src,const char *separator,char **dest,int *num) {
  13660. /*
  13661. src 源字串的首地址(buf的地址)
  13662. separator 指定的分割字元
  13663. dest 接收子字串的陣列
  13664. num 分割後子字串的個數
  13665. */
  13666. char *pNext;
  13667. int count = 0;
  13668. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  13669. return;
  13670. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  13671. return;
  13672. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  13673. while(pNext != NULL) {
  13674. *dest++ = pNext;
  13675. ++count;
  13676. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  13677. }
  13678. *num = count;
  13679. }
  13680. int GetTransactionId(int gunindex, unsigned char idTag[])
  13681. {
  13682. char ch;
  13683. FILE *fptr1;
  13684. int temptransactionId;
  13685. char str[100]={0};
  13686. temptransactionId = 0;
  13687. /*------ Read the file ----------------*/
  13688. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13689. if (!fptr1)
  13690. {
  13691. //printf(" File not found or unable to open the input file!!\n");
  13692. return temptransactionId;
  13693. }
  13694. ch=fgetc(fptr1);
  13695. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13696. rewind(fptr1);
  13697. if(ch!=EOF)
  13698. {
  13699. // printf("%c",ch);
  13700. while (fgets(str, 100, fptr1) != NULL)
  13701. {
  13702. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13703. if(str[0]=='\0')
  13704. {
  13705. break;
  13706. }
  13707. char *revbuf[8] = {0}; //存放分割後的子字串
  13708. int num = 0;//分割後子字串的個數
  13709. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13710. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13711. {
  13712. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13713. {
  13714. temptransactionId = atoi(revbuf[2]);
  13715. break;
  13716. }
  13717. }
  13718. }
  13719. }
  13720. fclose(fptr1);
  13721. /*------- End of reading ---------------*/
  13722. return temptransactionId;
  13723. }
  13724. void SetTransactionIdZero(int transactionId)
  13725. {
  13726. //TransactionId[gunindex] = 0;
  13727. char ch;
  13728. FILE *fptr1, *fptr2;
  13729. int temptransactionId = 0;
  13730. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13731. printf("\n Delete a specific line from a file :\n");
  13732. printf("-----------------------------------------\n");
  13733. //scanf("%s",fname);
  13734. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13735. if (!fptr1)
  13736. {
  13737. //printf(" File not found or unable to open the input file!!\n");
  13738. return ;
  13739. }
  13740. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13741. if (!fptr2)
  13742. {
  13743. printf("Unable to open a temporary file to write!!\n");
  13744. fclose(fptr1);
  13745. return ;
  13746. }
  13747. ch=fgetc(fptr1);
  13748. //printf(" Now the content of the file %s is : \n",fname);
  13749. rewind(fptr1);
  13750. if(ch!=EOF)
  13751. {
  13752. // copy all contents to the temporary file except the specific line
  13753. while (fgets(str, 100, fptr1) != NULL)
  13754. {
  13755. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13756. if(str[0]=='\0')
  13757. {
  13758. break;
  13759. }
  13760. char *revbuf[8] = {0}; //存放分割後的子字串
  13761. int num = 0;//分割後子字串的個數
  13762. strcpy(strtemp, str);
  13763. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13764. if(revbuf[2][0] != '\0')
  13765. {
  13766. temptransactionId = atoi(revbuf[2]);
  13767. if(transactionId != temptransactionId)
  13768. {
  13769. fprintf(fptr2, "%s", strtemp);
  13770. }
  13771. }
  13772. }
  13773. }
  13774. fclose(fptr1);
  13775. fclose(fptr2);
  13776. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13777. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13778. printf("\n Delete a specific line from a file End\n");
  13779. printf("-----------------------------------------\n");
  13780. /*------ Read the file ----------------*/
  13781. }
  13782. int InternetDisconnect(void)
  13783. {
  13784. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13785. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13786. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13787. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13788. }
  13789. void GetChargingProfileRequest(int gunindex)
  13790. {
  13791. mtrace();
  13792. //int connectorIdInt, durationInt;
  13793. //char chargingRateUnitStr[4]={0};
  13794. int tempdurationInt = 0;
  13795. int tempchargingProfileId = 0;
  13796. int tempstackLevel = 0;
  13797. int temptransactionId = 0;
  13798. float tempminChargingRateFloat = 0.0;
  13799. char tempchargingProfilePurposeStr[24]={0};
  13800. char tempchargingProfileKindStr[12]={0};
  13801. char temprecurrencyKindStr[8]={0};
  13802. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13803. char tempvalidToStr[28]={0};
  13804. int tempStartPeriodInt = 0;
  13805. float tempLimitInt = 0.0;//0.1;
  13806. int tempNumberPhasesInt=0;
  13807. char fname[200];
  13808. //char comfirmstr[20];
  13809. float MinChargingRate =0.0;
  13810. double diff_t;
  13811. struct tm tp;
  13812. FILE *fptr1;//, *fptr2;
  13813. int c = 0;
  13814. char * pch;
  13815. char *loc;
  13816. char sstr[200]={ 0 };
  13817. int n_chargingProfile = 0;
  13818. int n_SchedulePeriods = 0;
  13819. char SchedulePeriodList[10][200]={0};
  13820. char sLineWord[1600]={0};
  13821. char word[1000]={0};
  13822. int confirmPeriods = 0;
  13823. struct StructProfile ChargePointMaxProfile;
  13824. struct StructProfile TxDefaultProfile;
  13825. struct StructProfile TxProfile;
  13826. struct StructProfile TxDefaultProfiletemp[2]={0};
  13827. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13828. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13829. struct StructChargingProfile TxProfile_TEMP={0};
  13830. int TxDefaultProfileFileIsNull=FALSE;
  13831. int ChargePointMaxProfileIsNull=FALSE;
  13832. int TxProfileIsNull=FALSE;
  13833. // int CompositeSceduleIndex = 0;
  13834. char ChargePointMaxProfileScheduleStr[30]={0};
  13835. char TxDefaultProfileScheduleStr[30]={0};
  13836. char TxProfileScheduleStr[30]={0};
  13837. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13838. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13839. memset(&TxProfile,0,sizeof(struct StructProfile));
  13840. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13841. DEBUG_INFO("GetChargingProfileRequest\n");
  13842. //*****************************ChargePointMaxProfile******************************************/
  13843. strcpy(fname, ChargePointMaxProfile_JSON);
  13844. ChargePointMaxProfileIsNull=TRUE;
  13845. DEBUG_INFO("test 1\n");
  13846. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13847. {
  13848. fptr1 = fopen(fname, "r");
  13849. int c;
  13850. c = fgetc(fptr1);
  13851. //DEBUG_INFO("c:%d\n",c);
  13852. rewind(fptr1);
  13853. if(c == EOF)
  13854. {
  13855. DEBUG_INFO("\n End of file reached.");
  13856. ChargePointMaxProfileIsNull=TRUE;
  13857. fclose(fptr1);
  13858. }
  13859. else
  13860. {
  13861. DEBUG_INFO("test 2\n");
  13862. ChargePointMaxProfileIsNull=FALSE;
  13863. while(fscanf(fptr1, "%s", word) != EOF)
  13864. {
  13865. if(strcmp(word, "chargingProfileId") == 0)
  13866. {
  13867. n_chargingProfile = n_chargingProfile + 1;
  13868. }
  13869. }
  13870. rewind(fptr1);
  13871. //search Charging Profile Element
  13872. int i = 0;
  13873. int j = 0;
  13874. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13875. //***********chargingProfileId**************/
  13876. c = 0;
  13877. loc = strstr(sLineWord, "chargingProfileId");
  13878. //DEBUG_INFO("loc=%s\n",loc);
  13879. memset(sstr ,0, sizeof(sstr) );
  13880. if(loc != NULL)
  13881. {
  13882. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13883. {
  13884. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13885. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13886. c++;
  13887. }
  13888. sstr[c] = '\0';
  13889. tempchargingProfileId = atoi(sstr);
  13890. }
  13891. else
  13892. {
  13893. tempchargingProfileId = 0;
  13894. }
  13895. //***********stackLevel**************/
  13896. c = 0;
  13897. loc = strstr(sLineWord, "stackLevel");
  13898. //DEBUG_INFO("loc=%s\n",loc);
  13899. memset(sstr ,0, sizeof(sstr) );
  13900. if(loc != NULL)
  13901. {
  13902. while (loc[2+strlen("stackLevel")+c] != '\"')
  13903. {
  13904. sstr[c] = loc[2+strlen("stackLevel")+c];
  13905. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13906. c++;
  13907. }
  13908. sstr[c] = '\0';
  13909. tempstackLevel = atoi(sstr);
  13910. }
  13911. else
  13912. {
  13913. tempstackLevel = 0;
  13914. }
  13915. //***********chargingProfilePurpose **************/
  13916. c = 0;
  13917. loc = strstr(sLineWord, "chargingProfilePurpose");
  13918. //DEBUG_INFO("loc=%s\n",loc);
  13919. memset(sstr ,0, sizeof(sstr) );
  13920. if(loc != NULL)
  13921. {
  13922. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13923. {
  13924. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13925. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13926. c++;
  13927. }
  13928. sstr[c] = '\0';
  13929. strcpy(tempchargingProfilePurposeStr,sstr);
  13930. }
  13931. else
  13932. {
  13933. strcpy(tempchargingProfilePurposeStr,"");
  13934. }
  13935. //***********chargingProfileKind **************/
  13936. c = 0;
  13937. loc = strstr(sLineWord, "chargingProfileKind");
  13938. //DEBUG_INFO("loc=%s\n",loc);
  13939. memset(sstr ,0, sizeof(sstr) );
  13940. if(loc != NULL)
  13941. {
  13942. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13943. {
  13944. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13945. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13946. c++;
  13947. }
  13948. sstr[c] = '\0';
  13949. strcpy(tempchargingProfileKindStr,sstr);
  13950. }
  13951. else
  13952. {
  13953. strcpy(tempchargingProfileKindStr,"");
  13954. }
  13955. //***********recurrencyKind **************/
  13956. c = 0;
  13957. loc = strstr(sLineWord, "recurrencyKind");
  13958. //DEBUG_INFO("loc=%s\n",loc);
  13959. memset(sstr ,0, sizeof(sstr) );
  13960. if(loc != NULL)
  13961. {
  13962. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13963. {
  13964. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13965. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13966. c++;
  13967. }
  13968. sstr[c] = '\0';
  13969. strcpy(temprecurrencyKindStr,sstr);
  13970. }
  13971. else
  13972. {
  13973. strcpy(temprecurrencyKindStr,"");
  13974. }
  13975. //***********validFrom**************/
  13976. c = 0;
  13977. loc = strstr(sLineWord, "validFrom");
  13978. //DEBUG_INFO("loc=%s\n",loc);
  13979. memset(sstr ,0, sizeof(sstr) );
  13980. if(loc != NULL)
  13981. {
  13982. while (loc[3+strlen("validFrom")+c] != '\"')
  13983. {
  13984. sstr[c] = loc[3+strlen("validFrom")+c];
  13985. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13986. c++;
  13987. }
  13988. sstr[c] = '\0';
  13989. strcpy(tempvalidFromStr,sstr);
  13990. }
  13991. else
  13992. {
  13993. strcpy(tempvalidFromStr,"");
  13994. }
  13995. //***********validTo **************/
  13996. c = 0;
  13997. loc = strstr(sLineWord, "validTo");
  13998. //DEBUG_INFO("loc=%s\n",loc);
  13999. memset(sstr ,0, sizeof(sstr) );
  14000. if(loc != NULL)
  14001. {
  14002. while (loc[3+strlen("validTo")+c] != '\"')
  14003. {
  14004. sstr[c] = loc[3+strlen("validTo")+c];
  14005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14006. c++;
  14007. }
  14008. sstr[c] = '\0';
  14009. strcpy(tempvalidToStr,sstr);
  14010. }
  14011. else
  14012. {
  14013. strcpy(tempvalidToStr,"");
  14014. }
  14015. //***********validFrom**************/
  14016. c = 0;
  14017. loc = strstr(sLineWord, "validFrom");
  14018. if(loc != NULL)
  14019. {
  14020. memset(sstr ,0, sizeof(sstr) );
  14021. while (loc[3+strlen("validFrom")+c] != '\"')
  14022. {
  14023. sstr[c] = loc[3+strlen("validFrom")+c];
  14024. c++;
  14025. }
  14026. sstr[c] = '\0';
  14027. strcpy(tempvalidFromStr,sstr);
  14028. }
  14029. else
  14030. {
  14031. strcpy(tempvalidFromStr,"");
  14032. }
  14033. //***********validTo **************/
  14034. c = 0;
  14035. loc = strstr(sLineWord, "validTo");
  14036. if(loc != NULL)
  14037. {
  14038. memset(sstr ,0, sizeof(sstr) );
  14039. while (loc[3+strlen("validTo")+c] != '\"')
  14040. {
  14041. sstr[c] = loc[3+strlen("validTo")+c];
  14042. c++;
  14043. }
  14044. sstr[c] = '\0';
  14045. strcpy(tempvalidToStr,sstr);
  14046. }
  14047. else
  14048. {
  14049. strcpy(tempvalidToStr,"");
  14050. }
  14051. //***********duration**************/
  14052. c = 0;
  14053. loc = strstr(sLineWord, "duration");
  14054. if(loc != NULL)
  14055. {
  14056. memset(sstr ,0, sizeof(sstr) );
  14057. while (loc[2+strlen("duration")+c] != ',')
  14058. {
  14059. sstr[c] = loc[2+strlen("duration")+c];
  14060. c++;
  14061. }
  14062. sstr[c] = '\0';
  14063. tempdurationInt = atoi(sstr);
  14064. }
  14065. else
  14066. {
  14067. tempdurationInt = 0;
  14068. }
  14069. //**********startSchedule**********/
  14070. c = 0;
  14071. loc = strstr(sLineWord, "startSchedule");
  14072. if(loc != NULL)
  14073. {
  14074. memset(sstr ,0, sizeof(sstr) );
  14075. while (loc[3+strlen("startSchedule")+c] != '\"')
  14076. {
  14077. sstr[c] = loc[3+strlen("startSchedule")+c];
  14078. c++;
  14079. }
  14080. sstr[c] = '\0';
  14081. strcpy(tempstartScheduleStr, sstr);
  14082. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  14083. }
  14084. else
  14085. {
  14086. strcpy(tempstartScheduleStr, "");
  14087. strcpy(ChargePointMaxProfileScheduleStr, "");
  14088. }
  14089. //**********chargingRateUnit**********/
  14090. c = 0;
  14091. loc = strstr(sLineWord, "chargingRateUnit");
  14092. memset(sstr ,0, sizeof(sstr) );
  14093. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14094. {
  14095. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14096. c++;
  14097. }
  14098. sstr[c] = '\0';
  14099. strcpy(tempchargingRateUnitStr, sstr);
  14100. //**********minChargingRate*******/
  14101. c = 0;
  14102. loc = strstr(sLineWord, "minChargingRate");
  14103. if(loc != NULL)
  14104. {
  14105. memset(sstr ,0, sizeof(sstr) );
  14106. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14107. {
  14108. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14109. c++;
  14110. }
  14111. sstr[c] = '\0';
  14112. tempminChargingRateFloat = atof(sstr);
  14113. }
  14114. else
  14115. {
  14116. tempminChargingRateFloat = 0.0;
  14117. }
  14118. //
  14119. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14120. tp.tm_isdst = -1;
  14121. time_t utc = mktime(&tp);
  14122. time_t t = time(NULL);
  14123. diff_t = difftime(t, utc);
  14124. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14125. //parsing strings to words
  14126. i = 0;
  14127. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14128. loc = loc+3+strlen("chargingSchedulePeriod");
  14129. pch = strtok(loc ,"{");
  14130. while (pch != NULL)
  14131. {
  14132. strcpy(SchedulePeriodList[i], pch);
  14133. pch = strtok (NULL, "{");
  14134. i = i + 1;
  14135. }
  14136. n_SchedulePeriods = i;
  14137. for(int i=0;i<n_SchedulePeriods;i++)
  14138. {
  14139. //*************startPeriod****************/
  14140. c = 0;
  14141. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14142. memset(sstr ,0, sizeof(sstr) );
  14143. while (loc[strlen("startPeriod")+2+c] != ',')
  14144. {
  14145. sstr[c] = loc[strlen("startPeriod")+2+c];
  14146. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14147. c++;
  14148. }
  14149. sstr[c] = '\0';
  14150. tempStartPeriodInt = atoi(sstr);
  14151. //*************limit****************/
  14152. c = 0;
  14153. loc = strstr(SchedulePeriodList[i], "limit");
  14154. memset(sstr ,0, sizeof(sstr) );
  14155. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14156. {
  14157. sstr[c] = loc[strlen("limit")+2+c];
  14158. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14159. c++;
  14160. }
  14161. sstr[c] = '\0';
  14162. tempLimitInt = atof(sstr);
  14163. //*************numberPhases****************/
  14164. c = 0;
  14165. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14166. memset(sstr ,0, sizeof(sstr) );
  14167. if(loc != NULL)
  14168. {
  14169. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14170. {
  14171. sstr[c] = loc[strlen("numberPhases")+2+c];
  14172. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14173. c++;
  14174. }
  14175. sstr[c] = '\0';
  14176. tempNumberPhasesInt = atoi(sstr);
  14177. }
  14178. else
  14179. {
  14180. tempNumberPhasesInt = 0;
  14181. }
  14182. if(j == 0)
  14183. {
  14184. ChargePointMaxProfile.Duration = tempdurationInt;
  14185. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  14186. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  14187. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14188. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14189. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14190. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  14191. ChargePointMaxProfile_TEMP.TransactionId = 0;
  14192. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14193. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14194. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14195. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14196. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14197. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14198. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14199. }
  14200. }
  14201. if(MinChargingRate < tempminChargingRateFloat)
  14202. {
  14203. MinChargingRate = tempminChargingRateFloat;
  14204. }
  14205. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14206. if(confirmPeriods < n_SchedulePeriods)
  14207. {
  14208. confirmPeriods = n_SchedulePeriods;
  14209. }
  14210. j = j + 1;
  14211. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14212. fclose(fptr1);
  14213. }// end else
  14214. }// the end of access file ChargePointMaxProfile
  14215. DEBUG_INFO("test 3\n");
  14216. //****************************TxDefaultProfile************************************************/
  14217. memset(fname, 0, sizeof fname);
  14218. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  14219. TxDefaultProfileFileIsNull=TRUE;
  14220. if((access(fname,F_OK))!=-1)
  14221. {
  14222. fptr1 = fopen(fname, "r");
  14223. c = 0;
  14224. c = fgetc(fptr1);
  14225. //DEBUG_INFO("c:%d\n",c);
  14226. rewind(fptr1);
  14227. if(c == EOF)
  14228. {
  14229. DEBUG_INFO("\n End of file reached.");
  14230. TxDefaultProfileFileIsNull=TRUE;
  14231. fclose(fptr1);
  14232. }
  14233. else
  14234. {
  14235. TxDefaultProfileFileIsNull=FALSE;
  14236. while(fscanf(fptr1, "%s", word) != EOF)
  14237. {
  14238. if(strcmp(word, "chargingProfileId") == 0)
  14239. {
  14240. n_chargingProfile = n_chargingProfile + 1;
  14241. }
  14242. }
  14243. rewind(fptr1);
  14244. //search Charging Profile Element
  14245. int i = 0;
  14246. int j = 0;
  14247. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14248. {
  14249. #if 0
  14250. //***********connectorId****************/
  14251. c = 0;
  14252. loc = strstr(sLineWord, "connectorId");
  14253. memset(sstr ,0, sizeof(sstr) );
  14254. while (loc[strlen("connectorId")+2+c] != ',')
  14255. {
  14256. sstr[c] = loc[strlen("connectorId")+2+c];
  14257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14258. c++;
  14259. }
  14260. sstr[c] = '\0';
  14261. tempconnectorIdInt = atoi(sstr);
  14262. #endif
  14263. //***********chargingProfileId**************/
  14264. c = 0;
  14265. loc = strstr(sLineWord, "chargingProfileId");
  14266. //DEBUG_INFO("loc=%s\n",loc);
  14267. memset(sstr ,0, sizeof(sstr) );
  14268. if(loc != NULL)
  14269. {
  14270. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14271. {
  14272. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14273. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14274. c++;
  14275. }
  14276. sstr[c] = '\0';
  14277. tempchargingProfileId = atoi(sstr);
  14278. }
  14279. else
  14280. {
  14281. tempchargingProfileId = 0;
  14282. }
  14283. //***********stackLevel**************/
  14284. c = 0;
  14285. loc = strstr(sLineWord, "stackLevel");
  14286. //DEBUG_INFO("loc=%s\n",loc);
  14287. memset(sstr ,0, sizeof(sstr) );
  14288. if(loc != NULL)
  14289. {
  14290. while (loc[2+strlen("stackLevel")+c] != '\"')
  14291. {
  14292. sstr[c] = loc[2+strlen("stackLevel")+c];
  14293. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14294. c++;
  14295. }
  14296. sstr[c] = '\0';
  14297. tempstackLevel = atoi(sstr);
  14298. }
  14299. else
  14300. {
  14301. tempstackLevel = 0;
  14302. }
  14303. //***********chargingProfilePurpose **************/
  14304. c = 0;
  14305. loc = strstr(sLineWord, "chargingProfilePurpose");
  14306. //DEBUG_INFO("loc=%s\n",loc);
  14307. memset(sstr ,0, sizeof(sstr) );
  14308. if(loc != NULL)
  14309. {
  14310. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14311. {
  14312. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14313. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14314. c++;
  14315. }
  14316. sstr[c] = '\0';
  14317. strcpy(tempchargingProfilePurposeStr,sstr);
  14318. }
  14319. else
  14320. {
  14321. strcpy(tempchargingProfilePurposeStr,"");
  14322. }
  14323. //***********chargingProfileKind **************/
  14324. c = 0;
  14325. loc = strstr(sLineWord, "chargingProfileKind");
  14326. //DEBUG_INFO("loc=%s\n",loc);
  14327. memset(sstr ,0, sizeof(sstr) );
  14328. if(loc != NULL)
  14329. {
  14330. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14331. {
  14332. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14333. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14334. c++;
  14335. }
  14336. sstr[c] = '\0';
  14337. strcpy(tempchargingProfileKindStr,sstr);
  14338. }
  14339. else
  14340. {
  14341. strcpy(tempchargingProfileKindStr,"");
  14342. }
  14343. //***********recurrencyKind **************/
  14344. c = 0;
  14345. loc = strstr(sLineWord, "recurrencyKind");
  14346. //DEBUG_INFO("loc=%s\n",loc);
  14347. memset(sstr ,0, sizeof(sstr) );
  14348. if(loc != NULL)
  14349. {
  14350. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14351. {
  14352. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14353. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14354. c++;
  14355. }
  14356. sstr[c] = '\0';
  14357. strcpy(temprecurrencyKindStr,sstr);
  14358. }
  14359. else
  14360. {
  14361. strcpy(temprecurrencyKindStr,"");
  14362. }
  14363. //***********validFrom**************/
  14364. c = 0;
  14365. loc = strstr(sLineWord, "validFrom");
  14366. if(loc != NULL)
  14367. {
  14368. memset(sstr ,0, sizeof(sstr) );
  14369. while (loc[3+strlen("validFrom")+c] != '\"')
  14370. {
  14371. sstr[c] = loc[3+strlen("validFrom")+c];
  14372. c++;
  14373. }
  14374. sstr[c] = '\0';
  14375. strcpy(tempvalidFromStr,sstr);
  14376. }
  14377. else
  14378. {
  14379. strcpy(tempvalidFromStr,"");
  14380. }
  14381. //***********validTo **************/
  14382. c = 0;
  14383. loc = strstr(sLineWord, "validTo");
  14384. if(loc != NULL)
  14385. {
  14386. memset(sstr ,0, sizeof(sstr) );
  14387. while (loc[3+strlen("validTo")+c] != '\"')
  14388. {
  14389. sstr[c] = loc[3+strlen("validTo")+c];
  14390. c++;
  14391. }
  14392. sstr[c] = '\0';
  14393. strcpy(tempvalidToStr,sstr);
  14394. }
  14395. else
  14396. {
  14397. strcpy(tempvalidToStr,"");
  14398. }
  14399. //***********duration**************/
  14400. c = 0;
  14401. loc = strstr(sLineWord, "duration");
  14402. if(loc != NULL)
  14403. {
  14404. memset(sstr ,0, sizeof(sstr) );
  14405. while (loc[2+strlen("duration")+c] != ',')
  14406. {
  14407. sstr[c] = loc[2+strlen("duration")+c];
  14408. c++;
  14409. }
  14410. sstr[c] = '\0';
  14411. tempdurationInt = atoi(sstr);
  14412. }
  14413. else
  14414. {
  14415. tempdurationInt = 0;
  14416. }
  14417. //**********startSchedule**********/
  14418. c = 0;
  14419. loc = strstr(sLineWord, "startSchedule");
  14420. if(loc != NULL)
  14421. {
  14422. memset(sstr ,0, sizeof(sstr) );
  14423. while (loc[3+strlen("startSchedule")+c] != '\"')
  14424. {
  14425. sstr[c] = loc[3+strlen("startSchedule")+c];
  14426. c++;
  14427. }
  14428. sstr[c] = '\0';
  14429. strcpy(tempstartScheduleStr, sstr);
  14430. strcpy(TxDefaultProfileScheduleStr, sstr);
  14431. }
  14432. else
  14433. {
  14434. strcpy(tempstartScheduleStr, "");
  14435. strcpy(TxDefaultProfileScheduleStr, "");
  14436. }
  14437. //**********chargingRateUnit**********/
  14438. c = 0;
  14439. loc = strstr(sLineWord, "chargingRateUnit");
  14440. memset(sstr ,0, sizeof(sstr) );
  14441. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14442. {
  14443. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14444. c++;
  14445. }
  14446. sstr[c] = '\0';
  14447. strcpy(tempchargingRateUnitStr, sstr);
  14448. //**********minChargingRate*******/
  14449. c = 0;
  14450. loc = strstr(sLineWord, "minChargingRate");
  14451. if(loc != NULL)
  14452. {
  14453. memset(sstr ,0, sizeof(sstr) );
  14454. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14455. {
  14456. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14457. c++;
  14458. }
  14459. sstr[c] = '\0';
  14460. tempminChargingRateFloat = atof(sstr);
  14461. }
  14462. else
  14463. {
  14464. tempminChargingRateFloat = 0.0;
  14465. }
  14466. //
  14467. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14468. tp.tm_isdst = -1;
  14469. time_t utc = mktime(&tp);
  14470. time_t t = time(NULL);
  14471. diff_t = difftime(t, utc);
  14472. printf("diff between startScheduleStr and now =%f\n",diff_t);
  14473. //parsing strings to words
  14474. i = 0;
  14475. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14476. loc = loc+3+strlen("chargingSchedulePeriod");
  14477. pch = strtok(loc ,"{");
  14478. while (pch != NULL)
  14479. {
  14480. strcpy(SchedulePeriodList[i], pch);
  14481. pch = strtok (NULL, "{");
  14482. i = i + 1;
  14483. }
  14484. n_SchedulePeriods = i;
  14485. for(int i=0;i<n_SchedulePeriods;i++)
  14486. {
  14487. //*************startPeriod****************/
  14488. c = 0;
  14489. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14490. memset(sstr ,0, sizeof(sstr) );
  14491. while (loc[strlen("startPeriod")+2+c] != ',')
  14492. {
  14493. sstr[c] = loc[strlen("startPeriod")+2+c];
  14494. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14495. c++;
  14496. }
  14497. sstr[c] = '\0';
  14498. tempStartPeriodInt = atoi(sstr);
  14499. //*************limit****************/
  14500. c = 0;
  14501. loc = strstr(SchedulePeriodList[i], "limit");
  14502. memset(sstr ,0, sizeof(sstr) );
  14503. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14504. {
  14505. sstr[c] = loc[strlen("limit")+2+c];
  14506. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14507. c++;
  14508. }
  14509. sstr[c] = '\0';
  14510. tempLimitInt = atof(sstr);
  14511. //*************numberPhases****************/
  14512. c = 0;
  14513. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14514. memset(sstr ,0, sizeof(sstr) );
  14515. if(loc != NULL)
  14516. {
  14517. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14518. {
  14519. sstr[c] = loc[strlen("numberPhases")+2+c];
  14520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14521. c++;
  14522. }
  14523. sstr[c] = '\0';
  14524. tempNumberPhasesInt = atoi(sstr);
  14525. }
  14526. else
  14527. {
  14528. tempNumberPhasesInt = 0;
  14529. }
  14530. if(j == 0)
  14531. {
  14532. TxDefaultProfile.Duration = tempdurationInt;
  14533. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  14534. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  14535. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14536. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14537. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14538. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  14539. TxDefaultProfile_TEMP.TransactionId = 0;
  14540. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14541. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14542. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14543. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14544. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14545. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14546. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14547. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14548. }
  14549. else
  14550. {
  14551. //other stack level charging Profile
  14552. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  14553. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  14554. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  14555. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  14556. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  14557. }
  14558. }
  14559. if(MinChargingRate < tempminChargingRateFloat)
  14560. {
  14561. MinChargingRate = tempminChargingRateFloat;
  14562. }
  14563. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14564. if(confirmPeriods < n_SchedulePeriods)
  14565. confirmPeriods = n_SchedulePeriods;
  14566. j = j + 1;
  14567. }
  14568. fclose(fptr1);
  14569. //Stacking Charging Profiles
  14570. for(int l=0; l <(j-1) ;l++)
  14571. {
  14572. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  14573. {
  14574. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  14575. {
  14576. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  14577. {
  14578. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  14579. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  14580. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  14581. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14582. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14583. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14584. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14585. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14586. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14587. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14588. }
  14589. else
  14590. {
  14591. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14592. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14593. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14594. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14595. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14596. }
  14597. }
  14598. }
  14599. }//end of Stacking Charging Profiles
  14600. }// end else
  14601. }// the end of ACCESS TxDefaultProfile
  14602. //****************************TxProfile************************************************/
  14603. memset(fname, 0, sizeof fname);
  14604. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  14605. TxProfileIsNull=TRUE;
  14606. if((access(fname,F_OK))!=-1)
  14607. {
  14608. fptr1 = fopen(fname, "r");
  14609. c = 0;
  14610. c = fgetc(fptr1);
  14611. //DEBUG_INFO("c:%d\n",c);
  14612. rewind(fptr1);
  14613. if(c == EOF)
  14614. {
  14615. DEBUG_INFO("\n End of file reached.");
  14616. TxProfileIsNull=TRUE;
  14617. fclose(fptr1);
  14618. }
  14619. else
  14620. {
  14621. TxProfileIsNull=FALSE;
  14622. while(fscanf(fptr1, "%s", word) != EOF)
  14623. {
  14624. if(strcmp(word, "chargingProfileId") == 0)
  14625. {
  14626. n_chargingProfile = n_chargingProfile + 1;
  14627. }
  14628. }
  14629. rewind(fptr1);
  14630. //search Charging Profile Element
  14631. int i= 0;
  14632. int j= 0;
  14633. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14634. #if 0
  14635. /***********connectorId****************/
  14636. c = 0;
  14637. loc = strstr(sLineWord, "connectorId");
  14638. memset(sstr ,0, sizeof(sstr) );
  14639. while (loc[strlen("connectorId")+2+c] != ',')
  14640. {
  14641. sstr[c] = loc[strlen("connectorId")+2+c];
  14642. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14643. c++;
  14644. }
  14645. sstr[c] = '\0';
  14646. tempconnectorIdInt = atoi(sstr);
  14647. #endif
  14648. //***********chargingProfileId**************/
  14649. c = 0;
  14650. loc = strstr(sLineWord, "chargingProfileId");
  14651. memset(sstr ,0, sizeof(sstr) );
  14652. if(loc != NULL)
  14653. {
  14654. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14655. {
  14656. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14657. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14658. c++;
  14659. }
  14660. sstr[c] = '\0';
  14661. tempchargingProfileId = atoi(sstr);
  14662. }
  14663. else
  14664. {
  14665. tempchargingProfileId = 0;
  14666. }
  14667. //***********transactionId **************/
  14668. c = 0;
  14669. loc = strstr(sLineWord, "transactionId");
  14670. //DEBUG_INFO("loc=%s\n",loc);
  14671. memset(sstr ,0, sizeof(sstr) );
  14672. if(loc != NULL)
  14673. {
  14674. while (loc[2+strlen("transactionId")+c] != '\"')
  14675. {
  14676. sstr[c] = loc[2+strlen("transactionId")+c];
  14677. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14678. c++;
  14679. }
  14680. sstr[c] = '\0';
  14681. temptransactionId = atoi(sstr);
  14682. }
  14683. else
  14684. {
  14685. temptransactionId = 0;
  14686. }
  14687. //***********stackLevel**************/
  14688. c = 0;
  14689. loc = strstr(sLineWord, "stackLevel");
  14690. //DEBUG_INFO("loc=%s\n",loc);
  14691. memset(sstr ,0, sizeof(sstr) );
  14692. if(loc != NULL)
  14693. {
  14694. while (loc[2+strlen("stackLevel")+c] != '\"')
  14695. {
  14696. sstr[c] = loc[2+strlen("stackLevel")+c];
  14697. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14698. c++;
  14699. }
  14700. sstr[c] = '\0';
  14701. tempstackLevel = atoi(sstr);
  14702. }
  14703. else
  14704. {
  14705. tempstackLevel = 0;
  14706. }
  14707. //***********chargingProfilePurpose **************/
  14708. c = 0;
  14709. loc = strstr(sLineWord, "chargingProfilePurpose");
  14710. //DEBUG_INFO("loc=%s\n",loc);
  14711. memset(sstr ,0, sizeof(sstr) );
  14712. if(loc != NULL)
  14713. {
  14714. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14715. {
  14716. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14717. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14718. c++;
  14719. }
  14720. sstr[c] = '\0';
  14721. strcpy(tempchargingProfilePurposeStr,sstr);
  14722. }
  14723. else
  14724. {
  14725. strcpy(tempchargingProfilePurposeStr,"");
  14726. }
  14727. //***********chargingProfileKind **************/
  14728. c = 0;
  14729. loc = strstr(sLineWord, "chargingProfileKind");
  14730. //DEBUG_INFO("loc=%s\n",loc);
  14731. memset(sstr ,0, sizeof(sstr) );
  14732. if(loc != NULL)
  14733. {
  14734. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14735. {
  14736. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14737. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14738. c++;
  14739. }
  14740. sstr[c] = '\0';
  14741. strcpy(tempchargingProfileKindStr,sstr);
  14742. }
  14743. else
  14744. {
  14745. strcpy(tempchargingProfileKindStr,"");
  14746. }
  14747. //***********recurrencyKind **************/
  14748. c = 0;
  14749. loc = strstr(sLineWord, "recurrencyKind");
  14750. //DEBUG_INFO("loc=%s\n",loc);
  14751. memset(sstr ,0, sizeof(sstr) );
  14752. if(loc != NULL)
  14753. {
  14754. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14755. {
  14756. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14757. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14758. c++;
  14759. }
  14760. sstr[c] = '\0';
  14761. strcpy(temprecurrencyKindStr,sstr);
  14762. }
  14763. else
  14764. {
  14765. strcpy(temprecurrencyKindStr,"");
  14766. }
  14767. //***********validFrom**************/
  14768. c = 0;
  14769. loc = strstr(sLineWord, "validFrom");
  14770. if(loc != NULL)
  14771. {
  14772. memset(sstr ,0, sizeof(sstr) );
  14773. while (loc[3+strlen("validFrom")+c] != '\"')
  14774. {
  14775. sstr[c] = loc[3+strlen("validFrom")+c];
  14776. c++;
  14777. }
  14778. sstr[c] = '\0';
  14779. strcpy(tempvalidFromStr,sstr);
  14780. }
  14781. else
  14782. {
  14783. strcpy(tempvalidFromStr,"");
  14784. }
  14785. //***********validTo**************/
  14786. c = 0;
  14787. loc = strstr(sLineWord, "validTo");
  14788. if(loc != NULL)
  14789. {
  14790. memset(sstr ,0, sizeof(sstr) );
  14791. while (loc[3+strlen("validTo")+c] != '\"')
  14792. {
  14793. sstr[c] = loc[3+strlen("validTo")+c];
  14794. c++;
  14795. }
  14796. sstr[c] = '\0';
  14797. strcpy(tempvalidToStr,sstr);
  14798. }
  14799. else
  14800. {
  14801. strcpy(tempvalidToStr,"");
  14802. }
  14803. //***********duration**************/
  14804. c = 0;
  14805. loc = strstr(sLineWord, "duration");
  14806. //DEBUG_INFO("loc=%s\n",loc);
  14807. memset(sstr ,0, sizeof(sstr) );
  14808. if(loc != NULL)
  14809. {
  14810. while (loc[2+strlen("duration")+c] != '\"')
  14811. {
  14812. sstr[c] = loc[2+strlen("duration")+c];
  14813. c++;
  14814. }
  14815. sstr[c] = '\0';
  14816. tempdurationInt = atoi(sstr);
  14817. }
  14818. else
  14819. {
  14820. tempdurationInt = 0;
  14821. }
  14822. //**********startSchedule**********/
  14823. c = 0;
  14824. loc = strstr(sLineWord, "startSchedule");
  14825. if(loc != NULL)
  14826. {
  14827. memset(sstr ,0, sizeof(sstr) );
  14828. while (loc[3+strlen("startSchedule")+c] != '\"')
  14829. {
  14830. sstr[c] = loc[3+strlen("startSchedule")+c];
  14831. c++;
  14832. }
  14833. sstr[c] = '\0';
  14834. strcpy(tempstartScheduleStr, sstr);
  14835. strcpy(TxProfileScheduleStr, sstr);
  14836. }
  14837. else
  14838. {
  14839. strcpy(tempstartScheduleStr, "");
  14840. strcpy(TxProfileScheduleStr, "");
  14841. }
  14842. //**********chargingRateUnit**********/
  14843. c = 0;
  14844. loc = strstr(sLineWord, "chargingRateUnit");
  14845. memset(sstr ,0, sizeof(sstr) );
  14846. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14847. {
  14848. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14849. c++;
  14850. }
  14851. sstr[c] = '\0';
  14852. strcpy(tempchargingRateUnitStr, sstr);
  14853. //**********minChargingRate*******/
  14854. c = 0;
  14855. loc = strstr(sLineWord, "minChargingRate");
  14856. if(loc != NULL)
  14857. {
  14858. memset(sstr ,0, sizeof(sstr) );
  14859. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14860. {
  14861. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14862. c++;
  14863. }
  14864. sstr[c] = '\0';
  14865. tempminChargingRateFloat = atof(sstr);
  14866. }
  14867. else
  14868. {
  14869. tempminChargingRateFloat = 0.0;
  14870. }
  14871. //
  14872. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14873. tp.tm_isdst = -1;
  14874. time_t utc = mktime(&tp);
  14875. time_t t = time(NULL);
  14876. diff_t = difftime(t, utc);
  14877. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14878. //parsing strings to words
  14879. i = 0;
  14880. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14881. loc = loc+3+strlen("chargingSchedulePeriod");
  14882. pch = strtok(loc ,"{");
  14883. while (pch != NULL)
  14884. {
  14885. strcpy(SchedulePeriodList[i], pch);
  14886. pch = strtok (NULL, "{");
  14887. i = i + 1;
  14888. }
  14889. n_SchedulePeriods = i;
  14890. for(int i=0;i<n_SchedulePeriods;i++)
  14891. {
  14892. //*************startPeriod****************/
  14893. c = 0;
  14894. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14895. memset(sstr ,0, sizeof(sstr) );
  14896. while (loc[strlen("startPeriod")+2+c] != ',')
  14897. {
  14898. sstr[c] = loc[strlen("startPeriod")+2+c];
  14899. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14900. c++;
  14901. }
  14902. sstr[c] = '\0';
  14903. tempStartPeriodInt = atoi(sstr);
  14904. //*************limit****************/
  14905. c = 0;
  14906. loc = strstr(SchedulePeriodList[i], "limit");
  14907. memset(sstr ,0, sizeof(sstr) );
  14908. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14909. {
  14910. sstr[c] = loc[strlen("limit")+2+c];
  14911. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14912. c++;
  14913. }
  14914. sstr[c] = '\0';
  14915. tempLimitInt = atof(sstr);
  14916. //*************numberPhases****************/
  14917. c = 0;
  14918. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14919. memset(sstr ,0, sizeof(sstr) );
  14920. if(loc != NULL)
  14921. {
  14922. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14923. {
  14924. sstr[c] = loc[strlen("numberPhases")+2+c];
  14925. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14926. c++;
  14927. }
  14928. sstr[c] = '\0';
  14929. tempNumberPhasesInt = atoi(sstr);
  14930. }
  14931. else
  14932. {
  14933. tempNumberPhasesInt = 0;
  14934. }
  14935. //TxProfile.Duration = durationInt;
  14936. TxProfile.TotalPeriod = n_SchedulePeriods;
  14937. TxProfile.Period[i].Limit = tempLimitInt;
  14938. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14939. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14940. }
  14941. if(MinChargingRate < tempminChargingRateFloat)
  14942. {
  14943. MinChargingRate = tempminChargingRateFloat;
  14944. }
  14945. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14946. if(confirmPeriods < n_SchedulePeriods)
  14947. confirmPeriods = n_SchedulePeriods;
  14948. if(j == 0)
  14949. {
  14950. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14951. TxProfile_TEMP.StackLevel = tempstackLevel;
  14952. TxProfile_TEMP.TransactionId = 0;
  14953. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14954. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14955. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14956. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14957. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14958. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14959. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14960. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14961. }
  14962. }
  14963. fclose(fptr1);
  14964. }
  14965. }// the end of ACCESS TxProfile
  14966. //-----------------------------------------------CompositeSchedule--------------------------//
  14967. int period=0;
  14968. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14969. {
  14970. //TxProfile
  14971. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14972. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14973. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14974. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14975. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14976. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14977. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14978. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14979. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14980. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14981. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14982. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14983. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14984. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14985. {
  14986. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14987. {
  14988. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14989. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14990. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14991. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14992. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14993. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14994. period = period + 1;
  14995. }
  14996. else
  14997. {
  14998. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14999. {
  15000. }
  15001. else
  15002. {
  15003. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15004. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15005. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15006. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15007. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15008. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15009. period = period + 1;
  15010. }
  15011. }
  15012. }
  15013. struct tm tp;
  15014. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15015. tp.tm_isdst = -1;
  15016. time_t utc = mktime(&tp);
  15017. time_t t = time(NULL);
  15018. double diff_f = difftime(t, utc);
  15019. int diff_i;// = (int)diff_f;
  15020. int quotient; // = diff_i / 86400;//86400 seconds/day
  15021. if(diff_f >= 0)
  15022. {
  15023. diff_i = (int)diff_f;
  15024. quotient = diff_i / 86400;//86400 seconds/day
  15025. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15026. {
  15027. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  15028. {
  15029. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15030. {
  15031. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15032. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15033. }
  15034. else
  15035. {
  15036. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15037. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15038. }
  15039. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15040. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15041. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15042. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15043. period = period + 1;
  15044. }
  15045. }
  15046. }// end of if(diff_f >= 0)
  15047. }
  15048. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15049. {
  15050. //TxDefaultProfile
  15051. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15052. struct tm tp;
  15053. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15054. tp.tm_isdst = -1;
  15055. time_t utc = mktime(&tp);
  15056. time_t t = time(NULL);
  15057. double diff_f = difftime(t, utc);
  15058. int diff_i;// = (int)diff_f;
  15059. int quotient; // = diff_i / 86400;//86400 seconds/day
  15060. int remainder;
  15061. //---- Define StartSchedule----/
  15062. struct tm *gtime;
  15063. time_t now;
  15064. char buf[28];
  15065. //---Read the current system time---/
  15066. time(&now);
  15067. //---Convert the system time to GMT (now UTC)---/
  15068. gtime = gmtime(&now);
  15069. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15070. if(diff_f >= 0)
  15071. {
  15072. diff_i = (int)diff_f;
  15073. quotient = diff_i / 86400;//86400 seconds/day
  15074. remainder = diff_i % 86400;
  15075. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15076. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15077. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15078. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  15079. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15080. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15081. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15082. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15083. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15084. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15085. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15086. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15087. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  15088. {
  15089. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15090. {
  15091. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15092. {
  15093. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15094. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15095. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15096. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15097. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15098. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15099. period = period + 1;
  15100. }
  15101. else
  15102. {
  15103. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15104. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15105. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15106. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  15107. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15108. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15109. period = period + 1;
  15110. }
  15111. }
  15112. }
  15113. } // end of diff_f >= 0
  15114. }
  15115. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  15116. {
  15117. //TxDefaultProfile
  15118. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15119. struct tm tp;
  15120. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15121. tp.tm_isdst = -1;
  15122. time_t utc = mktime(&tp);
  15123. time_t t = time(NULL);
  15124. double diff_f = difftime(t, utc);
  15125. int diff_i;// = (int)diff_f;
  15126. int quotient; // = diff_i / 86400;//86400 seconds/day
  15127. int remainder;
  15128. //---- Define StartSchedule----/
  15129. struct tm *gtime;
  15130. time_t now;
  15131. char buf[28];
  15132. //---Read the current system time---/
  15133. time(&now);
  15134. //---Convert the system time to GMT (now UTC)---/
  15135. gtime = gmtime(&now);
  15136. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15137. if(diff_f >= 0)
  15138. {
  15139. diff_i = (int)diff_f;
  15140. quotient = diff_i / 86400;//86400 seconds/day
  15141. remainder = diff_i % 86400;
  15142. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15143. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15144. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15145. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  15146. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15147. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15148. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15149. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15150. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15151. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  15152. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15153. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15154. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15155. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15156. {
  15157. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15158. {
  15159. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15160. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15161. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15162. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15163. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15164. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15165. period = period + 1;
  15166. }
  15167. }
  15168. } //end of diff_f >= 0
  15169. }
  15170. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15171. {
  15172. //ChargePointMaxProfile
  15173. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  15174. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  15175. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15176. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  15177. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  15178. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15179. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15180. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  15181. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  15182. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  15183. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  15184. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  15185. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  15186. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  15187. {
  15188. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  15189. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  15190. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  15191. period = period + 1;
  15192. }
  15193. }
  15194. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  15195. {
  15196. //TxProfile Daily
  15197. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  15198. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  15199. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  15200. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  15201. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15202. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15203. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15204. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15205. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15206. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15207. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15208. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15209. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15210. for(int l=0; l< TxProfile.TotalPeriod; l++)
  15211. {
  15212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  15213. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  15214. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  15215. }
  15216. }
  15217. confirmPeriods = period;
  15218. if(confirmPeriods != 0)
  15219. {
  15220. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  15221. 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,"
  15222. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  15223. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  15224. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  15225. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  15226. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  15227. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  15228. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  15229. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  15230. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  15231. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  15232. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  15233. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  15234. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  15235. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  15236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  15237. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  15238. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  15239. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  15240. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  15241. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  15242. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  15243. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  15244. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  15245. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  15246. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  15247. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  15248. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  15249. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  15250. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  15251. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  15252. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  15253. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  15254. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  15255. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  15256. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  15257. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  15258. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  15259. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  15260. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  15261. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  15262. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  15263. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  15264. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  15265. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  15266. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  15267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  15268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  15269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  15270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  15271. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  15272. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  15273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  15274. }
  15275. }
  15276. void storeTempStopTransaction(int gun_index)
  15277. {
  15278. //int result = FAIL;
  15279. //char message[1500]={0};
  15280. char guid[37]={0};
  15281. int tempIndex = 0;
  15282. //char tempdata[65]={0};
  15283. //int idx_sample=0;
  15284. DEBUG_ERROR("sendStopTransactionRequest \n");
  15285. memset(queuedata, 0, sizeof(queuedata));
  15286. //ENERGY_ACTIVE_IMPORT_REGISTER
  15287. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15288. if(gunType[gun_index] == 'J')
  15289. {
  15290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15291. {
  15292. tempIndex = ((gun_index==2) ? 1: 0);
  15293. }
  15294. else
  15295. {
  15296. tempIndex = gun_index;
  15297. }
  15298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15299. {
  15300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15301. {
  15302. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  15303. }
  15304. }// END OF CHAdeMO_QUANTITY
  15305. }
  15306. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15307. {
  15308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15309. {
  15310. tempIndex = ((gun_index==2) ? 1: 0);
  15311. }
  15312. else
  15313. {
  15314. tempIndex = gun_index;
  15315. }
  15316. for (int index = 0; index < CCS_QUANTITY; index++)
  15317. {
  15318. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15319. {
  15320. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  15321. }
  15322. }// END OF CCS_QUANTITY
  15323. }
  15324. else if(gunType[gun_index] == 'G')
  15325. {
  15326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15327. {
  15328. tempIndex = ((gun_index==2) ? 1: 0);
  15329. }
  15330. else
  15331. {
  15332. tempIndex = gun_index;
  15333. }
  15334. for (int index = 0; index < GB_QUANTITY; index++)
  15335. {
  15336. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15337. {
  15338. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  15339. }
  15340. }// END OF GB_QUANTITY
  15341. }
  15342. else
  15343. {
  15344. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15345. {
  15346. tempIndex = 2;
  15347. }
  15348. else
  15349. {
  15350. tempIndex = gun_index;
  15351. }
  15352. for (int index = 0; index < AC_QUANTITY; index++)
  15353. {
  15354. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15355. {
  15356. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  15357. }
  15358. }// END OF AC_QUANTITY
  15359. }
  15360. //Stop Transaction Time
  15361. struct timeval tmnow;
  15362. struct tm *tm;
  15363. char buf[28];//, usec_buf[6];
  15364. gettimeofday(&tmnow, NULL);
  15365. time_t t;
  15366. t = time(NULL);
  15367. /*UTC time and date*/
  15368. tm = gmtime(&t);
  15369. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15371. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15372. random_uuid(guid);
  15373. /***********************************transactionData******************************************************/
  15374. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  15375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15376. //=================================
  15377. // Transaction_Begin
  15378. //=================================
  15379. // Energy.Active.Export.Interval
  15380. //idx_sample=0;
  15381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  15382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15384. 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*/]);
  15385. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15386. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15387. {
  15388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15389. }
  15390. else
  15391. {
  15392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15393. }
  15394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15396. //=================================
  15397. // Transaction_End
  15398. //=================================
  15399. //Current.Export
  15400. //idx_sample=1;
  15401. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15402. if(gunType[gun_index] == 'J')
  15403. {
  15404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15405. {
  15406. tempIndex = ((gun_index==2) ? 1: 0);
  15407. }
  15408. else
  15409. {
  15410. tempIndex = gun_index;
  15411. }
  15412. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15413. {
  15414. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15415. {
  15416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15417. }
  15418. }// End of for CHAdeMO_QUANTITY
  15419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15420. }
  15421. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15422. {
  15423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15424. {
  15425. tempIndex = ((gun_index==2) ? 1: 0);
  15426. }
  15427. else
  15428. {
  15429. tempIndex = gun_index;
  15430. }
  15431. for (int index = 0; index < CCS_QUANTITY; index++)
  15432. {
  15433. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15434. {
  15435. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15436. }
  15437. }// End of for CCS_QUANTITY
  15438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15439. }
  15440. else if(gunType[gun_index] == 'G')
  15441. {
  15442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15443. {
  15444. tempIndex = ((gun_index==2) ? 1: 0);
  15445. }
  15446. else
  15447. {
  15448. tempIndex = gun_index;
  15449. }
  15450. for (int index = 0; index < GB_QUANTITY; index++)
  15451. {
  15452. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15453. {
  15454. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15455. }
  15456. }// End of for GB_QUANTITY
  15457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15458. }
  15459. else
  15460. {
  15461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15462. {
  15463. tempIndex = 2;
  15464. }
  15465. else
  15466. {
  15467. tempIndex = gun_index;
  15468. }
  15469. for (int index = 0; index < AC_QUANTITY; index++)
  15470. {
  15471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15472. {
  15473. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15474. }
  15475. }// End of for AC_QUANTITY
  15476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15477. }
  15478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15481. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15484. //Energy.Active.Export.Interval
  15485. //idx_sample=2;
  15486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15487. if(gunType[gun_index] == 'J')
  15488. {
  15489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15490. {
  15491. tempIndex = ((gun_index==2) ? 1: 0);
  15492. }
  15493. else
  15494. {
  15495. tempIndex = gun_index;
  15496. }
  15497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15498. {
  15499. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15500. {
  15501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15502. }
  15503. }// END OF CHAdeMO_QUANTITY
  15504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15505. }
  15506. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15507. {
  15508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15509. {
  15510. tempIndex = ((gun_index==2) ? 1: 0);
  15511. }
  15512. else
  15513. {
  15514. tempIndex = gun_index;
  15515. }
  15516. for (int index = 0; index < CCS_QUANTITY; index++)
  15517. {
  15518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15519. {
  15520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15521. }
  15522. }// END OF CCS_QUANTITY
  15523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15524. }
  15525. else if(gunType[gun_index] == 'G')
  15526. {
  15527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15528. {
  15529. tempIndex = ((gun_index==2) ? 1: 0);
  15530. }
  15531. else
  15532. {
  15533. tempIndex = gun_index;
  15534. }
  15535. for (int index = 0; index < GB_QUANTITY; index++)
  15536. {
  15537. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15538. {
  15539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15540. }
  15541. }// END OF GB_QUANTITY
  15542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15543. }
  15544. else
  15545. {
  15546. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15547. {
  15548. tempIndex = 2;
  15549. }
  15550. else
  15551. {
  15552. tempIndex = gun_index;
  15553. }
  15554. for (int index = 0; index < AC_QUANTITY; index++)
  15555. {
  15556. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15557. {
  15558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15559. }
  15560. }// END OF AC_QUANTITY
  15561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15562. }
  15563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15566. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15569. //Power.Active.Export
  15570. //idx_sample=3;
  15571. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15572. if(gunType[gun_index] == 'J')
  15573. {
  15574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15575. {
  15576. tempIndex = ((gun_index==2) ? 1: 0);
  15577. }
  15578. else
  15579. {
  15580. tempIndex = gun_index;
  15581. }
  15582. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15583. {
  15584. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15585. {
  15586. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15587. }
  15588. } // End for CHAdeMO_QUANTITY
  15589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15590. }
  15591. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15592. {
  15593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15594. {
  15595. tempIndex = ((gun_index==2) ? 1: 0);
  15596. }
  15597. else
  15598. {
  15599. tempIndex = gun_index;
  15600. }
  15601. for (int index = 0; index < CCS_QUANTITY; index++)
  15602. {
  15603. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15604. {
  15605. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15606. }
  15607. } // END for CCS_QUANTITY
  15608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15609. }
  15610. else if(gunType[gun_index] == 'G')
  15611. {
  15612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15613. {
  15614. tempIndex = ((gun_index==2) ? 1: 0);
  15615. }
  15616. else
  15617. {
  15618. tempIndex = gun_index;
  15619. }
  15620. for (int index = 0; index < GB_QUANTITY; index++)
  15621. {
  15622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15623. {
  15624. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15625. }
  15626. }// END for GB_QUANTITY
  15627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15628. }
  15629. else
  15630. {
  15631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15632. {
  15633. tempIndex = 2;
  15634. }
  15635. else
  15636. {
  15637. tempIndex = gun_index;
  15638. }
  15639. for (int index = 0; index < AC_QUANTITY; index++)
  15640. {
  15641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15642. {
  15643. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15644. }
  15645. } // END for AC_QUANTITY
  15646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15647. }
  15648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15651. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15654. //Voltage
  15655. //idx_sample=4;
  15656. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15657. if(gunType[gun_index] == 'J')
  15658. {
  15659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15660. {
  15661. tempIndex = ((gun_index==2) ? 1: 0);
  15662. }
  15663. else
  15664. {
  15665. tempIndex = gun_index;
  15666. }
  15667. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15668. {
  15669. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15670. {
  15671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15672. }
  15673. } // END OF FOR CHAdeMO_QUANTITY
  15674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15675. }
  15676. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15677. {
  15678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15679. {
  15680. tempIndex = ((gun_index==2) ? 1: 0);
  15681. }
  15682. else
  15683. {
  15684. tempIndex = gun_index;
  15685. }
  15686. for (int index = 0; index < CCS_QUANTITY; index++)
  15687. {
  15688. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15689. {
  15690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15691. }
  15692. } // END OF FOR CCS_QUANTITY
  15693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15694. }
  15695. else if(gunType[gun_index] == 'G')
  15696. {
  15697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15698. {
  15699. tempIndex = ((gun_index==2) ? 1: 0);
  15700. }
  15701. else
  15702. {
  15703. tempIndex = gun_index;
  15704. }
  15705. for (int index = 0; index < GB_QUANTITY; index++)
  15706. {
  15707. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15708. {
  15709. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15710. }
  15711. } // END OF FOR GB_QUANTITY
  15712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15713. }
  15714. else
  15715. {
  15716. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15717. {
  15718. tempIndex = 2;
  15719. }
  15720. else
  15721. {
  15722. tempIndex = gun_index;
  15723. }
  15724. for (int index = 0; index < AC_QUANTITY; index++)
  15725. {
  15726. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15727. {
  15728. 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
  15729. }
  15730. } // END OF FOR AC_QUANTITY
  15731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15732. }
  15733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15736. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15739. //SoC
  15740. //idx_sample=5;
  15741. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15742. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15743. {
  15744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15745. {
  15746. tempIndex = ((gun_index==2) ? 1: 0);
  15747. }
  15748. else
  15749. {
  15750. tempIndex = gun_index;
  15751. }
  15752. if(gunType[gun_index] == 'J')
  15753. {
  15754. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15755. {
  15756. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15757. {
  15758. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15759. }
  15760. }
  15761. }
  15762. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15763. {
  15764. for (int index = 0; index < CCS_QUANTITY; index++)
  15765. {
  15766. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15767. {
  15768. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15769. }
  15770. }
  15771. }
  15772. else if(gunType[gun_index] == 'G')
  15773. {
  15774. for (int index = 0; index < GB_QUANTITY; index++)
  15775. {
  15776. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15777. {
  15778. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15779. }
  15780. }
  15781. }
  15782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  15787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15788. } // END FOR DC CASE
  15789. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15790. {
  15791. 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\"}]}]}]"
  15792. ,MESSAGE_TYPE_CALL
  15793. ,guid
  15794. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15795. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15796. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15798. ,"PowerLoss"
  15799. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  15836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  15837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  15838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  15839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  15840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  15841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  15842. );
  15843. }
  15844. else
  15845. {
  15846. 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\"}]}]}]"
  15847. ,MESSAGE_TYPE_CALL
  15848. ,guid
  15849. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15850. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15851. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15853. ,"PowerLoss"
  15854. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15890. );
  15891. }
  15892. // Check File "TempStopTransaction" Exist
  15893. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  15894. {
  15895. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15896. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  15897. }
  15898. else
  15899. {
  15900. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15901. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  15902. if(log == NULL)
  15903. {
  15904. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15905. return ;
  15906. }
  15907. else
  15908. {
  15909. fclose(log);
  15910. }
  15911. }
  15912. //Add TempStopTransaction | Update TempStopTransaction
  15913. // open file for writing
  15914. FILE *outfile;
  15915. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  15916. DEBUG_INFO("data=%s\n",queuedata);
  15917. fputs(queuedata, outfile);
  15918. fputs("\n", outfile);
  15919. fclose (outfile);
  15920. }
  15921. void checkTempStopTransaction(int gun_index)
  15922. {
  15923. FILE *fptr1;
  15924. char ch;
  15925. char str[1200]={0};
  15926. char guid[37]={0};
  15927. char tempdata[65]={0};
  15928. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  15929. if (!fptr1)
  15930. {
  15931. //printf(" File not found or unable to open the input file!!\n");
  15932. return ;
  15933. }
  15934. ch=fgetc(fptr1);
  15935. //printf(" Now the content of the file %s is : \n",fname);
  15936. rewind(fptr1);
  15937. if(ch!=EOF)
  15938. {
  15939. // copy all contents to the temporary file except the specific line
  15940. while (fgets(str, 1200, fptr1) != NULL)
  15941. {
  15942. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15943. if(str[0]=='\0')
  15944. {
  15945. break;
  15946. }
  15947. random_uuid(guid);
  15948. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15949. if(hashmap_operation(0, guid, tempdata) == 1)
  15950. {
  15951. DEBUG_INFO("StopTransaction mapitem pass\n");
  15952. }
  15953. queue_operation(4, guid, str );//addq(guid, queuedata); ---> remove temporally
  15954. memset(str,0,sizeof str);
  15955. }
  15956. }
  15957. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15958. fclose(fptr1);
  15959. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  15960. }
  15961. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15962. {
  15963. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15964. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15965. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15966. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15967. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15968. }
  15969. int GetWebSocketPingInterval(void)
  15970. {
  15971. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15972. }
  15973. int GetServerSign(void)
  15974. {
  15975. return server_sign;
  15976. }
  15977. void SetServerSign(int value)
  15978. {
  15979. server_sign = value;
  15980. }
  15981. int GetBootNotificationInterval(void)
  15982. {
  15983. return BootNotificationInterval;
  15984. }
  15985. int GetInternetConn(void)
  15986. {
  15987. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15988. }
  15989. void InitialSystemValue(void)
  15990. {
  15991. int connectorIndex = 0;
  15992. //int valueASCII = 0;
  15993. server_cycle_Status = 120;
  15994. gunTotalNumber=0;
  15995. SystemInitial = 0;
  15996. localversion=0;
  15997. BootNotificationInterval = 0;
  15998. authorizeRetryTimes = 0;
  15999. GunStatusInterval = 10;
  16000. TransactionMessageAttemptsValue = 0;
  16001. TransactionMessageRetryIntervalValue = 0;
  16002. //Hear Beat
  16003. HeartBeatWithNOResponse = 0;
  16004. HeartBeatCountPerHour = 0;
  16005. HeartBeatWaitTime = 10;
  16006. FirstHeartBeat = 0;
  16007. FirmwareStatusNotificationStatus = 3; // Idle
  16008. DiagnosticsStatusNotificationStatus = 0; // Idle
  16009. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  16010. memset(statusModeChage, 0, sizeof(statusModeChage));
  16011. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  16012. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  16013. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  16014. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  16015. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  16016. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  16017. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  16018. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  16019. memset(gunType, 0, sizeof(gunType));
  16020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16021. {
  16022. //check connector / socket type (index: 8, 9, 10)
  16023. for(int index=7; index <10 ; index++)
  16024. {
  16025. if(index != 8)
  16026. {
  16027. // DC Connector
  16028. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  16029. {
  16030. SystemInitial = SystemInitial + 1;
  16031. gunTotalNumber = gunTotalNumber + 1;
  16032. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16033. connectorIndex = connectorIndex + 1;
  16034. }
  16035. }
  16036. else
  16037. {
  16038. // AC Connector
  16039. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16040. {
  16041. SystemInitial = SystemInitial + 1;
  16042. gunTotalNumber = gunTotalNumber + 1;
  16043. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16044. connectorIndex = connectorIndex + 1;
  16045. }
  16046. }
  16047. }
  16048. //DEBUG_INFO("DC ...\n");
  16049. }
  16050. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16051. {
  16052. //check connector / socket type (index: 8, 9, 10)
  16053. for(int index=7; index <10 ; index++)
  16054. {
  16055. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16056. {
  16057. SystemInitial = SystemInitial + 1;
  16058. gunTotalNumber = gunTotalNumber + 1;
  16059. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16060. connectorIndex = connectorIndex + 1;
  16061. DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16062. }
  16063. }
  16064. DEBUG_INFO("gunTotalNumber: %d\n", gunTotalNumber);
  16065. DEBUG_INFO("connectorIndex: %d\n", connectorIndex);
  16066. DEBUG_INFO("SystemInitial: %d\n", SystemInitial);
  16067. //DEBUG_INFO("AC ...\n");
  16068. }
  16069. //Status && ConnectorPlugIn Setting
  16070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16071. {
  16072. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16073. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16074. }
  16075. for (int index = 0; index < CCS_QUANTITY; index++)
  16076. {
  16077. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16078. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16079. }
  16080. for (int index = 0; index < GB_QUANTITY; index++)
  16081. {
  16082. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16083. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16084. }
  16085. for (int index = 0; index < AC_QUANTITY; index++)
  16086. {
  16087. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16088. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16089. }
  16090. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16091. {
  16092. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16093. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16094. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16095. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  16096. }
  16097. // Charger PRE_SYS_MODE
  16098. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  16099. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16100. clientTime.Heartbeat=time((time_t*)NULL);
  16101. sleep(1);
  16102. }
  16103. void LWS_Send(char * str)
  16104. {
  16105. //=====================================================
  16106. // Check InternetConn 0: disconnected, 1: connected
  16107. //====================================================
  16108. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  16109. {
  16110. DEBUG_INFO("\n offline now !!!\n");
  16111. return;
  16112. }
  16113. pthread_mutex_lock(&lock);
  16114. memset(SendBuffer,0,SendBufLen);
  16115. sprintf((char *)SendBuffer, "%s", str);
  16116. pthread_mutex_unlock(&lock);
  16117. lws_callback_on_writable(wsi_client);
  16118. lws_service(context, 10000);//timeout_ms
  16119. }