MessageHandler.c 671 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704
  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((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1013. {
  1014. DEBUG_INFO("Heartbeat !!!\n");
  1015. //parameter for test
  1016. sendHeartbeatRequest(0);
  1017. //==============================================
  1018. // Reset Waiting Time
  1019. //==============================================
  1020. clientTime.Heartbeat=time((time_t*)NULL);
  1021. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1022. }
  1023. else if((server_sign == TRUE) &&(FirstHeartBeat == 0)) // Send First HeartBeat
  1024. {
  1025. DEBUG_INFO("FirstHeartBeat !!!\n");
  1026. //parameter for test
  1027. sendHeartbeatRequest(0);
  1028. //==============================================
  1029. // Reset Waiting Time
  1030. //==============================================
  1031. clientTime.Heartbeat=time((time_t*)NULL);
  1032. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1033. if(HeartBeatWaitTime <= 0)
  1034. {
  1035. HeartBeatWaitTime = 10;
  1036. }
  1037. DEBUG_INFO("difftime(time((time_t*)NULL), clientTime.Heartbeat)=%d !!!\n",difftime(time((time_t*)NULL), clientTime.Heartbeat));
  1038. DEBUG_INFO("HeartBeatWaitTime=%d !!!\n",HeartBeatWaitTime);
  1039. DEBUG_INFO("ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval=%d !!!\n",ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  1040. }
  1041. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1042. {
  1043. //===============================
  1044. // CSU Trigger Reset Conf
  1045. //===============================
  1046. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1047. {
  1048. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1049. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1050. {
  1051. server_sign = FALSE;
  1052. }
  1053. }
  1054. //===============================
  1055. // CSU Trigger Authorize Request
  1056. //===============================
  1057. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1058. {
  1059. sendAuthorizeRequest(0);
  1060. authorizeRetryTimes = authorizeRetryTimes + 1;
  1061. if(authorizeRetryTimes < 3)
  1062. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1063. }
  1064. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1065. {
  1066. authorizeRetryTimes = 0;
  1067. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1068. server_sign = FALSE;
  1069. }
  1070. 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))
  1071. {
  1072. sendAuthorizeRequest(0);
  1073. }
  1074. //===============================
  1075. // CSU Trigger Smart Charging Profilw
  1076. //===============================
  1077. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1078. {
  1079. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1080. GetChargingProfileRequest(gun_index);
  1081. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1082. }
  1083. //==============================================
  1084. // Charger start transaction
  1085. //==============================================
  1086. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1087. {
  1088. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1089. sendStartTransactionRequest(gun_index);
  1090. clientTime.StartTransaction = time((time_t*)NULL);
  1091. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1092. }
  1093. //==============================================
  1094. // Charger stop transaction
  1095. //==============================================
  1096. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1097. {
  1098. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1099. sendStopTransactionRequest(gun_index);
  1100. clientTime.StopTransaction = time((time_t*)NULL);
  1101. }
  1102. //==============================================
  1103. // Charger status report
  1104. //==============================================
  1105. //--- Check Mode Change ---//
  1106. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1107. if(gunType[gun_index] == 'J')
  1108. {
  1109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1110. {
  1111. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1112. {
  1113. 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]*/ )
  1114. {
  1115. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1116. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1117. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1118. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1119. statusModeChage[gun_index] = TRUE;
  1120. }
  1121. #if 0 // for TempStopTransaction
  1122. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1123. {
  1124. checkTempStopTransaction(gun_index);
  1125. }
  1126. #endif
  1127. }
  1128. }
  1129. }
  1130. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1131. {
  1132. for (int index = 0; index < CCS_QUANTITY; index++)
  1133. {
  1134. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1135. {
  1136. 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]*/ )
  1137. {
  1138. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1139. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1140. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1141. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1142. statusModeChage[gun_index] = TRUE;
  1143. }
  1144. #if 0 // for TempStopTransaction
  1145. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1146. {
  1147. checkTempStopTransaction(gun_index);
  1148. }
  1149. #endif
  1150. }
  1151. }
  1152. }
  1153. else if(gunType[gun_index] == 'G')
  1154. {
  1155. for (int index = 0; index < GB_QUANTITY; index++)
  1156. {
  1157. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1158. {
  1159. 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]*/ )
  1160. {
  1161. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1162. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1163. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1164. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1165. statusModeChage[gun_index] = TRUE;
  1166. }
  1167. #if 0 // for TempStopTransaction
  1168. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1169. {
  1170. checkTempStopTransaction(gun_index);
  1171. }
  1172. #endif
  1173. }
  1174. }
  1175. }
  1176. else
  1177. {
  1178. for (int index = 0; index < AC_QUANTITY; index++)
  1179. {
  1180. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1181. {
  1182. 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]*/ )
  1183. {
  1184. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1185. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1186. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1187. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1188. statusModeChage[gun_index] = TRUE;
  1189. }
  1190. #if 0 // for TempStopTransaction
  1191. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1192. {
  1193. checkTempStopTransaction(gun_index);
  1194. }
  1195. #endif
  1196. }
  1197. }// END
  1198. }
  1199. if(((SystemInitial > 0)&& (server_sign == TRUE))||
  1200. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1201. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1202. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1203. {
  1204. if(SystemInitial > 0)
  1205. SystemInitial = SystemInitial -1;
  1206. sendStatusNotificationRequest(gun_index);
  1207. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1208. statusModeChage[gun_index] = FALSE;
  1209. DEBUG_INFO("difftime(time((time_t*)NULL), clientTime.Heartbeat)=%d !!!\n",difftime(time((time_t*)NULL), clientTime.Heartbeat));
  1210. DEBUG_INFO("HeartBeatWaitTime=%d !!!\n",HeartBeatWaitTime);
  1211. DEBUG_INFO("ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval=%d !!!\n",ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  1212. }
  1213. //==============================================
  1214. // Meter report
  1215. //==============================================
  1216. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1217. {
  1218. //check Transaction active
  1219. if(gunType[gun_index] == 'J')
  1220. {
  1221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1222. {
  1223. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1224. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1225. {
  1226. meterValueSend[gun_index] =1;
  1227. }
  1228. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1229. {
  1230. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1231. if((access(filenmae,F_OK))!=-1)
  1232. {
  1233. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1234. sprintf(str,"rm -f %s",filenmae);
  1235. system(str);
  1236. }
  1237. }
  1238. }// End for CHAdeMO
  1239. }
  1240. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1241. {
  1242. for (int index = 0; index < CCS_QUANTITY; index++)
  1243. {
  1244. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1245. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1246. {
  1247. meterValueSend[gun_index] =1;
  1248. }
  1249. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1250. {
  1251. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1252. if((access(filenmae,F_OK))!=-1)
  1253. {
  1254. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1255. sprintf(str,"rm -f %s",filenmae);
  1256. system(str);
  1257. }
  1258. }
  1259. } // End for CCS
  1260. }
  1261. else if(gunType[gun_index] == 'G')
  1262. {
  1263. for (int index = 0; index < GB_QUANTITY; index++)
  1264. {
  1265. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1266. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1267. {
  1268. meterValueSend[gun_index] =1;
  1269. }
  1270. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1271. {
  1272. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1273. if((access(filenmae,F_OK))!=-1)
  1274. {
  1275. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1276. sprintf(str,"rm -f %s",filenmae);
  1277. system(str);
  1278. }
  1279. }
  1280. }// End for GB
  1281. }
  1282. else
  1283. {
  1284. for (int index = 0; index < AC_QUANTITY; index++)
  1285. {
  1286. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1287. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1288. {
  1289. meterValueSend[gun_index] =1;
  1290. }
  1291. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1292. {
  1293. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1294. if((access(filenmae,F_OK))!=-1)
  1295. {
  1296. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1297. sprintf(str,"rm -f %s",filenmae);
  1298. system(str);
  1299. }
  1300. }
  1301. }//End for AC
  1302. }
  1303. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1304. if(meterValueSend[gun_index] == 1)
  1305. {
  1306. sendMeterValuesRequest(gun_index);
  1307. #if 0 // for TempStopTransaction
  1308. storeTempStopTransaction(gun_index);
  1309. #endif
  1310. }
  1311. }
  1312. //==============================================
  1313. // Check Connector reserved
  1314. //==============================================
  1315. //===============================
  1316. // Check if Reserve is expired
  1317. //===============================
  1318. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1319. {
  1320. double diff_t;
  1321. struct tm tp;
  1322. // current time
  1323. time_t t = time(NULL);
  1324. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1325. tp.tm_isdst = -1;
  1326. time_t utc = mktime(&tp);
  1327. diff_t = difftime(utc, t);
  1328. if(diff_t <= 0)
  1329. {
  1330. DEBUG_INFO("reserve expired !!! \n");
  1331. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1332. }
  1333. }//END OF Check if Reserve is expired
  1334. //==========================================
  1335. // csu trigger FirmwareStatusNotificationReq
  1336. //==========================================
  1337. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1338. {
  1339. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1340. }
  1341. //==========================================
  1342. // csu trigger CancelReservationConf
  1343. //==========================================
  1344. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1345. {
  1346. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1347. }
  1348. //==========================================
  1349. // csu trigger ChangeAvailabilityConf
  1350. //==========================================
  1351. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1352. {
  1353. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1354. }
  1355. //==========================================
  1356. // csu trigger UnlockConnectorConf
  1357. //==========================================
  1358. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1359. {
  1360. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1361. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1362. }
  1363. //==========================================
  1364. // csu trigger ReserveNowConf
  1365. //==========================================
  1366. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1367. {
  1368. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1369. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1370. }
  1371. //==========================================
  1372. // csu trigger DataTransferReq
  1373. //==========================================
  1374. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1375. {
  1376. sendDataTransferRequest(gun_index);
  1377. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1378. }
  1379. }
  1380. }
  1381. //==========================================
  1382. // send request routine
  1383. //==========================================
  1384. int sendAuthorizeRequest(int gun_index)
  1385. {
  1386. mtrace();
  1387. int result = FAIL;
  1388. char message[100]={0};
  1389. char guid[37];
  1390. char tempdata[65]={0};
  1391. DEBUG_INFO("sendAuthorizeRequest \n");
  1392. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1393. //Local Authorize
  1394. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1395. {
  1396. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1397. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1398. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1399. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1400. result = PASS;
  1401. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1402. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1403. authorizeRetryTimes = 0;
  1404. return result;
  1405. }
  1406. 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))||
  1407. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1408. {
  1409. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1410. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1411. {
  1412. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1413. {
  1414. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1415. }
  1416. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1417. {
  1418. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1419. }
  1420. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1421. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1422. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1423. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1424. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1425. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1426. authorizeRetryTimes = 0;
  1427. return result;
  1428. }
  1429. else
  1430. {
  1431. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1432. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1433. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1434. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1435. result = PASS;
  1436. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1437. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1438. authorizeRetryTimes = 0;
  1439. return result;
  1440. }
  1441. }
  1442. //initailize struct Authorize
  1443. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1444. //get data from shared memory
  1445. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1446. random_uuid(guid);
  1447. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1448. LWS_Send(message);
  1449. sprintf(tempdata, "Authorize,%d", gun_index);
  1450. if(hashmap_operation(0, guid, tempdata) == 1)
  1451. {
  1452. result = PASS;
  1453. DEBUG_ERROR("Authorize mapItem pass\n");
  1454. }
  1455. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1456. return result;
  1457. }
  1458. int sendBootNotificationRequest(void)
  1459. {
  1460. mtrace();
  1461. int result = FAIL;
  1462. char message[500]={0}, payload[700]={0};
  1463. char guid[37]={0};
  1464. char tempdata[65]={0};
  1465. int IsGunCharging = FALSE;
  1466. //check Transaction active
  1467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1468. {
  1469. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1470. {
  1471. IsGunCharging = TRUE;
  1472. }
  1473. }
  1474. for (int index = 0; index < CCS_QUANTITY; index++)
  1475. {
  1476. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1477. {
  1478. IsGunCharging = TRUE;
  1479. }
  1480. }
  1481. for (int index = 0; index < GB_QUANTITY; index++)
  1482. {
  1483. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1484. {
  1485. IsGunCharging = TRUE;
  1486. }
  1487. }
  1488. for (int index = 0; index < AC_QUANTITY; index++)
  1489. {
  1490. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1491. {
  1492. IsGunCharging = TRUE;
  1493. }
  1494. }
  1495. if(IsGunCharging == TRUE)
  1496. {
  1497. server_sign = TRUE;
  1498. return result;
  1499. }
  1500. // Fill BootNotification fields
  1501. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1502. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1503. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1504. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1505. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1506. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1507. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1508. #if 0
  1509. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1510. ShmOCPP16Data->ChargeBoxId
  1511. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1512. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1513. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1514. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1515. ,ShmOCPP16Data->BootNotification.CpIccid
  1516. ,ShmOCPP16Data->BootNotification.CpImsi
  1517. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1518. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1519. #endif
  1520. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1521. ShmOCPP16Data->ChargeBoxId
  1522. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1523. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1524. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1525. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1526. ,ShmOCPP16Data->BootNotification.CpIccid
  1527. ,ShmOCPP16Data->BootNotification.CpImsi);
  1528. random_uuid(guid);
  1529. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1530. LWS_Send(message);
  1531. sprintf(tempdata, "BootNotification,0");
  1532. 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*/)
  1533. {
  1534. result = PASS;
  1535. }
  1536. memset(queuedata, 0, sizeof(queuedata));
  1537. strcpy(queuedata,message);
  1538. return result;
  1539. }
  1540. int sendDataTransferRequest(int gun_index)
  1541. {
  1542. mtrace();
  1543. char message[1000]={0};
  1544. char guid[37]={0};
  1545. char tempdata[65]={0};
  1546. int result = FAIL;
  1547. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1548. random_uuid(guid);
  1549. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1550. MESSAGE_TYPE_CALL,
  1551. guid,
  1552. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1553. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1554. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1555. LWS_Send(message);
  1556. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1557. 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*/)
  1558. {
  1559. result = PASS;
  1560. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1561. }
  1562. return result;
  1563. }
  1564. int sendDiagnosticsStatusNotificationRequest(char *status)
  1565. {
  1566. mtrace();
  1567. int result = FAIL;
  1568. char message[110]={0};
  1569. char guid[37]={0};
  1570. char tempdata[65]={0};
  1571. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1572. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1573. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1574. random_uuid(guid);
  1575. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1576. LWS_Send(message);
  1577. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1578. if(hashmap_operation(0, guid, tempdata) == 1)
  1579. {
  1580. result = PASS;
  1581. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1582. }
  1583. //#ifdef SystemLogMessage
  1584. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1585. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1586. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1587. //#endif
  1588. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1589. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1590. //record status
  1591. if(strcmp(status,"Idle")==0)
  1592. {
  1593. DiagnosticsStatusNotificationStatus = 0;
  1594. }
  1595. else if(strcmp(status,"Uploaded")==0)
  1596. {
  1597. DiagnosticsStatusNotificationStatus = 1;
  1598. }
  1599. else if(strcmp(status,"UploadFailed")==0)
  1600. {
  1601. DiagnosticsStatusNotificationStatus = 2;
  1602. }
  1603. else if(strcmp(status,"Uploading")==0)
  1604. {
  1605. DiagnosticsStatusNotificationStatus = 3;
  1606. }
  1607. return result;
  1608. }
  1609. int sendFirmwareStatusNotificationRequest(char *status)
  1610. {
  1611. mtrace();
  1612. int result = FAIL;
  1613. char message[110]={0};
  1614. char guid[37]={0};
  1615. char tempdata[65]={0};
  1616. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1617. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1618. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1619. random_uuid(guid);
  1620. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1621. LWS_Send(message);
  1622. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1623. 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*/)
  1624. {
  1625. result = PASS;
  1626. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1627. }
  1628. //#ifdef SystemLogMessage
  1629. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1630. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1631. //#endif
  1632. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1633. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1634. //record status
  1635. if(strcmp(status,"Downloaded")==0)
  1636. {
  1637. FirmwareStatusNotificationStatus = 0;
  1638. }
  1639. else if(strcmp(status,"DownloadFailed")==0)
  1640. {
  1641. FirmwareStatusNotificationStatus = 1;
  1642. }
  1643. else if(strcmp(status,"Downloading")==0)
  1644. {
  1645. FirmwareStatusNotificationStatus = 2;
  1646. }
  1647. else if(strcmp(status,"Idle")==0)
  1648. {
  1649. FirmwareStatusNotificationStatus = 3;
  1650. }
  1651. else if(strcmp(status,"InstallationFailed")==0)
  1652. {
  1653. FirmwareStatusNotificationStatus = 4;
  1654. }
  1655. else if(strcmp(status,"Installing")==0)
  1656. {
  1657. FirmwareStatusNotificationStatus = 5;
  1658. }
  1659. else if(strcmp(status,"Installed")==0)
  1660. {
  1661. FirmwareStatusNotificationStatus = 6;
  1662. }
  1663. return result;
  1664. }
  1665. int sendHeartbeatRequest(int gun_index)
  1666. {
  1667. mtrace();
  1668. int result = FAIL;
  1669. char message[80]={0};
  1670. char guid[37]={0};
  1671. char tempdata[65]={0};
  1672. random_uuid(guid);
  1673. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1674. , MESSAGE_TYPE_CALL
  1675. , guid );
  1676. LWS_Send(message);
  1677. sprintf(tempdata, "Heartbeat,%d", 0);
  1678. 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*/)
  1679. {
  1680. result = PASS;
  1681. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1682. }
  1683. return result;
  1684. }
  1685. int sendStartTransactionRequest(int gun_index)
  1686. {
  1687. mtrace();
  1688. int result = FAIL;
  1689. char message[250]={0};
  1690. char guid[37]={0};
  1691. struct timeval tmnow;
  1692. struct tm *tm;
  1693. char buf[28];//, usec_buf[6];
  1694. char tempdata[65]={0};
  1695. int tempIndex = 0;
  1696. DEBUG_INFO("sendStartTransactionRequest...");
  1697. gettimeofday(&tmnow, NULL);
  1698. time_t t;
  1699. t = time(NULL);
  1700. /*UTC time and date*/
  1701. tm = gmtime(&t);
  1702. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1703. #if 0 // remove temporally
  1704. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1705. strcat(buf,".");
  1706. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1707. strcat(buf,usec_buf);
  1708. #endif
  1709. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1710. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1711. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1712. // clear StartTransaction Response
  1713. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1714. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1715. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1716. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1717. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1718. if(gunType[gun_index] == 'J')
  1719. {
  1720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1721. {
  1722. tempIndex = ((gun_index==2) ? 1: 0);
  1723. }
  1724. else
  1725. {
  1726. tempIndex = gun_index;
  1727. }
  1728. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1729. {
  1730. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  1731. {
  1732. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1733. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1734. }
  1735. }
  1736. }
  1737. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1738. {
  1739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1740. {
  1741. tempIndex = ((gun_index==2) ? 1: 0);
  1742. }
  1743. else
  1744. {
  1745. tempIndex = gun_index;
  1746. }
  1747. for (int index = 0; index < CCS_QUANTITY; index++)
  1748. {
  1749. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1750. {
  1751. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1752. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1753. }
  1754. }
  1755. }
  1756. else if(gunType[gun_index] == 'G')
  1757. {
  1758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1759. {
  1760. tempIndex = ((gun_index==2) ? 1: 0);
  1761. }
  1762. else
  1763. {
  1764. tempIndex = gun_index;
  1765. }
  1766. for (int index = 0; index < GB_QUANTITY; index++)
  1767. {
  1768. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1769. {
  1770. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1771. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1772. }
  1773. }
  1774. }
  1775. else
  1776. {
  1777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1778. {
  1779. tempIndex = 2;
  1780. }
  1781. else
  1782. {
  1783. tempIndex = gun_index;
  1784. }
  1785. for (int index = 0; index < AC_QUANTITY; index++)
  1786. {
  1787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1788. {
  1789. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  1790. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1791. }
  1792. }
  1793. }
  1794. random_uuid(guid);
  1795. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1796. , MESSAGE_TYPE_CALL
  1797. , guid
  1798. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1799. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1800. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1801. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1802. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1803. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1804. 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*/)
  1805. {
  1806. result = PASS;
  1807. }
  1808. strcpy(queuedata, message);
  1809. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1810. if(GetTransactionQueueNum() == 1)
  1811. {
  1812. LWS_Send(message);
  1813. }
  1814. return result;
  1815. }
  1816. int sendStatusNotificationRequest(int gun_index)
  1817. {
  1818. mtrace();
  1819. int result = FAIL;
  1820. char message[600]={0};
  1821. char guid[37];
  1822. int currentStatus = 0;
  1823. struct timeval tmnow;
  1824. struct tm *tm;
  1825. char buf[28];//, usec_buf[6];
  1826. char tempdata[65]={0};
  1827. int tempIndex = 0;
  1828. gettimeofday(&tmnow, NULL);
  1829. time_t t;
  1830. t = time(NULL);
  1831. /*UTC time and date*/
  1832. tm = gmtime(&t);
  1833. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1834. #if 0 // remove temporally
  1835. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1836. strcat(buf,".");
  1837. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1838. strcat(buf,usec_buf);
  1839. #endif
  1840. printf("%s",buf);
  1841. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1842. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1843. // it's option
  1844. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1845. /*
  1846. enum _SYSTEM_STATUS
  1847. {
  1848. S_BOOTING = 0,
  1849. S_IDLE, = 1
  1850. S_AUTHORIZING, =2
  1851. S_REASSIGN_CHECK, =3
  1852. S_REASSIGN, =4
  1853. S_PRECHARGE, =5
  1854. S_PREPARING_FOR_EV, =6
  1855. S_PREPARING_FOR_EVSE, =7
  1856. S_CHARGING, =8
  1857. S_TERMINATING, =9
  1858. S_COMPLETE, =10
  1859. S_ALARM, =11
  1860. S_FAULT =12
  1861. }
  1862. */
  1863. //check Transaction active
  1864. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1865. if(gunType[gun_index] == 'J')
  1866. {
  1867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1868. {
  1869. tempIndex = ((gun_index==2) ? 1: 0);
  1870. }
  1871. else
  1872. {
  1873. tempIndex = gun_index;
  1874. }
  1875. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1876. {
  1877. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1878. {
  1879. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  1880. {
  1881. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1882. {
  1883. currentStatus = 1; //OCPP Status: Preparing
  1884. }
  1885. else
  1886. {
  1887. currentStatus = 0; //OCPP Status: Available
  1888. }
  1889. }
  1890. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1891. {
  1892. currentStatus = 1; //OCPP Status: Preparing
  1893. }
  1894. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1895. {
  1896. currentStatus = 2; //OCPP Status: Charging
  1897. }
  1898. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1899. {
  1900. currentStatus = 5; //OCPP Status: Finishing
  1901. }
  1902. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  1903. {
  1904. currentStatus = 4; //OCPP Status: SuspendedEV
  1905. }
  1906. 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
  1907. {
  1908. currentStatus = 7; //OCPP Status: Unavailable
  1909. }
  1910. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  1911. {
  1912. currentStatus = 8; //OCPP Status: Faulted
  1913. }
  1914. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1915. {
  1916. currentStatus = 6; //OCPP Status: Reserved
  1917. }
  1918. } //end of the same index
  1919. }//end of for CHAdeMO_QUANTITY
  1920. }
  1921. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1922. {
  1923. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1924. {
  1925. tempIndex = ((gun_index==2) ? 1: 0);
  1926. }
  1927. else
  1928. {
  1929. tempIndex = gun_index;
  1930. }
  1931. for (int index = 0; index < CCS_QUANTITY; index++)
  1932. {
  1933. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1934. {
  1935. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1936. {
  1937. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1938. {
  1939. currentStatus = 1; //OCPP Status: Preparing
  1940. }
  1941. else
  1942. {
  1943. currentStatus = 0; //OCPP Status: Available
  1944. }
  1945. }
  1946. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1947. {
  1948. currentStatus = 1; //OCPP Status: Preparing
  1949. }
  1950. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1951. {
  1952. currentStatus = 2; //OCPP Status: Charging
  1953. }
  1954. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1955. {
  1956. currentStatus = 5; //OCPP Status: Finishing
  1957. }
  1958. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  1959. {
  1960. currentStatus = 4; //OCPP Status: SuspendedEV
  1961. }
  1962. 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
  1963. {
  1964. currentStatus = 7; //OCPP Status : Unavailable
  1965. }
  1966. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  1967. {
  1968. currentStatus = 8; //OCPP Status: Faulted
  1969. }
  1970. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1971. {
  1972. currentStatus = 6; //OCPP Status: Reserved
  1973. }
  1974. } //end of the same index
  1975. } // end of for CCS_QUANTITY
  1976. }
  1977. else if(gunType[gun_index] == 'G')
  1978. {
  1979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1980. {
  1981. tempIndex = ((gun_index==2) ? 1: 0);
  1982. }
  1983. else
  1984. {
  1985. tempIndex = gun_index;
  1986. }
  1987. for (int index = 0; index < GB_QUANTITY; index++)
  1988. {
  1989. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1990. {
  1991. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1992. {
  1993. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1994. {
  1995. currentStatus = 1; //OCPP Status: Preparing
  1996. }
  1997. else
  1998. {
  1999. currentStatus = 0; //OCPP Status: Available
  2000. }
  2001. }
  2002. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  2003. {
  2004. currentStatus = 1; //OCPP Status: Preparing
  2005. }
  2006. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2007. {
  2008. currentStatus = 2; //OCPP Status: Charging
  2009. }
  2010. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2011. {
  2012. currentStatus = 5; //OCPP Status: Finishing
  2013. }
  2014. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2015. {
  2016. currentStatus = 4; //OCPP Status: SuspendedEV
  2017. }
  2018. 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
  2019. {
  2020. currentStatus = 7; //OCPP Status: Unavailable
  2021. }
  2022. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2023. {
  2024. currentStatus = 8; //OCPP Status: Faulted
  2025. }
  2026. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2027. {
  2028. currentStatus = 6; //OCPP Status: Reserved
  2029. }
  2030. } //end of the same index
  2031. } // end of for GB_QUANTITY
  2032. }
  2033. else
  2034. {
  2035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2036. {
  2037. tempIndex = 2;
  2038. }
  2039. else
  2040. {
  2041. tempIndex = gun_index;
  2042. }
  2043. for (int index = 0; index < AC_QUANTITY; index++)
  2044. {
  2045. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2046. {
  2047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  2048. {
  2049. 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))
  2050. {
  2051. currentStatus = 1; //OCPP Status: Preparing
  2052. }
  2053. else
  2054. {
  2055. currentStatus = 0; //OCPP Status: Available
  2056. }
  2057. }
  2058. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  2059. {
  2060. currentStatus = 1; //OCPP Status: Preparing
  2061. }
  2062. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  2063. {
  2064. currentStatus = 2; //OCPP Status: Charging
  2065. }
  2066. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  2067. {
  2068. currentStatus = 5; //OCPP Status: Finishing
  2069. }
  2070. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2071. {
  2072. currentStatus = 4; //OCPP Status: SuspendedEV
  2073. }
  2074. 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
  2075. {
  2076. currentStatus = 7; //OCPP Status: Unavailable
  2077. }
  2078. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2079. {
  2080. currentStatus = 8; //OCPP Status: Faulted
  2081. }
  2082. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2083. {
  2084. currentStatus = 6; //OCPP Status: Reserved
  2085. }
  2086. }//end of the same index
  2087. }//end of for AC_QUANTITY
  2088. }
  2089. //it's option
  2090. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2091. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2092. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2093. random_uuid(guid);
  2094. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2095. , MESSAGE_TYPE_CALL
  2096. , guid
  2097. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2098. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2099. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2100. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2101. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2102. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2103. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2104. LWS_Send(message);
  2105. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2106. 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*/)
  2107. {
  2108. //DEBUG_ERROR("statusNotification mapitem pass");
  2109. result = PASS;
  2110. }
  2111. return result;
  2112. }
  2113. int sendStopTransactionRequest(int gun_index)
  2114. {
  2115. mtrace();
  2116. int result = FAIL;
  2117. //char message[1500]={0};
  2118. char guid[37]={0};
  2119. char tempdata[65]={0};
  2120. int tempIndex = 0;
  2121. //int idx_sample=0;
  2122. DEBUG_ERROR("sendStopTransactionRequest \n");
  2123. memset(queuedata, 0, sizeof(queuedata));
  2124. //ENERGY_ACTIVE_IMPORT_REGISTER
  2125. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2126. if(gunType[gun_index] == 'J')
  2127. {
  2128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2129. {
  2130. tempIndex = ((gun_index==2) ? 1: 0);
  2131. }
  2132. else
  2133. {
  2134. tempIndex = gun_index;
  2135. }
  2136. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2137. {
  2138. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2139. {
  2140. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2141. }
  2142. }// END OF CHAdeMO_QUANTITY
  2143. }
  2144. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2145. {
  2146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2147. {
  2148. tempIndex = ((gun_index==2) ? 1: 0);
  2149. }
  2150. else
  2151. {
  2152. tempIndex = gun_index;
  2153. }
  2154. for (int index = 0; index < CCS_QUANTITY; index++)
  2155. {
  2156. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2157. {
  2158. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2159. }
  2160. }// END OF CCS_QUANTITY
  2161. }
  2162. else if(gunType[gun_index] == 'G')
  2163. {
  2164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2165. {
  2166. tempIndex = ((gun_index==2) ? 1: 0);
  2167. }
  2168. else
  2169. {
  2170. tempIndex = gun_index;
  2171. }
  2172. for (int index = 0; index < GB_QUANTITY; index++)
  2173. {
  2174. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2175. {
  2176. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2177. }
  2178. }// END OF GB_QUANTITY
  2179. }
  2180. else
  2181. {
  2182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2183. {
  2184. tempIndex = 2;
  2185. }
  2186. else
  2187. {
  2188. tempIndex = gun_index;
  2189. }
  2190. for (int index = 0; index < AC_QUANTITY; index++)
  2191. {
  2192. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2193. {
  2194. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  2195. }
  2196. }// END OF AC_QUANTITY
  2197. }
  2198. //Stop Transaction Time
  2199. struct timeval tmnow;
  2200. struct tm *tm;
  2201. char buf[28];//, usec_buf[6];
  2202. gettimeofday(&tmnow, NULL);
  2203. time_t t;
  2204. t = time(NULL);
  2205. /*UTC time and date*/
  2206. tm = gmtime(&t);
  2207. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2209. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2210. random_uuid(guid);
  2211. /***********************************transactionData******************************************************/
  2212. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2214. //=================================
  2215. // Transaction_Begin
  2216. //=================================
  2217. // Energy.Active.Export.Interval
  2218. //idx_sample=0;
  2219. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  2220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2222. 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*/]);
  2223. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2224. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2225. {
  2226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2227. }
  2228. else
  2229. {
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2231. }
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2234. //=================================
  2235. // Transaction_End
  2236. //=================================
  2237. //Current.Export
  2238. //idx_sample=1;
  2239. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  2240. if(gunType[gun_index] == 'J')
  2241. {
  2242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2243. {
  2244. tempIndex = ((gun_index==2) ? 1: 0);
  2245. }
  2246. else
  2247. {
  2248. tempIndex = gun_index;
  2249. }
  2250. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2251. {
  2252. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2253. {
  2254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2255. }
  2256. }// End of for CHAdeMO_QUANTITY
  2257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2258. }
  2259. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2260. {
  2261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2262. {
  2263. tempIndex = ((gun_index==2) ? 1: 0);
  2264. }
  2265. else
  2266. {
  2267. tempIndex = gun_index;
  2268. }
  2269. for (int index = 0; index < CCS_QUANTITY; index++)
  2270. {
  2271. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2272. {
  2273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2274. }
  2275. }// End of for CCS_QUANTITY
  2276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2277. }
  2278. else if(gunType[gun_index] == 'G')
  2279. {
  2280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2281. {
  2282. tempIndex = ((gun_index==2) ? 1: 0);
  2283. }
  2284. else
  2285. {
  2286. tempIndex = gun_index;
  2287. }
  2288. for (int index = 0; index < GB_QUANTITY; index++)
  2289. {
  2290. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2291. {
  2292. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2293. }
  2294. }// End of for GB_QUANTITY
  2295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2296. }
  2297. else
  2298. {
  2299. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2300. {
  2301. tempIndex = 2;
  2302. }
  2303. else
  2304. {
  2305. tempIndex = gun_index;
  2306. }
  2307. for (int index = 0; index < AC_QUANTITY; index++)
  2308. {
  2309. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2310. {
  2311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2312. }
  2313. }// End of for AC_QUANTITY
  2314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2315. }
  2316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  2319. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2322. //Energy.Active.Export.Interval
  2323. //idx_sample=2;
  2324. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2325. if(gunType[gun_index] == 'J')
  2326. {
  2327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2328. {
  2329. tempIndex = ((gun_index==2) ? 1: 0);
  2330. }
  2331. else
  2332. {
  2333. tempIndex = gun_index;
  2334. }
  2335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2336. {
  2337. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2338. {
  2339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2340. }
  2341. }// END OF CHAdeMO_QUANTITY
  2342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2343. }
  2344. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2345. {
  2346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2347. {
  2348. tempIndex = ((gun_index==2) ? 1: 0);
  2349. }
  2350. else
  2351. {
  2352. tempIndex = gun_index;
  2353. }
  2354. for (int index = 0; index < CCS_QUANTITY; index++)
  2355. {
  2356. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2357. {
  2358. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2359. }
  2360. }// END OF CCS_QUANTITY
  2361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2362. }
  2363. else if(gunType[gun_index] == 'G')
  2364. {
  2365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2366. {
  2367. tempIndex = ((gun_index==2) ? 1: 0);
  2368. }
  2369. else
  2370. {
  2371. tempIndex = gun_index;
  2372. }
  2373. for (int index = 0; index < GB_QUANTITY; index++)
  2374. {
  2375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2376. {
  2377. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2378. }
  2379. }// END OF GB_QUANTITY
  2380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2381. }
  2382. else
  2383. {
  2384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2385. {
  2386. tempIndex = 2;
  2387. }
  2388. else
  2389. {
  2390. tempIndex = gun_index;
  2391. }
  2392. for (int index = 0; index < AC_QUANTITY; index++)
  2393. {
  2394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2395. {
  2396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2397. }
  2398. }// END OF AC_QUANTITY
  2399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2400. }
  2401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  2404. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2407. //Power.Active.Export
  2408. //idx_sample=3;
  2409. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2410. if(gunType[gun_index] == 'J')
  2411. {
  2412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2413. {
  2414. tempIndex = ((gun_index==2) ? 1: 0);
  2415. }
  2416. else
  2417. {
  2418. tempIndex = gun_index;
  2419. }
  2420. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2421. {
  2422. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2423. {
  2424. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2425. }
  2426. } // End for CHAdeMO_QUANTITY
  2427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2428. }
  2429. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2430. {
  2431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2432. {
  2433. tempIndex = ((gun_index==2) ? 1: 0);
  2434. }
  2435. else
  2436. {
  2437. tempIndex = gun_index;
  2438. }
  2439. for (int index = 0; index < CCS_QUANTITY; index++)
  2440. {
  2441. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2442. {
  2443. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2444. }
  2445. } // END for CCS_QUANTITY
  2446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2447. }
  2448. else if(gunType[gun_index] == 'G')
  2449. {
  2450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2451. {
  2452. tempIndex = ((gun_index==2) ? 1: 0);
  2453. }
  2454. else
  2455. {
  2456. tempIndex = gun_index;
  2457. }
  2458. for (int index = 0; index < GB_QUANTITY; index++)
  2459. {
  2460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2461. {
  2462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2463. }
  2464. }// END for GB_QUANTITY
  2465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2466. }
  2467. else
  2468. {
  2469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2470. {
  2471. tempIndex = 2;
  2472. }
  2473. else
  2474. {
  2475. tempIndex = gun_index;
  2476. }
  2477. for (int index = 0; index < AC_QUANTITY; index++)
  2478. {
  2479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2480. {
  2481. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2482. }
  2483. } // END for AC_QUANTITY
  2484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2485. }
  2486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  2489. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2492. //Voltage
  2493. //idx_sample=4;
  2494. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2495. if(gunType[gun_index] == 'J')
  2496. {
  2497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2498. {
  2499. tempIndex = ((gun_index==2) ? 1: 0);
  2500. }
  2501. else
  2502. {
  2503. tempIndex = gun_index;
  2504. }
  2505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2506. {
  2507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2508. {
  2509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2510. }
  2511. } // END OF FOR CHAdeMO_QUANTITY
  2512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2513. }
  2514. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2515. {
  2516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2517. {
  2518. tempIndex = ((gun_index==2) ? 1: 0);
  2519. }
  2520. else
  2521. {
  2522. tempIndex = gun_index;
  2523. }
  2524. for (int index = 0; index < CCS_QUANTITY; index++)
  2525. {
  2526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2527. {
  2528. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2529. }
  2530. } // END OF FOR CCS_QUANTITY
  2531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2532. }
  2533. else if(gunType[gun_index] == 'G')
  2534. {
  2535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2536. {
  2537. tempIndex = ((gun_index==2) ? 1: 0);
  2538. }
  2539. else
  2540. {
  2541. tempIndex = gun_index;
  2542. }
  2543. for (int index = 0; index < GB_QUANTITY; index++)
  2544. {
  2545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2546. {
  2547. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2548. }
  2549. } // END OF FOR GB_QUANTITY
  2550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2551. }
  2552. else
  2553. {
  2554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2555. {
  2556. tempIndex = 2;
  2557. }
  2558. else
  2559. {
  2560. tempIndex = gun_index;
  2561. }
  2562. for (int index = 0; index < AC_QUANTITY; index++)
  2563. {
  2564. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2565. {
  2566. 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
  2567. }
  2568. } // END OF FOR AC_QUANTITY
  2569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2570. }
  2571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2574. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2577. //SoC
  2578. //idx_sample=5;
  2579. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2580. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2581. {
  2582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2583. {
  2584. tempIndex = ((gun_index==2) ? 1: 0);
  2585. }
  2586. else
  2587. {
  2588. tempIndex = gun_index;
  2589. }
  2590. if(gunType[gun_index] == 'J')
  2591. {
  2592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2593. {
  2594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2595. {
  2596. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2597. }
  2598. }
  2599. }
  2600. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2601. {
  2602. for (int index = 0; index < CCS_QUANTITY; index++)
  2603. {
  2604. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2605. {
  2606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2607. }
  2608. }
  2609. }
  2610. else if(gunType[gun_index] == 'G')
  2611. {
  2612. for (int index = 0; index < GB_QUANTITY; index++)
  2613. {
  2614. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2615. {
  2616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2617. }
  2618. }
  2619. }
  2620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2626. } // END FOR DC CASE
  2627. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2628. {
  2629. 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\"}]}]}]"
  2630. ,MESSAGE_TYPE_CALL
  2631. ,guid
  2632. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2633. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2634. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2635. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2636. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2637. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2638. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2639. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2640. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2641. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2642. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2643. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2644. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2645. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2646. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2647. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2648. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2649. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2650. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2651. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2652. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2653. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2654. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2655. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2656. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2657. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2658. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2659. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2660. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2661. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2662. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2663. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2664. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2665. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2666. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2667. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2668. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2669. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2670. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2671. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2672. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2673. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2674. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2675. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2676. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2677. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2678. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2679. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2680. );
  2681. }
  2682. else
  2683. {
  2684. 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\"}]}]}]"
  2685. ,MESSAGE_TYPE_CALL
  2686. ,guid
  2687. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2688. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2689. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2691. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2692. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2699. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2700. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2701. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2702. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2703. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2704. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2705. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2706. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2707. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2708. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2709. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2710. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2711. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2712. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2722. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2723. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2724. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2725. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2726. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2727. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2728. );
  2729. }
  2730. #if 0 // for TempStopTransaction
  2731. //Delete TempStopTransaction
  2732. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  2733. {
  2734. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  2735. }
  2736. #endif
  2737. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2738. if(hashmap_operation(0, guid, tempdata) == 1)
  2739. {
  2740. result = PASS;
  2741. DEBUG_INFO("StopTransaction mapitem pass\n");
  2742. }
  2743. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2744. if(GetTransactionQueueNum() == 1)
  2745. {
  2746. LWS_Send(queuedata);
  2747. }
  2748. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2749. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2750. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2751. {
  2752. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2753. }
  2754. //for test
  2755. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2756. return result;
  2757. }
  2758. int sendMeterValuesRequest(int gun_index)
  2759. {
  2760. mtrace();
  2761. int result = FAIL;
  2762. // char message[1500]={0};
  2763. char guid[37]={0};
  2764. //int idx_sample=0;
  2765. //int length = 0;
  2766. char tempdata[65]={0};
  2767. int tempIndex = 0;
  2768. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2769. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2770. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2771. {
  2772. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2773. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2774. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2775. return result;
  2776. }
  2777. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2778. {
  2779. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2780. }
  2781. memset(queuedata, 0, sizeof(queuedata));
  2782. //set value
  2783. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2784. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2785. random_uuid(guid);
  2786. //UTC Date time
  2787. struct timeval tmnow;
  2788. struct tm *tm;
  2789. char buf[28];//, usec_buf[6];
  2790. gettimeofday(&tmnow, NULL);
  2791. time_t t;
  2792. t = time(NULL);
  2793. /*UTC time and date*/
  2794. tm = gmtime(&t);
  2795. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2797. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2798. //idx_sample=0;
  2799. //********************************(1)Current.Export************************************************/
  2800. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2801. if(gunType[gun_index] == 'J')
  2802. {
  2803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2804. {
  2805. tempIndex = ((gun_index==2) ? 1: 0);
  2806. }
  2807. else
  2808. {
  2809. tempIndex = gun_index;
  2810. }
  2811. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2812. {
  2813. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2814. {
  2815. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2816. }
  2817. }
  2818. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2819. }
  2820. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2821. {
  2822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2823. {
  2824. tempIndex = ((gun_index==2) ? 1: 0);
  2825. }
  2826. else
  2827. {
  2828. tempIndex = gun_index;
  2829. }
  2830. for (int index = 0; index < CCS_QUANTITY; index++)
  2831. {
  2832. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2833. {
  2834. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2835. }
  2836. }
  2837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2838. }
  2839. else if(gunType[gun_index] == 'G')
  2840. {
  2841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2842. {
  2843. tempIndex = ((gun_index==2) ? 1: 0);
  2844. }
  2845. else
  2846. {
  2847. tempIndex = gun_index;
  2848. }
  2849. for (int index = 0; index < GB_QUANTITY; index++)
  2850. {
  2851. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2852. {
  2853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2854. }
  2855. }
  2856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2857. }
  2858. else
  2859. {
  2860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2861. {
  2862. tempIndex = 2;
  2863. }
  2864. else
  2865. {
  2866. tempIndex = gun_index;
  2867. }
  2868. for (int index = 0; index < AC_QUANTITY; index++)
  2869. {
  2870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2871. {
  2872. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2873. }
  2874. }
  2875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2876. }
  2877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2879. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  2880. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2881. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2883. //idx_sample=1;
  2884. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2885. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2886. if(gunType[gun_index] == 'J')
  2887. {
  2888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2889. {
  2890. tempIndex = ((gun_index==2) ? 1: 0);
  2891. }
  2892. else
  2893. {
  2894. tempIndex = gun_index;
  2895. }
  2896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2897. {
  2898. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2899. {
  2900. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2901. }
  2902. } // END OF FOR CHAdeMO_QUANTITY
  2903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2904. }
  2905. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2906. {
  2907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2908. {
  2909. tempIndex = ((gun_index==2) ? 1: 0);
  2910. }
  2911. else
  2912. {
  2913. tempIndex = gun_index;
  2914. }
  2915. for (int index = 0; index < CCS_QUANTITY; index++)
  2916. {
  2917. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2918. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2919. {
  2920. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2921. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2922. }
  2923. } // END OF CCS_QUANTITY
  2924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2925. }
  2926. else if(gunType[gun_index] == 'G')
  2927. {
  2928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2929. {
  2930. tempIndex = ((gun_index==2) ? 1: 0);
  2931. }
  2932. else
  2933. {
  2934. tempIndex = gun_index;
  2935. }
  2936. for (int index = 0; index < GB_QUANTITY; index++)
  2937. {
  2938. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2939. {
  2940. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2941. }
  2942. } // END OF GB_QUANTITY
  2943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2944. }
  2945. else
  2946. {
  2947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2948. {
  2949. tempIndex = 2;
  2950. }
  2951. else
  2952. {
  2953. tempIndex = gun_index;
  2954. }
  2955. for (int index = 0; index < AC_QUANTITY; index++)
  2956. {
  2957. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2958. {
  2959. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2960. }
  2961. }
  2962. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2963. }
  2964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  2967. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2968. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2969. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2970. //idx_sample=2;
  2971. //********************************(4)Power.Active.Export************************************************/
  2972. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2973. if(gunType[gun_index] == 'J')
  2974. {
  2975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2976. {
  2977. tempIndex = ((gun_index==2) ? 1: 0);
  2978. }
  2979. else
  2980. {
  2981. tempIndex = gun_index;
  2982. }
  2983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2984. {
  2985. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2986. {
  2987. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2988. }
  2989. } // END OF FOR
  2990. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2991. }
  2992. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2993. {
  2994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2995. {
  2996. tempIndex = ((gun_index==2) ? 1: 0);
  2997. }
  2998. else
  2999. {
  3000. tempIndex = gun_index;
  3001. }
  3002. for (int index = 0; index < CCS_QUANTITY; index++)
  3003. {
  3004. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3005. {
  3006. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  3007. }
  3008. }
  3009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3010. }
  3011. else if(gunType[gun_index] == 'G')
  3012. {
  3013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3014. {
  3015. tempIndex = ((gun_index==2) ? 1: 0);
  3016. }
  3017. else
  3018. {
  3019. tempIndex = gun_index;
  3020. }
  3021. for (int index = 0; index < GB_QUANTITY; index++)
  3022. {
  3023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3024. {
  3025. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  3026. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  3027. }
  3028. }
  3029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3030. }
  3031. else
  3032. {
  3033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3034. {
  3035. tempIndex = 2;
  3036. }
  3037. else
  3038. {
  3039. tempIndex = gun_index;
  3040. }
  3041. for (int index = 0; index < AC_QUANTITY; index++)
  3042. {
  3043. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3044. {
  3045. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  3046. }
  3047. }
  3048. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3049. }
  3050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3051. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  3052. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Import]);
  3053. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  3055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  3056. //idx_sample=3;
  3057. //***********************************************(5)VOLTAGE******************************************************/
  3058. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3059. if(gunType[gun_index] == 'J')
  3060. {
  3061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3062. {
  3063. tempIndex = ((gun_index==2) ? 1: 0);
  3064. }
  3065. else
  3066. {
  3067. tempIndex = gun_index;
  3068. }
  3069. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3070. {
  3071. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3072. {
  3073. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  3074. }
  3075. }
  3076. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3077. }
  3078. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3079. {
  3080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3081. {
  3082. tempIndex = ((gun_index==2) ? 1: 0);
  3083. }
  3084. else
  3085. {
  3086. tempIndex = gun_index;
  3087. }
  3088. for (int index = 0; index < CCS_QUANTITY; index++)
  3089. {
  3090. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3091. {
  3092. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  3093. }
  3094. }
  3095. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3096. }
  3097. else if(gunType[gun_index] == 'G')
  3098. {
  3099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3100. {
  3101. tempIndex = ((gun_index==2) ? 1: 0);
  3102. }
  3103. else
  3104. {
  3105. tempIndex = gun_index;
  3106. }
  3107. for (int index = 0; index < GB_QUANTITY; index++)
  3108. {
  3109. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3110. {
  3111. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  3112. }
  3113. }
  3114. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3115. }
  3116. else
  3117. {
  3118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3119. {
  3120. tempIndex = 2;
  3121. }
  3122. else
  3123. {
  3124. tempIndex = gun_index;
  3125. }
  3126. for (int index = 0; index < AC_QUANTITY; index++)
  3127. {
  3128. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3129. {
  3130. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  3131. }
  3132. }
  3133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3134. }
  3135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  3137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  3138. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  3140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3141. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3142. {
  3143. //idx_sample=4;
  3144. //sampledValue = NULL;
  3145. //***********************************************(6)SOC******************************************************/
  3146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3147. {
  3148. tempIndex = ((gun_index==2) ? 1: 0);
  3149. }
  3150. else
  3151. {
  3152. tempIndex = gun_index;
  3153. }
  3154. if(gunType[gun_index] == 'J')
  3155. {
  3156. //tempIndex = ((gun_index==2) ? 1: 0);
  3157. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3158. {
  3159. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3160. {
  3161. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  3162. }
  3163. }
  3164. }
  3165. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3166. {
  3167. //tempIndex = ((gun_index==2) ? 1: 0);
  3168. for (int index = 0; index < CCS_QUANTITY; index++)
  3169. {
  3170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3171. {
  3172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  3173. }
  3174. }
  3175. }
  3176. else if(gunType[gun_index] == 'G')
  3177. {
  3178. //tempIndex = ((gun_index==2) ? 1: 0);
  3179. for (int index = 0; index < GB_QUANTITY; index++)
  3180. {
  3181. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3182. {
  3183. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  3184. }
  3185. }
  3186. }
  3187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  3189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  3190. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3191. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  3192. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  3193. }
  3194. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3195. {
  3196. 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\"}]}]}]"
  3197. ,MESSAGE_TYPE_CALL
  3198. ,guid
  3199. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3200. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3201. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3202. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3203. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3204. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3205. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3206. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3207. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3208. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3209. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3210. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3211. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3212. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3213. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3214. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3215. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3216. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3217. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3218. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3219. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3220. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3221. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3222. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3223. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3224. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3225. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3226. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3227. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3228. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3229. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3230. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  3231. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  3232. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  3233. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  3234. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  3235. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  3236. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  3237. );
  3238. }
  3239. else
  3240. {
  3241. 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\"}]}]}]"
  3242. ,MESSAGE_TYPE_CALL
  3243. ,guid
  3244. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3245. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3246. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3247. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3248. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3249. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3250. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3251. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3252. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3253. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3254. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3255. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3256. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3257. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3258. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3259. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3260. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3261. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3262. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3263. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3264. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3265. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3266. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3267. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3268. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3269. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3270. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3271. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3272. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3273. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3274. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3275. );
  3276. }
  3277. // Put request guid to hash map
  3278. sprintf(tempdata, "MeterValues,%d", (gun_index));
  3279. 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*/)
  3280. {
  3281. result = PASS;
  3282. DEBUG_INFO("MeterValues mapitem pass\n");
  3283. }
  3284. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3285. if(GetTransactionQueueNum() == 1)
  3286. {
  3287. LWS_Send(queuedata);
  3288. }
  3289. return result;
  3290. }
  3291. //==========================================
  3292. // send confirm routine
  3293. //==========================================
  3294. int sendCancelReservationConfirmation(char *uuid,char *payload)
  3295. {
  3296. mtrace();
  3297. int result = FAIL;
  3298. char message[100]={0};
  3299. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  3300. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3301. LWS_Send(message);
  3302. result = TRUE;
  3303. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  3304. return result;
  3305. }
  3306. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  3307. {
  3308. mtrace();
  3309. int result = FAIL;
  3310. char message[100]={0};
  3311. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  3312. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3313. LWS_Send(message);
  3314. result = TRUE;
  3315. return result;
  3316. }
  3317. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  3318. {
  3319. mtrace();
  3320. int result = FAIL;
  3321. char message[100]={0};
  3322. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  3323. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3324. LWS_Send(message);
  3325. result = TRUE;
  3326. return result;
  3327. }
  3328. int sendClearCacheConfirmation(char *uuid,char *payload)
  3329. {
  3330. mtrace();
  3331. int result = FAIL;
  3332. char message[500]={0};
  3333. // int count = 0;
  3334. // int gun_index = 0;
  3335. // char guid[37];
  3336. // [ 3, "1570592744204", { "status": "Accepted" } ]
  3337. DEBUG_ERROR("sendClearCacheConfirmation\n");
  3338. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3339. LWS_Send(message);
  3340. return result;
  3341. }
  3342. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  3343. {
  3344. mtrace();
  3345. int result = FAIL;
  3346. char message[500]={0};
  3347. // [ 3, "1571284268200", { "status": "Unknown" } ]
  3348. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  3349. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3350. LWS_Send(message);
  3351. return result;
  3352. }
  3353. int sendDataTransferConfirmation(char *uuid,char *payload)
  3354. {
  3355. mtrace();
  3356. char statusStr[20]={0};
  3357. char dataStr[10]={0};
  3358. char sstr[20]={0};
  3359. int c = 0;
  3360. char *loc;
  3361. int result = FAIL;
  3362. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3363. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3364. /**********************status**************************/
  3365. loc = strstr(payload, "status");
  3366. memset(sstr ,0, sizeof(sstr) );
  3367. c = 0;
  3368. while (loc[3+strlen("status")+c] != '\"')
  3369. {
  3370. sstr[c] = loc[3+strlen("status")+c];
  3371. c++;
  3372. }
  3373. sstr[c] = '\0';
  3374. strcpy(statusStr, sstr);
  3375. /**********************data**************************/
  3376. loc = strstr(payload, "data");
  3377. memset(sstr ,0, sizeof(sstr) );
  3378. c = 0;
  3379. while (loc[3+strlen("data")+c] != '\"')
  3380. {
  3381. sstr[c] = loc[3+strlen("data")+c];
  3382. c++;
  3383. }
  3384. sstr[c] = '\0';
  3385. strcpy(dataStr, sstr);
  3386. return result;
  3387. }
  3388. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3389. {
  3390. mtrace();
  3391. int result = FAIL;
  3392. char message[1000]={0};
  3393. double diff_f = 0.0;
  3394. int diff_i = 0;
  3395. int diffSeconds = 0;
  3396. struct tm tp;
  3397. int TimeZero = FALSE;
  3398. int CompositeScheduleIndex = 0;
  3399. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  3400. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  3401. {
  3402. TimeZero = TRUE;
  3403. }
  3404. else
  3405. {
  3406. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3407. }
  3408. if(TimeZero == FALSE)
  3409. {
  3410. tp.tm_isdst = -1;
  3411. time_t utc = mktime(&tp);
  3412. time_t t = time(NULL);
  3413. diff_f = difftime(t, utc);
  3414. diff_i = (int)diff_f;
  3415. diffSeconds = diff_i % 86400;//86400 seconds/day
  3416. }
  3417. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3418. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3419. #if 0 //remove temporally
  3420. 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}"
  3421. ,MESSAGE_TYPE_CALLRESULT
  3422. ,uuid
  3423. ,payload
  3424. ,connectorIdInt
  3425. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3426. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3427. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3428. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3429. #endif
  3430. if(nPeriod == 0)
  3431. {
  3432. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  3433. {
  3434. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  3435. ,MESSAGE_TYPE_CALLRESULT
  3436. ,uuid
  3437. ,payload
  3438. ,connectorIdInt);
  3439. }
  3440. else
  3441. {
  3442. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3443. ,MESSAGE_TYPE_CALLRESULT
  3444. ,uuid
  3445. ,payload
  3446. ,connectorIdInt
  3447. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3448. }
  3449. }
  3450. else
  3451. {
  3452. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3453. ,MESSAGE_TYPE_CALLRESULT
  3454. ,uuid
  3455. ,payload
  3456. ,connectorIdInt
  3457. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3458. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3459. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3460. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3461. int len = nPeriod;
  3462. //Last Period StartPriod is less than diffSeconds
  3463. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds) || (diffSeconds == 0))
  3464. {
  3465. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3466. , 0
  3467. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3468. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3469. }
  3470. else
  3471. {
  3472. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3473. {
  3474. 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)
  3475. {
  3476. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3477. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3478. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3479. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3480. }
  3481. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3482. {
  3483. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3484. , ((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*/))
  3485. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3486. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3487. }
  3488. }
  3489. }
  3490. sprintf(message + strlen(message), "]}}]");
  3491. }
  3492. LWS_Send(message);
  3493. result = TRUE;
  3494. return result;
  3495. }
  3496. int sendGetConfigurationConfirmation(char *uuid)
  3497. {
  3498. mtrace();
  3499. int result = FAIL;
  3500. int MaxKeySupported = 0;
  3501. int sentConfigurationNumber= 0;
  3502. int sentunConfigurationNumber= 0;
  3503. char message[4000]={0};
  3504. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3505. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3506. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3507. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3508. ,MESSAGE_TYPE_CALLRESULT
  3509. ,uuid );
  3510. //configuration key
  3511. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3512. {
  3513. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3514. {
  3515. if (sentConfigurationNumber == 0)
  3516. {
  3517. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3518. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3519. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3520. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3521. }
  3522. else
  3523. {
  3524. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3525. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3526. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3527. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3528. }
  3529. sentConfigurationNumber = sentConfigurationNumber + 1;
  3530. }
  3531. }
  3532. sprintf(message + strlen(message), "]");
  3533. if(UnknownKeynum != 0)
  3534. {
  3535. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3536. //unkown key
  3537. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3538. {
  3539. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3540. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3541. if(sentunConfigurationNumber == 0)
  3542. {
  3543. sprintf(message + strlen(message), "\"%s\""
  3544. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3545. }
  3546. else
  3547. {
  3548. sprintf(message + strlen(message), ",\"%s\""
  3549. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3550. }
  3551. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3552. }
  3553. sprintf(message + strlen(message), "]");
  3554. }
  3555. sprintf(message + strlen(message), "}]");
  3556. LWS_Send(message);
  3557. return result;
  3558. }
  3559. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3560. {
  3561. mtrace();
  3562. int result = FAIL;
  3563. char message[400]={0};
  3564. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3565. if(strcmp(payload,"")==0)
  3566. {
  3567. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3568. }
  3569. else
  3570. {
  3571. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3572. }
  3573. LWS_Send(message);
  3574. result = TRUE;
  3575. return result;
  3576. }
  3577. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3578. {
  3579. mtrace();
  3580. int result = FAIL;
  3581. char message[80]={0};
  3582. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3583. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3584. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3585. LWS_Send(message);
  3586. result = TRUE;
  3587. return result;
  3588. }
  3589. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3590. {
  3591. mtrace();
  3592. int result = FAIL;
  3593. char message[80]={0};
  3594. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3595. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3596. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3597. LWS_Send(message);
  3598. result = TRUE;
  3599. return result;
  3600. }
  3601. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3602. {
  3603. mtrace();
  3604. int result = FAIL;
  3605. char message[80]={0};
  3606. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3607. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3608. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3609. LWS_Send(message);
  3610. result = TRUE;
  3611. return result;
  3612. }
  3613. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3614. {
  3615. mtrace();
  3616. int result = FAIL;
  3617. char message[80]={0};
  3618. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3619. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3620. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3621. LWS_Send(message);
  3622. result = TRUE;
  3623. return result;
  3624. }
  3625. int sendResetConfirmation(char *uuid,char *payload)
  3626. {
  3627. mtrace();
  3628. int result = FAIL;
  3629. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3630. char message[80]={0};
  3631. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3632. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3633. LWS_Send(message);
  3634. result = TRUE;
  3635. return result;
  3636. }
  3637. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3638. {
  3639. mtrace();
  3640. int result = FAIL;
  3641. char message[500]={0};
  3642. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3643. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3644. LWS_Send(message);
  3645. result = TRUE;
  3646. return result;
  3647. }
  3648. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3649. {
  3650. mtrace();
  3651. int result = FAIL;
  3652. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3653. char message[80]={0};
  3654. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3655. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3656. LWS_Send(message);
  3657. result = TRUE;
  3658. return result;
  3659. }
  3660. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3661. {
  3662. mtrace();
  3663. int result = FAIL;
  3664. char message[80]={0};
  3665. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3666. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3667. LWS_Send(message);
  3668. result = TRUE;
  3669. return result;
  3670. }
  3671. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3672. {
  3673. mtrace();
  3674. int result = FAIL;
  3675. char message[80]={0};
  3676. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3677. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3678. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3679. LWS_Send(message);
  3680. result = TRUE;
  3681. return result;
  3682. }
  3683. int sendUpdateFirmwareConfirmation(char *uuid)
  3684. {
  3685. mtrace();
  3686. int result = FAIL;
  3687. char message[60]={0};
  3688. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3689. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3690. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3691. LWS_Send(message);
  3692. result = TRUE;
  3693. return result;
  3694. }
  3695. //==========================================
  3696. // send CallError routine
  3697. //==========================================
  3698. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3699. {
  3700. mtrace();
  3701. //int result = FAIL;
  3702. char message[220]={0};
  3703. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3704. #ifdef SystemLogMessage
  3705. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3706. uniqueId, action, errorCode, errorDescription);
  3707. #endif
  3708. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3709. LWS_Send(message);
  3710. //result = TRUE;
  3711. }
  3712. //==========================================
  3713. // Handle server request routine Start
  3714. //==========================================
  3715. #define GUN_NUM 1
  3716. int handleCancelReservationRequest(char *uuid, char *payload)
  3717. {
  3718. mtrace();
  3719. int result = FAIL;
  3720. int gunNO = 0;
  3721. int reservationIdInt =0;
  3722. char comfirmstr[20];
  3723. int c = 0;
  3724. int copyTo = 0;
  3725. char *loc;
  3726. char sstr[100]={0};
  3727. DEBUG_INFO("handle CancelReservationRequest\n");
  3728. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3729. c = 0;
  3730. copyTo = 0;
  3731. loc = strstr(payload, "reservationId");
  3732. memset(sstr ,0, sizeof(sstr) );
  3733. while (loc[strlen("reservationId")+2+c] != '}')
  3734. {
  3735. if(loc[strlen("interval")+2+c] != ' ')
  3736. {
  3737. sstr[copyTo] = loc[strlen("reservationId")+2+c];
  3738. copyTo = copyTo + 1;
  3739. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3740. }
  3741. c++;
  3742. }
  3743. sstr[copyTo] = '\0';
  3744. reservationIdInt = atoi(sstr);
  3745. memset(comfirmstr, 0, sizeof comfirmstr);
  3746. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3747. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3748. //check Transaction active
  3749. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3750. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3751. {
  3752. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3753. {
  3754. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3755. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3756. if(gunType[2] == 'J')
  3757. {
  3758. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  3759. }
  3760. else
  3761. {
  3762. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3763. }
  3764. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3765. goto end;
  3766. }
  3767. }
  3768. for (int index = 0; index < CCS_QUANTITY; index++)
  3769. {
  3770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3771. {
  3772. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3773. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3774. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  3775. {
  3776. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  3777. }
  3778. else
  3779. {
  3780. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3781. }
  3782. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3783. goto end;
  3784. }
  3785. }
  3786. for (int index = 0; index < GB_QUANTITY; index++)
  3787. {
  3788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3789. {
  3790. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3791. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3792. if(gunType[2] == 'G')
  3793. {
  3794. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  3795. }
  3796. else
  3797. {
  3798. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3799. }
  3800. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3801. goto end;
  3802. }
  3803. }
  3804. for (int index = 0; index < AC_QUANTITY; index++)
  3805. {
  3806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3807. {
  3808. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3809. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3811. {
  3812. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  3813. }
  3814. else
  3815. {
  3816. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3817. }
  3818. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3819. goto end;
  3820. }
  3821. }
  3822. //The reservationId does NOT match the reservationId
  3823. sendCancelReservationConfirmation(uuid, comfirmstr);
  3824. end:
  3825. // Fill in ocpp packet uuid
  3826. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3827. return result;
  3828. }
  3829. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3830. {
  3831. mtrace();
  3832. int result = FAIL;
  3833. int gunIndex = 0;
  3834. char sstr[90]={0},sstrtemp[50]={ 0 };
  3835. char typeStr[16]={0};
  3836. char comfirmstr[20];
  3837. int specificId = FALSE;
  3838. char *loc;
  3839. //int intervalInt = 0;
  3840. int c = 0;
  3841. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3842. strcpy(sstrtemp, stringtrimspace(payload));
  3843. /*** connectorId ****/
  3844. loc = strstr(sstrtemp, "connectorId");
  3845. memset(sstr ,0, sizeof(sstr) );
  3846. c = 0;
  3847. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') ) // 2: ":
  3848. {
  3849. sstr[c] = loc[strlen("connectorId")+2+c];
  3850. c++;
  3851. }
  3852. sstr[c] = '\0';
  3853. gunIndex = atoi(sstr);
  3854. /***type ****/
  3855. loc = strstr(sstrtemp, "type");
  3856. memset(sstr ,0, sizeof(sstr) );
  3857. c = 0;
  3858. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3859. {
  3860. sstr[c] = loc[3+strlen("type")+c];
  3861. c++;
  3862. }
  3863. sstr[c] = '\0';
  3864. strcpy(typeStr, sstr);
  3865. if(gunIndex != 0)
  3866. {
  3867. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3868. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3869. }
  3870. else
  3871. {
  3872. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3873. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3874. }
  3875. memset(comfirmstr, 0, sizeof comfirmstr);
  3876. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3877. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3878. {
  3879. specificId = TRUE;
  3880. }
  3881. if(specificId == FALSE)
  3882. goto end;
  3883. if(gunIndex != 0)
  3884. {
  3885. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3886. }
  3887. else
  3888. {
  3889. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3890. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3891. }
  3892. /*
  3893. enum SYSTEM_STATUS
  3894. {
  3895. SYS_MODE_BOOTING = 0,
  3896. SYS_MODE_IDLE = 1,
  3897. SYS_MODE_AUTHORIZING = 2,
  3898. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3899. SYS_MODE_REASSIGN = 4,
  3900. SYS_MODE_PREPARING = 5,
  3901. SYS_MODE_PREPARE_FOR_EV = 6,
  3902. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3903. SYS_MODE_CHARGING = 8,
  3904. SYS_MODE_TERMINATING = 9,
  3905. SYS_MODE_COMPLETE = 10,
  3906. SYS_MODE_ALARM = 11,
  3907. SYS_MODE_FAULT = 12,
  3908. SYS_MODE_RESERVATION = 13,
  3909. SYS_MODE_BOOKING = 14,
  3910. SYS_MODE_MAINTAIN = 15,
  3911. SYS_MODE_DEBUG = 16,
  3912. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3913. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3914. SYS_MODE_UPDATE = 19
  3915. };
  3916. */
  3917. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3918. {
  3919. //check Transaction active
  3920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3921. {
  3922. if ((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')))
  3923. {
  3924. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3925. {
  3926. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3927. }
  3928. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3929. {
  3930. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3931. }
  3932. else
  3933. {
  3934. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3935. }
  3936. goto end;
  3937. }
  3938. }//END FOR CHAdeMO_QUANTITY
  3939. for (int index = 0; index < CCS_QUANTITY; index++)
  3940. {
  3941. if ((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))))
  3942. {
  3943. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3944. {
  3945. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3946. }
  3947. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3948. {
  3949. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3950. }
  3951. else
  3952. {
  3953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3954. }
  3955. goto end;
  3956. }
  3957. }//END FOR CCS_QUANTITY
  3958. for (int index = 0; index < GB_QUANTITY; index++)
  3959. {
  3960. if ((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))
  3961. {
  3962. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3963. {
  3964. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3965. }
  3966. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3967. {
  3968. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3969. }
  3970. else
  3971. {
  3972. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3973. }
  3974. goto end;
  3975. }
  3976. }// END FOR GB_QUANTITY
  3977. for (int index = 0; index < AC_QUANTITY; index++)
  3978. {
  3979. if ((gunIndex == 0) || ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))))
  3980. {
  3981. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3982. {
  3983. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3984. }
  3985. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3986. {
  3987. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3988. }
  3989. else
  3990. {
  3991. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3992. }
  3993. goto end;
  3994. }
  3995. }//END FOR AC_QUANTITY
  3996. }//END FOR AvailabilityTypeStr[Inoperative]
  3997. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3998. {
  3999. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  4000. //check Transaction active
  4001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4002. {
  4003. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4004. {
  4005. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4006. goto end;
  4007. }
  4008. }//END FOR CHAdeMO_QUANTITY
  4009. for (int index = 0; index < CCS_QUANTITY; index++)
  4010. {
  4011. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4012. {
  4013. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4014. goto end;
  4015. }
  4016. }//END FOR CCS_QUANTITY
  4017. for (int index = 0; index < GB_QUANTITY; index++)
  4018. {
  4019. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4020. {
  4021. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  4022. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4023. goto end;
  4024. }
  4025. }// END FOR GB_QUANTITY
  4026. for (int index = 0; index < AC_QUANTITY; index++)
  4027. {
  4028. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4029. {
  4030. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4031. goto end;
  4032. }
  4033. }//END FOR CHAdeMO_QUANTITY
  4034. }//END FOR AvailabilityTypeStr[Operative]
  4035. end:
  4036. if(gunIndex != 0)
  4037. {
  4038. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  4039. }
  4040. else
  4041. {
  4042. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  4043. }
  4044. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  4045. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  4046. return result;
  4047. }
  4048. int handleChangeConfigurationRequest(char *uuid, char *payload)
  4049. {
  4050. mtrace();
  4051. int result = FAIL;
  4052. char sstr[100]={0},sstrtemp[160]={ 0 };
  4053. char keystr[40]={0};
  4054. char valuestr[100]={0};
  4055. char *loc;
  4056. int c = 0;
  4057. char comfirmstr[20]={0};
  4058. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  4059. strcpy(sstrtemp, stringtrimspace(payload));
  4060. /***key ****/
  4061. loc = strstr(sstrtemp, "key");
  4062. memset(sstr ,0, sizeof(sstr) );
  4063. c = 0;
  4064. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  4065. {
  4066. sstr[c] = loc[3+strlen("key")+c];
  4067. c++;
  4068. }
  4069. sstr[c] = '\0';
  4070. strcpy(keystr, sstr);
  4071. //DEBUG_INFO( "keystr=%s\n",keystr);
  4072. /***value ****/
  4073. loc = strstr(sstrtemp, "value");
  4074. memset(sstr ,0, sizeof(sstr) );
  4075. c = 0;
  4076. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  4077. {
  4078. sstr[c] = loc[3+strlen("value")+c];
  4079. c++;
  4080. }
  4081. sstr[c] = '\0';
  4082. strcpy(valuestr, sstr);
  4083. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  4084. if((uuid==NULL) || (payload ==NULL) )
  4085. {
  4086. #ifdef Debug
  4087. DEBUG_INFO("payload is null\n");
  4088. #endif
  4089. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4090. }
  4091. else
  4092. {
  4093. int status = setKeyValue(keystr, valuestr);
  4094. switch(status)
  4095. {
  4096. case ConfigurationStatus_Accepted:
  4097. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  4098. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  4099. StoreConfigurationTable();
  4100. break;
  4101. case ConfigurationStatus_Rejected:
  4102. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4103. break;
  4104. case RebootRequired:
  4105. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  4106. StoreConfigurationTable();
  4107. break;
  4108. case NotSupported:
  4109. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  4110. break;
  4111. default:
  4112. break;
  4113. }
  4114. }
  4115. //confirmation.setStatus(ConfigurationStatus.Rejected);
  4116. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  4117. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  4118. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  4119. {
  4120. ChageWebSocketPingInterval(atoi(valuestr));
  4121. }
  4122. return result;
  4123. }
  4124. int handleClearCacheRequest(char *uuid, char *payload)
  4125. {
  4126. mtrace();
  4127. int result = FAIL;
  4128. char comfirmstr[20];
  4129. int fd;
  4130. char rmFileCmd[100]={0};
  4131. struct stat stats;
  4132. DEBUG_INFO("handle ClearCacheRequest\n");
  4133. stat("/Storage/OCPP", &stats);
  4134. // Check for directory existence
  4135. if (S_ISDIR(stats.st_mode) == 1)
  4136. {
  4137. //DEBUG_ERROR("\n OCPP directory exist \n");
  4138. }
  4139. else
  4140. {
  4141. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  4142. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  4143. system(rmFileCmd);
  4144. }
  4145. memset(rmFileCmd, 0, sizeof rmFileCmd);
  4146. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  4147. {
  4148. DEBUG_INFO("AuthorizationCache file exist.\n");
  4149. }
  4150. else
  4151. {
  4152. DEBUG_INFO("AuthorizationCache file not exist\n");
  4153. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  4154. if(log == NULL)
  4155. {
  4156. DEBUG_INFO("AuthorizationCache file is NULL\n");
  4157. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4158. goto end;
  4159. }
  4160. else
  4161. {
  4162. fclose(log);
  4163. }
  4164. }
  4165. fd = open(AuthorizationCache_JSON,O_RDWR);
  4166. if(fd < 0)
  4167. {
  4168. DEBUG_INFO("open AuthorizationCache file failed\n");
  4169. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4170. }
  4171. else
  4172. {
  4173. DEBUG_INFO("open AuthorizationCache file successful\n");
  4174. //* 清空? 件 */
  4175. ftruncate(fd,0);
  4176. //* ? 新设置? 件? 移??*/
  4177. lseek(fd,0,SEEK_SET);
  4178. close(fd);
  4179. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  4180. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  4181. }
  4182. end:
  4183. sendClearCacheConfirmation(uuid, comfirmstr);
  4184. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  4185. return result;
  4186. }
  4187. int handleClearChargingProfileRequest(char *uuid, char *payload)
  4188. {
  4189. mtrace();
  4190. int result = FAIL;
  4191. int resultRename;
  4192. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  4193. char chargingProfilePurposeStr[26]={0};
  4194. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  4195. char tempchargingProfilePurposeStr[26]={0};
  4196. char sstr[160]={0},sstrtemp[160]={ 0 };//sstr[200]={ 0 };
  4197. char str[100]={0};
  4198. int c = 0;
  4199. //int i = 0;
  4200. //char * pch;
  4201. char *loc;
  4202. char fname[200]={0};
  4203. char comfirmstr[20]={0};
  4204. char word[1600]={0};
  4205. int clearflag = FALSE;
  4206. int chargingProfileIdIsNULL = FALSE;
  4207. int connectorIsNULL = FALSE;
  4208. int chargingProfilePurposeIsNULL = FALSE;
  4209. int stackLevelIsNULL = FALSE;
  4210. //int GotoEnd = FALSE;
  4211. FILE *fptr1, *fptr2;
  4212. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  4213. int n_chargingProfile=0;
  4214. int isEmptyFile = FALSE;
  4215. char sLineWord[1600]={0};
  4216. char chargingProfiles[10][100]={0};
  4217. int ChargeProfileCount = 0;
  4218. char ch;
  4219. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  4220. strcpy(sstrtemp, stringtrimspace(payload));
  4221. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  4222. //***id ****/
  4223. c = 0;
  4224. loc = strstr(sstrtemp, "id");
  4225. memset(sstr ,0, sizeof(sstr) );
  4226. if(loc == NULL)
  4227. {
  4228. chargingProfileIdIsNULL = TRUE;
  4229. }
  4230. else
  4231. {
  4232. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  4233. {
  4234. sstr[c] = loc[strlen("id")+2+c];
  4235. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4236. c++;
  4237. }
  4238. sstr[c] = '\0';
  4239. chargingProfileIdInt = atoi(sstr);
  4240. }
  4241. //***connectorId ****/
  4242. c=0;
  4243. loc = strstr(sstrtemp, "connectorId");
  4244. memset(sstr ,0, sizeof(sstr) );
  4245. if(loc == NULL)
  4246. {
  4247. connectorIsNULL = TRUE;
  4248. }
  4249. else
  4250. {
  4251. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  4252. {
  4253. sstr[c] = loc[strlen("connectorId")+2+c];
  4254. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4255. c++;
  4256. }
  4257. sstr[c] = '\0';
  4258. connectorIdInt = atoi(sstr);
  4259. }
  4260. //***chargingProfilePurpose ****/
  4261. loc = strstr(sstrtemp, "chargingProfilePurpose");
  4262. memset(sstr ,0, sizeof(sstr) );
  4263. c = 0;
  4264. if(loc == NULL)
  4265. {
  4266. chargingProfilePurposeIsNULL = TRUE;
  4267. }
  4268. else
  4269. {
  4270. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  4271. {
  4272. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4273. c++;
  4274. }
  4275. sstr[c] = '\0';
  4276. strcpy(chargingProfilePurposeStr, sstr);
  4277. }
  4278. //***stackLevel ****/
  4279. c=0;
  4280. loc = strstr(sstrtemp, "stackLevel");
  4281. memset(sstr ,0, sizeof(sstr) );
  4282. if(loc == NULL)
  4283. {
  4284. stackLevelIsNULL = TRUE;
  4285. }
  4286. else
  4287. {
  4288. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  4289. {
  4290. sstr[c] = loc[strlen("stackLevel")+2+c];
  4291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4292. c++;
  4293. }
  4294. sstr[c] = '\0';
  4295. stackLevelInt = atoi(sstr);
  4296. }
  4297. if(connectorIsNULL == FALSE)
  4298. {
  4299. switch(connectorIdInt)
  4300. {
  4301. case 0:
  4302. if(chargingProfilePurposeIsNULL == TRUE)
  4303. {
  4304. int l = 0;
  4305. strcpy(fname, ChargePointMaxProfile_JSON);
  4306. if((access(fname,F_OK))!=-1)
  4307. {
  4308. strcpy(chargingProfiles[l], fname);
  4309. l = l + 1;
  4310. }
  4311. strcpy(fname, TxDefaultProfile_0_JSON);
  4312. if((access(fname,F_OK))!=-1)
  4313. {
  4314. strcpy(chargingProfiles[l], fname);
  4315. l = l + 1;
  4316. }
  4317. ChargeProfileCount = l;
  4318. }
  4319. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  4320. {
  4321. strcpy(fname, ChargePointMaxProfile_JSON);
  4322. if((access(fname,F_OK))!=-1)
  4323. {
  4324. strcpy(chargingProfiles[0], fname);
  4325. ChargeProfileCount = 1;
  4326. }
  4327. }
  4328. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4329. {
  4330. strcpy(fname, TxDefaultProfile_0_JSON);
  4331. if((access(fname,F_OK))!=-1)
  4332. {
  4333. strcpy(chargingProfiles[0], fname);
  4334. ChargeProfileCount = 1;
  4335. }
  4336. }
  4337. break;
  4338. default:
  4339. if(chargingProfilePurposeIsNULL == TRUE)
  4340. {
  4341. int m = 0;
  4342. memset(fname, 0, sizeof fname);
  4343. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4344. if((access(fname,F_OK))!=-1)
  4345. {
  4346. strcpy(chargingProfiles[m], fname);
  4347. m = m + 1;
  4348. }
  4349. memset(fname, 0, sizeof fname);
  4350. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4351. if((access(fname,F_OK))!=-1)
  4352. {
  4353. strcpy(chargingProfiles[m], fname);
  4354. m = m + 1;
  4355. }
  4356. ChargeProfileCount = m;
  4357. }
  4358. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4359. {
  4360. //strcpy(fname, TxDefaultProfile_1_JSON);
  4361. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4362. if((access(fname,F_OK))!=-1)
  4363. {
  4364. strcpy(chargingProfiles[0], fname);
  4365. ChargeProfileCount = 1;
  4366. }
  4367. }
  4368. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  4369. {
  4370. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4371. if((access(fname,F_OK))!=-1)
  4372. {
  4373. strcpy(chargingProfiles[0], fname);
  4374. ChargeProfileCount = 1;
  4375. }
  4376. //strcpy(fname, TxProfile_1_JSON);
  4377. }
  4378. //strcpy(fname, ChargePointMaxProfile_JSON );
  4379. break;
  4380. }
  4381. }
  4382. else // Check all Charging Profiles
  4383. {
  4384. int i = 0;
  4385. char fnametemp[200]={0};
  4386. ChargeProfileCount = 0;
  4387. //Check ChargePointMaxProfile.json exit
  4388. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  4389. {
  4390. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  4391. i = i + 1;
  4392. }
  4393. //Check TxDefaultProfile_0.json exit
  4394. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  4395. {
  4396. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  4397. i = i + 1;
  4398. }
  4399. //Check TxDefaultProfile_%d.json
  4400. for(int j=1; j <= gunTotalNumber; j++)
  4401. {
  4402. memset(fnametemp, 0, sizeof fnametemp);
  4403. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  4404. if((access(fnametemp,F_OK))!=-1)
  4405. {
  4406. strcpy(chargingProfiles[i], fnametemp);
  4407. i = i + 1;
  4408. }
  4409. }
  4410. //Check TxProfile_%d.json
  4411. for(int j=1; j <= gunTotalNumber; j++)
  4412. {
  4413. memset(fnametemp, 0, sizeof fnametemp);
  4414. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  4415. if((access(fnametemp,F_OK))!=-1)
  4416. {
  4417. strcpy(chargingProfiles[i], fnametemp);
  4418. i = i + 1;
  4419. }
  4420. }
  4421. ChargeProfileCount = i;
  4422. }// End connectorIsNULL is TRUE
  4423. if(ChargeProfileCount == 0)
  4424. {
  4425. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4426. goto end;
  4427. }
  4428. #if 0
  4429. fptr1 = fopen(fname, "r");
  4430. if (!fptr1)
  4431. {
  4432. //file not exist
  4433. DEBUG_INFO("Unable to open the input file!!\n");
  4434. fptr1 = fopen(fname, "w+");
  4435. }
  4436. fclose(fptr1);
  4437. #endif
  4438. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  4439. {
  4440. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4441. goto end;
  4442. }
  4443. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  4444. {
  4445. memset(str, 0, sizeof str);
  4446. // clear temp file
  4447. sprintf(str,"rm -f %s",temp);
  4448. system(str);
  4449. for(int k=0; k < ChargeProfileCount; k++)
  4450. {
  4451. memset(str, 0, sizeof str);
  4452. //clear file in C
  4453. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4454. system(str);
  4455. }
  4456. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4457. goto end;
  4458. }
  4459. else if(connectorIsNULL == TRUE)
  4460. {
  4461. for(int k=0; k < ChargeProfileCount; k++)
  4462. {
  4463. fptr1 = fopen(chargingProfiles[k], "r");
  4464. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  4465. //Check Charging Profile Count
  4466. while(fscanf(fptr1, "%s", word) != EOF)
  4467. {
  4468. //DEBUG_INFO("word=%s\n",word);
  4469. if(strstr(word, "chargingProfileId")!= NULL)
  4470. {
  4471. //DEBUG_INFO("test chargingProfileId \n");
  4472. n_chargingProfile = n_chargingProfile + 1;
  4473. //DEBUG_INFO("chargingProfileId Found\n");
  4474. }
  4475. }
  4476. rewind(fptr1);
  4477. //search Charging Profile Element
  4478. //int i= 0;
  4479. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4480. {
  4481. //------------------------tempconnectorIdInt------------------------//
  4482. loc = strstr(sLineWord, "connectorId");
  4483. c = 0;
  4484. memset(sstr ,0, sizeof(sstr) );
  4485. while (loc[strlen("connectorId")+2+c] != ',')
  4486. {
  4487. sstr[c] = loc[strlen("connectorId")+2+c];
  4488. c++;
  4489. }
  4490. sstr[c] = '\0';
  4491. tempconnectorIdInt = atoi(sstr);
  4492. printf("file's gun number is %d\n", tempconnectorIdInt);
  4493. //--------------------------chargingProfileId--------------------//
  4494. c = 0;
  4495. loc = strstr(sLineWord, "chargingProfileId");
  4496. memset(sstr ,0, sizeof(sstr) );
  4497. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4498. {
  4499. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4501. c++;
  4502. }
  4503. sstr[c] = '\0';
  4504. tempchargingProfileIdInt = atoi(sstr);
  4505. //stackLevel
  4506. c = 0;
  4507. loc = strstr(sLineWord, "stackLevel");
  4508. memset(sstr ,0, sizeof(sstr) );
  4509. while (loc[strlen("stackLevel")+2+c] != ',')
  4510. {
  4511. sstr[c] = loc[strlen("stackLevel")+2+c];
  4512. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4513. c++;
  4514. }
  4515. sstr[c] = '\0';
  4516. tempstackLevelInt = atoi(sstr);
  4517. c = 0;
  4518. loc = strstr(sLineWord, "chargingProfilePurpose");
  4519. memset(sstr ,0, sizeof(sstr) );
  4520. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4521. {
  4522. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4523. c++;
  4524. }
  4525. sstr[c] = '\0';
  4526. strcpy(tempchargingProfilePurposeStr, sstr);
  4527. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4528. {
  4529. //------- not write to fptr2-------//
  4530. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4531. //clearflag = TRUE;
  4532. }
  4533. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4534. {
  4535. //------- not write to fptr2-------//
  4536. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4537. }
  4538. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4539. {
  4540. //------- not write to fptr2-------//
  4541. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4542. }
  4543. else
  4544. {
  4545. fprintf(fptr2, sLineWord);//writing data into file
  4546. }
  4547. memset(sLineWord, 0, sizeof sLineWord);
  4548. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4549. if(clearflag == TRUE)
  4550. {
  4551. fclose(fptr1);
  4552. fclose(fptr2);
  4553. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4554. system(str);
  4555. // clear temp file
  4556. sprintf(str,"rm -f %s",temp);
  4557. system(str);
  4558. }
  4559. else
  4560. {
  4561. fclose(fptr1);
  4562. fclose(fptr2);
  4563. memset(str, 0, sizeof str);
  4564. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4565. system(str);
  4566. resultRename = rename(temp, chargingProfiles[k]);
  4567. if(resultRename == 0)
  4568. {
  4569. DEBUG_INFO("File ChargingProfile renamed successfully");
  4570. }
  4571. else
  4572. {
  4573. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4574. }
  4575. if(comfirmstr[0]== 0)
  4576. {
  4577. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4578. }
  4579. //Check chargingProfile is empty file
  4580. /*------ Read the file ----------------*/
  4581. fptr1=fopen(chargingProfiles[k],"r");
  4582. ch=fgetc(fptr1);
  4583. rewind(fptr1);
  4584. memset(sLineWord, 0, sizeof sLineWord);
  4585. if(ch!=EOF)
  4586. {
  4587. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4588. {
  4589. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4590. if(sLineWord[0]=='\0')
  4591. {
  4592. isEmptyFile = TRUE;
  4593. break;
  4594. }
  4595. else
  4596. {
  4597. isEmptyFile = FALSE;
  4598. break;
  4599. }
  4600. }
  4601. }
  4602. fclose(fptr1);
  4603. if(isEmptyFile == TRUE)
  4604. {
  4605. memset(str, 0, sizeof str);
  4606. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4607. system(str);
  4608. }
  4609. }
  4610. }// End of while(int k=0; k < ChargePointCount; k++)
  4611. }
  4612. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4613. {
  4614. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4615. for(int k=0; k < ChargeProfileCount; k++)
  4616. {
  4617. fptr1 = fopen(chargingProfiles[k], "r");
  4618. fptr2 = fopen(temp, "w+");
  4619. //Check Charging Profile Count
  4620. while(fscanf(fptr1, "%s", word) != EOF)
  4621. {
  4622. //DEBUG_INFO("word=%s\n",word);
  4623. if(strstr(word, "chargingProfileId")!= NULL)
  4624. {
  4625. //DEBUG_INFO("test chargingProfileId \n");
  4626. n_chargingProfile = n_chargingProfile + 1;
  4627. //DEBUG_INFO("chargingProfileId Found\n");
  4628. }
  4629. }
  4630. rewind(fptr1);
  4631. //search Charging Profile Element
  4632. //int i= 0;
  4633. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4634. {
  4635. //*************************tempconnectorIdInt*********************************/
  4636. loc = strstr(sLineWord, "connectorId");
  4637. c = 0;
  4638. memset(sstr ,0, sizeof(sstr) );
  4639. while (loc[strlen("connectorId")+2+c] != ',')
  4640. {
  4641. sstr[c] = loc[strlen("connectorId")+2+c];
  4642. c++;
  4643. }
  4644. sstr[c] = '\0';
  4645. tempconnectorIdInt = atoi(sstr);
  4646. //chargingProfileId
  4647. c = 0;
  4648. loc = strstr(sLineWord, "chargingProfileId");
  4649. memset(sstr ,0, sizeof(sstr) );
  4650. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4651. {
  4652. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4653. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4654. c++;
  4655. }
  4656. sstr[c] = '\0';
  4657. tempchargingProfileIdInt = atoi(sstr);
  4658. //stackLevel
  4659. c = 0;
  4660. loc = strstr(sLineWord, "stackLevel");
  4661. memset(sstr ,0, sizeof(sstr) );
  4662. while (loc[strlen("stackLevel")+2+c] != ',')
  4663. {
  4664. sstr[c] = loc[strlen("stackLevel")+2+c];
  4665. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4666. c++;
  4667. }
  4668. sstr[c] = '\0';
  4669. tempstackLevelInt = atoi(sstr);
  4670. c = 0;
  4671. loc = strstr(sLineWord, "chargingProfilePurpose");
  4672. memset(sstr ,0, sizeof(sstr) );
  4673. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4674. {
  4675. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4676. c++;
  4677. }
  4678. sstr[c] = '\0';
  4679. strcpy(tempchargingProfilePurposeStr, sstr);
  4680. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4681. {
  4682. //------- not write to fptr2-------//
  4683. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4684. //clearflag = TRUE;
  4685. }
  4686. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4687. {
  4688. //------- not write to fptr2-------//
  4689. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4690. }
  4691. else if(stackLevelIsNULL == TRUE)
  4692. {
  4693. //Clear Whole File
  4694. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4695. clearflag = TRUE;
  4696. break;
  4697. }
  4698. else
  4699. {
  4700. fprintf(fptr2, sLineWord);//writing data into file
  4701. }
  4702. memset(sLineWord, 0, sizeof sLineWord);
  4703. }
  4704. if(clearflag == TRUE)
  4705. {
  4706. fclose(fptr1);
  4707. fclose(fptr2);
  4708. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4709. system(str);
  4710. // clear temp file
  4711. sprintf(str,"rm -f %s",temp);
  4712. system(str);
  4713. }
  4714. else
  4715. {
  4716. fclose(fptr1);
  4717. fclose(fptr2);
  4718. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4719. system(str);
  4720. resultRename = rename(temp, chargingProfiles[k]);
  4721. if(resultRename == 0)
  4722. {
  4723. DEBUG_INFO("File ChargingProfile renamed successfully");
  4724. }
  4725. else
  4726. {
  4727. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4728. }
  4729. if(comfirmstr[0]== 0)
  4730. {
  4731. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4732. }
  4733. //Check chargingProfile is empty file
  4734. /*------ Read the file ----------------*/
  4735. fptr1=fopen(chargingProfiles[k],"r");
  4736. ch=fgetc(fptr1);
  4737. rewind(fptr1);
  4738. memset(sLineWord, 0, sizeof sLineWord);
  4739. if(ch!=EOF)
  4740. {
  4741. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4742. {
  4743. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4744. if(sLineWord[0]=='\0')
  4745. {
  4746. isEmptyFile = TRUE;
  4747. break;
  4748. }
  4749. else
  4750. {
  4751. isEmptyFile = FALSE;
  4752. break;
  4753. }
  4754. }
  4755. }
  4756. fclose(fptr1);
  4757. if(isEmptyFile == TRUE)
  4758. {
  4759. memset(str, 0, sizeof str);
  4760. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4761. system(str);
  4762. }
  4763. /*------- End of reading ---------------*/
  4764. }
  4765. } // while(int k=0; k < ChargeProfileCount; k++)
  4766. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4767. end:
  4768. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4769. return result;
  4770. }
  4771. int handleDataTransferRequest(char *uuid, char *payload)
  4772. {
  4773. mtrace();
  4774. int result = FAIL;
  4775. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4776. char tempvendorId[255]={0};
  4777. char tempmessageId[50]={0};
  4778. char tempdata[50]={0};
  4779. char sstr[160]={0};//sstr[200]={ 0 };
  4780. char message[80]={0};
  4781. int c = 0;
  4782. char *loc;
  4783. DEBUG_INFO("handle DataTransferRequest\n");
  4784. if((uuid != NULL) && (payload != NULL))
  4785. {
  4786. //===============================
  4787. // vendorId
  4788. //===============================
  4789. c = 0;
  4790. loc = strstr(payload, "vendorId");
  4791. while (loc[strlen("vendorId")+3+c] != '\"')
  4792. {
  4793. sstr[c] = loc[strlen("vendorId")+3+c];
  4794. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4795. c++;
  4796. }
  4797. sstr[c] = '\0';
  4798. strcpy(tempvendorId,sstr);
  4799. //===============================
  4800. // messageId
  4801. //===============================
  4802. memset(sstr ,0, sizeof(sstr) );
  4803. c = 0;
  4804. loc = strstr(payload, "messageId");
  4805. while (loc[strlen("messageId")+3+c] != '\"')
  4806. {
  4807. sstr[c] = loc[strlen("messageId")+3+c];
  4808. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4809. c++;
  4810. }
  4811. sstr[c] = '\0';
  4812. strcpy(tempmessageId,sstr);
  4813. //===============================
  4814. // data
  4815. //===============================
  4816. memset(sstr ,0, sizeof(sstr) );
  4817. c = 0;
  4818. loc = strstr(payload, "data");
  4819. printf("loc=%s\n",loc);
  4820. while (loc[strlen("data")+3+c] != '\"')
  4821. {
  4822. sstr[c] = loc[strlen("data")+3+c];
  4823. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4824. c++;
  4825. }
  4826. sstr[c] = '\0';
  4827. strcpy(tempdata,sstr);
  4828. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4829. }
  4830. else
  4831. {
  4832. char guid[37]={0};
  4833. random_uuid(guid);
  4834. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4835. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4836. }
  4837. LWS_Send(message);
  4838. return result;
  4839. }
  4840. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4841. {
  4842. mtrace();
  4843. int result = FAIL;
  4844. int connectorIdInt, durationInt;
  4845. char chargingRateUnitStr[4]={0};
  4846. //int tempconnectorIdInt,
  4847. int tempdurationInt;
  4848. float tempminChargingRateFloat = 0.0;
  4849. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4850. int tempStartPeriodInt=0;
  4851. float tempLimitInt=0.0;//0.1;
  4852. int tempNumberPhasesInt=0;
  4853. char fname[200];
  4854. char comfirmstr[20];
  4855. //float totallimit =0.0;
  4856. float MinChargingRate =0.0;
  4857. //double diff_t;
  4858. //struct tm tp;
  4859. FILE *fptr1;
  4860. int c = 0;
  4861. //int i = 0;
  4862. char * pch;
  4863. char *loc;
  4864. char sstr[200]={ 0 },sstrtemp[50]={ 0 };
  4865. int n_chargingProfile = 0;
  4866. int n_SchedulePeriods = 0;
  4867. char SchedulePeriodList[10][200]={0};
  4868. char sLineWord[1600]={0};
  4869. //int n_periods = 0;
  4870. char word[1000]={0};
  4871. int confirmPeriods = 0;
  4872. struct StructProfile ChargePointMaxProfile;
  4873. struct StructProfile TxDefaultProfile;
  4874. struct StructProfile TxProfile;
  4875. struct StructProfile TxDefaultProfiletemp[2]={0};
  4876. int TxDefaultProfileFileIsNull=FALSE;
  4877. int ChargePointMaxProfileIsNull=FALSE;
  4878. int TxProfileIsNull=FALSE;
  4879. int CompositeSceduleIndex = 0;
  4880. char ChargePointMaxProfileScheduleStr[30]={0};
  4881. char TxDefaultProfileScheduleStr[30]={0};
  4882. char TxProfileScheduleStr[30]={0};
  4883. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4884. strcpy(sstrtemp, stringtrimspace(payload));
  4885. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4886. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4887. memset(&TxProfile,0,sizeof(struct StructProfile));
  4888. c=0;
  4889. loc = strstr(sstrtemp, "connectorId");
  4890. memset(sstr ,0, sizeof(sstr) );
  4891. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4892. {
  4893. sstr[c] = loc[strlen("connectorId")+2+c];
  4894. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4895. c++;
  4896. }
  4897. sstr[c] = '\0';
  4898. connectorIdInt = atoi(sstr);
  4899. c=0;
  4900. loc = strstr(sstrtemp, "duration");
  4901. memset(sstr ,0, sizeof(sstr) );
  4902. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4903. {
  4904. sstr[c] = loc[strlen("duration")+2+c];
  4905. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4906. c++;
  4907. }
  4908. sstr[c] = '\0';
  4909. durationInt = atoi(sstr);
  4910. c = 0;
  4911. loc = strstr(sstrtemp, "chargingRateUnit");
  4912. memset(sstr ,0, sizeof(sstr) );
  4913. if(loc == NULL)
  4914. {
  4915. }
  4916. else
  4917. {
  4918. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4919. {
  4920. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4921. c++;
  4922. }
  4923. sstr[c] = '\0';
  4924. strcpy(chargingRateUnitStr, sstr);
  4925. }
  4926. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4927. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4928. if(connectorIdInt==0) // connectorId is 0
  4929. {
  4930. //******************************ChargePointMaxProfile*****************************************************/
  4931. strcpy(fname, ChargePointMaxProfile_JSON );
  4932. char word[30]={0};
  4933. char sLineWord[1060]={0};
  4934. int n_chargingProfile=0;
  4935. ChargePointMaxProfileIsNull=TRUE;
  4936. if((access(fname,F_OK))!=-1)
  4937. {
  4938. fptr1 = fopen(fname, "r");
  4939. int c;
  4940. c = fgetc(fptr1);
  4941. //DEBUG_INFO("c:%d\n",c);
  4942. rewind(fptr1);
  4943. if(c == EOF)
  4944. {
  4945. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4946. ChargePointMaxProfileIsNull=TRUE;
  4947. fclose(fptr1);
  4948. }
  4949. else
  4950. {
  4951. ChargePointMaxProfileIsNull=FALSE;
  4952. while(fscanf(fptr1, "%s", word) != EOF)
  4953. {
  4954. if(strcmp(word, "chargingProfileId") == 0)
  4955. {
  4956. n_chargingProfile = n_chargingProfile + 1;
  4957. printf("Found\n");
  4958. }
  4959. }
  4960. rewind(fptr1);
  4961. //search Charging Profile Element
  4962. int i= 0;
  4963. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4964. #if 0
  4965. /***********connectorId****************/
  4966. c = 0;
  4967. loc = strstr(sLineWord, "connectorId");
  4968. // printf("loc=%s\n",loc);
  4969. memset(sstr ,0, sizeof(sstr) );
  4970. while (loc[strlen("connectorId")+2+c] != ',')
  4971. {
  4972. sstr[c] = loc[strlen("connectorId")+2+c];
  4973. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4974. c++;
  4975. }
  4976. sstr[c] = '\0';
  4977. tempconnectorIdInt = atoi(sstr);
  4978. #endif
  4979. //***********validFrom**************/
  4980. c = 0;
  4981. loc = strstr(sLineWord, "validFrom");
  4982. //DEBUG_INFO("loc=%s\n",loc);
  4983. memset(sstr ,0, sizeof(sstr) );
  4984. if(loc != NULL)
  4985. {
  4986. while (loc[3+strlen("validFrom")+c] != '\"')
  4987. {
  4988. sstr[c] = loc[3+strlen("validFrom")+c];
  4989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4990. c++;
  4991. }
  4992. sstr[c] = '\0';
  4993. DEBUG_INFO("validFrom=%s\n",sstr);
  4994. strcpy(tempvalidFromStr,sstr);
  4995. }
  4996. else
  4997. {
  4998. strcpy(tempvalidFromStr,"");
  4999. }
  5000. //**********startSchedule**********/
  5001. c = 0;
  5002. loc = strstr(sLineWord, "startSchedule");
  5003. //DEBUG_INFO("loc=%s\n",loc);
  5004. memset(sstr ,0, sizeof(sstr) );
  5005. if(loc != NULL)
  5006. {
  5007. while (loc[3+strlen("startSchedule")+c] != '\"')
  5008. {
  5009. sstr[c] = loc[3+strlen("startSchedule")+c];
  5010. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5011. c++;
  5012. }
  5013. sstr[c] = '\0';
  5014. strcpy(tempstartScheduleStr, sstr);
  5015. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5016. }
  5017. else
  5018. {
  5019. strcpy(tempstartScheduleStr, "");
  5020. strcpy(ChargePointMaxProfileScheduleStr, "");
  5021. }
  5022. //**********chargingRateUnit**********/
  5023. c = 0;
  5024. loc = strstr(sLineWord, "chargingRateUnit");
  5025. memset(sstr ,0, sizeof(sstr) );
  5026. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5027. {
  5028. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5029. c++;
  5030. }
  5031. sstr[c] = '\0';
  5032. strcpy(tempchargingRateUnitStr, sstr);
  5033. //**********minChargingRate*******/
  5034. c = 0;
  5035. loc = strstr(sLineWord, "minChargingRate");
  5036. //printf("loc=%s\n",loc);
  5037. if(loc != NULL)
  5038. {
  5039. memset(sstr ,0, sizeof(sstr) );
  5040. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5041. {
  5042. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5043. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5044. c++;
  5045. }
  5046. sstr[c] = '\0';
  5047. tempminChargingRateFloat = atof(sstr);
  5048. }
  5049. else
  5050. {
  5051. tempminChargingRateFloat = 0.0;
  5052. }
  5053. //
  5054. #if 0
  5055. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5056. tp.tm_isdst = -1;
  5057. time_t utc = mktime(&tp);
  5058. // current time
  5059. time_t t = time(NULL);
  5060. #endif
  5061. //diff_t = difftime(t, utc);
  5062. //parsing strings to words
  5063. i = 0;
  5064. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5065. loc = loc+3+strlen("chargingSchedulePeriod");
  5066. pch = strtok(loc ,"{");
  5067. while (pch != NULL)
  5068. {
  5069. strcpy(SchedulePeriodList[i], pch);
  5070. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5071. //printf ("%s\n",pch);
  5072. pch = strtok (NULL, "{");
  5073. i = i + 1;
  5074. }
  5075. n_SchedulePeriods = i;
  5076. for(int i=0;i<n_SchedulePeriods;i++)
  5077. {
  5078. //*************startPeriod****************/
  5079. c = 0;
  5080. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5081. memset(sstr ,0, sizeof(sstr) );
  5082. while (loc[strlen("startPeriod")+2+c] != ',')
  5083. {
  5084. sstr[c] = loc[strlen("startPeriod")+2+c];
  5085. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5086. c++;
  5087. }
  5088. sstr[c] = '\0';
  5089. tempStartPeriodInt = atoi(sstr);
  5090. //*************limit****************/
  5091. c = 0;
  5092. loc = strstr(SchedulePeriodList[i], "limit");
  5093. memset(sstr ,0, sizeof(sstr) );
  5094. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5095. {
  5096. sstr[c] = loc[strlen("limit")+2+c];
  5097. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5098. c++;
  5099. }
  5100. sstr[c] = '\0';
  5101. tempLimitInt = atof(sstr);
  5102. //*************numberPhases****************/
  5103. c = 0;
  5104. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5105. memset(sstr ,0, sizeof(sstr) );
  5106. if(loc != NULL)
  5107. {
  5108. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5109. {
  5110. sstr[c] = loc[strlen("numberPhases")+2+c];
  5111. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5112. c++;
  5113. }
  5114. sstr[c] = '\0';
  5115. tempNumberPhasesInt = atoi(sstr);
  5116. }
  5117. else
  5118. {
  5119. tempNumberPhasesInt = 0;
  5120. }
  5121. ChargePointMaxProfile.Duration = durationInt;
  5122. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5123. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5124. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5125. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5126. }
  5127. if(MinChargingRate < tempminChargingRateFloat)
  5128. MinChargingRate = tempminChargingRateFloat;
  5129. }
  5130. }// End of file ChargingProfile
  5131. } //THE END OF ACCESS ChargePointMaxProfile
  5132. //******************************TxDefaultProfile***********************************************/
  5133. strcpy(fname, TxDefaultProfile_0_JSON);
  5134. memset(word, 0, 30);
  5135. memset(sLineWord, 0, 1060);
  5136. //char word[30]={0};
  5137. //char sLineWord[1060]={0};
  5138. n_chargingProfile=0;
  5139. TxDefaultProfileFileIsNull=TRUE;
  5140. if((access(fname,F_OK))!=-1)
  5141. {
  5142. fptr1 = fopen(fname, "r");
  5143. c = 0;
  5144. c = fgetc(fptr1);
  5145. //DEBUG_INFO("c:%d\n",c);
  5146. rewind(fptr1);
  5147. if(c == EOF)
  5148. {
  5149. DEBUG_INFO("\n End of file ChargingProfile reached.");
  5150. TxDefaultProfileFileIsNull=TRUE;
  5151. fclose(fptr1);
  5152. }
  5153. else
  5154. {
  5155. TxDefaultProfileFileIsNull=FALSE;
  5156. while(fscanf(fptr1, "%s", word) != EOF)
  5157. {
  5158. if(strcmp(word, "chargingProfileId") == 0)
  5159. {
  5160. n_chargingProfile = n_chargingProfile + 1;
  5161. printf("Found\n");
  5162. }
  5163. }
  5164. rewind(fptr1);
  5165. //search Charging Profile Element
  5166. int i= 0;
  5167. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5168. #if 0
  5169. /***********connectorId****************/
  5170. c = 0;
  5171. loc = strstr(sLineWord, "connectorId");
  5172. // printf("loc=%s\n",loc);
  5173. memset(sstr ,0, sizeof(sstr) );
  5174. while (loc[strlen("connectorId")+2+c] != ',')
  5175. {
  5176. sstr[c] = loc[strlen("connectorId")+2+c];
  5177. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5178. c++;
  5179. }
  5180. sstr[c] = '\0';
  5181. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  5182. tempconnectorIdInt = atoi(sstr);
  5183. #endif
  5184. //***********validFrom**************/
  5185. c = 0;
  5186. loc = strstr(sLineWord, "validFrom");
  5187. //DEBUG_INFO("loc=%s\n",loc);
  5188. memset(sstr ,0, sizeof(sstr) );
  5189. if(loc != NULL)
  5190. {
  5191. while (loc[3+strlen("validFrom")+c] != '\"')
  5192. {
  5193. sstr[c] = loc[3+strlen("validFrom")+c];
  5194. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5195. c++;
  5196. }
  5197. sstr[c] = '\0';
  5198. DEBUG_INFO("validFrom=%s\n",sstr);
  5199. strcpy(tempvalidFromStr,sstr);
  5200. }
  5201. else
  5202. {
  5203. strcpy(tempvalidFromStr,"");
  5204. }
  5205. //**********startSchedule**********/
  5206. c = 0;
  5207. loc = strstr(sLineWord, "startSchedule");
  5208. //DEBUG_INFO("loc=%s\n",loc);
  5209. memset(sstr ,0, sizeof(sstr) );
  5210. if(loc != NULL)
  5211. {
  5212. while (loc[3+strlen("startSchedule")+c] != '\"')
  5213. {
  5214. sstr[c] = loc[3+strlen("startSchedule")+c];
  5215. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5216. c++;
  5217. }
  5218. sstr[c] = '\0';
  5219. strcpy(tempstartScheduleStr, sstr);
  5220. strcpy(TxDefaultProfileScheduleStr, sstr);
  5221. }
  5222. else
  5223. {
  5224. strcpy(tempstartScheduleStr, "");
  5225. strcpy(TxDefaultProfileScheduleStr, "");
  5226. }
  5227. //**********chargingRateUnit**********/
  5228. c = 0;
  5229. loc = strstr(sLineWord, "chargingRateUnit");
  5230. memset(sstr ,0, sizeof(sstr) );
  5231. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5232. {
  5233. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5234. c++;
  5235. }
  5236. sstr[c] = '\0';
  5237. strcpy(tempchargingRateUnitStr, sstr);
  5238. //**********minChargingRate*******/
  5239. c = 0;
  5240. loc = strstr(sLineWord, "minChargingRate");
  5241. //printf("loc=%s\n",loc);
  5242. if(loc != NULL)
  5243. {
  5244. memset(sstr ,0, sizeof(sstr) );
  5245. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5246. {
  5247. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5248. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5249. c++;
  5250. }
  5251. sstr[c] = '\0';
  5252. tempminChargingRateFloat = atof(sstr);
  5253. }
  5254. else
  5255. {
  5256. tempminChargingRateFloat = 0.0;
  5257. }
  5258. #if 0
  5259. //
  5260. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5261. tp.tm_isdst = -1;
  5262. time_t utc = mktime(&tp);
  5263. // current time
  5264. time_t t = time(NULL);
  5265. //diff_t = difftime(t, utc);
  5266. #endif
  5267. //parsing strings to words
  5268. i = 0;
  5269. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5270. loc = loc+3+strlen("chargingSchedulePeriod");
  5271. pch = strtok(loc ,"{");
  5272. while (pch != NULL)
  5273. {
  5274. strcpy(SchedulePeriodList[i], pch);
  5275. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5276. //printf ("%s\n",pch);
  5277. pch = strtok (NULL, "{");
  5278. i = i + 1;
  5279. }
  5280. n_SchedulePeriods = i;
  5281. for(int i=0;i<n_SchedulePeriods;i++)
  5282. {
  5283. //*************startPeriod****************/
  5284. c = 0;
  5285. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5286. memset(sstr ,0, sizeof(sstr) );
  5287. while (loc[strlen("startPeriod")+2+c] != ',')
  5288. {
  5289. sstr[c] = loc[strlen("startPeriod")+2+c];
  5290. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5291. c++;
  5292. }
  5293. sstr[c] = '\0';
  5294. tempStartPeriodInt = atoi(sstr);
  5295. //*************limit****************/
  5296. c = 0;
  5297. loc = strstr(SchedulePeriodList[i], "limit");
  5298. memset(sstr ,0, sizeof(sstr) );
  5299. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5300. {
  5301. sstr[c] = loc[strlen("limit")+2+c];
  5302. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5303. c++;
  5304. }
  5305. sstr[c] = '\0';
  5306. tempLimitInt = atof(sstr);
  5307. //*************numberPhases****************/
  5308. c = 0;
  5309. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5310. memset(sstr ,0, sizeof(sstr) );
  5311. if(loc != NULL)
  5312. {
  5313. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5314. {
  5315. sstr[c] = loc[strlen("numberPhases")+2+c];
  5316. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5317. c++;
  5318. }
  5319. sstr[c] = '\0';
  5320. tempNumberPhasesInt = atoi(sstr);
  5321. }
  5322. else
  5323. {
  5324. tempNumberPhasesInt = 0;
  5325. }
  5326. TxDefaultProfile.Duration = durationInt;
  5327. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5328. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5329. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5330. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5331. }
  5332. if(MinChargingRate < tempminChargingRateFloat)
  5333. MinChargingRate = tempminChargingRateFloat;
  5334. }
  5335. }
  5336. }// the end of ACCESS TxDefaultProfile
  5337. //--------------------- Composite Schedule-----------------------------//
  5338. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  5339. {
  5340. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5341. struct tm tp;
  5342. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5343. tp.tm_isdst = -1;
  5344. time_t utc = mktime(&tp);
  5345. time_t t = time(NULL);
  5346. double diff_f = difftime(t, utc);
  5347. int diff_i; //= (int)diff_f;
  5348. int quotient; //= diff_i / 86400;//86400 seconds/day
  5349. int period = 0;
  5350. if(diff_f >= 0)
  5351. {
  5352. diff_i = (int)diff_f;
  5353. quotient = diff_i / 86400;
  5354. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5355. {
  5356. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5357. {
  5358. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  5359. {
  5360. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5361. }
  5362. else
  5363. {
  5364. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5365. }
  5366. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5367. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5368. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5369. period = period + 1;
  5370. }
  5371. }
  5372. }
  5373. confirmPeriods = period;
  5374. }
  5375. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  5376. {
  5377. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5378. struct tm tp;
  5379. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5380. tp.tm_isdst = -1;
  5381. time_t utc = mktime(&tp);
  5382. time_t t = time(NULL);
  5383. double diff_f = difftime(t, utc);
  5384. int diff_i; // = (int)diff_f;
  5385. int quotient; // = diff_i / 86400;//86400 seconds/day
  5386. int period = 0;
  5387. if(diff_f >= 0)
  5388. {
  5389. diff_i = (int)diff_f;
  5390. quotient = diff_i / 86400;//86400 seconds/day
  5391. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5392. {
  5393. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5394. {
  5395. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5396. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5397. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5398. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5399. period = period + 1;
  5400. }
  5401. }
  5402. }
  5403. confirmPeriods = period;
  5404. }
  5405. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  5406. {
  5407. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  5408. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  5409. {
  5410. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  5411. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  5412. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  5413. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5414. }
  5415. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  5416. }
  5417. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  5418. {
  5419. confirmPeriods = 0;
  5420. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5421. //goto end;
  5422. }
  5423. //* Define temporary variables */
  5424. struct tm *gtime;
  5425. time_t now;
  5426. char buf[28];
  5427. /* Read the current system time */
  5428. time(&now);
  5429. /* Convert the system time to GMT (now UTC) */
  5430. gtime = gmtime(&now);
  5431. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5432. // make .conf
  5433. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5434. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5435. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5436. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5437. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5438. }
  5439. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  5440. {
  5441. //*****************************ChargePointMaxProfile******************************************/
  5442. strcpy(fname, ChargePointMaxProfile_JSON);
  5443. ChargePointMaxProfileIsNull=TRUE;
  5444. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  5445. {
  5446. fptr1 = fopen(fname, "r");
  5447. int c;
  5448. c = fgetc(fptr1);
  5449. //DEBUG_INFO("c:%d\n",c);
  5450. rewind(fptr1);
  5451. if(c == EOF)
  5452. {
  5453. DEBUG_INFO("\n End of file reached.");
  5454. ChargePointMaxProfileIsNull=TRUE;
  5455. fclose(fptr1);
  5456. }
  5457. else
  5458. {
  5459. ChargePointMaxProfileIsNull=FALSE;
  5460. while(fscanf(fptr1, "%s", word) != EOF)
  5461. {
  5462. if(strcmp(word, "chargingProfileId") == 0)
  5463. {
  5464. n_chargingProfile = n_chargingProfile + 1;
  5465. }
  5466. }
  5467. rewind(fptr1);
  5468. //search Charging Profile Element
  5469. int i = 0;
  5470. int j = 0;
  5471. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5472. #if 0
  5473. /***********connectorId****************/
  5474. c = 0;
  5475. loc = strstr(sLineWord, "connectorId");
  5476. memset(sstr ,0, sizeof(sstr) );
  5477. while (loc[strlen("connectorId")+2+c] != ',')
  5478. {
  5479. sstr[c] = loc[strlen("connectorId")+2+c];
  5480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5481. c++;
  5482. }
  5483. sstr[c] = '\0';
  5484. tempconnectorIdInt = atoi(sstr);
  5485. #endif
  5486. //***********validFrom**************/
  5487. c = 0;
  5488. loc = strstr(sLineWord, "validFrom");
  5489. if(loc != NULL)
  5490. {
  5491. memset(sstr ,0, sizeof(sstr) );
  5492. while (loc[3+strlen("validFrom")+c] != '\"')
  5493. {
  5494. sstr[c] = loc[3+strlen("validFrom")+c];
  5495. c++;
  5496. }
  5497. sstr[c] = '\0';
  5498. strcpy(tempvalidFromStr,sstr);
  5499. }
  5500. else
  5501. {
  5502. strcpy(tempvalidFromStr,"");
  5503. }
  5504. //***********validFrom**************/
  5505. c = 0;
  5506. loc = strstr(sLineWord, "duration");
  5507. if(loc != NULL)
  5508. {
  5509. memset(sstr ,0, sizeof(sstr) );
  5510. while (loc[2+strlen("duration")+c] != ',')
  5511. {
  5512. sstr[c] = loc[2+strlen("duration")+c];
  5513. c++;
  5514. }
  5515. sstr[c] = '\0';
  5516. tempdurationInt = atoi(sstr);
  5517. }
  5518. else
  5519. {
  5520. tempdurationInt = 0;
  5521. }
  5522. //**********startSchedule**********/
  5523. c = 0;
  5524. loc = strstr(sLineWord, "startSchedule");
  5525. memset(sstr ,0, sizeof(sstr) );
  5526. if(loc != NULL)
  5527. {
  5528. while (loc[3+strlen("startSchedule")+c] != '\"')
  5529. {
  5530. sstr[c] = loc[3+strlen("startSchedule")+c];
  5531. c++;
  5532. }
  5533. sstr[c] = '\0';
  5534. strcpy(tempstartScheduleStr, sstr);
  5535. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5536. }
  5537. else
  5538. {
  5539. strcpy(tempstartScheduleStr, "");
  5540. strcpy(ChargePointMaxProfileScheduleStr, "");
  5541. }
  5542. //**********chargingRateUnit**********/
  5543. c = 0;
  5544. loc = strstr(sLineWord, "chargingRateUnit");
  5545. memset(sstr ,0, sizeof(sstr) );
  5546. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5547. {
  5548. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5549. c++;
  5550. }
  5551. sstr[c] = '\0';
  5552. strcpy(tempchargingRateUnitStr, sstr);
  5553. //**********minChargingRate*******/
  5554. c = 0;
  5555. loc = strstr(sLineWord, "minChargingRate");
  5556. if(loc != NULL)
  5557. {
  5558. memset(sstr ,0, sizeof(sstr) );
  5559. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5560. {
  5561. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5562. c++;
  5563. }
  5564. sstr[c] = '\0';
  5565. tempminChargingRateFloat = atof(sstr);
  5566. }
  5567. else
  5568. {
  5569. tempminChargingRateFloat = 0.0;
  5570. }
  5571. #if 0
  5572. //
  5573. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5574. tp.tm_isdst = -1;
  5575. time_t utc = mktime(&tp);
  5576. time_t t = time(NULL);
  5577. //diff_t = difftime(t, utc);
  5578. #endif
  5579. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5580. //DEBUG_INFO(" debug 5 -1\n");
  5581. //parsing strings to words
  5582. i = 0;
  5583. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5584. loc = loc+3+strlen("chargingSchedulePeriod");
  5585. pch = strtok(loc ,"{");
  5586. while (pch != NULL)
  5587. {
  5588. strcpy(SchedulePeriodList[i], pch);
  5589. pch = strtok (NULL, "{");
  5590. i = i + 1;
  5591. }
  5592. n_SchedulePeriods = i;
  5593. for(int i=0;i<n_SchedulePeriods;i++)
  5594. {
  5595. //*************startPeriod****************/
  5596. c = 0;
  5597. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5598. memset(sstr ,0, sizeof(sstr) );
  5599. while (loc[strlen("startPeriod")+2+c] != ',')
  5600. {
  5601. sstr[c] = loc[strlen("startPeriod")+2+c];
  5602. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5603. c++;
  5604. }
  5605. sstr[c] = '\0';
  5606. tempStartPeriodInt = atoi(sstr);
  5607. //*************limit****************/
  5608. c = 0;
  5609. loc = strstr(SchedulePeriodList[i], "limit");
  5610. memset(sstr ,0, sizeof(sstr) );
  5611. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5612. {
  5613. sstr[c] = loc[strlen("limit")+2+c];
  5614. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5615. c++;
  5616. }
  5617. sstr[c] = '\0';
  5618. tempLimitInt = atof(sstr);
  5619. //*************numberPhases****************/
  5620. c = 0;
  5621. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5622. memset(sstr ,0, sizeof(sstr) );
  5623. if(loc != NULL)
  5624. {
  5625. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5626. {
  5627. sstr[c] = loc[strlen("numberPhases")+2+c];
  5628. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5629. c++;
  5630. }
  5631. sstr[c] = '\0';
  5632. tempNumberPhasesInt = atoi(sstr);
  5633. }
  5634. else
  5635. {
  5636. tempNumberPhasesInt = 0;
  5637. }
  5638. if(j == 0)
  5639. {
  5640. ChargePointMaxProfile.Duration = tempdurationInt;
  5641. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5642. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5643. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5644. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5645. }
  5646. }
  5647. if(MinChargingRate < tempminChargingRateFloat)
  5648. {
  5649. MinChargingRate = tempminChargingRateFloat;
  5650. }
  5651. if(confirmPeriods < n_SchedulePeriods)
  5652. {
  5653. confirmPeriods = n_SchedulePeriods;
  5654. }
  5655. j = j + 1;
  5656. }
  5657. fclose(fptr1);
  5658. }
  5659. }// the end of access file ChargePointMaxProfile
  5660. //****************************TxDefaultProfile************************************************/
  5661. memset(fname, 0, sizeof fname);
  5662. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5663. TxDefaultProfileFileIsNull=TRUE;
  5664. if((access(fname,F_OK))!=-1)
  5665. {
  5666. fptr1 = fopen(fname, "r");
  5667. c = 0;
  5668. c = fgetc(fptr1);
  5669. //DEBUG_INFO("c:%d\n",c);
  5670. rewind(fptr1);
  5671. if(c == EOF)
  5672. {
  5673. DEBUG_INFO("\n End of file reached.");
  5674. TxDefaultProfileFileIsNull=TRUE;
  5675. fclose(fptr1);
  5676. }
  5677. else
  5678. {
  5679. TxDefaultProfileFileIsNull=FALSE;
  5680. while(fscanf(fptr1, "%s", word) != EOF)
  5681. {
  5682. if(strcmp(word, "chargingProfileId") == 0)
  5683. {
  5684. n_chargingProfile = n_chargingProfile + 1;
  5685. }
  5686. }
  5687. rewind(fptr1);
  5688. //search Charging Profile Element
  5689. int i = 0;
  5690. int j = 0;
  5691. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5692. //DEBUG_INFO(" 1-1\n");
  5693. #if 0
  5694. /***********connectorId****************/
  5695. c = 0;
  5696. loc = strstr(sLineWord, "connectorId");
  5697. memset(sstr ,0, sizeof(sstr) );
  5698. while (loc[strlen("connectorId")+2+c] != ',')
  5699. {
  5700. sstr[c] = loc[strlen("connectorId")+2+c];
  5701. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5702. c++;
  5703. }
  5704. sstr[c] = '\0';
  5705. tempconnectorIdInt = atoi(sstr);
  5706. #endif
  5707. //***********validFrom**************/
  5708. c = 0;
  5709. loc = strstr(sLineWord, "validFrom");
  5710. if(loc != NULL)
  5711. {
  5712. memset(sstr ,0, sizeof(sstr) );
  5713. while (loc[3+strlen("validFrom")+c] != '\"')
  5714. {
  5715. sstr[c] = loc[3+strlen("validFrom")+c];
  5716. c++;
  5717. }
  5718. sstr[c] = '\0';
  5719. strcpy(tempvalidFromStr,sstr);
  5720. }
  5721. else
  5722. {
  5723. strcpy(tempvalidFromStr,"");
  5724. }
  5725. //***********duration**************/
  5726. c = 0;
  5727. loc = strstr(sLineWord, "duration");
  5728. if(loc != NULL)
  5729. {
  5730. memset(sstr ,0, sizeof(sstr) );
  5731. while (loc[2+strlen("duration")+c] != ',')
  5732. {
  5733. sstr[c] = loc[2+strlen("duration")+c];
  5734. c++;
  5735. }
  5736. sstr[c] = '\0';
  5737. tempdurationInt = atoi(sstr);
  5738. }
  5739. else
  5740. {
  5741. tempdurationInt = 0;
  5742. }
  5743. //**********startSchedule**********/
  5744. c = 0;
  5745. loc = strstr(sLineWord, "startSchedule");
  5746. memset(sstr ,0, sizeof(sstr) );
  5747. if(loc != NULL)
  5748. {
  5749. while (loc[3+strlen("startSchedule")+c] != '\"')
  5750. {
  5751. sstr[c] = loc[3+strlen("startSchedule")+c];
  5752. c++;
  5753. }
  5754. sstr[c] = '\0';
  5755. strcpy(tempstartScheduleStr, sstr);
  5756. strcpy(TxDefaultProfileScheduleStr, sstr);
  5757. }
  5758. else
  5759. {
  5760. strcpy(tempstartScheduleStr, "");
  5761. strcpy(TxDefaultProfileScheduleStr, "");
  5762. }
  5763. //**********chargingRateUnit**********/
  5764. c = 0;
  5765. loc = strstr(sLineWord, "chargingRateUnit");
  5766. memset(sstr ,0, sizeof(sstr) );
  5767. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5768. {
  5769. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5770. c++;
  5771. }
  5772. sstr[c] = '\0';
  5773. strcpy(tempchargingRateUnitStr, sstr);
  5774. //**********minChargingRate*******/
  5775. c = 0;
  5776. loc = strstr(sLineWord, "minChargingRate");
  5777. if(loc != NULL)
  5778. {
  5779. memset(sstr ,0, sizeof(sstr) );
  5780. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5781. {
  5782. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5783. c++;
  5784. }
  5785. sstr[c] = '\0';
  5786. tempminChargingRateFloat = atof(sstr);
  5787. }
  5788. else
  5789. {
  5790. tempminChargingRateFloat = 0.0;
  5791. }
  5792. #if 0
  5793. //
  5794. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5795. tp.tm_isdst = -1;
  5796. time_t utc = mktime(&tp);
  5797. time_t t = time(NULL);
  5798. //diff_t = difftime(t, utc);
  5799. #endif
  5800. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5801. //parsing strings to words
  5802. i = 0;
  5803. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5804. loc = loc+3+strlen("chargingSchedulePeriod");
  5805. pch = strtok(loc ,"{");
  5806. while (pch != NULL)
  5807. {
  5808. strcpy(SchedulePeriodList[i], pch);
  5809. pch = strtok (NULL, "{");
  5810. i = i + 1;
  5811. }
  5812. n_SchedulePeriods = i;
  5813. for(int i=0;i<n_SchedulePeriods;i++)
  5814. {
  5815. //*************startPeriod****************/
  5816. c = 0;
  5817. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5818. memset(sstr ,0, sizeof(sstr) );
  5819. while (loc[strlen("startPeriod")+2+c] != ',')
  5820. {
  5821. sstr[c] = loc[strlen("startPeriod")+2+c];
  5822. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5823. c++;
  5824. }
  5825. sstr[c] = '\0';
  5826. tempStartPeriodInt = atoi(sstr);
  5827. //*************limit****************/
  5828. c = 0;
  5829. loc = strstr(SchedulePeriodList[i], "limit");
  5830. memset(sstr ,0, sizeof(sstr) );
  5831. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5832. {
  5833. sstr[c] = loc[strlen("limit")+2+c];
  5834. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5835. c++;
  5836. }
  5837. sstr[c] = '\0';
  5838. tempLimitInt = atof(sstr);
  5839. //*************numberPhases****************/
  5840. c = 0;
  5841. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5842. memset(sstr ,0, sizeof(sstr) );
  5843. if(loc != NULL)
  5844. {
  5845. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5846. {
  5847. sstr[c] = loc[strlen("numberPhases")+2+c];
  5848. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5849. c++;
  5850. }
  5851. sstr[c] = '\0';
  5852. tempNumberPhasesInt = atoi(sstr);
  5853. }
  5854. else
  5855. {
  5856. tempNumberPhasesInt = 0;
  5857. }
  5858. if(j == 0)
  5859. {
  5860. TxDefaultProfile.Duration = tempdurationInt;
  5861. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5862. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5863. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5864. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5865. }
  5866. else
  5867. {
  5868. //other stack level charging Profile
  5869. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5870. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5871. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5872. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5873. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5874. }
  5875. }
  5876. if(MinChargingRate < tempminChargingRateFloat)
  5877. MinChargingRate = tempminChargingRateFloat;
  5878. if(confirmPeriods < n_SchedulePeriods)
  5879. confirmPeriods = n_SchedulePeriods;
  5880. j = j + 1;
  5881. //DEBUG_INFO(" 1-2\n");
  5882. }
  5883. fclose(fptr1);
  5884. //Stacking Charging Profiles
  5885. for(int l=0; l <(j-1) ;l++)
  5886. {
  5887. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5888. {
  5889. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5890. {
  5891. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5892. {
  5893. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5894. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5895. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5896. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5897. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5898. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5899. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5900. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5901. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5902. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5903. }
  5904. else
  5905. {
  5906. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5907. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5908. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5909. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5910. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5911. }
  5912. }
  5913. }
  5914. }
  5915. //end of Stacking Charging Profiles
  5916. }
  5917. }// the end of ACCESS TxDefaultProfile
  5918. //****************************TxProfile************************************************/
  5919. memset(fname, 0, sizeof fname);
  5920. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5921. TxProfileIsNull=TRUE;
  5922. if((access(fname,F_OK))!=-1)
  5923. {
  5924. fptr1 = fopen(fname, "r");
  5925. c = 0;
  5926. c = fgetc(fptr1);
  5927. //DEBUG_INFO("c:%d\n",c);
  5928. rewind(fptr1);
  5929. if(c == EOF)
  5930. {
  5931. DEBUG_INFO("\n End of file reached.");
  5932. TxProfileIsNull=TRUE;
  5933. fclose(fptr1);
  5934. }
  5935. else
  5936. {
  5937. TxProfileIsNull=FALSE;
  5938. while(fscanf(fptr1, "%s", word) != EOF)
  5939. {
  5940. if(strcmp(word, "chargingProfileId") == 0)
  5941. {
  5942. n_chargingProfile = n_chargingProfile + 1;
  5943. }
  5944. }
  5945. rewind(fptr1);
  5946. //search Charging Profile Element
  5947. int i= 0;
  5948. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5949. #if 0
  5950. /***********connectorId****************/
  5951. c = 0;
  5952. loc = strstr(sLineWord, "connectorId");
  5953. memset(sstr ,0, sizeof(sstr) );
  5954. while (loc[strlen("connectorId")+2+c] != ',')
  5955. {
  5956. sstr[c] = loc[strlen("connectorId")+2+c];
  5957. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5958. c++;
  5959. }
  5960. sstr[c] = '\0';
  5961. tempconnectorIdInt = atoi(sstr);
  5962. #endif
  5963. //***********validFrom**************/
  5964. c = 0;
  5965. loc = strstr(sLineWord, "validFrom");
  5966. if(loc != NULL)
  5967. {
  5968. memset(sstr ,0, sizeof(sstr) );
  5969. while (loc[3+strlen("validFrom")+c] != '\"')
  5970. {
  5971. sstr[c] = loc[3+strlen("validFrom")+c];
  5972. c++;
  5973. }
  5974. sstr[c] = '\0';
  5975. strcpy(tempvalidFromStr,sstr);
  5976. }
  5977. else
  5978. {
  5979. strcpy(tempvalidFromStr,"");
  5980. }
  5981. //**********startSchedule**********/
  5982. c = 0;
  5983. loc = strstr(sLineWord, "startSchedule");
  5984. memset(sstr ,0, sizeof(sstr) );
  5985. if(loc != NULL)
  5986. {
  5987. while (loc[3+strlen("startSchedule")+c] != '\"')
  5988. {
  5989. sstr[c] = loc[3+strlen("startSchedule")+c];
  5990. c++;
  5991. }
  5992. sstr[c] = '\0';
  5993. strcpy(tempstartScheduleStr, sstr);
  5994. strcpy(TxProfileScheduleStr, sstr);
  5995. }
  5996. else
  5997. {
  5998. strcpy(tempstartScheduleStr, "");
  5999. strcpy(TxProfileScheduleStr, "");
  6000. }
  6001. //**********chargingRateUnit**********/
  6002. c = 0;
  6003. loc = strstr(sLineWord, "chargingRateUnit");
  6004. memset(sstr ,0, sizeof(sstr) );
  6005. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6006. {
  6007. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6008. c++;
  6009. }
  6010. sstr[c] = '\0';
  6011. strcpy(tempchargingRateUnitStr, sstr);
  6012. //**********minChargingRate*******/
  6013. c = 0;
  6014. loc = strstr(sLineWord, "minChargingRate");
  6015. if(loc != NULL)
  6016. {
  6017. memset(sstr ,0, sizeof(sstr) );
  6018. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  6019. {
  6020. sstr[c] = loc[2+strlen("minChargingRate")+c];
  6021. c++;
  6022. }
  6023. sstr[c] = '\0';
  6024. tempminChargingRateFloat = atof(sstr);
  6025. }
  6026. else
  6027. {
  6028. tempminChargingRateFloat = 0.0;
  6029. }
  6030. #if 0
  6031. //
  6032. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6033. tp.tm_isdst = -1;
  6034. time_t utc = mktime(&tp);
  6035. time_t t = time(NULL);
  6036. //diff_t = difftime(t, utc);
  6037. #endif
  6038. //DEBUG_INFO("diff_t=%f\n",diff_t);
  6039. //parsing strings to words
  6040. i = 0;
  6041. loc = strstr(sLineWord, "chargingSchedulePeriod");
  6042. loc = loc+3+strlen("chargingSchedulePeriod");
  6043. pch = strtok(loc ,"{");
  6044. while (pch != NULL)
  6045. {
  6046. strcpy(SchedulePeriodList[i], pch);
  6047. pch = strtok (NULL, "{");
  6048. i = i + 1;
  6049. }
  6050. n_SchedulePeriods = i;
  6051. for(int i=0;i<n_SchedulePeriods;i++)
  6052. {
  6053. //*************startPeriod****************/
  6054. c = 0;
  6055. loc = strstr(SchedulePeriodList[i], "startPeriod");
  6056. memset(sstr ,0, sizeof(sstr) );
  6057. while (loc[strlen("startPeriod")+2+c] != ',')
  6058. {
  6059. sstr[c] = loc[strlen("startPeriod")+2+c];
  6060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6061. c++;
  6062. }
  6063. sstr[c] = '\0';
  6064. tempStartPeriodInt = atoi(sstr);
  6065. //*************limit****************/
  6066. c = 0;
  6067. loc = strstr(SchedulePeriodList[i], "limit");
  6068. memset(sstr ,0, sizeof(sstr) );
  6069. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  6070. {
  6071. sstr[c] = loc[strlen("limit")+2+c];
  6072. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6073. c++;
  6074. }
  6075. sstr[c] = '\0';
  6076. tempLimitInt = atof(sstr);
  6077. //*************numberPhases****************/
  6078. c = 0;
  6079. loc = strstr(SchedulePeriodList[i], "numberPhases");
  6080. memset(sstr ,0, sizeof(sstr) );
  6081. if(loc != NULL)
  6082. {
  6083. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  6084. {
  6085. sstr[c] = loc[strlen("numberPhases")+2+c];
  6086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6087. c++;
  6088. }
  6089. sstr[c] = '\0';
  6090. tempNumberPhasesInt = atoi(sstr);
  6091. }
  6092. else
  6093. {
  6094. tempNumberPhasesInt = 0;
  6095. }
  6096. TxProfile.Duration = durationInt;
  6097. TxProfile.TotalPeriod = n_SchedulePeriods;
  6098. TxProfile.Period[i].Limit = tempLimitInt;
  6099. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  6100. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  6101. }
  6102. if(MinChargingRate < tempminChargingRateFloat)
  6103. MinChargingRate = tempminChargingRateFloat;
  6104. if(confirmPeriods < n_SchedulePeriods)
  6105. confirmPeriods = n_SchedulePeriods;
  6106. }
  6107. fclose(fptr1);
  6108. }
  6109. }// the end of ACCESS TxProfile
  6110. //CompositeSchedule
  6111. int period=0;
  6112. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  6113. {
  6114. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  6115. struct tm tp;
  6116. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6117. tp.tm_isdst = -1;
  6118. time_t utc = mktime(&tp);
  6119. time_t t = time(NULL);
  6120. double diff_f = difftime(t, utc);
  6121. int diff_i; // = (int)diff_f;
  6122. int quotient; // = diff_i / 86400;//86400 seconds/day
  6123. //int remainder = diff_i % 86400;
  6124. for(int k=0; k < TxProfile.TotalPeriod;k++)
  6125. {
  6126. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  6127. {
  6128. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  6129. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6130. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6131. period = period + 1;
  6132. }
  6133. else
  6134. {
  6135. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  6136. {
  6137. }
  6138. else
  6139. {
  6140. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6141. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6142. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6143. period = period + 1;
  6144. }
  6145. }
  6146. }
  6147. if( diff_f >= 0)
  6148. {
  6149. diff_i = (int)diff_f;
  6150. quotient = diff_i / 86400;//86400 seconds/day
  6151. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6152. {
  6153. 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))
  6154. {
  6155. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6156. {
  6157. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6158. }
  6159. else
  6160. {
  6161. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6162. }
  6163. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6164. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  6165. period = period + 1;
  6166. }
  6167. }
  6168. // Check Last Period
  6169. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  6170. {
  6171. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6172. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  6173. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  6174. period = period + 1;
  6175. }
  6176. } // diff_f >= 0
  6177. }
  6178. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  6179. {
  6180. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6181. struct tm tp;
  6182. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6183. tp.tm_isdst = -1;
  6184. time_t utc = mktime(&tp);
  6185. time_t t = time(NULL);
  6186. double diff_f = difftime(t, utc);
  6187. int diff_i;// = (int)diff_f;
  6188. int quotient; // = diff_i / 86400;//86400 seconds/day
  6189. //int remainder = diff_i % 86400;
  6190. if(diff_f >= 0)
  6191. {
  6192. diff_i = (int)diff_f;
  6193. quotient = diff_i / 86400;//86400 seconds/day
  6194. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6195. {
  6196. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6197. {
  6198. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6199. {
  6200. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6201. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6202. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6203. period = period + 1;
  6204. }
  6205. else
  6206. {
  6207. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6208. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6209. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6210. period = period + 1;
  6211. }
  6212. }
  6213. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6214. {
  6215. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6216. {
  6217. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6218. {
  6219. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6220. {
  6221. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6222. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6223. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6224. period = period + 1;
  6225. }
  6226. else
  6227. {
  6228. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6229. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6230. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6231. period = period + 1;
  6232. }
  6233. }
  6234. }
  6235. }
  6236. }
  6237. } // end diff_f >= 0
  6238. }
  6239. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  6240. {
  6241. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6242. struct tm tp;
  6243. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6244. tp.tm_isdst = -1;
  6245. time_t utc = mktime(&tp);
  6246. time_t t = time(NULL);
  6247. double diff_f = difftime(t, utc);
  6248. int diff_i; // = (int)diff_f;
  6249. int quotient; // = diff_i / 86400;//86400 seconds/day
  6250. //int remainder = diff_i % 86400;
  6251. if(diff_f >= 0)
  6252. {
  6253. diff_i = (int)diff_f;
  6254. quotient = diff_i / 86400;//86400 seconds/day
  6255. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6256. {
  6257. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6258. {
  6259. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6260. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6261. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6262. period = period + 1;
  6263. }
  6264. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6265. {
  6266. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6267. {
  6268. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6269. {
  6270. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6271. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6272. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6273. period = period + 1;
  6274. }
  6275. }
  6276. }
  6277. }
  6278. } // diff_f >= 0
  6279. }
  6280. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  6281. {
  6282. confirmPeriods = 0;
  6283. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6284. //goto end;
  6285. }
  6286. confirmPeriods = period;
  6287. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  6288. //---- Define StartSchedule----/
  6289. struct tm *gtime;
  6290. time_t now;
  6291. char buf[28];
  6292. //---Read the current system time---/
  6293. time(&now);
  6294. //---Convert the system time to GMT (now UTC)---/
  6295. gtime = gmtime(&now);
  6296. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  6297. // make .conf
  6298. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  6299. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  6300. //DEBUG_INFO(" debug 11\n");
  6301. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  6302. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  6303. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6304. }
  6305. else
  6306. {
  6307. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6308. }
  6309. //end:
  6310. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  6311. return result;
  6312. }
  6313. int handleGetConfigurationRequest(char *uuid, char *payload)
  6314. {
  6315. mtrace();
  6316. int result = FAIL;
  6317. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  6318. //struct json_object *jsonitem;
  6319. int MaxKeySupported = 0;
  6320. int n_keys = 0;
  6321. char requestKey[43][50]={0};
  6322. char search[]="[";
  6323. char sstr[500]={ 0 },sstrtemp[60]={ 0 };
  6324. //int pos;
  6325. int l, c = 0;
  6326. int i = 0;
  6327. char *delim = "\",\"";
  6328. char * pch;
  6329. strcpy(sstrtemp, stringtrimspace(payload));
  6330. char *loc = strstr(sstrtemp, search);
  6331. //********************* Parsing String ***********************************/
  6332. if(loc == NULL) {
  6333. DEBUG_INFO("no key match in Configuration \n");
  6334. }
  6335. else {
  6336. //pos = loc - payload;
  6337. l = strlen(loc)-4;
  6338. while (c < l)
  6339. {
  6340. sstr[c] = loc[c+2];
  6341. c++;
  6342. }
  6343. sstr[c] = '\0';
  6344. //parsing strings to words
  6345. pch = strtok(sstr,delim);
  6346. if(pch == NULL)
  6347. {
  6348. strcpy(requestKey[0], sstr);
  6349. }
  6350. else
  6351. {
  6352. while (pch != NULL)
  6353. {
  6354. strcpy(requestKey[i], pch);
  6355. pch = strtok (NULL, delim);
  6356. i = i + 1;
  6357. }
  6358. n_keys = i;
  6359. }
  6360. }
  6361. UnknownKeynum = 0;
  6362. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  6363. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  6364. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6365. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6366. if(n_keys != 0)
  6367. {
  6368. for(int i=0;i<n_keys;i++)
  6369. {
  6370. getKeyValue(requestKey[i]);
  6371. //json_object_put(jsonitem);
  6372. }
  6373. }
  6374. else
  6375. {
  6376. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6377. getKeyValue("");
  6378. }
  6379. processUnkownKey();
  6380. sendGetConfigurationConfirmation(uuid);
  6381. return result;
  6382. }
  6383. static char fnamePlusPath[100]={0};
  6384. static char fnamePWithNoPath[60]={0};
  6385. void checkUploadLog(void)
  6386. {
  6387. FILE *fp;
  6388. /* Open the command for reading. */
  6389. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6390. if (fp == NULL) {
  6391. printf("Failed to run command\n" );
  6392. exit(1);
  6393. }
  6394. int ftppathlen = 0;
  6395. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6396. int i = 0;
  6397. /* Read the output a line at a time - output it. */
  6398. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6399. if(i==0)
  6400. {
  6401. ftppathlen = strlen(fnamePlusPath);
  6402. printf("%s\n", fnamePlusPath);
  6403. fnamePlusPath[ftppathlen]='\0';
  6404. break;
  6405. }
  6406. i= i+1;
  6407. }
  6408. /* close */
  6409. pclose(fp);
  6410. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6411. {
  6412. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6413. {
  6414. fnamePlusPath[k]='\0';
  6415. }
  6416. }
  6417. i=1;
  6418. //char fname[60]={0};
  6419. while(i < ftppathlen)
  6420. {
  6421. int len=ftppathlen-i;
  6422. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6423. {
  6424. printf("compare '/' all right\n");
  6425. break;
  6426. }
  6427. i=i+1;
  6428. }
  6429. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6430. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6431. fnamePWithNoPath[i+1] = '\0';
  6432. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6433. {
  6434. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6435. {
  6436. fnamePWithNoPath[j]='\0';
  6437. }
  6438. }
  6439. FILE* fp1 = fopen(fnamePlusPath, "r");
  6440. if (fp1)
  6441. {
  6442. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6443. // file exists
  6444. fclose(fp1);
  6445. }
  6446. else
  6447. {
  6448. // file doesn't exist
  6449. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6450. }
  6451. }
  6452. static char GetDiagnosticspayloadData[300]={0};
  6453. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6454. {
  6455. mtrace();
  6456. int result = FAIL;
  6457. pthread_t t; // pthread 變數
  6458. system("exec /root/logPackTools 'log' 6");
  6459. #if 0
  6460. //char buffer [128];
  6461. time (&rawtime);
  6462. //printf("%ld\n", rawtime);
  6463. timeinfo = localtime (&rawtime);
  6464. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6465. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6466. if((access(fnamePlusPath,F_OK))!=-1)
  6467. {
  6468. DEBUG_INFO("fnamePlusPath exist.\n");
  6469. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6470. }
  6471. else
  6472. {
  6473. DEBUG_INFO("fnamePlusPath not exist!\n");
  6474. }
  6475. #endif
  6476. checkUploadLog();
  6477. memset(GetDiagnosticspayloadData, 0, 300);
  6478. strcpy(GetDiagnosticspayloadData, stringtrimspace(payload));
  6479. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  6480. pthread_create(&t, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6481. return result;
  6482. }
  6483. void* GetDiagnosticsProcess(void* data)
  6484. {
  6485. pthread_detach(pthread_self());
  6486. mtrace();
  6487. int retriesInt=0, retryIntervalInt=0;
  6488. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6489. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6490. 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};
  6491. int port=0;
  6492. char sstr[260]={ 0 };//sstr[200]={ 0 };
  6493. int c = 0;
  6494. char *loc;
  6495. int isSuccess = FALSE;
  6496. char ftpbuf[200]={0};
  6497. //char temp[100]={0};
  6498. char * pch;
  6499. // [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"}]
  6500. char str[300]={ 0 };
  6501. strcpy(str,(const char*)GetDiagnosticspayloadData);
  6502. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6503. DEBUG_INFO("GetDiagnosticsProcess\n");
  6504. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6505. //****************location*******************/
  6506. c = 0;
  6507. memset(sstr ,0, sizeof(sstr) );
  6508. loc = strstr(str, "location");
  6509. while (loc[3+strlen("location")+c] != '\"')
  6510. {
  6511. sstr[c] = loc[3+strlen("location")+c];
  6512. c++;
  6513. }
  6514. sstr[c] = '\0';
  6515. strcpy(locationstr,sstr);
  6516. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6517. if(strcmp(locationstr,"")==0)
  6518. {
  6519. DEBUG_INFO("location is <Empty>!\n");
  6520. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6521. goto end;
  6522. }
  6523. //****************retries*******************/
  6524. c = 0;
  6525. loc = strstr(str, "retries");
  6526. if(loc == NULL)
  6527. {
  6528. retriesIsNULL = TRUE;
  6529. }
  6530. else
  6531. {
  6532. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6533. {
  6534. sstr[c] = loc[strlen("retries")+2+c];
  6535. c++;
  6536. }
  6537. sstr[c] = '\0';
  6538. retriesInt = atoi(sstr);
  6539. }
  6540. if(retriesIsNULL == TRUE)
  6541. {
  6542. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6543. }
  6544. //****************retryInterval*******************/
  6545. c = 0;
  6546. loc = strstr(str, "retryInterval");
  6547. if(loc == NULL)
  6548. {
  6549. retryIntervalIsNULL = TRUE;
  6550. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6551. }
  6552. else
  6553. {
  6554. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6555. {
  6556. sstr[c] = loc[strlen("retryInterval")+2+c];
  6557. c++;
  6558. }
  6559. sstr[c] = '\0';
  6560. retryIntervalInt = atoi(sstr);
  6561. }
  6562. //****************startTime*******************/
  6563. c = 0;
  6564. memset(sstr ,0, sizeof(sstr) );
  6565. loc = strstr(str, "startTime");
  6566. if(loc == NULL)
  6567. {
  6568. startTimeIsNULL = TRUE;
  6569. }
  6570. else
  6571. {
  6572. while (loc[3+strlen("startTime")+c] != '\"')
  6573. {
  6574. sstr[c] = loc[3+strlen("startTime")+c];
  6575. c++;
  6576. }
  6577. sstr[c] = '\0';
  6578. strcpy(startTimestr,sstr);
  6579. }
  6580. //****************stopTime*******************/
  6581. c = 0;
  6582. memset(sstr ,0, sizeof(sstr) );
  6583. loc = strstr(str, "stopTime");
  6584. if(loc == NULL)
  6585. {
  6586. stopTimeIsNULL = TRUE;
  6587. }
  6588. else
  6589. {
  6590. while (loc[3+strlen("stopTime")+c] != '\"')
  6591. {
  6592. sstr[c] = loc[3+strlen("stopTime")+c];
  6593. c++;
  6594. }
  6595. sstr[c] = '\0';
  6596. strcpy(stopTimestr,sstr);
  6597. }
  6598. memset(protocol, 0, sizeof(protocol));
  6599. memset(user, 0, sizeof(user) );
  6600. memset(password, 0, sizeof(password));
  6601. memset(host, 0, sizeof(host));
  6602. memset(path, 0, sizeof(path));
  6603. memset(ftppath, 0, sizeof(ftppath));
  6604. memset(host1, 0, sizeof(host1));
  6605. memset(path1, 0, sizeof(path1));
  6606. /*location: ftp://user:password@host:port/path*/
  6607. #if 0
  6608. time_t rawtime;
  6609. struct tm * timeinfo;
  6610. //char buffer [128];
  6611. time (&rawtime);
  6612. //printf("%ld\n", rawtime);
  6613. timeinfo = localtime (&rawtime);
  6614. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6615. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6616. #endif
  6617. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6618. if((access(fnamePlusPath,F_OK))!=-1)
  6619. {
  6620. DEBUG_INFO("fnamePlusPath exist.\n");
  6621. }
  6622. else
  6623. {
  6624. DEBUG_INFO("fnamePlusPath not exist!\n");
  6625. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6626. goto end;
  6627. }
  6628. pch=strchr(locationstr,'@');
  6629. if(pch==NULL)
  6630. {
  6631. sscanf(locationstr,
  6632. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6633. protocol, host, &port, path);
  6634. strcpy(user,"anonymous");
  6635. strcpy(password,"");
  6636. }
  6637. else
  6638. {
  6639. //DEBUG_INFO("pch=%s\n", pch);
  6640. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6641. protocol, user, password, host, &port, path);
  6642. }
  6643. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6644. {
  6645. DEBUG_INFO("protocol is not ftp/http ! \n");
  6646. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6647. goto end;
  6648. }
  6649. if(strncmp(locationstr,"http", 4) == 0)
  6650. {
  6651. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6652. sprintf(ftppath,"/%s", path);
  6653. do{
  6654. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6655. sleep(retryIntervalInt);
  6656. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6657. if(!isSuccess)
  6658. {
  6659. DEBUG_INFO("Diagnostics fail.\n");
  6660. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6661. }
  6662. else
  6663. {
  6664. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6665. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6666. }
  6667. }
  6668. else
  6669. {
  6670. sscanf(host,"%[^/]%s",host1, path1);
  6671. sprintf(ftppath,"%s", path1);
  6672. int ftppathlen=strlen(ftppath);
  6673. int i=1;
  6674. char filenametemp[50];
  6675. while(i < ftppathlen)
  6676. {
  6677. int len=ftppathlen-i;
  6678. if(ftppath[len]== 47) // '/' ascll code: 47
  6679. {
  6680. DEBUG_INFO("find '/' all right\n");
  6681. break;
  6682. }
  6683. i=i+1;
  6684. }
  6685. memset(filenametemp, 0, sizeof(filenametemp));
  6686. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6687. filenametemp[i+1] = 0;
  6688. memset(ftpbuf, 0, sizeof(ftpbuf));
  6689. if(port == 0)
  6690. port = 21;
  6691. do{
  6692. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6693. sleep(retryIntervalInt);
  6694. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6695. if(!isSuccess)
  6696. {
  6697. DEBUG_INFO("Diagnostics fail.\n");
  6698. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6699. }
  6700. else
  6701. {
  6702. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6703. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6704. }
  6705. }
  6706. end:
  6707. DiagnosticsStatusNotificationStatus = 0; //Idle
  6708. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6709. }
  6710. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6711. {
  6712. mtrace();
  6713. int result = FAIL;
  6714. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6715. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6716. {
  6717. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6718. localversion = -1;
  6719. }
  6720. else
  6721. {
  6722. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6723. OCPP_getListVerion();
  6724. }
  6725. //from db.OCPP_getListVerion
  6726. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6727. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6728. sendGetLocalListVersionConfirmation(uuid,"");
  6729. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6730. return result;
  6731. }
  6732. int handleRemoteStartRequest(char *uuid, char *payload)
  6733. {
  6734. mtrace();
  6735. int result = FAIL;
  6736. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6737. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6738. int tempIndex = 0;
  6739. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6740. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6741. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6742. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6743. int chargingSchedulePeriodCount = 0;
  6744. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6745. int c = 0;
  6746. char *loc;
  6747. char comfirmstr[20]={0};
  6748. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6749. if(server_pending == TRUE)
  6750. {
  6751. return 0;
  6752. }
  6753. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6754. strcpy(sstrtemp, stringtrimspace(payload));
  6755. //**********connectorId****************/
  6756. c = 0;
  6757. memset(sstr ,0, sizeof(sstr) );
  6758. loc = strstr(sstrtemp, "connectorId");
  6759. if(loc == NULL)
  6760. {
  6761. connectorIdIsNULL = TRUE;
  6762. }
  6763. else
  6764. {
  6765. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6766. {
  6767. sstr[c] = loc[strlen("connectorId")+2+c];
  6768. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6769. c++;
  6770. }
  6771. sstr[c] = '\0';
  6772. connectorIdInt = atoi(sstr);
  6773. }
  6774. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6775. {
  6776. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6777. goto end;
  6778. }
  6779. //****************idTag*******************/
  6780. c = 0;
  6781. memset(sstr ,0, sizeof(sstr) );
  6782. loc = strstr(sstrtemp, "idTag");
  6783. while (loc[3+strlen("idTag")+c] != '\"')
  6784. {
  6785. sstr[c] = loc[3+strlen("idTag")+c];
  6786. c++;
  6787. }
  6788. sstr[c] = '\0';
  6789. strcpy(idTagstr,sstr);
  6790. //****************chargingProfile*******************/
  6791. c = 0;
  6792. memset(sstr ,0, sizeof(sstr) );
  6793. loc = strstr(sstrtemp, "chargingProfile");
  6794. if(loc == NULL)
  6795. {
  6796. chargingProfileIsNULL = TRUE;
  6797. }
  6798. else
  6799. {
  6800. //****************chargingProfileId*******************/
  6801. c=0;
  6802. loc = strstr(sstrtemp, "chargingProfileId");
  6803. memset(sstr ,0, sizeof(sstr) );
  6804. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6805. {
  6806. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6807. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6808. c++;
  6809. }
  6810. sstr[c] = '\0';
  6811. chargingProfileIdInt = atoi(sstr);
  6812. //****************transactionId*******************/
  6813. loc = strstr(sstrtemp, "transactionId");
  6814. if(loc == NULL)
  6815. {
  6816. transactionIdIsNULL = TRUE;
  6817. }
  6818. else
  6819. {
  6820. c=0;
  6821. memset(sstr ,0, sizeof(sstr) );
  6822. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6823. {
  6824. sstr[c] = loc[strlen("transactionId")+2+c];
  6825. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6826. c++;
  6827. }
  6828. sstr[c] = '\0';
  6829. transactionIdInt = atoi(sstr);
  6830. }
  6831. //****************stackLevel*******************/
  6832. c=0;
  6833. loc = strstr(sstrtemp, "stackLevel");
  6834. memset(sstr ,0, sizeof(sstr) );
  6835. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6836. {
  6837. sstr[c] = loc[strlen("stackLevel")+2+c];
  6838. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6839. c++;
  6840. }
  6841. sstr[c] = '\0';
  6842. stackLevelInt = atoi(sstr);
  6843. //****************chargingProfilePurpose*******************/
  6844. c = 0;
  6845. memset(sstr ,0, sizeof(sstr) );
  6846. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6847. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6848. {
  6849. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6850. c++;
  6851. }
  6852. sstr[c] = '\0';
  6853. strcpy(chargingProfilePurposestr,sstr);
  6854. //****************chargingProfileKind*******************/
  6855. c = 0;
  6856. memset(sstr ,0, sizeof(sstr) );
  6857. loc = strstr(sstrtemp, "chargingProfileKind");
  6858. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6859. {
  6860. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6861. c++;
  6862. }
  6863. sstr[c] = '\0';
  6864. strcpy(chargingProfileKindstr,sstr);
  6865. //****************recurrencyKind*******************/
  6866. loc = strstr(sstrtemp, "recurrencyKind");
  6867. if(loc == NULL)
  6868. {
  6869. recurrencyKindIsNULL = TRUE;
  6870. }
  6871. else
  6872. {
  6873. c = 0;
  6874. memset(sstr ,0, sizeof(sstr) );
  6875. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6876. {
  6877. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6878. c++;
  6879. }
  6880. sstr[c] = '\0';
  6881. strcpy(recurrencyKindstr,sstr);
  6882. }
  6883. //****************validFrom*******************/
  6884. loc = strstr(sstrtemp, "validFrom");
  6885. if(loc == NULL)
  6886. {
  6887. validFromIsNULL = TRUE;
  6888. }
  6889. else
  6890. {
  6891. c = 0;
  6892. memset(sstr ,0, sizeof(sstr) );
  6893. while (loc[3+strlen("validFrom")+c] != '\"')
  6894. {
  6895. sstr[c] = loc[3+strlen("validFrom")+c];
  6896. c++;
  6897. }
  6898. sstr[c] = '\0';
  6899. strcpy(validFromstr,sstr);
  6900. }
  6901. //****************validTo*******************/
  6902. loc = strstr(sstrtemp, "validTo");
  6903. if(loc == NULL)
  6904. {
  6905. validToIsNULL = TRUE;
  6906. }
  6907. else
  6908. {
  6909. c = 0;
  6910. memset(sstr ,0, sizeof(sstr) );
  6911. while (loc[3+strlen("validTo")+c] != '\"')
  6912. {
  6913. sstr[c] = loc[3+strlen("validTo")+c];
  6914. c++;
  6915. }
  6916. sstr[c] = '\0';
  6917. strcpy(validTostr,sstr);
  6918. }
  6919. //****************chargingSchedule*******************/
  6920. loc = strstr(sstrtemp, "chargingSchedule");
  6921. if(loc != NULL)
  6922. {
  6923. //****************duration*******************/
  6924. loc = strstr(sstrtemp, "duration");
  6925. if(loc == NULL)
  6926. {
  6927. durationIsNULL = TRUE;
  6928. }
  6929. else
  6930. {
  6931. c=0;
  6932. memset(sstr ,0, sizeof(sstr) );
  6933. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6934. {
  6935. sstr[c] = loc[strlen("duration")+2+c];
  6936. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6937. c++;
  6938. }
  6939. sstr[c] = '\0';
  6940. durationInt = atoi(sstr);
  6941. }
  6942. //****************startSchedule******************/
  6943. loc = strstr(sstrtemp, "startSchedule");
  6944. if(loc == NULL)
  6945. {
  6946. startScheduleIsNULL = TRUE;
  6947. }
  6948. else
  6949. {
  6950. c = 0;
  6951. memset(sstr ,0, sizeof(sstr) );
  6952. while (loc[3+strlen("startSchedule")+c] != '\"')
  6953. {
  6954. sstr[c] = loc[3+strlen("startSchedule")+c];
  6955. c++;
  6956. }
  6957. sstr[c] = '\0';
  6958. strcpy(startSchedulestr,sstr);
  6959. }
  6960. //****************chargingRateUnit*******************/
  6961. c = 0;
  6962. memset(sstr ,0, sizeof(sstr) );
  6963. loc = strstr(sstrtemp, "chargingRateUnit");
  6964. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6965. {
  6966. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6967. c++;
  6968. }
  6969. sstr[c] = '\0';
  6970. strcpy(chargingRateUnitstr,sstr);
  6971. //****************minChargingRate*******************/
  6972. loc = strstr(sstrtemp, "minChargingRate");
  6973. if(loc == NULL)
  6974. {
  6975. minChargingRateIsNULL = TRUE;
  6976. }
  6977. else
  6978. {
  6979. c=0;
  6980. memset(sstr ,0, sizeof(sstr) );
  6981. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6982. {
  6983. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6984. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6985. c++;
  6986. }
  6987. sstr[c] = '\0';
  6988. minChargingRateflaot = atof(sstr);
  6989. }
  6990. //****************chargingSchedulePeriod count*******************/
  6991. int what_len = strlen("startPeriod");
  6992. char *where = sstrtemp;
  6993. while ((where = strstr(where, "startPeriod"))) {
  6994. where += what_len;
  6995. chargingSchedulePeriodCount++;
  6996. }
  6997. where = sstrtemp;
  6998. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6999. {
  7000. //****************startPeriod*******************/
  7001. c=0;
  7002. loc = strstr(where, "startPeriod");
  7003. memset(sstr ,0, sizeof(sstr) );
  7004. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7005. {
  7006. sstr[c] = loc[strlen("startPeriod")+2+c];
  7007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7008. c++;
  7009. }
  7010. sstr[c] = '\0';
  7011. startPeriodInt[periodNums] = atoi(sstr);
  7012. //****************limit*******************/
  7013. c=0;
  7014. loc = strstr(where, "limit");
  7015. memset(sstr ,0, sizeof(sstr) );
  7016. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7017. {
  7018. sstr[c] = loc[strlen("limit")+2+c];
  7019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7020. c++;
  7021. }
  7022. sstr[c] = '\0';
  7023. limitflaot[periodNums] = atof(sstr);
  7024. //****************numberPhases*******************/
  7025. loc = strstr(where, "numberPhases");
  7026. if(loc == NULL)
  7027. {
  7028. numberPhasesIsNULL = TRUE;
  7029. }
  7030. else
  7031. {
  7032. c=0;
  7033. memset(sstr ,0, sizeof(sstr) );
  7034. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7035. {
  7036. sstr[c] = loc[strlen("numberPhases")+2+c];
  7037. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7038. c++;
  7039. }
  7040. sstr[c] = '\0';
  7041. numberPhasesInt[periodNums] = atoi(sstr);
  7042. }
  7043. where = loc;
  7044. } // END FOR chargingSchedulePeriodCount
  7045. }// END IF chargingSchedule
  7046. } // END chargingProfile
  7047. /*
  7048. enum _SYSTEM_STATUS
  7049. {
  7050. S_BOOTING = 0,
  7051. S_IDLE, = 1
  7052. S_AUTHORIZING, =2
  7053. S_REASSIGN_CHECK, =3
  7054. S_REASSIGN, =4
  7055. S_PRECHARGE, =5
  7056. S_PREPARING_FOR_EV, =6
  7057. S_PREPARING_FOR_EVSE, =7
  7058. S_CHARGING, =8
  7059. S_TERMINATING, =9
  7060. S_COMPLETE, =10
  7061. S_ALARM, =11
  7062. S_FAULT =12
  7063. }
  7064. */
  7065. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7066. {
  7067. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7068. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7069. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7070. //check Transaction active
  7071. if(gunType[connectorIdInt -1] == 'J')
  7072. {
  7073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7074. {
  7075. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7076. }
  7077. else
  7078. {
  7079. tempIndex = connectorIdInt -1;
  7080. }
  7081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7082. {
  7083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7084. {
  7085. 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 matches the idTag of Reservation!!!\n");
  7089. }
  7090. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7091. {
  7092. //Reserved
  7093. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7094. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7095. goto end;
  7096. }
  7097. else
  7098. {
  7099. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7100. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7101. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7102. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7103. {
  7104. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7105. goto end;
  7106. }
  7107. }//END FOR ELSE
  7108. }
  7109. }// END FOR CHAdeMO_QUANTITY
  7110. }
  7111. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7112. {
  7113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7114. {
  7115. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7116. }
  7117. else
  7118. {
  7119. tempIndex = connectorIdInt -1;
  7120. }
  7121. for (int index = 0; index < CCS_QUANTITY; index++)
  7122. {
  7123. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7124. {
  7125. 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 matches the idTag of Reservation!!!\n");
  7129. }
  7130. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7131. {
  7132. //Reserved
  7133. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7134. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7135. goto end;
  7136. }
  7137. else
  7138. {
  7139. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7140. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7141. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7142. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7143. {
  7144. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7145. goto end;
  7146. }
  7147. }// END FOR ELSE
  7148. }
  7149. }// END FOR CCS_QUANTITY
  7150. }
  7151. else if(gunType[connectorIdInt -1] == 'G')
  7152. {
  7153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7154. {
  7155. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7156. }
  7157. else
  7158. {
  7159. tempIndex = connectorIdInt -1;
  7160. }
  7161. for (int index = 0; index < GB_QUANTITY; index++)
  7162. {
  7163. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7164. {
  7165. 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 matches the idTag of Reservation!!!\n");
  7169. }
  7170. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7171. {
  7172. //Reserved
  7173. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7174. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7175. goto end;
  7176. }
  7177. else
  7178. {
  7179. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7180. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7181. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7182. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7183. {
  7184. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7185. goto end;
  7186. }
  7187. }// END FOR ELSE
  7188. }
  7189. } // END FOR GB_QUANTITY
  7190. }
  7191. else
  7192. {
  7193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7194. {
  7195. tempIndex = 2;
  7196. }
  7197. else
  7198. {
  7199. tempIndex = connectorIdInt -1;
  7200. }
  7201. for (int index = 0; index < AC_QUANTITY; index++)
  7202. {
  7203. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7204. {
  7205. 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 matches the idTag of Reservation!!!\n");
  7209. }
  7210. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7211. {
  7212. //Reserved
  7213. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7214. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7215. goto end;
  7216. }
  7217. else
  7218. {
  7219. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7220. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7221. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7222. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7223. {
  7224. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7225. goto end;
  7226. }
  7227. }//END FOR ELSE
  7228. }
  7229. }// END FOR AC_QUANTITY
  7230. }
  7231. if(chargingProfileIsNULL == FALSE)
  7232. {
  7233. //ChargingProfile
  7234. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7235. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7236. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7237. if(recurrencyKindIsNULL == FALSE) //OPTION
  7238. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7239. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7240. if(transactionIdIsNULL == FALSE) // OPTION
  7241. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7242. if(validFromIsNULL == FALSE) // OPTION
  7243. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7244. if(validToIsNULL == FALSE) //OPTION
  7245. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7246. //ChargingSchedule
  7247. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7248. if(durationIsNULL == FALSE) //OPTION
  7249. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7250. if(minChargingRateIsNULL == FALSE) //OPTION
  7251. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7252. if(startScheduleIsNULL == FALSE) //OPTION
  7253. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7254. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7255. {
  7256. //ChargingSchedulePeriod
  7257. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7258. if(numberPhasesIsNULL == FALSE)
  7259. {
  7260. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7261. }
  7262. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7263. }
  7264. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7265. {
  7266. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7267. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7268. //memset idTag
  7269. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7270. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7271. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7272. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7273. }
  7274. else
  7275. {
  7276. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7277. }
  7278. }
  7279. else
  7280. {
  7281. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7282. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7283. //memset idTag
  7284. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7285. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7286. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7287. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7288. }
  7289. }
  7290. else
  7291. {
  7292. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7293. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7294. }
  7295. end:
  7296. if(connectorIdIsNULL == FALSE)
  7297. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7298. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7299. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7300. //OCPP send RemoteStartConfirmation by first.
  7301. sendRemoteStartConfirmation(uuid, comfirmstr);
  7302. return result;
  7303. }
  7304. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7305. {
  7306. mtrace();
  7307. int result = FAIL;
  7308. int match = FALSE;
  7309. int GunNO = 0;
  7310. int tempIndex = 0;
  7311. int transactionIdInt=0;
  7312. int transactionIdIsNULL= FALSE;
  7313. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7314. int c = 0;
  7315. char *loc;
  7316. char comfirmstr[20];
  7317. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7318. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7319. if(server_pending == TRUE)
  7320. {
  7321. return 0;
  7322. }
  7323. strcpy(sstrtemp, stringtrimspace(payload));
  7324. c=0;
  7325. loc = strstr(sstrtemp, "transactionId");
  7326. if(loc == NULL)
  7327. {
  7328. transactionIdIsNULL= TRUE;
  7329. }
  7330. else
  7331. {
  7332. memset(sstr ,0, sizeof(sstr) );
  7333. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7334. {
  7335. sstr[c] = loc[strlen("transactionId")+2+c];
  7336. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7337. c++;
  7338. }
  7339. sstr[c] = '\0';
  7340. transactionIdInt = atoi(sstr);
  7341. }
  7342. if(transactionIdIsNULL == FALSE)
  7343. {
  7344. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7345. {
  7346. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7347. {
  7348. //check Transaction active
  7349. if(gunType[gun_index] == 'J')
  7350. {
  7351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7352. {
  7353. tempIndex = ((gun_index==2) ? 1: 0);
  7354. }
  7355. else
  7356. {
  7357. tempIndex = gun_index;
  7358. }
  7359. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7360. {
  7361. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7362. {
  7363. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7364. {
  7365. match = TRUE;
  7366. GunNO = gun_index;
  7367. }
  7368. }
  7369. }// END FOR CHAdeMO_QUANTITY
  7370. }
  7371. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7372. {
  7373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7374. {
  7375. tempIndex = ((gun_index==2) ? 1: 0);
  7376. }
  7377. else
  7378. {
  7379. tempIndex = gun_index;
  7380. }
  7381. for (int index = 0; index < CCS_QUANTITY; index++)
  7382. {
  7383. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7384. {
  7385. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7386. {
  7387. match = TRUE;
  7388. GunNO = gun_index;
  7389. }
  7390. }
  7391. }// END FOR CCS_QUANTITY
  7392. }
  7393. else if(gunType[gun_index] == 'G')
  7394. {
  7395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7396. {
  7397. tempIndex = ((gun_index==2) ? 1: 0);
  7398. }
  7399. else
  7400. {
  7401. tempIndex = gun_index;
  7402. }
  7403. for (int index = 0; index < GB_QUANTITY; index++)
  7404. {
  7405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7406. {
  7407. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7408. {
  7409. match = TRUE;
  7410. GunNO = gun_index;
  7411. }
  7412. }
  7413. }// END FOR GB_QUANTITY
  7414. }
  7415. else
  7416. {
  7417. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7418. {
  7419. tempIndex = 2;
  7420. }
  7421. else
  7422. {
  7423. tempIndex = gun_index;
  7424. }
  7425. for (int index = 0; index < AC_QUANTITY; index++)
  7426. {
  7427. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7428. {
  7429. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7430. {
  7431. match = TRUE;
  7432. GunNO = gun_index;
  7433. }
  7434. }
  7435. }// END FOR CHAdeMO_QUANTITY
  7436. } // END FOR AC ELSE
  7437. }// CHECK IF ResponseTransactionId == transactionIdInt
  7438. }//END FOR
  7439. if( match == TRUE)
  7440. {
  7441. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7443. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7444. }
  7445. else
  7446. {
  7447. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7448. }
  7449. }
  7450. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7451. return result;
  7452. }
  7453. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7454. {
  7455. mtrace();
  7456. int result = FAIL;
  7457. int connectorIdInt=0, reservationIdInt=0;
  7458. int tempIndex = 0;
  7459. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7460. char comfirmstr[20]={0};
  7461. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7462. int c = 0;
  7463. char *loc;
  7464. //char *ptr;
  7465. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  7466. strcpy(sstrtemp, stringtrimspace(payload));
  7467. //***(1)connectorId ****/
  7468. c=0;
  7469. loc = strstr(sstrtemp, "connectorId");
  7470. memset(sstr ,0, sizeof(sstr) );
  7471. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7472. {
  7473. sstr[c] = loc[strlen("connectorId")+2+c];
  7474. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7475. c++;
  7476. }
  7477. sstr[c] = '\0';
  7478. connectorIdInt = atoi(sstr);
  7479. //***(2)expiryDate ****/
  7480. loc = strstr(sstrtemp, "expiryDate");
  7481. memset(sstr ,0, sizeof(sstr) );
  7482. c = 0;
  7483. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7484. {
  7485. sstr[c] = loc[3+strlen("expiryDate")+c];
  7486. c++;
  7487. }
  7488. sstr[c] = '\0';
  7489. strcpy(expiryDatestr, sstr);
  7490. //***(3)idTag ****/
  7491. loc = strstr(sstrtemp, "idTag");
  7492. memset(sstr ,0, sizeof(sstr) );
  7493. c = 0;
  7494. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7495. {
  7496. sstr[c] = loc[3+strlen("idTag")+c];
  7497. c++;
  7498. }
  7499. sstr[c] = '\0';
  7500. strcpy(idTagstr, sstr);
  7501. //***(4)parentIdTag ****/
  7502. loc = strstr(sstrtemp, "parentIdTag");
  7503. memset(sstr ,0, sizeof(sstr) );
  7504. c = 0;
  7505. if(loc == NULL)
  7506. {
  7507. strcpy(parentIdTagstr, "");
  7508. }
  7509. else
  7510. {
  7511. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7512. {
  7513. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7514. c++;
  7515. }
  7516. sstr[c] = '\0';
  7517. strcpy(parentIdTagstr, sstr);
  7518. }
  7519. //***(5)reservationId ****/
  7520. c=0;
  7521. loc = strstr(sstrtemp, "reservationId");
  7522. memset(sstr ,0, sizeof(sstr) );
  7523. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7524. {
  7525. sstr[c] = loc[strlen("reservationId")+2+c];
  7526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7527. c++;
  7528. }
  7529. sstr[c] = '\0';
  7530. reservationIdInt = atoi(sstr);
  7531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7532. /*
  7533. enum SYSTEM_STATUS
  7534. {
  7535. SYS_MODE_BOOTING = 0,
  7536. SYS_MODE_IDLE = 1,
  7537. SYS_MODE_AUTHORIZING = 2,
  7538. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7539. SYS_MODE_REASSIGN = 4,
  7540. SYS_MODE_PREPARING = 5,
  7541. SYS_MODE_PREPARE_FOR_EV = 6,
  7542. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7543. SYS_MODE_CHARGING = 8,
  7544. SYS_MODE_TERMINATING = 9,
  7545. SYS_MODE_COMPLETE = 10,
  7546. SYS_MODE_ALARM = 11,
  7547. SYS_MODE_FAULT = 12,
  7548. SYS_MODE_RESERVATION = 13,
  7549. SYS_MODE_BOOKING = 14,
  7550. SYS_MODE_MAINTAIN = 15,
  7551. SYS_MODE_DEBUG = 16,
  7552. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7553. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7554. SYS_MODE_UPDATE = 19
  7555. };
  7556. */
  7557. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7558. {
  7559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7560. goto end;
  7561. }
  7562. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7563. {
  7564. //check Transaction active
  7565. if(gunType[connectorIdInt -1] == 'J')
  7566. {
  7567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7568. {
  7569. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7570. }
  7571. else
  7572. {
  7573. tempIndex = connectorIdInt -1;
  7574. }
  7575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7576. {
  7577. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7578. {
  7579. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7580. {
  7581. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7582. {
  7583. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7584. {
  7585. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7587. }
  7588. 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'))
  7589. {
  7590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7591. }
  7592. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7593. {
  7594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7595. }
  7596. else
  7597. {
  7598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7599. }
  7600. }
  7601. 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
  7602. {
  7603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7604. }
  7605. }
  7606. else
  7607. {
  7608. //replace reservation
  7609. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7611. }
  7612. }
  7613. } // END FOR CHAdeMO_QUANTITY
  7614. }
  7615. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7616. {
  7617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7618. {
  7619. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7620. }
  7621. else
  7622. {
  7623. tempIndex = connectorIdInt -1;
  7624. }
  7625. for (int index = 0; index < CCS_QUANTITY; index++)
  7626. {
  7627. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7628. {
  7629. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7630. {
  7631. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7632. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7633. {
  7634. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7635. {
  7636. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7638. }
  7639. 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'))
  7640. {
  7641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7642. }
  7643. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7644. {
  7645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7646. }
  7647. else
  7648. {
  7649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7650. }
  7651. }
  7652. 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
  7653. {
  7654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7655. }
  7656. }
  7657. else
  7658. {
  7659. //replace reservation
  7660. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7662. }
  7663. }
  7664. } // END FOR CCS_QUANTITY
  7665. }
  7666. else if(gunType[connectorIdInt -1] == 'G')
  7667. {
  7668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7669. {
  7670. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7671. }
  7672. else
  7673. {
  7674. tempIndex = connectorIdInt -1;
  7675. }
  7676. for (int index = 0; index < GB_QUANTITY; index++)
  7677. {
  7678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7679. {
  7680. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7681. {
  7682. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7683. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7684. {
  7685. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7686. {
  7687. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7689. }
  7690. 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'))
  7691. {
  7692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7693. }
  7694. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7695. {
  7696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7697. }
  7698. else
  7699. {
  7700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7701. }
  7702. }
  7703. 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
  7704. {
  7705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7706. }
  7707. }
  7708. else
  7709. {
  7710. //replace reservation
  7711. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7713. }
  7714. }
  7715. }// END FOR GB_QUANTITY
  7716. }
  7717. else
  7718. {
  7719. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7720. {
  7721. tempIndex = 2;
  7722. }
  7723. else
  7724. {
  7725. tempIndex = (connectorIdInt -1);
  7726. }
  7727. for (int index = 0; index < AC_QUANTITY; index++)
  7728. {
  7729. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7730. {
  7731. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7732. {
  7733. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7734. {
  7735. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7736. {
  7737. 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))
  7738. {
  7739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7740. }
  7741. else
  7742. {
  7743. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7745. }
  7746. }
  7747. 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'))
  7748. {
  7749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7750. }
  7751. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7752. {
  7753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7754. }
  7755. else
  7756. {
  7757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7758. }
  7759. }
  7760. 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
  7761. {
  7762. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7763. }
  7764. }
  7765. else
  7766. {
  7767. //replace reservation
  7768. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7770. }
  7771. }
  7772. } // END FOR AC_QUANTITY
  7773. }
  7774. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7775. }
  7776. else if(connectorIdInt == 0)
  7777. {
  7778. //check Transaction active
  7779. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7780. {
  7781. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7782. {
  7783. 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'))
  7784. {
  7785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7786. goto end;
  7787. }
  7788. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7789. {
  7790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7791. goto end;
  7792. }
  7793. 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
  7794. {
  7795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7796. goto end;
  7797. }
  7798. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7799. {
  7800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7801. goto end;
  7802. }
  7803. }
  7804. }// END FOR CHAdeMO_QUANTITY
  7805. for (int index = 0; index < CCS_QUANTITY; index++)
  7806. {
  7807. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7808. {
  7809. 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'))
  7810. {
  7811. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7812. goto end;
  7813. }
  7814. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7815. {
  7816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7817. goto end;
  7818. }
  7819. 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
  7820. {
  7821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7822. goto end;
  7823. }
  7824. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7825. {
  7826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7827. goto end;
  7828. }
  7829. }
  7830. } // END FOR CCS_QUANTITY
  7831. for (int index = 0; index < GB_QUANTITY; index++)
  7832. {
  7833. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7834. {
  7835. 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'))
  7836. {
  7837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7838. goto end;
  7839. }
  7840. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7841. {
  7842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7843. goto end;
  7844. }
  7845. 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
  7846. {
  7847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7848. goto end;
  7849. }
  7850. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7851. {
  7852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7853. goto end;
  7854. }
  7855. }
  7856. } // END FOR GB_QUANTITY
  7857. for (int index = 0; index < AC_QUANTITY; index++)
  7858. {
  7859. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7860. {
  7861. 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'))
  7862. {
  7863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7864. goto end;
  7865. }
  7866. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7867. {
  7868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7869. goto end;
  7870. }
  7871. 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
  7872. {
  7873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7874. goto end;
  7875. }
  7876. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7877. {
  7878. 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))
  7879. {
  7880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7881. goto end;
  7882. }
  7883. }
  7884. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7885. {
  7886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7887. goto end;
  7888. }
  7889. }
  7890. }// END FOR AC_QUANTITY
  7891. //The connectorId is 0
  7892. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7894. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7895. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7896. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7897. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7898. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7899. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7900. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7901. result = TRUE;
  7902. return result;
  7903. }
  7904. else
  7905. {
  7906. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7907. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7908. }
  7909. if(strcmp(comfirmstr,"Accepted") == 0)
  7910. {
  7911. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7912. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7913. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7914. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7915. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7916. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7917. result = TRUE;
  7918. return result;
  7919. }
  7920. end:
  7921. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7922. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7923. return result;
  7924. }
  7925. int handleResetRequest(char *uuid, char *payload)
  7926. {
  7927. mtrace();
  7928. int result = FAIL;
  7929. char sstr[10]={0},sstrtemp[30]={ 0 };
  7930. char typestr[10]={0};
  7931. char comfirmstr[20]={0};
  7932. int c = 0;
  7933. char *loc;
  7934. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7935. DEBUG_INFO("handleResetRequest ...\n");
  7936. strcpy(sstrtemp, stringtrimspace(payload));
  7937. loc = strstr(sstrtemp, "type");
  7938. memset(sstr ,0, sizeof(sstr) );
  7939. c = 0;
  7940. while (loc[3+strlen("type")+c] != '\"')
  7941. {
  7942. sstr[c] = loc[3+strlen("type")+c];
  7943. c++;
  7944. }
  7945. sstr[c] = '\0';
  7946. strcpy(typestr,sstr);
  7947. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7948. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7949. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7950. {
  7951. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7952. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7953. result = TRUE;
  7954. return result;
  7955. }
  7956. else
  7957. {
  7958. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7959. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7960. goto errorend;
  7961. }
  7962. errorend:
  7963. sendResetConfirmation(uuid, comfirmstr);
  7964. return result;
  7965. }
  7966. int handleSendLocalListRequest(char *uuid, char *payload)
  7967. {
  7968. mtrace();
  7969. int result = FAIL;
  7970. int listVersionInt;
  7971. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7972. char listsearch[]="listVersion";
  7973. char updateTypesearch[]="updateType";
  7974. char localAuthorizationListsearch[]="localAuthorizationList";
  7975. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7976. char CardList[500][160]={0};
  7977. char updateTypestr[15]={0};
  7978. char idTagstr[20]={0};
  7979. char parentIdTag[20]={0};
  7980. char expiryDate[30]={0};
  7981. char idTagstatus[16]={0};
  7982. int c = 0;
  7983. int i = 0;
  7984. char *delim1 = "}";
  7985. char * pch;
  7986. char *loc;
  7987. //char *ptr;
  7988. char comfirmstr[20];
  7989. //int n_localAuthorizations = 0;
  7990. int checkState_Faulted = FALSE;
  7991. DEBUG_INFO("handleSendLocalListRequest\n");
  7992. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7993. {
  7994. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7995. goto end;
  7996. }
  7997. //check Charge Point state
  7998. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7999. {
  8000. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8001. {
  8002. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8003. }
  8004. }
  8005. for (int index = 0; index < CCS_QUANTITY; index++)
  8006. {
  8007. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8008. {
  8009. checkState_Faulted = TRUE; //OCPP Status
  8010. }
  8011. }
  8012. for (int index = 0; index < GB_QUANTITY; index++)
  8013. {
  8014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8015. {
  8016. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8017. }
  8018. }
  8019. //check Charge Point state
  8020. for (int index = 0; index < AC_QUANTITY; index++)
  8021. {
  8022. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8023. {
  8024. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8025. }
  8026. }
  8027. if(checkState_Faulted == TRUE)
  8028. {
  8029. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8030. goto end;
  8031. }
  8032. //Filter payload space
  8033. strcpy(sstrtemp, stringtrimspace(payload));
  8034. //listVersion
  8035. c = 0;
  8036. loc = strstr(sstrtemp, listsearch);
  8037. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8038. {
  8039. sstr[c] = loc[strlen("listVersion")+2+c];
  8040. c++;
  8041. }
  8042. sstr[c] = '\0';
  8043. listVersionInt = atoi(sstr);
  8044. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8045. //updateType
  8046. loc = strstr(sstrtemp, updateTypesearch);
  8047. c = 0;
  8048. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8049. {
  8050. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8051. c++;
  8052. }
  8053. sstr[c] = '\0';
  8054. strcpy(updateTypestr, sstr);
  8055. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8056. //localAuthorizationList
  8057. memset(sstr ,0, sizeof(sstr) );
  8058. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8059. if(loc != NULL) // localAuthorizationList is not NULL
  8060. {
  8061. //Check UpdateType
  8062. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8063. {
  8064. //Local list full update
  8065. printf("Local list full update.\n");
  8066. OCPP_getListVerion();
  8067. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8068. {
  8069. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8070. goto end;
  8071. }
  8072. OCPP_cleanLocalList();
  8073. }
  8074. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8075. {
  8076. //Local list different update
  8077. printf("Local list different update.\n");
  8078. OCPP_getListVerion();
  8079. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8080. {
  8081. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8082. goto end;
  8083. }
  8084. }
  8085. else
  8086. {
  8087. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8088. goto end;
  8089. }
  8090. c = 0;
  8091. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8092. {
  8093. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8094. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8095. c++;
  8096. }
  8097. sstr[c] = '\0';
  8098. //DEBUG_INFO("sstr=%s\n", sstr);
  8099. //parsing strings to words
  8100. i = 0;
  8101. pch = strtok(sstr,delim1);
  8102. while (pch != NULL)
  8103. {
  8104. strcpy(CardList[i], pch);
  8105. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8106. pch = strtok (NULL, delim1);
  8107. i = i + 1;
  8108. }
  8109. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8110. //local Authorizations List Numbers
  8111. //n_localAuthorizations = i;
  8112. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8113. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8114. c= 0;
  8115. while(c < i) // i is CardList Number
  8116. {
  8117. //Search "IdToken"
  8118. memset(sstr ,0, sizeof(sstr) );
  8119. loc = strstr(CardList[c], "idTag");
  8120. int j = 0;
  8121. while (loc[3+strlen("idTag")+j] != '\"')
  8122. {
  8123. sstr[j] = loc[3+strlen("idTag")+j];
  8124. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8125. j++;
  8126. }
  8127. sstr[j] = '\0';
  8128. strcpy(idTagstr, sstr);
  8129. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8130. //Search "expiryDate"
  8131. memset(sstr ,0, sizeof(sstr) );
  8132. loc = strstr(CardList[c], "expiryDate");
  8133. j = 0;
  8134. if(loc != NULL)
  8135. {
  8136. while (loc[3+strlen("expiryDate")+j] != '\"')
  8137. {
  8138. sstr[j] = loc[3+strlen("expiryDate")+j];
  8139. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8140. j++;
  8141. }
  8142. sstr[j] = '\0';
  8143. strcpy(expiryDate, sstr);
  8144. }
  8145. else
  8146. {
  8147. strcpy(expiryDate, "");
  8148. }
  8149. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8150. //Search "parentIdTag"
  8151. memset(sstr ,0, sizeof(sstr) );
  8152. loc = strstr(CardList[c], "parentIdTag");
  8153. j = 0;
  8154. if(loc != NULL)
  8155. {
  8156. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8157. {
  8158. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8159. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8160. j++;
  8161. }
  8162. sstr[j] = '\0';
  8163. strcpy(parentIdTag, sstr);
  8164. }
  8165. else
  8166. {
  8167. strcpy(parentIdTag, "");
  8168. }
  8169. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8170. //Search "status"
  8171. memset(sstr ,0, sizeof(sstr) );
  8172. loc = strstr(CardList[c], "status");
  8173. j = 0;
  8174. while (loc[3+strlen("status")+j] != '\"')
  8175. {
  8176. sstr[j] = loc[3+strlen("status")+j];
  8177. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8178. j++;
  8179. }
  8180. sstr[j] = '\0';
  8181. strcpy(idTagstatus, sstr);
  8182. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8183. OCPP_getIdTag(idTagstr);
  8184. //OCPP_getIdTag("test"); For Test
  8185. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8186. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8187. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8188. {
  8189. //Local list full update
  8190. DEBUG_INFO("Local list full update.\n");
  8191. // update list
  8192. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8193. //DEBUG_INFO("Local list full update. 1\n");
  8194. //OCPP_get_TableAuthlocalAllData();
  8195. //DEBUG_INFO("Local list full update. 2\n");
  8196. }
  8197. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8198. {
  8199. #if 0
  8200. if(strcmp(idTagstr, idTagAuthorization) == 0)
  8201. {
  8202. //OCPP_deleteIdTag(idTagstr);
  8203. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  8204. }
  8205. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  8206. {
  8207. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  8208. }
  8209. #endif
  8210. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8211. }
  8212. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8213. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8214. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8215. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8216. c++;
  8217. }
  8218. }
  8219. else
  8220. {
  8221. //Check UpdateType
  8222. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8223. {
  8224. //Local list full update
  8225. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8226. OCPP_cleanLocalList();
  8227. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8228. goto end;
  8229. }
  8230. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8231. {
  8232. //Local list different update
  8233. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8234. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8235. goto end;
  8236. }
  8237. }
  8238. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8239. end:
  8240. sendSendLocalListConfirmation(uuid, comfirmstr);
  8241. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8242. return result;
  8243. }
  8244. #define MAX 200
  8245. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8246. {
  8247. mtrace();
  8248. int result = FAIL;
  8249. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8250. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8251. char chargingProfilePurposeStr[30]={0};
  8252. char chargingProfileKindStr[16]={0};
  8253. char recurrencyKindStr[10]={0};
  8254. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8255. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8256. int chargingSchedulePeriodCount = 0;
  8257. //int updateflag = FALSE;
  8258. char comfirmstr[20]={0};
  8259. int meet= FALSE;
  8260. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8261. int c = 0;
  8262. char *loc;
  8263. FILE *fptr1;//, *fptr2;
  8264. //int lno=0;//, linectr = 0;
  8265. //int modifyflag = FALSE;
  8266. char filename[MAX]={0};
  8267. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8268. //int resultRename=0;
  8269. char rmFileCmd[50]={0};
  8270. char tempchargingProfilePurposeStr[30]={0};
  8271. char word[1600]={0};
  8272. int n_chargingProfile = 0;
  8273. //[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}}}]
  8274. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8275. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8276. //Filter string space
  8277. strcpy(sstrtemp, stringtrimspace(payload));
  8278. //*********************connectorId***************************/
  8279. loc = strstr(sstrtemp, "connectorId");
  8280. c = 0;
  8281. memset(sstr ,0, sizeof(sstr) );
  8282. while (loc[strlen("connectorId")+2+c] != ',')
  8283. {
  8284. sstr[c] = loc[strlen("connectorId")+2+c];
  8285. c++;
  8286. }
  8287. sstr[c] = '\0';
  8288. connectorIdInt = atoi(sstr);
  8289. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8290. {
  8291. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8292. }
  8293. else
  8294. {
  8295. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8296. }
  8297. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8298. //*********************chargingProfileId***************************/
  8299. loc = strstr(sstrtemp, "chargingProfileId");
  8300. c = 0;
  8301. memset(sstr ,0, sizeof(sstr) );
  8302. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8303. {
  8304. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8305. c++;
  8306. }
  8307. sstr[c] = '\0';
  8308. chargingProfileIdInt = atoi(sstr);
  8309. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8310. {
  8311. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8312. }
  8313. else
  8314. {
  8315. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8316. }
  8317. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8318. //*********************transactionId***************************/
  8319. loc = strstr(sstrtemp, "transactionId");
  8320. if(loc != NULL)
  8321. {
  8322. c = 0;
  8323. memset(sstr ,0, sizeof(sstr) );
  8324. while (loc[strlen("transactionId")+2+c] != ',')
  8325. {
  8326. sstr[c] = loc[strlen("transactionId")+2+c];
  8327. c++;
  8328. }
  8329. sstr[c] = '\0';
  8330. transactionIdInt = atoi(sstr);
  8331. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8332. {
  8333. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8334. }
  8335. else
  8336. {
  8337. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8338. }
  8339. }
  8340. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8341. //*********************stackLevel***************************/
  8342. loc = strstr(sstrtemp, "stackLevel");
  8343. c = 0;
  8344. memset(sstr ,0, sizeof(sstr) );
  8345. while (loc[strlen("stackLevel")+2+c] != ',')
  8346. {
  8347. sstr[c] = loc[strlen("stackLevel")+2+c];
  8348. c++;
  8349. }
  8350. sstr[c] = '\0';
  8351. stackLevelInt = atoi(sstr);
  8352. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8353. {
  8354. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8355. }
  8356. else
  8357. {
  8358. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8359. }
  8360. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8361. //*********************chargingProfilePurpose***************************/
  8362. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8363. c = 0;
  8364. memset(sstr ,0, sizeof(sstr) );
  8365. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8366. {
  8367. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8369. c++;
  8370. }
  8371. sstr[c] = '\0';
  8372. strcpy(chargingProfilePurposeStr,sstr);
  8373. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8374. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8375. {
  8376. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8377. }
  8378. else
  8379. {
  8380. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8381. }
  8382. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8383. //*********************chargingProfileKind***************************/
  8384. loc = strstr(sstrtemp, "chargingProfileKind");
  8385. c = 0;
  8386. memset(sstr ,0, sizeof(sstr) );
  8387. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8388. {
  8389. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8390. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8391. c++;
  8392. }
  8393. sstr[c] = '\0';
  8394. strcpy(chargingProfileKindStr,sstr);
  8395. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8396. {
  8397. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8398. }
  8399. else
  8400. {
  8401. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8402. }
  8403. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8404. //*********************recurrencyKind***************************/
  8405. loc = strstr(sstrtemp, "recurrencyKind");
  8406. if(loc != NULL)
  8407. {
  8408. c = 0;
  8409. memset(sstr ,0, sizeof(sstr) );
  8410. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8411. {
  8412. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8413. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8414. c++;
  8415. }
  8416. sstr[c] = '\0';
  8417. strcpy(recurrencyKindStr,sstr);
  8418. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8419. {
  8420. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8421. }
  8422. else
  8423. {
  8424. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8425. }
  8426. }
  8427. else
  8428. {
  8429. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8430. {
  8431. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8432. }
  8433. else
  8434. {
  8435. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8436. }
  8437. }
  8438. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8439. //*********************validFrom***************************/
  8440. loc = strstr(sstrtemp, "validFrom");
  8441. if(loc != NULL)
  8442. {
  8443. c = 0;
  8444. memset(sstr ,0, sizeof(sstr) );
  8445. while (loc[3+strlen("validFrom")+c] != '\"')
  8446. {
  8447. sstr[c] = loc[3+strlen("validFrom")+c];
  8448. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8449. c++;
  8450. }
  8451. sstr[c] = '\0';
  8452. strcpy(validFromStr,sstr);
  8453. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8454. {
  8455. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8456. }
  8457. else
  8458. {
  8459. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8460. }
  8461. }
  8462. else
  8463. {
  8464. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8465. {
  8466. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8467. }
  8468. else
  8469. {
  8470. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8471. }
  8472. }
  8473. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8474. //*********************validTo***************************/
  8475. loc = strstr(sstrtemp, "validTo");
  8476. if(loc != NULL)
  8477. {
  8478. c = 0;
  8479. memset(sstr ,0, sizeof(sstr) );
  8480. while (loc[3+strlen("validTo")+c] != '\"')
  8481. {
  8482. sstr[c] = loc[3+strlen("validTo")+c];
  8483. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8484. c++;
  8485. }
  8486. sstr[c] = '\0';
  8487. strcpy(validToStr,sstr);
  8488. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8489. {
  8490. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8491. }
  8492. else
  8493. {
  8494. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8495. }
  8496. }
  8497. else
  8498. {
  8499. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8500. {
  8501. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8502. }
  8503. else
  8504. {
  8505. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8506. }
  8507. }
  8508. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8509. //*********************duration***************************/
  8510. loc = strstr(sstrtemp, "duration");
  8511. if(loc != NULL)
  8512. {
  8513. c = 0;
  8514. memset(sstr ,0, sizeof(sstr) );
  8515. while (loc[strlen("duration")+2+c] != ',')
  8516. {
  8517. sstr[c] = loc[strlen("duration")+2+c];
  8518. c++;
  8519. }
  8520. sstr[c] = '\0';
  8521. durationInt = atoi(sstr);
  8522. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8523. {
  8524. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8525. }
  8526. else
  8527. {
  8528. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8529. }
  8530. }
  8531. else
  8532. {
  8533. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8534. {
  8535. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8536. }
  8537. else
  8538. {
  8539. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8540. }
  8541. }
  8542. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8543. //*********************startSchedule***************************/
  8544. loc = strstr(sstrtemp, "startSchedule");
  8545. if(loc != NULL)
  8546. {
  8547. c = 0;
  8548. memset(sstr ,0, sizeof(sstr) );
  8549. while (loc[3+strlen("startSchedule")+c] != '\"')
  8550. {
  8551. sstr[c] = loc[3+strlen("startSchedule")+c];
  8552. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8553. c++;
  8554. }
  8555. sstr[c] = '\0';
  8556. strcpy(startScheduleStr,sstr);
  8557. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8558. {
  8559. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8560. }
  8561. else
  8562. {
  8563. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8564. }
  8565. }
  8566. else
  8567. {
  8568. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8569. {
  8570. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8571. }
  8572. else
  8573. {
  8574. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8575. }
  8576. }
  8577. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8578. //*********************chargingRateUnit***************************/
  8579. loc = strstr(sstrtemp, "chargingRateUnit");
  8580. if(loc != NULL)
  8581. {
  8582. c = 0;
  8583. memset(sstr ,0, sizeof(sstr) );
  8584. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8585. {
  8586. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8587. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8588. c++;
  8589. }
  8590. sstr[c] = '\0';
  8591. strcpy(chargingRateUnitStr,sstr);
  8592. #if 0
  8593. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8594. {
  8595. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8596. goto end;
  8597. }
  8598. #endif
  8599. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8600. {
  8601. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8602. }
  8603. else
  8604. {
  8605. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8606. }
  8607. }
  8608. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8609. //****************chargingSchedulePeriod count start*******************/
  8610. int what_len = strlen("startPeriod");
  8611. char tempChargingProfile[1600]={0};
  8612. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8613. char *where = tempChargingProfile;
  8614. if (what_len)
  8615. {
  8616. while ((where = strstr(where, "startPeriod"))) {
  8617. where += what_len;
  8618. chargingSchedulePeriodCount++;
  8619. }
  8620. }
  8621. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8622. {
  8623. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8624. goto end;
  8625. }
  8626. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8627. //where = payload;
  8628. int templength = 0;
  8629. //int searchstart = 0;
  8630. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8631. {
  8632. //****************startPeriod*******************/
  8633. c=0;
  8634. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8635. memset(sstr ,0, sizeof(sstr) );
  8636. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8637. {
  8638. sstr[c] = loc[strlen("startPeriod")+2+c];
  8639. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8640. c++;
  8641. }
  8642. sstr[c] = '\0';
  8643. startPeriodInt[periodNums] = atoi(sstr);
  8644. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8645. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8646. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8647. {
  8648. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8649. }
  8650. else
  8651. {
  8652. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8653. }
  8654. templength = strlen("startPeriod")+2+c;
  8655. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8656. //****************limit*******************/
  8657. c=0;
  8658. loc = strstr(tempChargingProfile + templength, "limit");
  8659. memset(sstr ,0, sizeof(sstr) );
  8660. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8661. {
  8662. sstr[c] = loc[strlen("limit")+2+c];
  8663. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8664. c++;
  8665. }
  8666. sstr[c] = '\0';
  8667. limitflaot[periodNums] = atof(sstr);
  8668. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8669. {
  8670. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8671. }
  8672. else
  8673. {
  8674. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8675. }
  8676. templength = templength + strlen("limit")+2+c;
  8677. //****************numberPhases*******************/
  8678. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8679. if(loc != NULL)
  8680. {
  8681. c=0;
  8682. memset(sstr ,0, sizeof(sstr) );
  8683. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8684. {
  8685. sstr[c] = loc[strlen("numberPhases")+2+c];
  8686. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8687. c++;
  8688. }
  8689. sstr[c] = '\0';
  8690. numberPhasesInt[periodNums] = atoi(sstr);
  8691. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8692. {
  8693. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8694. }
  8695. else
  8696. {
  8697. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8698. }
  8699. templength = templength + strlen("numberPhases")+2+c;
  8700. }
  8701. //where = loc;
  8702. }
  8703. //****************chargingSchedulePeriod count end*******************/
  8704. //*********************minChargingRate***************************/
  8705. loc = strstr(sstrtemp, "minChargingRate");
  8706. if(loc != NULL)
  8707. {
  8708. c = 0;
  8709. memset(sstr ,0, sizeof(sstr) );
  8710. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8711. {
  8712. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8713. c++;
  8714. }
  8715. sstr[c] = '\0';
  8716. minChargingRateFloat = atof(sstr);
  8717. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8718. {
  8719. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8720. }
  8721. else
  8722. {
  8723. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8724. }
  8725. }
  8726. else
  8727. {
  8728. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8729. {
  8730. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8731. }
  8732. else
  8733. {
  8734. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8735. }
  8736. }
  8737. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8738. {
  8739. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8740. if(connectorIdInt != 0)
  8741. {
  8742. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8743. goto end;
  8744. }
  8745. strcpy(filename, ChargePointMaxProfile_JSON );
  8746. fptr1 = fopen(filename, "r");
  8747. if (!fptr1)
  8748. {
  8749. //file not exist
  8750. DEBUG_INFO("Unable to open the input file!!\n");
  8751. fptr1 = fopen(filename, "w+");
  8752. }
  8753. else
  8754. {
  8755. //Check Charging Profile Count
  8756. while(fscanf(fptr1, "%s", word) != EOF)
  8757. {
  8758. //DEBUG_INFO("word=%s\n",word);
  8759. if(strstr(word, "chargingProfileId")!= NULL)
  8760. {
  8761. //DEBUG_INFO("test chargingProfileId \n");
  8762. n_chargingProfile = n_chargingProfile + 1;
  8763. //DEBUG_INFO("chargingProfileId Found\n");
  8764. }
  8765. }
  8766. }
  8767. fclose(fptr1);
  8768. }
  8769. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8770. {
  8771. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8772. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8773. {
  8774. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8775. goto end;
  8776. }
  8777. memset(filename, 0, sizeof filename);
  8778. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8779. fptr1 = fopen(filename, "r");
  8780. if (!fptr1)
  8781. {
  8782. //file not exist
  8783. //DEBUG_INFO("Unable to open the input file!!\n");
  8784. fptr1 = fopen(filename, "w+");
  8785. }
  8786. else
  8787. {
  8788. //Check Charging Profile Count
  8789. while(fscanf(fptr1, "%s", word) != EOF)
  8790. {
  8791. //DEBUG_INFO("word=%s\n",word);
  8792. if(strstr(word, "chargingProfileId")!= NULL)
  8793. {
  8794. //DEBUG_INFO("test chargingProfileId \n");
  8795. n_chargingProfile = n_chargingProfile + 1;
  8796. //DEBUG_INFO("chargingProfileId Found\n");
  8797. }
  8798. }
  8799. }
  8800. fclose(fptr1);
  8801. }
  8802. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8803. {
  8804. //printf("set chargingProfile 1-4\n");
  8805. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8806. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8807. if(connectorIdInt == 0)
  8808. {
  8809. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8810. goto end;
  8811. }
  8812. int tempIndex = 0;
  8813. //check Transaction active
  8814. if(gunType[connectorIdInt -1] == 'J')
  8815. {
  8816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8817. {
  8818. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8819. }
  8820. else
  8821. {
  8822. tempIndex = connectorIdInt -1;
  8823. }
  8824. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8825. {
  8826. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8827. {
  8828. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8829. {
  8830. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8831. {
  8832. meet = TRUE;
  8833. break;
  8834. }
  8835. }
  8836. }
  8837. }
  8838. }
  8839. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8840. {
  8841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8842. {
  8843. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8844. }
  8845. else
  8846. {
  8847. tempIndex = connectorIdInt -1;
  8848. }
  8849. for (int index = 0; index < CCS_QUANTITY; index++)
  8850. {
  8851. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8852. {
  8853. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8854. {
  8855. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8856. {
  8857. meet = TRUE;
  8858. break;
  8859. }
  8860. }
  8861. }
  8862. }
  8863. }
  8864. else if(gunType[connectorIdInt -1] == 'G')
  8865. {
  8866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8867. {
  8868. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8869. }
  8870. else
  8871. {
  8872. tempIndex = connectorIdInt -1;
  8873. }
  8874. for (int index = 0; index < GB_QUANTITY; index++)
  8875. {
  8876. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8877. {
  8878. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8879. {
  8880. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8881. {
  8882. meet = TRUE;
  8883. break;
  8884. }
  8885. }
  8886. }
  8887. }
  8888. }
  8889. else
  8890. {
  8891. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8892. {
  8893. tempIndex = 2;
  8894. }
  8895. else
  8896. {
  8897. tempIndex = (connectorIdInt -1);
  8898. }
  8899. for (int index = 0; index < AC_QUANTITY; index++)
  8900. {
  8901. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8902. {
  8903. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8904. {
  8905. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8906. {
  8907. meet = TRUE;
  8908. break;
  8909. }
  8910. }
  8911. }
  8912. }
  8913. }
  8914. //check Transaction active
  8915. if(meet == FALSE)
  8916. {
  8917. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8918. goto end;
  8919. }
  8920. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8921. {
  8922. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8923. goto end;
  8924. }
  8925. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8926. fptr1 = fopen(filename, "r");
  8927. if (!fptr1)
  8928. {
  8929. //file not exist
  8930. DEBUG_INFO("Unable to open the input file!!\n");
  8931. fptr1 = fopen(filename, "w+");
  8932. }
  8933. else
  8934. {
  8935. //Check Charging Profile Count
  8936. while(fscanf(fptr1, "%s", word) != EOF)
  8937. {
  8938. //DEBUG_INFO("word=%s\n",word);
  8939. if(strstr(word, "chargingProfileId")!= NULL)
  8940. {
  8941. //DEBUG_INFO("test chargingProfileId \n");
  8942. n_chargingProfile = n_chargingProfile + 1;
  8943. //DEBUG_INFO("chargingProfileId Found\n");
  8944. }
  8945. }
  8946. }
  8947. fclose(fptr1);
  8948. }
  8949. // Check ChargeProfileMaxStackLevel
  8950. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8951. {
  8952. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8953. goto end;
  8954. }
  8955. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8956. {
  8957. int i = 0;
  8958. char fnametemp[200]={0};
  8959. n_chargingProfile = 0;
  8960. //Check ChargePointMaxProfile.json exit
  8961. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8962. {
  8963. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8964. //Check Charging Profile Count
  8965. while(fscanf(fptr1, "%s", word) != EOF)
  8966. {
  8967. //DEBUG_INFO("word=%s\n",word);
  8968. if(strstr(word, "chargingProfileId")!= NULL)
  8969. {
  8970. //DEBUG_INFO("test chargingProfileId \n");
  8971. n_chargingProfile = n_chargingProfile + 1;
  8972. i = i + 1;
  8973. //DEBUG_INFO("chargingProfileId Found\n");
  8974. }
  8975. memset(word, 0, sizeof word);
  8976. }
  8977. fclose(fptr1);
  8978. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8979. }
  8980. //Check TxDefaultProfile_0.json exit
  8981. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8982. {
  8983. i = 0;
  8984. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8985. //Check Charging Profile Count
  8986. while(fscanf(fptr1, "%s", word) != EOF)
  8987. {
  8988. //DEBUG_INFO("word=%s\n",word);
  8989. if(strstr(word, "chargingProfileId")!= NULL)
  8990. {
  8991. //DEBUG_INFO("test chargingProfileId \n");
  8992. n_chargingProfile = n_chargingProfile + 1;
  8993. i = i + 1;
  8994. //DEBUG_INFO("chargingProfileId Found\n");
  8995. }
  8996. memset(word, 0, sizeof word);
  8997. }
  8998. fclose(fptr1);
  8999. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9000. }
  9001. //Check TxDefaultProfile_%d.json
  9002. for(int j=1; j <= gunTotalNumber; j++)
  9003. {
  9004. memset(fnametemp, 0, sizeof fnametemp);
  9005. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9006. if((access(fnametemp,F_OK))!=-1)
  9007. {
  9008. i = 0;
  9009. fptr1 = fopen(fnametemp, "r");
  9010. //Check Charging Profile Count
  9011. while(fscanf(fptr1, "%s", word) != EOF)
  9012. {
  9013. //DEBUG_INFO("word=%s\n",word);
  9014. if(strstr(word, "chargingProfileId")!= NULL)
  9015. {
  9016. //DEBUG_INFO("test chargingProfileId \n");
  9017. n_chargingProfile = n_chargingProfile + 1;
  9018. i = i + 1;
  9019. //DEBUG_INFO("chargingProfileId Found\n");
  9020. }
  9021. memset(word, 0, sizeof word);
  9022. }
  9023. fclose(fptr1);
  9024. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9025. }
  9026. }
  9027. //Check TxProfile_%d.json
  9028. for(int j=1; j <= gunTotalNumber; j++)
  9029. {
  9030. memset(fnametemp, 0, sizeof fnametemp);
  9031. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9032. if((access(fnametemp,F_OK))!=-1)
  9033. {
  9034. i = 0;
  9035. fptr1 = fopen(fnametemp, "r");
  9036. //Check Charging Profile Count
  9037. while(fscanf(fptr1, "%s", word) != EOF)
  9038. {
  9039. //DEBUG_INFO("word=%s\n",word);
  9040. if(strstr(word, "chargingProfileId")!= NULL)
  9041. {
  9042. //DEBUG_INFO("test chargingProfileId \n");
  9043. n_chargingProfile = n_chargingProfile + 1;
  9044. i = i + 1;
  9045. //DEBUG_INFO("chargingProfileId Found\n");
  9046. }
  9047. memset(word, 0, sizeof word);
  9048. }
  9049. fclose(fptr1);
  9050. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9051. }
  9052. }
  9053. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9054. {
  9055. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9056. goto end;
  9057. }
  9058. }
  9059. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9060. //**********************************Write to File********************************************************/
  9061. FILE *infile;
  9062. FILE *outfile;
  9063. // open file for writing
  9064. infile = fopen (filename, "r");
  9065. outfile = fopen (tempfile, "w");
  9066. int d =0;
  9067. d = fgetc(infile);
  9068. //DEBUG_INFO("d:%d\n",d);
  9069. rewind(infile);
  9070. //*检测到文件结束标识返回1,否则返回0。*/
  9071. if(d == EOF)
  9072. {
  9073. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9074. fprintf(outfile,"%s\n",payload);
  9075. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9076. fclose(infile);
  9077. fclose(outfile);
  9078. sprintf(rmFileCmd,"rm -f %s",filename);
  9079. system(rmFileCmd);
  9080. rename(tempfile, filename);
  9081. sleep(1);
  9082. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9083. //system(rmFileCmd);
  9084. }
  9085. else
  9086. {
  9087. char buf[1000]={0};
  9088. int ChargingProfileAdded = FALSE;
  9089. while (fgets(buf, sizeof(buf), infile) != NULL)
  9090. {
  9091. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9092. //*************************tempconnectorIdInt*********************************/
  9093. loc = strstr(buf, "connectorId");
  9094. c = 0;
  9095. memset(sstr ,0, sizeof(sstr) );
  9096. while (loc[strlen("connectorId")+2+c] != ',')
  9097. {
  9098. sstr[c] = loc[strlen("connectorId")+2+c];
  9099. c++;
  9100. }
  9101. sstr[c] = '\0';
  9102. tempconnectorIdInt = atoi(sstr);
  9103. //*************************tempchargingProfileIdInt*********************************/
  9104. loc = strstr(buf, "chargingProfileId");
  9105. c = 0;
  9106. memset(sstr ,0, sizeof(sstr) );
  9107. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9108. {
  9109. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9110. c++;
  9111. }
  9112. sstr[c] = '\0';
  9113. tempchargingProfileIdInt = atoi(sstr);
  9114. //*************************tempstackLevelInt*********************************/
  9115. loc = strstr(buf, "stackLevel");
  9116. c = 0;
  9117. memset(sstr ,0, sizeof(sstr) );
  9118. while (loc[strlen("stackLevel")+2+c] != ',')
  9119. {
  9120. sstr[c] = loc[strlen("stackLevel")+2+c];
  9121. c++;
  9122. }
  9123. sstr[c] = '\0';
  9124. tempstackLevelInt = atoi(sstr);
  9125. //*************************tempchargingProfilePurposeStr*********************************/
  9126. loc = strstr(payload, "chargingProfilePurpose");
  9127. c = 0;
  9128. memset(sstr ,0, sizeof(sstr) );
  9129. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9130. {
  9131. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9132. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9133. c++;
  9134. }
  9135. sstr[c] = '\0';
  9136. strcpy(tempchargingProfilePurposeStr,sstr);
  9137. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9138. {
  9139. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9140. {
  9141. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9142. if(ChargingProfileAdded == FALSE)
  9143. {
  9144. fprintf(outfile,"%s\n",payload);
  9145. ChargingProfileAdded = TRUE;
  9146. }
  9147. }
  9148. else
  9149. {
  9150. if(tempstackLevelInt < stackLevelInt)
  9151. {
  9152. if(ChargingProfileAdded == FALSE)
  9153. {
  9154. fprintf(outfile,"%s\n",payload);
  9155. ChargingProfileAdded = TRUE;
  9156. fprintf(outfile,"%s\n",buf);
  9157. }
  9158. else
  9159. {
  9160. fprintf(outfile,"%s\n",buf);
  9161. }
  9162. }
  9163. else
  9164. {
  9165. if(ChargingProfileAdded == FALSE)
  9166. {
  9167. fprintf(outfile,"%s\n",buf);
  9168. fprintf(outfile,"%s\n",payload);
  9169. ChargingProfileAdded = TRUE;
  9170. }
  9171. else
  9172. {
  9173. fprintf(outfile,"%s\n",buf);
  9174. }
  9175. }
  9176. }
  9177. }
  9178. else
  9179. {
  9180. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9181. {
  9182. if(ChargingProfileAdded == FALSE)
  9183. {
  9184. fprintf(outfile,"%s\n",payload);
  9185. ChargingProfileAdded = TRUE;
  9186. fprintf(outfile,"%s\n",buf);
  9187. }
  9188. else
  9189. {
  9190. fprintf(outfile,"%s\n",buf);
  9191. }
  9192. }
  9193. else if(tempstackLevelInt < stackLevelInt)
  9194. {
  9195. if(ChargingProfileAdded == FALSE)
  9196. {
  9197. fprintf(outfile,"%s\n",payload);
  9198. ChargingProfileAdded = TRUE;
  9199. fprintf(outfile,"%s\n",buf);
  9200. }
  9201. else
  9202. {
  9203. fprintf(outfile,"%s\n",buf);
  9204. }
  9205. }
  9206. else
  9207. {
  9208. if(ChargingProfileAdded == FALSE)
  9209. {
  9210. fprintf(outfile,"%s\n",buf);
  9211. fprintf(outfile,"%s\n",payload);
  9212. ChargingProfileAdded = TRUE;
  9213. }
  9214. else
  9215. {
  9216. fprintf(outfile,"%s\n",buf);
  9217. }
  9218. }
  9219. }
  9220. } // end of while loop
  9221. fclose(infile);
  9222. fclose(outfile);
  9223. sprintf(rmFileCmd,"rm -f %s",filename);
  9224. system(rmFileCmd);
  9225. rename(tempfile, filename);
  9226. sleep(1);
  9227. result = TRUE;
  9228. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9229. }
  9230. end:
  9231. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9232. return result;
  9233. return result;
  9234. }
  9235. int handleTriggerMessageRequest(char *uuid, char *payload)
  9236. {
  9237. mtrace();
  9238. int result = FAIL;
  9239. int connectorIdIsNULL = FALSE;
  9240. int connectorIdInt =0;
  9241. char sstr[40]={0},sstrtemp[100]={ 0 };
  9242. char requestedMessagestr[40]={0};
  9243. char comfirmstr[20]={0};
  9244. int c = 0;
  9245. char *loc;
  9246. DEBUG_INFO("handleTriggerMessageRequest\n");
  9247. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9248. strcpy(sstrtemp, stringtrimspace(payload));
  9249. c = 0;
  9250. loc = strstr(sstrtemp, "requestedMessage");
  9251. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9252. {
  9253. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9254. c++;
  9255. }
  9256. sstr[c] = '\0';
  9257. strcpy(requestedMessagestr, sstr);
  9258. c = 0;
  9259. loc = strstr(sstrtemp, "connectorId");
  9260. if(loc == NULL)
  9261. {
  9262. connectorIdIsNULL = TRUE;
  9263. }
  9264. else
  9265. {
  9266. memset(sstr ,0, sizeof(sstr) );
  9267. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9268. {
  9269. sstr[c] = loc[strlen("connectorId")+2+c];
  9270. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9271. c++;
  9272. }
  9273. sstr[c] = '\0';
  9274. connectorIdInt = atoi(sstr);
  9275. }
  9276. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9277. {
  9278. //connectorIdInt = json_object_get_int(connectorId);
  9279. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9280. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9281. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9282. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9283. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9284. }
  9285. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9286. {
  9287. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9288. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9289. return TRUE;
  9290. }
  9291. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9292. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9293. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9294. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9295. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9296. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9297. {
  9298. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9299. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9300. return TRUE;
  9301. }
  9302. else
  9303. {
  9304. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9305. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9306. }
  9307. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9308. {
  9309. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  9310. {
  9311. FirmwareStatusNotificationStatus = 3;
  9312. }
  9313. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9314. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9315. }
  9316. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9317. {
  9318. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9319. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9320. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9321. }
  9322. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9323. {
  9324. sendBootNotificationRequest();
  9325. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9326. }
  9327. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9328. {
  9329. sendHeartbeatRequest(connectorIdInt);
  9330. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9331. }
  9332. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9333. {
  9334. if(connectorIdIsNULL == FALSE)
  9335. {
  9336. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9337. {
  9338. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9339. sendMeterValuesRequest(connectorIdInt -1);
  9340. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9341. }
  9342. }
  9343. else
  9344. {
  9345. for(int idx=0;idx< gunTotalNumber;idx++)
  9346. {
  9347. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9348. sendMeterValuesRequest(idx);
  9349. }
  9350. }
  9351. }
  9352. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9353. {
  9354. if(connectorIdIsNULL == FALSE)
  9355. {
  9356. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9357. {
  9358. sendStatusNotificationRequest(connectorIdInt -1);
  9359. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9360. }
  9361. }
  9362. else
  9363. {
  9364. for(int idx=0;idx< gunTotalNumber;idx++)
  9365. sendStatusNotificationRequest(idx);
  9366. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9367. }
  9368. }
  9369. return result;
  9370. }
  9371. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9372. {
  9373. mtrace();
  9374. int result = FAIL;
  9375. char sstr[6]={0},sstrtemp[50]={ 0 };
  9376. int connectorIdInt =0;
  9377. char comfirmstr[20]={0};
  9378. int c = 0;
  9379. int tempIndex = 0;
  9380. char *loc;
  9381. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9382. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9383. strcpy(sstrtemp, stringtrimspace(payload));
  9384. c = 0;
  9385. loc = strstr(sstrtemp, "connectorId");
  9386. memset(sstr ,0, sizeof(sstr) );
  9387. while (loc[strlen("connectorId")+2+c] != '}')
  9388. {
  9389. sstr[c] = loc[strlen("connectorId")+2+c];
  9390. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9391. c++;
  9392. }
  9393. sstr[c] = '\0';
  9394. connectorIdInt = atoi(sstr);
  9395. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9396. if(gunTotalNumber == 0)
  9397. {
  9398. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9399. goto end;
  9400. }
  9401. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9402. {
  9403. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9404. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9405. goto end;
  9406. }
  9407. else
  9408. {
  9409. //check Transaction active
  9410. if(gunType[connectorIdInt-1] == 'J')
  9411. {
  9412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9413. {
  9414. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9415. }
  9416. else
  9417. {
  9418. tempIndex = connectorIdInt -1;
  9419. }
  9420. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9421. {
  9422. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9423. {
  9424. //stop Transaction
  9425. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9426. }
  9427. }
  9428. }
  9429. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9430. {
  9431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9432. {
  9433. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9434. }
  9435. else
  9436. {
  9437. tempIndex = connectorIdInt -1;
  9438. }
  9439. for (int index = 0; index < CCS_QUANTITY; index++)
  9440. {
  9441. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9442. {
  9443. //stop Transaction
  9444. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9445. }
  9446. }
  9447. }
  9448. else if(gunType[connectorIdInt-1] == 'G')
  9449. {
  9450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9451. {
  9452. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9453. }
  9454. else
  9455. {
  9456. tempIndex = connectorIdInt -1;
  9457. }
  9458. for (int index = 0; index < GB_QUANTITY; index++)
  9459. {
  9460. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9461. {
  9462. //stop Transaction
  9463. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9464. }
  9465. }
  9466. }
  9467. else
  9468. {
  9469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9470. {
  9471. tempIndex = 2;
  9472. }
  9473. else
  9474. {
  9475. tempIndex = connectorIdInt-1;
  9476. }
  9477. for (int index = 0; index < AC_QUANTITY; index++)
  9478. {
  9479. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9480. {
  9481. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9482. }
  9483. }
  9484. }
  9485. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9486. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9487. result = TRUE;
  9488. return result;
  9489. }
  9490. end:
  9491. //json_object_put(obj); --- remove temporally
  9492. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9493. return result;
  9494. }
  9495. static char UpdateFirmwarepayloadData[300]={0};
  9496. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9497. {
  9498. mtrace();
  9499. int result = FAIL;
  9500. pthread_t t;
  9501. sendUpdateFirmwareConfirmation(uuid);
  9502. memset(UpdateFirmwarepayloadData, 0, 300);
  9503. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9504. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9505. ////pthread_join(t, NULL); //
  9506. //pthread_detach(t);
  9507. //sendUpdateFirmwareConfirmation(uuid);
  9508. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9509. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9510. return result;
  9511. }
  9512. void *UpdateFirmwareProcess(void *data)
  9513. {
  9514. pthread_detach(pthread_self());
  9515. mtrace();
  9516. int retriesInt =0, retryIntervalInt=0;
  9517. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9518. int port=0;
  9519. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9520. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9521. //char comfirmstr[20];
  9522. int isSuccess = 0;
  9523. char ftpbuf[200];
  9524. char temp[100];
  9525. char * pch;
  9526. int retriesISNULL=FALSE;
  9527. int retryInterval=FALSE;
  9528. int c = 0;
  9529. //int i = 0;
  9530. char *loc;
  9531. char sstr[300]={ 0 };
  9532. char str[300]={ 0 };
  9533. //char *str = (char*) data; // ? ?輸入資 ?
  9534. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9535. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9536. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9537. //***************location **************/
  9538. loc = strstr(str, "location");
  9539. memset(sstr ,0, sizeof(sstr) );
  9540. c = 0;
  9541. while (loc[3+strlen("location")+c] != '\"')
  9542. {
  9543. sstr[c] = loc[3+strlen("location")+c];
  9544. c++;
  9545. }
  9546. sstr[c] = '\0';
  9547. strcpy(locationstr, sstr);
  9548. //***************retries**************/
  9549. c = 0;
  9550. loc = strstr(str, "retries");
  9551. if(loc == NULL)
  9552. {
  9553. retriesISNULL=TRUE;
  9554. }
  9555. else
  9556. {
  9557. memset(sstr ,0, sizeof(sstr) );
  9558. while (loc[strlen("retries")+2+c] != ',')
  9559. {
  9560. sstr[c] = loc[strlen("retries")+2+c];
  9561. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9562. c++;
  9563. }
  9564. sstr[c] = '\0';
  9565. }
  9566. if(retriesISNULL == FALSE)
  9567. {
  9568. retriesInt = atoi(sstr);
  9569. }
  9570. //***************retrieveDate **************/
  9571. loc = strstr(str, "retrieveDate");
  9572. memset(sstr ,0, sizeof(sstr) );
  9573. c = 0;
  9574. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9575. {
  9576. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9577. c++;
  9578. }
  9579. sstr[c] = '\0';
  9580. strcpy(retrieveDatestr, sstr);
  9581. //***************retryInterval **************/
  9582. c = 0;
  9583. loc = strstr(str, "retryInterval");
  9584. memset(sstr ,0, sizeof(sstr) );
  9585. if(loc == NULL)
  9586. {
  9587. retryInterval=TRUE;
  9588. }
  9589. else
  9590. {
  9591. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9592. {
  9593. sstr[c] = loc[strlen("retryInterval")+2+c];
  9594. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9595. c++;
  9596. }
  9597. sstr[c] = '\0';
  9598. }
  9599. if(retryInterval==FALSE)
  9600. {
  9601. retryIntervalInt = atoi(sstr);
  9602. }
  9603. memset(ftppath, 0, sizeof(ftppath));
  9604. memset(path, 0, sizeof(path));
  9605. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9606. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9607. if(strncmp(locationstr,"http", 4) == 0)
  9608. {
  9609. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9610. protocol, host, path);
  9611. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9612. // protocol, user, password, host, path);
  9613. sprintf(ftppath,"/%s", path);
  9614. //DEBUG_INFO("protocol =%s\n",protocol);
  9615. //DEBUG_INFO("host =%s\n",host);
  9616. //DEBUG_INFO("path =%s\n",path);
  9617. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9618. int ftppathlen=strlen(ftppath);
  9619. int i=1;
  9620. char filenametemp[50];
  9621. while(i < ftppathlen)
  9622. {
  9623. int len=ftppathlen-i;
  9624. if(ftppath[len]== 47) // '/' ascll code: 47
  9625. {
  9626. DEBUG_INFO("compare '/' all right\n");
  9627. break;
  9628. }
  9629. i=i+1;
  9630. }
  9631. memset(filenametemp, 0, sizeof(filenametemp));
  9632. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9633. filenametemp[i+1] = 0;
  9634. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9635. do{
  9636. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9637. sleep(retryIntervalInt);
  9638. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9639. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9640. if(!isSuccess)
  9641. {
  9642. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9643. }
  9644. else
  9645. {
  9646. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9647. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9648. //isUpdateRequest = TRUE;
  9649. }
  9650. }
  9651. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9652. {
  9653. memset(ftpbuf, 0, sizeof(ftpbuf));
  9654. memset(temp, 0, sizeof(temp));
  9655. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9656. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9657. int ftppathlen=strlen(ftpbuf);
  9658. int i=1;
  9659. char filenametemp[50];
  9660. while(i < ftppathlen)
  9661. {
  9662. int len=ftppathlen-i;
  9663. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9664. {
  9665. DEBUG_INFO(" compare '/' all right\n");
  9666. break;
  9667. }
  9668. i=i+1;
  9669. }
  9670. memset(filenametemp, 0, sizeof(filenametemp));
  9671. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9672. filenametemp[i+1] = 0;
  9673. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9674. pch=strchr(temp,'@');
  9675. if(pch==NULL)
  9676. {
  9677. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9678. protocol, host, &port, path);
  9679. strcpy(user,"anonymous");
  9680. strcpy(password,"");
  9681. }
  9682. else
  9683. {
  9684. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9685. protocol, user, password, host, &port, path);
  9686. }
  9687. sscanf(host,"%[^/]%s",host1, path1);
  9688. sprintf(ftppath,"%s", path1);
  9689. //DEBUG_INFO("protocol =%s\n",protocol);
  9690. //DEBUG_INFO("user =%s\n",user);
  9691. //DEBUG_INFO("password =%s\n",password);
  9692. //DEBUG_INFO("host1 =%s\n",host1);
  9693. //DEBUG_INFO("port =%d\n",port);
  9694. //DEBUG_INFO("path1 =%s\n",path1);
  9695. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9696. //ftpFile(host, user, password, port, ftppath, fname);
  9697. //download firmware pthred
  9698. if(port == 0)
  9699. {
  9700. port = 21;
  9701. }
  9702. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9703. do{
  9704. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9705. sleep(retryIntervalInt);
  9706. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9707. if(!isSuccess)
  9708. {
  9709. //BulldogUtil.sleepMs(interval*1000);
  9710. DEBUG_INFO("Update firmware request and download file fail.\n");
  9711. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9712. }
  9713. else
  9714. {
  9715. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9716. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9717. //isUpdateRequest = TRUE;
  9718. }
  9719. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9720. }
  9721. else
  9722. {
  9723. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9724. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9725. }
  9726. pthread_exit(NULL);
  9727. }
  9728. //==========================================
  9729. // Handle server response routine
  9730. //==========================================
  9731. void handleAuthorizeResponse(char *payload, int gun_index)
  9732. {
  9733. mtrace();
  9734. char expiryDatestr[30]={0};
  9735. char parentIdTagstr[20]={0};
  9736. char statusstr[20]={0};
  9737. char expiryDatestrtemp[30]={0};
  9738. char parentIdTagstrtemp[20]={0};
  9739. char IdTagstrtemp[20]={0};
  9740. char statusstrtemp[20]={0};
  9741. int expiryDateISNULL=FALSE;
  9742. int parentIdTagISNULL=FALSE;
  9743. char sstr[160]={0},sstrtemp[160]={0};
  9744. char* filename = AuthorizationCache_JSON;
  9745. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9746. int c = 0;
  9747. char *loc;
  9748. int resultRename=0;
  9749. int responseIdTagInfoAsZero= 0;
  9750. char rmFileCmd[50]={0};
  9751. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9752. strcpy(sstrtemp, stringtrimspace(payload));
  9753. //***********expiryDate*************/
  9754. loc = strstr(sstrtemp, "expiryDate");
  9755. memset(sstr ,0, sizeof(sstr) );
  9756. c = 0;
  9757. if(loc == NULL)
  9758. {
  9759. expiryDateISNULL = TRUE;
  9760. }
  9761. else
  9762. {
  9763. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9764. {
  9765. sstr[c] = loc[3+strlen("expiryDate")+c];
  9766. c++;
  9767. }
  9768. sstr[c] = '\0';
  9769. strcpy(expiryDatestr, sstr);
  9770. }
  9771. //***********parentIdTag*************/
  9772. loc = strstr(sstrtemp, "parentIdTag");
  9773. memset(sstr ,0, sizeof(sstr) );
  9774. c = 0;
  9775. if(loc == NULL)
  9776. {
  9777. parentIdTagISNULL = TRUE;
  9778. }
  9779. else
  9780. {
  9781. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9782. {
  9783. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9784. c++;
  9785. }
  9786. sstr[c] = '\0';
  9787. strcpy(parentIdTagstr, sstr);
  9788. }
  9789. //***********status*************/
  9790. loc = strstr(sstrtemp, "status");
  9791. memset(sstr ,0, sizeof(sstr) );
  9792. c = 0;
  9793. while (loc[3+strlen("status")+c] != '\"')
  9794. {
  9795. sstr[c] = loc[3+strlen("status")+c];
  9796. c++;
  9797. }
  9798. sstr[c] = '\0';
  9799. strcpy(statusstr, sstr);
  9800. if(expiryDateISNULL == FALSE)
  9801. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9802. if(parentIdTagISNULL == FALSE)
  9803. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9804. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9805. //Update idTag information to authorization cache if supproted
  9806. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9807. {
  9808. if((access(filename,F_OK))!=-1)
  9809. {
  9810. printf("AuthorizationCache exist.\n");
  9811. }
  9812. else
  9813. {
  9814. printf("AuthorizationCache not exist\n");
  9815. FILE *log = fopen(filename, "w+");
  9816. if(log == NULL)
  9817. {
  9818. printf("log is NULL\n");
  9819. goto out;
  9820. }
  9821. else
  9822. {
  9823. fclose(log);
  9824. }
  9825. }
  9826. FILE *infile;
  9827. FILE *outfile;
  9828. // open file for writing
  9829. infile = fopen (filename, "r");
  9830. outfile = fopen (tempfile, "w");
  9831. //*检测到文件结束标识返回1,否则返回0。*/
  9832. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9833. int c;
  9834. c = fgetc(infile);
  9835. //DEBUG_INFO("c:%d\n",c);
  9836. rewind(infile);
  9837. if(c == EOF)
  9838. {
  9839. DEBUG_INFO("Orignal File is NULL\n");
  9840. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9841. {
  9842. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9843. }
  9844. else
  9845. {
  9846. strcpy(expiryDatestrtemp, "");
  9847. }
  9848. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9849. {
  9850. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9851. }
  9852. else
  9853. {
  9854. //write Authorize IdTag
  9855. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9856. }
  9857. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9858. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9859. fclose(infile);
  9860. fclose(outfile);
  9861. sprintf(rmFileCmd,"rm -f %s",filename);
  9862. system(rmFileCmd);
  9863. resultRename = rename(tempfile, filename);
  9864. if(resultRename == 0)
  9865. {
  9866. printf("File renamed successfully");
  9867. }
  9868. else
  9869. {
  9870. printf("Error: unable to rename the file");
  9871. }
  9872. }
  9873. else
  9874. {
  9875. char buf[160]={0};
  9876. while (fgets(buf, sizeof(buf), infile) != NULL)
  9877. {
  9878. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9879. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9880. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9881. memset(statusstr, 0, sizeof(statusstrtemp));
  9882. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9883. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9884. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9885. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9886. //------------------IdTag-----------------------
  9887. loc = strstr(buf, "idTag");
  9888. memset(sstr ,0, sizeof(sstr) );
  9889. c = 0;
  9890. while (loc[3+strlen("idTag")+c] != '\"')
  9891. {
  9892. sstr[c] = loc[3+strlen("idTag")+c];
  9893. c++;
  9894. }
  9895. sstr[c] = '\0';
  9896. strcpy(IdTagstrtemp,sstr);
  9897. //*********************expiryDate***************/
  9898. loc = strstr(buf, "expiryDate");
  9899. memset(sstr ,0, sizeof(sstr) );
  9900. c = 0;
  9901. while (loc[3+strlen("expiryDate")+c] != '\"')
  9902. {
  9903. sstr[c] = loc[3+strlen("expiryDate")+c];
  9904. c++;
  9905. }
  9906. sstr[c] = '\0';
  9907. strcpy(expiryDatestr,sstr);
  9908. //*********************parentIdTag***************/
  9909. loc = strstr(buf, "parentIdTag");
  9910. memset(sstr ,0, sizeof(sstr) );
  9911. c = 0;
  9912. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9913. {
  9914. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9915. c++;
  9916. }
  9917. sstr[c] = '\0';
  9918. strcpy(parentIdTagstr,sstr);
  9919. //*********************status***************/
  9920. loc = strstr(buf, "status");
  9921. memset(sstr ,0, sizeof(sstr) );
  9922. c = 0;
  9923. while (loc[3+strlen("status")+c] != '\"')
  9924. {
  9925. sstr[c] = loc[3+strlen("status")+c];
  9926. c++;
  9927. }
  9928. sstr[c] = '\0';
  9929. strcpy(statusstr,sstr);
  9930. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9931. {
  9932. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9933. responseIdTagInfoAsZero = 1;
  9934. }
  9935. else
  9936. {
  9937. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9938. }
  9939. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9940. {
  9941. //modify item
  9942. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9943. {
  9944. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9945. }
  9946. else
  9947. {
  9948. strcpy(expiryDatestrtemp, "");
  9949. }
  9950. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9951. {
  9952. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9953. }
  9954. else
  9955. {
  9956. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9957. }
  9958. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9959. }
  9960. else
  9961. {
  9962. //wrie original item
  9963. strcpy(expiryDatestrtemp, expiryDatestr);
  9964. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9965. strcpy(statusstrtemp, statusstr);
  9966. }
  9967. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9968. }
  9969. fclose(infile);
  9970. fclose(outfile);
  9971. sprintf(rmFileCmd,"rm -f %s",filename);
  9972. system(rmFileCmd);
  9973. resultRename = rename(tempfile, filename);
  9974. if(resultRename == 0)
  9975. {
  9976. DEBUG_INFO("File renamed successfully");
  9977. }
  9978. else
  9979. {
  9980. DEBUG_INFO("Error: unable to rename the file");
  9981. }
  9982. }
  9983. }
  9984. out:
  9985. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9986. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9987. authorizeRetryTimes = 0;
  9988. }
  9989. char * strtrimc( char * s )
  9990. {
  9991. char * p1 = s;
  9992. char * p2 = s;
  9993. while(*p1 != '\0')
  9994. {
  9995. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9996. {
  9997. if(*p1 != ',')
  9998. {
  9999. p1 ++;
  10000. }
  10001. else
  10002. {
  10003. break;
  10004. }
  10005. }
  10006. if(*p1 != ',')
  10007. {
  10008. * p2 ++ = *p1 ++;
  10009. //printf("p2=%s\n",p2);
  10010. }
  10011. else
  10012. {
  10013. break;
  10014. }
  10015. }
  10016. *p2 = '\0';
  10017. return (s);
  10018. }
  10019. void handleBootNotificationResponse(char *payload, int gun_index)
  10020. {
  10021. mtrace();
  10022. char sstr[140]={0}, sstrtemp[140]={0};//sstr[200]={ 0 };
  10023. char statusStr[12]={0};
  10024. char currentTimeStr[30]={0};
  10025. char *loc;
  10026. int intervalInt = 0;
  10027. int c = 0;
  10028. //double diff_t;
  10029. struct tm tp;
  10030. char buf[28]={0};
  10031. char timebuf[50]={0};
  10032. DEBUG_INFO("handleBootNotificationResponse ...\n");
  10033. //Filter string space
  10034. strcpy(sstrtemp, stringtrimspace(payload));
  10035. //*** interval ****/
  10036. c = 0;
  10037. loc = strstr(sstrtemp, "interval");
  10038. //printf("loc=%s\n",loc);
  10039. memset(sstr ,0, sizeof(sstr) );
  10040. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  10041. {
  10042. sstr[c] = loc[strlen("interval")+2+c];
  10043. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10044. c++;
  10045. }
  10046. sstr[c] = '\0';
  10047. //DEBUG_INFO("id=%d\n",atoi(sstr));
  10048. intervalInt = atoi(sstr);
  10049. //***status ****/
  10050. loc = strstr(sstrtemp, "status");
  10051. memset(sstr ,0, sizeof(sstr) );
  10052. c = 0;
  10053. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  10054. {
  10055. sstr[c] = loc[3+strlen("status")+c];
  10056. c++;
  10057. }
  10058. sstr[c] = '\0';
  10059. strcpy(statusStr, sstr);
  10060. //***currentTime ****/
  10061. loc = strstr(sstrtemp, "currentTime");
  10062. //printf("loc=%s\n",loc);
  10063. memset(sstr ,0, sizeof(sstr) );
  10064. c = 0;
  10065. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  10066. {
  10067. sstr[c] = loc[3+strlen("currentTime")+c];
  10068. c++;
  10069. }
  10070. sstr[c] = '\0';
  10071. strcpy(currentTimeStr, sstr);
  10072. //BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10073. //HeartBeatWaitTime = BootNotificationInterval;
  10074. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10075. BootNotificationInterval = intervalInt;
  10076. HeartBeatWaitTime = intervalInt;
  10077. clientTime.Heartbeat=time((time_t*)NULL);
  10078. //write back to ShmOCPP16Data->BootNotification
  10079. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10080. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10081. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10082. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  10083. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  10084. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  10085. {
  10086. server_sign = TRUE;
  10087. server_pending =FALSE;
  10088. }
  10089. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10090. {
  10091. server_pending = TRUE;
  10092. }
  10093. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10094. tp.tm_isdst = -1;
  10095. //time_t utc = mktime(&tp);
  10096. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10097. memset(timebuf, 0, sizeof timebuf);
  10098. sprintf(timebuf,"date -s '%s'",buf);
  10099. //DEBUG_INFO("timebuf=%s\n",timebuf);
  10100. system(timebuf);
  10101. //==============================================
  10102. // RTC sync
  10103. //==============================================
  10104. system("/sbin/hwclock -w --systohc");
  10105. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10106. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10107. }
  10108. void handleDataTransferResponse(char *payload, int gun_index)
  10109. {
  10110. char sstr[160]={0};//sstr[200]={ 0 };
  10111. int c = 0;
  10112. char *loc;
  10113. DEBUG_INFO("handleDataTransferResponse ...\n");
  10114. loc = strstr(payload, "status");
  10115. printf("loc=%s\n",loc);
  10116. c = 0;
  10117. while (loc[3+strlen("status")+c] != '\"')
  10118. {
  10119. sstr[c] = loc[3+strlen("status")+c];
  10120. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10121. c++;
  10122. }
  10123. sstr[c] = '\0';
  10124. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10125. }
  10126. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10127. {
  10128. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10129. //struct json_object *obj;
  10130. // obj = json_tokener_parse(payload);
  10131. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10132. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10133. //No fields are defined.
  10134. }
  10135. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10136. {
  10137. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10138. //struct json_object *obj;
  10139. // obj = json_tokener_parse(payload);
  10140. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10141. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10142. //No fields are defined.
  10143. }
  10144. void handleHeartbeatResponse(char *payload, int gun_index)
  10145. {
  10146. mtrace();
  10147. //double diff_t;
  10148. struct tm tp;
  10149. char buf[28]={0};
  10150. char timebuf[50]={0},sstrtemp[100]={0};
  10151. char sstr[30]={ 0 };
  10152. int c = 0;
  10153. char *loc;
  10154. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  10155. if(FirstHeartBeat == 0)
  10156. {
  10157. FirstHeartBeat = 1;
  10158. DEBUG_INFO("FirstHeartBeat \n");
  10159. }
  10160. HeartBeatWithNOResponse = 0;
  10161. strcpy(sstrtemp, stringtrimspace(payload));
  10162. c = 0;
  10163. loc = strstr(sstrtemp, "currentTime");
  10164. memset(sstr ,0, sizeof(sstr) );
  10165. while (loc[3+strlen("currentTime")+c] != '\"')
  10166. {
  10167. sstr[c] = loc[3+strlen("currentTime")+c];
  10168. c++;
  10169. }
  10170. sstr[c] = '\0';
  10171. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  10172. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10173. tp.tm_isdst = -1;
  10174. //time_t utc = mktime(&tp);
  10175. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10176. memset(timebuf, 0, sizeof timebuf);
  10177. sprintf(timebuf,"date -s '%s'",buf);
  10178. system(timebuf);
  10179. //==============================================
  10180. // RTC sync
  10181. //==============================================
  10182. system("/sbin/hwclock -w --systohc");
  10183. //===============================================
  10184. //Print Out HeartBeat log
  10185. //===============================================
  10186. {
  10187. double diff_t;
  10188. struct tm tp,tp1;
  10189. // BootNotification Receive Time
  10190. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10191. tp.tm_isdst = -1;
  10192. time_t BootNotificationReceiveTime = mktime(&tp);
  10193. //HeartBeat Receive Time
  10194. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10195. tp1.tm_isdst = -1;
  10196. time_t HeartBeatReceiveTime = mktime(&tp1);
  10197. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10198. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10199. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10200. {
  10201. HeartBeatCountPerHour = (int)diff_t / 3600;
  10202. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10203. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10204. }
  10205. }
  10206. }
  10207. void handleMeterValuesResponse(char *payload, int gun_index)
  10208. {
  10209. mtrace();
  10210. //struct json_object *obj;
  10211. DEBUG_INFO("handleMeterValuesResponse ...\n");
  10212. //No fields are defined.
  10213. }
  10214. void handleStartTransactionResponse(char *payload, int gun_index)
  10215. {
  10216. mtrace();
  10217. char sstr[28]={ 0 },sstrtemp[200]={ 0 };
  10218. int c = 0;
  10219. int copyTo = 0;
  10220. char *loc;
  10221. //int transactionIdInt = 0;
  10222. FILE *outfile;
  10223. char data[100]={0};
  10224. //char *delim = ":";
  10225. //char requestKey[2][50]={0};
  10226. //char * pch;
  10227. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  10228. DEBUG_INFO("handleStartTransactionResponse\n");
  10229. //****************expiryDate********************/
  10230. strcpy(sstrtemp, stringtrimspace(payload));
  10231. loc = strstr(sstrtemp, "expiryDate");
  10232. if(loc == NULL)
  10233. {
  10234. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  10235. }
  10236. else
  10237. {
  10238. #if 0
  10239. c = 0;
  10240. memset(sstr ,0, sizeof(sstr) );
  10241. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10242. memset(requestKey ,0, sizeof(requestKey) );
  10243. strcpy(sstrtemp,loc+strlen("expiryDate")+2); // 2: ":
  10244. //printf("sstrtemp=%s\n",sstrtemp);
  10245. //parsing strings to words
  10246. pch = strtok(sstrtemp,",");
  10247. while (pch != NULL)
  10248. {
  10249. strcpy(requestKey[c], pch);
  10250. pch = strtok (NULL, ",");
  10251. c = c + 1;
  10252. }
  10253. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10254. //strcpy(currentTimeStr, strtrimc(requestKey[0]));
  10255. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", stringtrim(requestKey[0]));
  10256. #endif
  10257. #if 1
  10258. c = 0;
  10259. memset(sstr ,0, sizeof(sstr) );
  10260. while (loc[3+strlen("expiryDate")+c] != '\"')
  10261. {
  10262. sstr[c] = loc[3+strlen("expiryDate")+c];
  10263. c++;
  10264. }
  10265. sstr[c] = '\0';
  10266. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10267. #endif
  10268. }
  10269. //****************parentIdTag********************/
  10270. loc = strstr(sstrtemp, "parentIdTag");
  10271. if(loc == NULL)
  10272. {
  10273. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  10274. }
  10275. else
  10276. {
  10277. #if 0
  10278. c = 0;
  10279. memset(sstr ,0, sizeof(sstr) );
  10280. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10281. memset(requestKey ,0, sizeof(requestKey) );
  10282. strcpy(sstrtemp,loc);
  10283. //printf("sstrtemp=%s\n",sstrtemp);
  10284. //parsing strings to words
  10285. pch = strtok(sstrtemp,delim);
  10286. while (pch != NULL)
  10287. {
  10288. strcpy(requestKey[c], pch);
  10289. pch = strtok (NULL, delim);
  10290. c = c + 1;
  10291. }
  10292. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10293. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", strtrimc(requestKey[1]));
  10294. #endif
  10295. #if 1
  10296. c = 0;
  10297. memset(sstr ,0, sizeof(sstr) );
  10298. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10299. {
  10300. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10301. c++;
  10302. }
  10303. sstr[c] = '\0';
  10304. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10305. #endif
  10306. }
  10307. //****************status********************/
  10308. loc = strstr(sstrtemp, "status");
  10309. if(loc == NULL)
  10310. {
  10311. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  10312. }
  10313. else
  10314. {
  10315. #if 0
  10316. c = 0;
  10317. memset(sstr ,0, sizeof(sstr) );
  10318. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10319. memset(requestKey ,0, sizeof(requestKey) );
  10320. strcpy(sstrtemp,loc);
  10321. //printf("sstrtemp=%s\n",sstrtemp);
  10322. //parsing strings to words
  10323. pch = strtok(sstrtemp,delim);
  10324. while (pch != NULL)
  10325. {
  10326. strcpy(requestKey[c], pch);
  10327. pch = strtok (NULL, delim);
  10328. c = c + 1;
  10329. }
  10330. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10331. //strcpy(statusStr, strtrimc(requestKey[1]));
  10332. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", strtrimc(requestKey[1]));
  10333. #endif
  10334. #if 1
  10335. c = 0;
  10336. memset(sstr ,0, sizeof(sstr) );
  10337. while (loc[3+strlen("status")+c] != '\"')
  10338. {
  10339. sstr[c] = loc[3+strlen("status")+c];
  10340. c++;
  10341. }
  10342. sstr[c] = '\0';
  10343. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10344. #endif
  10345. }
  10346. //****************transactionId********************/
  10347. c=0;
  10348. copyTo = 0;
  10349. loc = strstr(sstrtemp, "transactionId");
  10350. memset(sstr ,0, sizeof(sstr) );
  10351. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  10352. {
  10353. if(loc[strlen("transactionId")+2+c] != ' ')
  10354. {
  10355. sstr[copyTo] = loc[strlen("transactionId")+2+c];
  10356. copyTo = copyTo + 1;
  10357. }
  10358. c++;
  10359. }
  10360. sstr[copyTo] = '\0';
  10361. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  10362. //transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  10363. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10364. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10365. //-----------Start : write to the Queue TransactionId file -----------------//
  10366. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10367. {
  10368. //DEBUG_INFO("QueueTransactionId exist.\n");
  10369. }
  10370. else
  10371. {
  10372. //DEBUG_INFO("QueueTransactionId not exist\n");
  10373. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10374. if(log == NULL)
  10375. {
  10376. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10377. return ;
  10378. }
  10379. else
  10380. {
  10381. fclose(log);
  10382. }
  10383. }
  10384. // open file for writing
  10385. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10386. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10387. {
  10388. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10389. //DEBUG_INFO("data=%s\n",data);
  10390. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10391. fputs(data, outfile);
  10392. //fputs("\n", outfile);
  10393. fclose (outfile);
  10394. }
  10395. //-------------End: write to the Queue TransactionId file------------------------------------------//
  10396. //TransactionId[gun_index] = transactionIdInt;
  10397. //DEBUG_INFO("gun_index: %d\n", gun_index);
  10398. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  10399. #ifdef SystemLogMessage
  10400. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10401. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10402. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10403. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10404. #endif
  10405. }
  10406. void handleStatusNotificationResponse(char *payload, int gun_index)
  10407. {
  10408. mtrace();
  10409. printf("handleStatusNotificationResponse\n");
  10410. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10411. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10412. }
  10413. void handleStopTransactionnResponse(char *payload, int gun_index)
  10414. {
  10415. mtrace();
  10416. char sstr[30]={ 0 },sstrtemp[140]={ 0 };
  10417. int c = 0;
  10418. char *loc;
  10419. //char *delim = ":";
  10420. //char requestKey[3][50]={0};
  10421. //char * pch;
  10422. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  10423. strcpy(sstrtemp, stringtrimspace(payload));
  10424. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10425. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10426. loc = strstr(sstrtemp, "idTagInfo");
  10427. //***********************idTagInfo************************/
  10428. if(loc != NULL)
  10429. {
  10430. //***********************expiryDate************************/
  10431. loc = strstr(sstrtemp, "expiryDate");
  10432. if(loc != NULL)
  10433. {
  10434. memset(sstr ,0, sizeof(sstr) );
  10435. c = 0;
  10436. while (loc[3+strlen("expiryDate")+c] != '\"')
  10437. {
  10438. sstr[c] = loc[3+strlen("expiryDate")+c];
  10439. c++;
  10440. }
  10441. sstr[c] = '\0';
  10442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10443. }
  10444. //***********************parentIdTag************************/
  10445. loc = strstr(sstrtemp, "parentIdTag");
  10446. if(loc != NULL)
  10447. {
  10448. memset(sstr ,0, sizeof(sstr) );
  10449. c = 0;
  10450. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10451. {
  10452. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10453. c++;
  10454. }
  10455. sstr[c] = '\0';
  10456. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10457. }
  10458. //***********************status************************/
  10459. loc = strstr(sstrtemp, "status");
  10460. memset(sstr ,0, sizeof(sstr) );
  10461. c = 0;
  10462. while (loc[3+strlen("status")+c] != '\"')
  10463. {
  10464. sstr[c] = loc[3+strlen("status")+c];
  10465. c++;
  10466. }
  10467. sstr[c] = '\0';
  10468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10469. }
  10470. #ifdef SystemLogMessage
  10471. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10472. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10473. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10474. #endif
  10475. }
  10476. //==========================================
  10477. // Handle Error routine
  10478. //==========================================
  10479. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10480. {
  10481. mtrace();
  10482. #ifdef SystemLogMessage
  10483. DEBUG_INFO("errorCode: %s\n", errorCode);
  10484. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10485. DEBUG_INFO("errorDetails: %s\n", payload);
  10486. #endif
  10487. }
  10488. //===============================================
  10489. // Common routine
  10490. //===============================================
  10491. int initialConfigurationTable(void)
  10492. {
  10493. //clock_t start_t, end_t, total_t;
  10494. FILE *fp;
  10495. FILE *outfile;
  10496. char str[200]={0};
  10497. char sstr[100]={0};
  10498. int c = 0;
  10499. char *loc;
  10500. printf("initialConfigurationTable \n");
  10501. //start_t = clock();
  10502. //printf("Starting of the program, start_t = %ld\n", start_t);
  10503. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10504. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10505. {
  10506. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10507. if(outfile == NULL) {
  10508. DEBUG_INFO("Error opening file");
  10509. return FALSE;
  10510. }
  10511. /*Core Profile*/
  10512. //AllowOfflineTxForUnknownId
  10513. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10514. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10518. //AuthorizationCacheEnabled
  10519. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10523. //AuthorizeRemoteTxRequests
  10524. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10528. //BlinkRepeat
  10529. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10533. //ClockAlignedDataInterval
  10534. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10538. //ConnectionTimeOut
  10539. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10543. //GetConfigurationMaxKeys
  10544. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10548. // HeartbeatInterval
  10549. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10553. // LightIntensity
  10554. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10558. // LocalAuthorizeOffline
  10559. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10563. // LocalPreAuthorize
  10564. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10568. // MaxEnergyOnInvalidId
  10569. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10572. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10574. // MeterValuesAlignedData
  10575. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10579. // MeterValuesAlignedDataMaxLength
  10580. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10584. // MeterValuesSampledData
  10585. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10589. // MeterValuesSampledDataMaxLength
  10590. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  10594. // MeterValueSampleInterval
  10595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10599. // MinimumStatusDuration
  10600. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10603. server_cycle_Status = 120; //StatusNotification cycle
  10604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10605. // NumberOfConnectors
  10606. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10609. {
  10610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10611. }
  10612. else
  10613. {
  10614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10615. }
  10616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10617. // ResetRetries
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10622. // ConnectorPhaseRotation
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10627. // ConnectorPhaseRotationMaxLength
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10632. // StopTransactionOnEVSideDisconnect
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10637. // StopTransactionOnInvalidId
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10642. // StopTxnAlignedData
  10643. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10647. // StopTxnAlignedDataMaxLength
  10648. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10652. // StopTxnSampledData
  10653. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10657. // StopTxnSampledDataMaxLength
  10658. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10661. {
  10662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10663. }
  10664. else
  10665. {
  10666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10667. }
  10668. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10670. // SupportedFeatureProfiles
  10671. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10675. // SupportedFeatureProfilesMaxLength
  10676. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10680. // TransactionMessageAttempts
  10681. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10684. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10686. // TransactionMessageRetryInterval
  10687. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10690. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10692. // UnlockConnectorOnEVSideDisconnect
  10693. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10697. // WebSocketPingInterval
  10698. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10702. //* Local Auth List Management Profile*/
  10703. #if 0
  10704. //For OCTT Test Case
  10705. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10708. #endif
  10709. #if 1
  10710. //LocalAuthListEnabled
  10711. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10715. #endif
  10716. //LocalAuthListMaxLength
  10717. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10721. //SendLocalListMaxLength
  10722. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10726. //ReserveConnectorZeroSupported
  10727. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10731. //* Smart Charging Profile */
  10732. //ChargeProfileMaxStackLevel
  10733. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10737. // ChargingScheduleAllowedChargingRateUnit
  10738. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10742. // ChargingScheduleMaxPeriods
  10743. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10747. // ConnectorSwitch3to1PhaseSupported
  10748. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10752. // MaxChargingProfilesInstalled
  10753. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10757. fclose(outfile);
  10758. }
  10759. else
  10760. {
  10761. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10762. char keystr[60]={0};
  10763. char readonlystr[10]={0};
  10764. char valuestr[100]={0};
  10765. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10766. if(fp == NULL) {
  10767. DEBUG_INFO("Error opening file");
  10768. return FALSE;
  10769. }
  10770. while( fgets (str, sizeof(str), fp)!=NULL )
  10771. {
  10772. //DEBUG_INFO("Get Configuration \n");
  10773. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10774. //*************************key*********************************/
  10775. loc = strstr(str, "key");
  10776. c = 0;
  10777. memset(sstr ,0, sizeof(sstr) );
  10778. while (loc[strlen("key")+3+c] != '\"')
  10779. {
  10780. sstr[c] = loc[strlen("key")+3+c];
  10781. c++;
  10782. }
  10783. sstr[c] = '\0';
  10784. strcpy(keystr,sstr);
  10785. //*************************readonly*********************************/
  10786. loc = strstr(str, "readonly");
  10787. c = 0;
  10788. memset(sstr ,0, sizeof(sstr) );
  10789. while (loc[strlen("readonly")+2+c] != ',')
  10790. {
  10791. sstr[c] = loc[strlen("readonly")+2+c];
  10792. c++;
  10793. }
  10794. sstr[c] = '\0';
  10795. strcpy(readonlystr,sstr);
  10796. //*************************value*********************************/
  10797. loc = strstr(str, "value");
  10798. c = 0;
  10799. memset(sstr ,0, sizeof(sstr) );
  10800. while (loc[strlen("value")+3+c] != '\"')
  10801. {
  10802. sstr[c] = loc[strlen("value")+3+c];
  10803. c++;
  10804. }
  10805. sstr[c] = '\0';
  10806. strcpy(valuestr,sstr);
  10807. // DEBUG_INFO("keystr=%s\n",keystr);
  10808. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10809. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10810. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10811. {
  10812. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10813. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10815. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10816. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10817. }
  10818. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10819. {
  10820. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10823. }
  10824. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10825. {
  10826. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10828. }
  10829. if(strcmp(keystr, "BlinkRepeat") == 0)
  10830. {
  10831. //Charger.BlinkRepeat = Integer.parseInt(value);
  10832. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10834. }
  10835. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10836. {
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10839. }
  10840. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10841. {
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10844. }
  10845. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10846. {
  10847. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10849. }
  10850. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10851. {
  10852. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10854. HeartBeatWaitTime = atoi(valuestr);
  10855. }
  10856. if(strcmp(keystr, "LightIntensity") == 0)
  10857. {
  10858. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10860. }
  10861. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10862. {
  10863. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10865. }
  10866. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10867. {
  10868. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10870. }
  10871. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10872. {
  10873. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10875. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10876. }
  10877. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10878. {
  10879. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10881. }
  10882. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10883. {
  10884. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10886. }
  10887. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10888. {
  10889. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10891. }
  10892. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10893. {
  10894. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10896. }
  10897. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10898. {
  10899. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10901. }
  10902. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10903. {
  10904. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10906. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10907. }
  10908. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10909. {
  10910. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10912. }
  10913. if(strcmp(keystr, "ResetRetries") == 0)
  10914. {
  10915. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10917. }
  10918. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10919. {
  10920. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10922. }
  10923. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10924. {
  10925. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10927. }
  10928. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10929. {
  10930. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10932. }
  10933. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10934. {
  10935. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10937. }
  10938. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10939. {
  10940. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10942. }
  10943. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10944. {
  10945. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10947. }
  10948. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10949. {
  10950. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10952. }
  10953. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10954. {
  10955. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10957. }
  10958. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10959. {
  10960. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10962. }
  10963. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10964. {
  10965. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10967. }
  10968. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10969. {
  10970. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10972. TransactionMessageAttemptsValue = atoi(valuestr);
  10973. }
  10974. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10975. {
  10976. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10978. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10979. }
  10980. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10981. {
  10982. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10984. }
  10985. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10986. {
  10987. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10989. }
  10990. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10991. {
  10992. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10994. }
  10995. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10996. {
  10997. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10999. }
  11000. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11001. {
  11002. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11004. }
  11005. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11006. {
  11007. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11009. }
  11010. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11011. {
  11012. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11014. }
  11015. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11016. {
  11017. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11019. }
  11020. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11021. {
  11022. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11024. }
  11025. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11026. {
  11027. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11029. }
  11030. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11031. {
  11032. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11034. }
  11035. }
  11036. fclose(fp);
  11037. }
  11038. //end_t = clock();
  11039. //printf("End of the big loop, end_t = %ld\n", end_t);
  11040. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  11041. //printf("Total time taken by CPU: %f\n", total_t );
  11042. return 0;
  11043. }
  11044. void StoreConfigurationTable(void)
  11045. {
  11046. FILE *outfile;
  11047. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11048. if(outfile == NULL)
  11049. {
  11050. DEBUG_INFO("Error opening file");
  11051. return ;
  11052. }
  11053. /*Core Profile*/
  11054. //AllowOfflineTxForUnknownId
  11055. /*
  11056. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11057. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11060. */
  11061. //DEBUG_INFO("data=%s\n",data);
  11062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11063. //AuthorizationCacheEnabled
  11064. /*
  11065. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11068. */
  11069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11070. //AuthorizeRemoteTxRequests
  11071. /*
  11072. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11075. */
  11076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11077. //BlinkRepeat
  11078. /*
  11079. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11082. */
  11083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11084. //ClockAlignedDataInterval
  11085. /*
  11086. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11089. */
  11090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11091. //ConnectionTimeOut
  11092. /*
  11093. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11096. */
  11097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11098. //GetConfigurationMaxKeys
  11099. /*
  11100. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11103. */
  11104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11105. // HeartbeatInterval
  11106. /*
  11107. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11110. */
  11111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11112. // LightIntensity
  11113. /*
  11114. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11117. */
  11118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11119. // LocalAuthorizeOffline
  11120. /*
  11121. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11124. */
  11125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11126. // LocalPreAuthorize
  11127. /*
  11128. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11131. */
  11132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11133. // MaxEnergyOnInvalidId
  11134. /*
  11135. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11138. */
  11139. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11141. // MeterValuesAlignedData
  11142. /*
  11143. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11146. */
  11147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11148. // MeterValuesAlignedDataMaxLength
  11149. /*
  11150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11153. */
  11154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11155. // MeterValuesSampledData
  11156. /*
  11157. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11160. */
  11161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11162. // MeterValuesSampledDataMaxLength
  11163. /*
  11164. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11167. */
  11168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11169. // MeterValueSampleInterval
  11170. /*
  11171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11174. */
  11175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11176. // MinimumStatusDuration
  11177. /*
  11178. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11181. */
  11182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11183. // NumberOfConnectors
  11184. /*
  11185. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11188. {
  11189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11190. }
  11191. else
  11192. {
  11193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11194. }
  11195. */
  11196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11197. // ResetRetries
  11198. /*
  11199. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11202. */
  11203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11204. // ConnectorPhaseRotation
  11205. /*
  11206. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11209. */
  11210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11211. // ConnectorPhaseRotationMaxLength
  11212. /*
  11213. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11216. */
  11217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11218. // StopTransactionOnEVSideDisconnect
  11219. /*
  11220. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11223. */
  11224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11225. // StopTransactionOnInvalidId
  11226. /*
  11227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11230. */
  11231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11232. // StopTxnAlignedData
  11233. /*
  11234. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11237. */
  11238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11239. // StopTxnAlignedDataMaxLength
  11240. /*
  11241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11244. */
  11245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11246. // StopTxnSampledData
  11247. /*
  11248. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11251. */
  11252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11253. // StopTxnSampledDataMaxLength
  11254. /*
  11255. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11258. */
  11259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11260. // SupportedFeatureProfiles
  11261. /*
  11262. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11265. */
  11266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11267. // SupportedFeatureProfilesMaxLength
  11268. /*
  11269. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11272. */
  11273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11274. // TransactionMessageAttempts
  11275. /*
  11276. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11279. */
  11280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11281. // TransactionMessageRetryInterval
  11282. /*
  11283. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11286. */
  11287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11288. // UnlockConnectorOnEVSideDisconnect
  11289. /*
  11290. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11293. */
  11294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11295. // WebSocketPingInterval
  11296. /*
  11297. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11300. */
  11301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11302. //* Local Auth List Management Profile*/
  11303. //LocalAuthListEnabled
  11304. /*
  11305. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11308. */
  11309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11310. //LocalAuthListMaxLength
  11311. /*
  11312. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11315. */
  11316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11317. //SendLocalListMaxLength
  11318. /*
  11319. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11322. */
  11323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11324. //ReserveConnectorZeroSupported
  11325. /*
  11326. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11329. */
  11330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11331. //* Smart Charging Profile */
  11332. //ChargeProfileMaxStackLevel
  11333. /*
  11334. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11337. */
  11338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11339. // ChargingScheduleAllowedChargingRateUnit
  11340. /*
  11341. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11344. */
  11345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11346. // ChargingScheduleMaxPeriods
  11347. /*
  11348. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11351. */
  11352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11353. // ConnectorSwitch3to1PhaseSupported
  11354. /*
  11355. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11358. */
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11360. // MaxChargingProfilesInstalled
  11361. /*
  11362. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11365. */
  11366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11367. fclose(outfile);
  11368. }
  11369. void getKeyValue(char *keyReq)
  11370. {
  11371. int isEmpty = FALSE;
  11372. int isKnowKey = FALSE;
  11373. //int unKnowIndex = 0;
  11374. DEBUG_INFO("getKeyValue \n");
  11375. DEBUG_INFO("keyReq=%s \n",keyReq);
  11376. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11377. isEmpty = TRUE;
  11378. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11383. {
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11385. }
  11386. else
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11389. }
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11391. isKnowKey = TRUE;
  11392. }
  11393. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11398. {
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11400. }
  11401. else
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11404. }
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11406. isKnowKey = TRUE;
  11407. }
  11408. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11415. }
  11416. else
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11419. }
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11421. isKnowKey = TRUE;
  11422. }
  11423. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11430. }
  11431. else
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11434. }
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11436. isKnowKey = TRUE;
  11437. }
  11438. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11445. }
  11446. else
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11449. }
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11451. isKnowKey = TRUE;
  11452. }
  11453. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11460. }
  11461. else
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11464. }
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11466. isKnowKey = TRUE;
  11467. }
  11468. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11475. }
  11476. else
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11479. }
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11481. isKnowKey = TRUE;
  11482. }
  11483. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11490. }
  11491. else
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11494. }
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11496. isKnowKey = TRUE;
  11497. }
  11498. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11505. }
  11506. else
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11509. }
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11511. isKnowKey = TRUE;
  11512. }
  11513. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11520. }
  11521. else
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11524. }
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11526. isKnowKey = TRUE;
  11527. }
  11528. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11535. }
  11536. else
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11539. }
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11541. isKnowKey = TRUE;
  11542. }
  11543. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11550. }
  11551. else
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11554. }
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11556. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11557. isKnowKey = TRUE;
  11558. }
  11559. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11564. {
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11566. }
  11567. else
  11568. {
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11570. }
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11572. isKnowKey = TRUE;
  11573. }
  11574. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11581. }
  11582. else
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11585. }
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11587. isKnowKey = TRUE;
  11588. }
  11589. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11590. {
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11594. {
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11596. }
  11597. else
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11600. }
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11602. isKnowKey = TRUE;
  11603. }
  11604. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11611. }
  11612. else
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11615. }
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11617. isKnowKey = TRUE;
  11618. }
  11619. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11620. {
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11624. {
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11626. }
  11627. else
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11630. }
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11632. isKnowKey = TRUE;
  11633. }
  11634. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11635. {
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11639. {
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11641. }
  11642. else
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11645. }
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11647. isKnowKey = TRUE;
  11648. }
  11649. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11650. {
  11651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11654. {
  11655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11656. }
  11657. else
  11658. {
  11659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11660. }
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11662. isKnowKey = TRUE;
  11663. }
  11664. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11665. {
  11666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11669. {
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11671. }
  11672. else
  11673. {
  11674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11675. }
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11677. isKnowKey = TRUE;
  11678. }
  11679. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11680. {
  11681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11684. {
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11686. }
  11687. else
  11688. {
  11689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11690. }
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11692. isKnowKey = TRUE;
  11693. }
  11694. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11695. {
  11696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11699. {
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11701. }
  11702. else
  11703. {
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11705. }
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11707. isKnowKey = TRUE;
  11708. }
  11709. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11710. {
  11711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11714. {
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11716. }
  11717. else
  11718. {
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11720. }
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11722. isKnowKey = TRUE;
  11723. }
  11724. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11725. {
  11726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11729. {
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11731. }
  11732. else
  11733. {
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11735. }
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11737. isKnowKey = TRUE;
  11738. }
  11739. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11740. {
  11741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11744. {
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11746. }
  11747. else
  11748. {
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11750. }
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11752. isKnowKey = TRUE;
  11753. }
  11754. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11755. {
  11756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11759. {
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11761. }
  11762. else
  11763. {
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11765. }
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11767. isKnowKey = TRUE;
  11768. }
  11769. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11770. {
  11771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11774. {
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11776. }
  11777. else
  11778. {
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11780. }
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11782. isKnowKey = TRUE;
  11783. }
  11784. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11785. {
  11786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11789. {
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11791. }
  11792. else
  11793. {
  11794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11795. }
  11796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11797. isKnowKey = TRUE;
  11798. }
  11799. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11800. {
  11801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11804. {
  11805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11806. }
  11807. else
  11808. {
  11809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11810. }
  11811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11812. isKnowKey = TRUE;
  11813. }
  11814. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11815. {
  11816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11819. {
  11820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11821. }
  11822. else
  11823. {
  11824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11825. }
  11826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11827. isKnowKey = TRUE;
  11828. }
  11829. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11830. {
  11831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11834. {
  11835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11836. }
  11837. else
  11838. {
  11839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11840. }
  11841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11842. isKnowKey = TRUE;
  11843. }
  11844. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11845. {
  11846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11849. {
  11850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11851. }
  11852. else
  11853. {
  11854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11855. }
  11856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11857. isKnowKey = TRUE;
  11858. }
  11859. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11860. {
  11861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11864. {
  11865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11866. }
  11867. else
  11868. {
  11869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11870. }
  11871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11872. isKnowKey = TRUE;
  11873. }
  11874. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11875. {
  11876. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11879. {
  11880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11881. }
  11882. else
  11883. {
  11884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11885. }
  11886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11887. isKnowKey = TRUE;
  11888. }
  11889. #if 0
  11890. //For OCTT Test Case
  11891. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11892. {
  11893. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11895. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11896. {
  11897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11898. }
  11899. else
  11900. {
  11901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11902. }
  11903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11904. isKnowKey = TRUE;
  11905. }
  11906. #endif
  11907. #if 1
  11908. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11909. {
  11910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11912. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11913. {
  11914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11915. }
  11916. else
  11917. {
  11918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11919. }
  11920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11921. isKnowKey = TRUE;
  11922. }
  11923. #endif
  11924. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11925. {
  11926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11928. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11929. {
  11930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11931. }
  11932. else
  11933. {
  11934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11935. }
  11936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11937. isKnowKey = TRUE;
  11938. }
  11939. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11940. {
  11941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11943. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11944. {
  11945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11946. }
  11947. else
  11948. {
  11949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11950. }
  11951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11952. isKnowKey = TRUE;
  11953. }
  11954. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11955. {
  11956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11958. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11959. {
  11960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11961. }
  11962. else
  11963. {
  11964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11965. }
  11966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11967. isKnowKey = TRUE;
  11968. }
  11969. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11970. {
  11971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11973. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11974. {
  11975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11976. }
  11977. else
  11978. {
  11979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11980. }
  11981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11982. isKnowKey = TRUE;
  11983. }
  11984. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11985. {
  11986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11988. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11989. {
  11990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11991. }
  11992. else
  11993. {
  11994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11995. }
  11996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11997. isKnowKey = TRUE;
  11998. }
  11999. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12000. {
  12001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12003. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12004. {
  12005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12006. }
  12007. else
  12008. {
  12009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12010. }
  12011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12012. isKnowKey = TRUE;
  12013. }
  12014. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12015. {
  12016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12018. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12019. {
  12020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12021. }
  12022. else
  12023. {
  12024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12025. }
  12026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12027. isKnowKey = TRUE;
  12028. }
  12029. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12030. {
  12031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12033. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12034. {
  12035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12036. }
  12037. else
  12038. {
  12039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12040. }
  12041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12042. isKnowKey = TRUE;
  12043. }
  12044. //=========================================================
  12045. if(!isEmpty && !isKnowKey)
  12046. {
  12047. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12048. strcpy(unknownkey[UnknownKeynum], keyReq);
  12049. UnknownKeynum = UnknownKeynum + 1;
  12050. }
  12051. }
  12052. void processUnkownKey(void)
  12053. {
  12054. DEBUG_INFO("processUnkownKey\n");
  12055. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12056. for(int index=0; index < UnknownKeynum; index++)
  12057. {
  12058. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12059. {
  12060. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12061. }
  12062. }
  12063. }
  12064. int setKeyValue(char *key, char *value)
  12065. {
  12066. int isSuccess = NotSupported;
  12067. int check_ascii=0;
  12068. char str[10]={0};
  12069. #ifdef Debug
  12070. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  12071. #endif
  12072. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12073. {
  12074. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12076. {
  12077. strcpy(str, (const char*)value);
  12078. for(int i = 0; str[i]; i++){
  12079. str[i] = tolower(str[i]);
  12080. }
  12081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12082. isSuccess = ConfigurationStatus_Accepted;
  12083. }
  12084. else
  12085. {
  12086. isSuccess = ConfigurationStatus_Rejected;
  12087. }
  12088. }
  12089. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12090. {
  12091. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12093. {
  12094. strcpy(str, (const char*)value);
  12095. for(int i = 0; str[i]; i++){
  12096. str[i] = tolower(str[i]);
  12097. }
  12098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12099. isSuccess = ConfigurationStatus_Accepted;
  12100. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  12101. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12102. }
  12103. else
  12104. {
  12105. isSuccess = ConfigurationStatus_Rejected;
  12106. }
  12107. }
  12108. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12109. {
  12110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12111. {
  12112. strcpy(str, (const char*)value);
  12113. for(int i = 0; str[i]; i++)
  12114. {
  12115. str[i] = tolower(str[i]);
  12116. }
  12117. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12119. isSuccess = ConfigurationStatus_Accepted;
  12120. }
  12121. else
  12122. {
  12123. isSuccess = ConfigurationStatus_Rejected;
  12124. }
  12125. }
  12126. if(strcmp(key, "BlinkRepeat") == 0)
  12127. {
  12128. //Charger.BlinkRepeat = Integer.parseInt(value);
  12129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12130. {
  12131. check_ascii = value[0];
  12132. if( (check_ascii < 48) || (check_ascii > 57) )
  12133. {
  12134. isSuccess = ConfigurationStatus_Rejected;
  12135. }
  12136. else
  12137. {
  12138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12139. isSuccess = ConfigurationStatus_Accepted;
  12140. }
  12141. }
  12142. else
  12143. {
  12144. isSuccess = ConfigurationStatus_Rejected;
  12145. }
  12146. }
  12147. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12148. {
  12149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12150. {
  12151. check_ascii = value[0];
  12152. if( (check_ascii < 48) || (check_ascii > 57) )
  12153. {
  12154. isSuccess = ConfigurationStatus_Rejected;
  12155. }
  12156. else
  12157. {
  12158. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12160. isSuccess = ConfigurationStatus_Accepted;
  12161. }
  12162. }
  12163. else
  12164. {
  12165. isSuccess = ConfigurationStatus_Rejected;
  12166. }
  12167. }
  12168. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12169. {
  12170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12171. {
  12172. check_ascii = value[0];
  12173. if( (check_ascii < 48) || (check_ascii > 57) )
  12174. {
  12175. isSuccess = ConfigurationStatus_Rejected;
  12176. }
  12177. else
  12178. {
  12179. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12181. isSuccess = ConfigurationStatus_Accepted;
  12182. }
  12183. }
  12184. else
  12185. {
  12186. isSuccess = ConfigurationStatus_Rejected;
  12187. }
  12188. }
  12189. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12190. {
  12191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12192. {
  12193. check_ascii = value[0];
  12194. if( (check_ascii < 48) || (check_ascii > 57) )
  12195. {
  12196. isSuccess = ConfigurationStatus_Rejected;
  12197. }
  12198. else
  12199. {
  12200. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12202. isSuccess = ConfigurationStatus_Accepted;
  12203. }
  12204. }
  12205. else
  12206. {
  12207. isSuccess = ConfigurationStatus_Rejected;
  12208. }
  12209. }
  12210. if(strcmp(key, "HeartbeatInterval") == 0)
  12211. {
  12212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12213. {
  12214. check_ascii = value[0];
  12215. if( (check_ascii < 48) || (check_ascii > 57) )
  12216. {
  12217. isSuccess = ConfigurationStatus_Rejected;
  12218. }
  12219. else
  12220. {
  12221. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12223. HeartBeatWaitTime = atoi(value);
  12224. isSuccess = ConfigurationStatus_Accepted;
  12225. }
  12226. }
  12227. else
  12228. {
  12229. isSuccess = ConfigurationStatus_Rejected;
  12230. }
  12231. }
  12232. if(strcmp(key, "LightIntensity") == 0)
  12233. {
  12234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12235. {
  12236. check_ascii = value[0];
  12237. if( (check_ascii < 48) || (check_ascii > 57) )
  12238. {
  12239. isSuccess = ConfigurationStatus_Rejected;
  12240. }
  12241. else
  12242. {
  12243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12244. isSuccess = ConfigurationStatus_Accepted;
  12245. }
  12246. }
  12247. else
  12248. {
  12249. isSuccess = ConfigurationStatus_Rejected;
  12250. }
  12251. }
  12252. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12253. {
  12254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12255. {
  12256. strcpy(str, (const char*)value);
  12257. for(int i = 0; str[i]; i++)
  12258. {
  12259. str[i] = tolower(str[i]);
  12260. }
  12261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12262. isSuccess = ConfigurationStatus_Accepted;
  12263. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12264. }
  12265. else
  12266. {
  12267. isSuccess = ConfigurationStatus_Rejected;
  12268. }
  12269. }
  12270. if(strcmp(key, "LocalPreAuthorize") == 0)
  12271. {
  12272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12273. {
  12274. strcpy(str, (const char*)value);
  12275. for(int i = 0; str[i]; i++)
  12276. {
  12277. str[i] = tolower(str[i]);
  12278. }
  12279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12280. isSuccess = ConfigurationStatus_Accepted;
  12281. }
  12282. else
  12283. {
  12284. isSuccess = ConfigurationStatus_Rejected;
  12285. }
  12286. }
  12287. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12288. {
  12289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12290. {
  12291. check_ascii = value[0];
  12292. if( (check_ascii < 48) || (check_ascii > 57) )
  12293. {
  12294. isSuccess = ConfigurationStatus_Rejected;
  12295. }
  12296. else
  12297. {
  12298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12299. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12300. isSuccess = ConfigurationStatus_Accepted;
  12301. }
  12302. }
  12303. else
  12304. {
  12305. isSuccess = ConfigurationStatus_Rejected;
  12306. }
  12307. }
  12308. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12309. {
  12310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12311. {
  12312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12313. isSuccess = ConfigurationStatus_Accepted;
  12314. }
  12315. else
  12316. {
  12317. isSuccess = ConfigurationStatus_Rejected;
  12318. }
  12319. }
  12320. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12321. {
  12322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12323. {
  12324. check_ascii = value[0];
  12325. if( (check_ascii < 48) || (check_ascii > 57) )
  12326. {
  12327. isSuccess = ConfigurationStatus_Rejected;
  12328. }
  12329. else
  12330. {
  12331. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12333. isSuccess = ConfigurationStatus_Accepted;
  12334. }
  12335. }
  12336. else
  12337. {
  12338. isSuccess = ConfigurationStatus_Rejected;
  12339. }
  12340. }
  12341. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12342. {
  12343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12344. {
  12345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12346. isSuccess = ConfigurationStatus_Accepted;
  12347. }
  12348. else
  12349. {
  12350. isSuccess = ConfigurationStatus_Rejected;
  12351. }
  12352. }
  12353. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12354. {
  12355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12356. {
  12357. check_ascii = value[0];
  12358. if( (check_ascii < 48) || (check_ascii > 57) )
  12359. {
  12360. isSuccess = ConfigurationStatus_Rejected;
  12361. }
  12362. else
  12363. {
  12364. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12366. isSuccess = ConfigurationStatus_Accepted;
  12367. }
  12368. }
  12369. else
  12370. {
  12371. isSuccess = ConfigurationStatus_Rejected;
  12372. }
  12373. }
  12374. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12375. {
  12376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12377. {
  12378. check_ascii = value[0];
  12379. if( (check_ascii < 48) || (check_ascii > 57) )
  12380. {
  12381. isSuccess = ConfigurationStatus_Rejected;
  12382. }
  12383. else
  12384. {
  12385. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12387. isSuccess = ConfigurationStatus_Accepted;
  12388. }
  12389. }
  12390. else
  12391. {
  12392. isSuccess = ConfigurationStatus_Rejected;
  12393. }
  12394. }
  12395. if(strcmp(key, "MinimumStatusDuration") == 0)
  12396. {
  12397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12398. {
  12399. check_ascii = value[0];
  12400. if( (check_ascii < 48) || (check_ascii > 57) )
  12401. {
  12402. isSuccess = ConfigurationStatus_Rejected;
  12403. }
  12404. else
  12405. {
  12406. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12407. {
  12408. isSuccess = ConfigurationStatus_Rejected;
  12409. }
  12410. else
  12411. {
  12412. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12414. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12415. isSuccess = ConfigurationStatus_Accepted;
  12416. }
  12417. }
  12418. }
  12419. else
  12420. {
  12421. isSuccess = ConfigurationStatus_Rejected;
  12422. }
  12423. }
  12424. if(strcmp(key, "NumberOfConnectors") == 0)
  12425. {
  12426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12427. {
  12428. check_ascii = value[0];
  12429. if( (check_ascii < 48) || (check_ascii > 57) )
  12430. {
  12431. isSuccess = ConfigurationStatus_Rejected;
  12432. }
  12433. else
  12434. {
  12435. //Charger.ResetRetries = Integer.parseInt(value);
  12436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12437. isSuccess = ConfigurationStatus_Accepted;
  12438. }
  12439. }
  12440. else
  12441. {
  12442. isSuccess = ConfigurationStatus_Rejected;
  12443. }
  12444. }
  12445. if(strcmp(key, "ResetRetries") == 0)
  12446. {
  12447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12448. {
  12449. check_ascii = value[0];
  12450. if( (check_ascii < 48) || (check_ascii > 57) )
  12451. {
  12452. isSuccess = ConfigurationStatus_Rejected;
  12453. }
  12454. else
  12455. {
  12456. //Charger.ResetRetries = Integer.parseInt(value);
  12457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12458. isSuccess = ConfigurationStatus_Accepted;
  12459. }
  12460. }
  12461. else
  12462. {
  12463. isSuccess = ConfigurationStatus_Rejected;
  12464. }
  12465. }
  12466. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12467. {
  12468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12469. {
  12470. strcpy(str, (const char*)value);
  12471. for(int i = 0; str[i]; i++)
  12472. {
  12473. str[i] = tolower(str[i]);
  12474. }
  12475. if(strcmp(str, "notapplicable")== 0)
  12476. {
  12477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12478. isSuccess = ConfigurationStatus_Accepted;
  12479. }
  12480. else if(strcmp(str, "unknown")== 0)
  12481. {
  12482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12483. isSuccess = ConfigurationStatus_Accepted;
  12484. }
  12485. else if(strcmp(str, "rst")== 0)
  12486. {
  12487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12488. isSuccess = ConfigurationStatus_Accepted;
  12489. }
  12490. else if(strcmp(str, "rts")== 0)
  12491. {
  12492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12493. isSuccess = ConfigurationStatus_Accepted;
  12494. }
  12495. else if(strcmp(str, "srt")== 0)
  12496. {
  12497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12498. isSuccess = ConfigurationStatus_Accepted;
  12499. }
  12500. else if(strcmp(str, "str")== 0)
  12501. {
  12502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12503. isSuccess = ConfigurationStatus_Accepted;
  12504. }
  12505. else if(strcmp(str, "trs")== 0)
  12506. {
  12507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12508. isSuccess = ConfigurationStatus_Accepted;
  12509. }
  12510. else if(strcmp(str, "tsr")== 0)
  12511. {
  12512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12513. isSuccess = ConfigurationStatus_Accepted;
  12514. }
  12515. else
  12516. {
  12517. isSuccess = ConfigurationStatus_Rejected;
  12518. }
  12519. }
  12520. else
  12521. {
  12522. isSuccess = ConfigurationStatus_Rejected;
  12523. }
  12524. }
  12525. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12526. {
  12527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12528. {
  12529. check_ascii = value[0];
  12530. if( (check_ascii < 48) || (check_ascii > 57) )
  12531. {
  12532. isSuccess = ConfigurationStatus_Rejected;
  12533. }
  12534. else
  12535. {
  12536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12537. isSuccess = ConfigurationStatus_Accepted;
  12538. }
  12539. }
  12540. else
  12541. {
  12542. isSuccess = ConfigurationStatus_Rejected;
  12543. }
  12544. }
  12545. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12546. {
  12547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12548. {
  12549. strcpy(str, (const char*)value);
  12550. for(int i = 0; str[i]; i++)
  12551. {
  12552. str[i] = tolower(str[i]);
  12553. }
  12554. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12556. isSuccess = ConfigurationStatus_Accepted;
  12557. }
  12558. else
  12559. {
  12560. isSuccess = ConfigurationStatus_Rejected;
  12561. }
  12562. }
  12563. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12564. {
  12565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12566. {
  12567. strcpy(str, (const char*)value);
  12568. for(int i = 0; str[i]; i++)
  12569. {
  12570. str[i] = tolower(str[i]);
  12571. }
  12572. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12574. isSuccess = ConfigurationStatus_Accepted;
  12575. }
  12576. else
  12577. {
  12578. isSuccess = ConfigurationStatus_Rejected;
  12579. }
  12580. }
  12581. if(strcmp(key, "StopTxnAlignedData") == 0)
  12582. {
  12583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12584. {
  12585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12586. isSuccess = ConfigurationStatus_Accepted;
  12587. }
  12588. else
  12589. {
  12590. isSuccess = ConfigurationStatus_Rejected;
  12591. }
  12592. }
  12593. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12594. {
  12595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12596. {
  12597. check_ascii = value[0];
  12598. if( (check_ascii < 48) || (check_ascii > 57) )
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. else
  12603. {
  12604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12605. isSuccess = ConfigurationStatus_Accepted;
  12606. }
  12607. }
  12608. else
  12609. {
  12610. isSuccess = ConfigurationStatus_Rejected;
  12611. }
  12612. }
  12613. if(strcmp(key, "StopTxnSampledData") == 0)
  12614. {
  12615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12616. {
  12617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12618. isSuccess = ConfigurationStatus_Accepted;
  12619. }
  12620. else
  12621. {
  12622. isSuccess = ConfigurationStatus_Rejected;
  12623. }
  12624. }
  12625. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12626. {
  12627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12628. {
  12629. check_ascii = value[0];
  12630. if( (check_ascii < 48) || (check_ascii > 57) )
  12631. {
  12632. isSuccess = ConfigurationStatus_Rejected;
  12633. }
  12634. else
  12635. {
  12636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12637. isSuccess = ConfigurationStatus_Accepted;
  12638. }
  12639. }
  12640. else
  12641. {
  12642. isSuccess = ConfigurationStatus_Rejected;
  12643. }
  12644. }
  12645. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12646. {
  12647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12648. {
  12649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12650. isSuccess = ConfigurationStatus_Accepted;
  12651. }
  12652. else
  12653. {
  12654. isSuccess = ConfigurationStatus_Rejected;
  12655. }
  12656. }
  12657. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12658. {
  12659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12660. {
  12661. check_ascii = value[0];
  12662. if( (check_ascii < 48) || (check_ascii > 57) )
  12663. {
  12664. isSuccess = ConfigurationStatus_Rejected;
  12665. }
  12666. else
  12667. {
  12668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12669. isSuccess = ConfigurationStatus_Accepted;
  12670. }
  12671. }
  12672. else
  12673. {
  12674. isSuccess = ConfigurationStatus_Rejected;
  12675. }
  12676. }
  12677. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12678. {
  12679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12680. {
  12681. check_ascii = value[0];
  12682. if( (check_ascii < 48) || (check_ascii > 57) )
  12683. {
  12684. isSuccess = ConfigurationStatus_Rejected;
  12685. }
  12686. else
  12687. {
  12688. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12690. TransactionMessageAttemptsValue = atoi(value);
  12691. isSuccess = ConfigurationStatus_Accepted;
  12692. }
  12693. }
  12694. else
  12695. {
  12696. isSuccess = ConfigurationStatus_Rejected;
  12697. }
  12698. }
  12699. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12700. {
  12701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12702. {
  12703. check_ascii = value[0];
  12704. if( (check_ascii < 48) || (check_ascii > 57) )
  12705. {
  12706. isSuccess = ConfigurationStatus_Rejected;
  12707. }
  12708. else
  12709. {
  12710. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12712. TransactionMessageRetryIntervalValue = atoi(value);
  12713. isSuccess = ConfigurationStatus_Accepted;
  12714. }
  12715. }
  12716. else
  12717. {
  12718. isSuccess = ConfigurationStatus_Rejected;
  12719. }
  12720. }
  12721. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12722. {
  12723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12724. {
  12725. strcpy(str, (const char*)value);
  12726. for(int i = 0; str[i]; i++)
  12727. {
  12728. str[i] = tolower(str[i]);
  12729. }
  12730. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12732. isSuccess = ConfigurationStatus_Accepted;
  12733. }
  12734. else
  12735. {
  12736. isSuccess = ConfigurationStatus_Rejected;
  12737. }
  12738. }
  12739. if(strcmp(key, "WebSocketPingInterval") == 0)
  12740. {
  12741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12742. {
  12743. check_ascii = value[0];
  12744. if( (check_ascii < 48) || (check_ascii > 57) )
  12745. {
  12746. isSuccess = ConfigurationStatus_Rejected;
  12747. }
  12748. else
  12749. {
  12750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12751. isSuccess = ConfigurationStatus_Accepted;
  12752. }
  12753. }
  12754. else
  12755. {
  12756. isSuccess = ConfigurationStatus_Rejected;
  12757. }
  12758. }
  12759. #if 0
  12760. //For OCPP Test Case
  12761. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12762. {
  12763. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12764. {
  12765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12766. isSuccess = ConfigurationStatus_Accepted;
  12767. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12768. }
  12769. else
  12770. {
  12771. isSuccess = ConfigurationStatus_Rejected;
  12772. }
  12773. }
  12774. #endif
  12775. #if 1
  12776. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12777. {
  12778. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12779. {
  12780. strcpy(str, (const char*)value);
  12781. for(int i = 0; str[i]; i++)
  12782. {
  12783. str[i] = tolower(str[i]);
  12784. }
  12785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12786. isSuccess = ConfigurationStatus_Accepted;
  12787. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12788. }
  12789. else
  12790. {
  12791. isSuccess = ConfigurationStatus_Rejected;
  12792. }
  12793. }
  12794. #endif
  12795. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12796. {
  12797. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12798. {
  12799. check_ascii = value[0];
  12800. if( (check_ascii < 48) || (check_ascii > 57) )
  12801. {
  12802. isSuccess = ConfigurationStatus_Rejected;
  12803. }
  12804. else
  12805. {
  12806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12807. isSuccess = ConfigurationStatus_Accepted;
  12808. }
  12809. }
  12810. else
  12811. {
  12812. isSuccess = ConfigurationStatus_Rejected;
  12813. }
  12814. }
  12815. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12816. {
  12817. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12818. {
  12819. check_ascii = value[0];
  12820. if( (check_ascii < 48) || (check_ascii > 57) )
  12821. {
  12822. isSuccess = ConfigurationStatus_Rejected;
  12823. }
  12824. else
  12825. {
  12826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12827. isSuccess = ConfigurationStatus_Accepted;
  12828. }
  12829. }
  12830. else
  12831. {
  12832. isSuccess = ConfigurationStatus_Rejected;
  12833. }
  12834. }
  12835. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12836. {
  12837. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12838. {
  12839. strcpy(str, (const char*)value);
  12840. for(int i = 0; str[i]; i++)
  12841. {
  12842. str[i] = tolower(str[i]);
  12843. }
  12844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12845. isSuccess = ConfigurationStatus_Accepted;
  12846. }
  12847. else
  12848. {
  12849. isSuccess = ConfigurationStatus_Rejected;
  12850. }
  12851. }
  12852. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12853. {
  12854. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12855. {
  12856. check_ascii = value[0];
  12857. if( (check_ascii < 48) || (check_ascii > 57) )
  12858. {
  12859. isSuccess = ConfigurationStatus_Rejected;
  12860. }
  12861. else
  12862. {
  12863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12864. isSuccess = ConfigurationStatus_Accepted;
  12865. }
  12866. }
  12867. else
  12868. {
  12869. isSuccess = ConfigurationStatus_Rejected;
  12870. }
  12871. }
  12872. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12873. {
  12874. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12875. {
  12876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12877. isSuccess = ConfigurationStatus_Accepted;
  12878. }
  12879. else
  12880. {
  12881. isSuccess = ConfigurationStatus_Rejected;
  12882. }
  12883. }
  12884. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12885. {
  12886. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12887. {
  12888. check_ascii = value[0];
  12889. if( (check_ascii < 48) || (check_ascii > 57) )
  12890. {
  12891. isSuccess = ConfigurationStatus_Rejected;
  12892. }
  12893. else
  12894. {
  12895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12896. isSuccess = ConfigurationStatus_Accepted;
  12897. }
  12898. }
  12899. else
  12900. {
  12901. isSuccess = ConfigurationStatus_Rejected;
  12902. }
  12903. }
  12904. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12905. {
  12906. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12907. {
  12908. strcpy(str, (const char*)value);
  12909. for(int i = 0; str[i]; i++)
  12910. {
  12911. str[i] = tolower(str[i]);
  12912. }
  12913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12914. isSuccess = ConfigurationStatus_Accepted;
  12915. }
  12916. else
  12917. {
  12918. isSuccess = ConfigurationStatus_Rejected;
  12919. }
  12920. }
  12921. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12922. {
  12923. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12924. {
  12925. check_ascii = value[0];
  12926. if( (check_ascii < 48) || (check_ascii > 57) )
  12927. {
  12928. isSuccess = ConfigurationStatus_Rejected;
  12929. }
  12930. else
  12931. {
  12932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12933. isSuccess = ConfigurationStatus_Accepted;
  12934. }
  12935. }
  12936. else
  12937. {
  12938. isSuccess = ConfigurationStatus_Rejected;
  12939. }
  12940. }
  12941. return isSuccess;
  12942. }
  12943. int updateSetting(char *key, char *value)
  12944. {
  12945. mtrace();
  12946. int isSuccess = FALSE;
  12947. char string[1000]={0}, buffer[1000]={0};
  12948. char strtemp[50]={0};
  12949. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12950. int pos, c = 0;
  12951. char *loc;
  12952. int pos1=0;
  12953. FILE *f = fopen("/var/www/settings1", "r");
  12954. if(f == NULL)
  12955. {
  12956. #ifdef Debug
  12957. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12958. #endif
  12959. return isSuccess;
  12960. }
  12961. fseek(f, 0, SEEK_END);
  12962. long fsize = ftell(f);
  12963. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12964. fread(string, 1, fsize, f);
  12965. fclose(f);
  12966. string[fsize] = 0;
  12967. loc = strstr(string, key);
  12968. if(loc != NULL)
  12969. {
  12970. DEBUG_INFO("key exist!\n");
  12971. pos = loc - string-1;
  12972. f = fopen("/var/www/settings1", "w");
  12973. strncpy(buffer, string, pos);
  12974. fprintf(f, "%s", buffer);
  12975. memset(sstr ,0, sizeof(sstr) );
  12976. c = 0;
  12977. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12978. {
  12979. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12980. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12981. c++;
  12982. }
  12983. sstr[c] = '\0';
  12984. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12985. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12986. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12987. memset(buffer ,0, sizeof(buffer) );
  12988. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12989. //printf("buffer=%s",buffer);
  12990. fprintf(f, "%s", buffer);
  12991. fclose(f);
  12992. }
  12993. else
  12994. {
  12995. printf("key not exist!\n");
  12996. f = fopen("/var/www/settings1", "w+");
  12997. fputs(string, f);
  12998. fseek(f, -1, SEEK_CUR);
  12999. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  13000. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  13001. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  13002. fclose(f);
  13003. }
  13004. isSuccess = TRUE;
  13005. return isSuccess;
  13006. }
  13007. int TransactionMessageAttemptsGet(void)
  13008. {
  13009. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13010. }
  13011. int FirstHeartBeatResponse(void)
  13012. {
  13013. return FirstHeartBeat;
  13014. }
  13015. int TransactionMessageRetryIntervalGet(void)
  13016. {
  13017. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13018. }
  13019. #define SA struct sockaddr
  13020. #define MAXBUF 1024
  13021. //static int m_socket_data;
  13022. //static int sockfd;
  13023. int ReadHttpStatus(int sock){
  13024. //char c;
  13025. char buff[1024]="",*ptr=buff+1;
  13026. int bytes_received, status;
  13027. DEBUG_INFO("Begin Response ..\n");
  13028. while((bytes_received = recv(sock, ptr, 1, 0))){
  13029. if(bytes_received==-1){
  13030. perror("ReadHttpStatus");
  13031. exit(1);
  13032. }
  13033. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13034. ptr++;
  13035. }
  13036. *ptr=0;
  13037. ptr=buff+1;
  13038. sscanf(ptr,"%*s %d ", &status);
  13039. DEBUG_INFO("%s\n",ptr);
  13040. DEBUG_INFO("status=%d\n",status);
  13041. DEBUG_INFO("End Response ..\n");
  13042. return (bytes_received>0)?status:0;
  13043. }
  13044. //the only filed that it parsed is 'Content-Length'
  13045. int ParseHeader(int sock){
  13046. //char c;
  13047. char buff[1024]="",*ptr=buff+4;
  13048. int bytes_received;
  13049. DEBUG_INFO("Begin HEADER ..\n");
  13050. while((bytes_received = recv(sock, ptr, 1, 0))){
  13051. if(bytes_received==-1){
  13052. perror("Parse Header");
  13053. exit(1);
  13054. }
  13055. if(
  13056. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13057. (ptr[-1]=='\r') && (*ptr=='\n' )
  13058. ) break;
  13059. ptr++;
  13060. }
  13061. *ptr=0;
  13062. ptr=buff+4;
  13063. //printf("%s",ptr);
  13064. if(bytes_received){
  13065. ptr=strstr(ptr,"Content-Length:");
  13066. if(ptr){
  13067. sscanf(ptr,"%*s %d",&bytes_received);
  13068. }else
  13069. bytes_received=-1; //unknown size
  13070. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13071. }
  13072. DEBUG_INFO("End HEADER ..\n");
  13073. return bytes_received ;
  13074. }
  13075. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13076. {
  13077. char rmFileCmd[100]={0};
  13078. char FilePath[100]={0};
  13079. char ftpbuf[200];
  13080. int systemresult;
  13081. //DEBUG_INFO("filename=%s\n",filename);
  13082. //DEBUG_INFO("url=%s\n",url);
  13083. sprintf(FilePath,"/mnt/%s",filename);
  13084. if((access(FilePath,F_OK))!=-1)
  13085. {
  13086. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13087. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13088. system(rmFileCmd);
  13089. }
  13090. memset(ftpbuf, 0, sizeof(ftpbuf));
  13091. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13092. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13093. systemresult = system(ftpbuf);
  13094. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13095. if(systemresult != 0)
  13096. {
  13097. DEBUG_INFO("http DownLoad error!\n");
  13098. return FALSE;
  13099. }
  13100. return TRUE;
  13101. }
  13102. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13103. {
  13104. char rmFileCmd[100]={0};
  13105. char FilePath[100]={0};
  13106. char ftpbuf[200];
  13107. int systemresult;
  13108. //char temp[100];
  13109. #if 0
  13110. struct hostent* server;
  13111. char *IPbuffer;
  13112. server = gethostbyname(location);
  13113. // To convert an Internet network
  13114. // address into ASCII string
  13115. IPbuffer = inet_ntoa(*((struct in_addr*)
  13116. server->h_addr_list[0]));
  13117. #endif
  13118. sprintf(FilePath,"/mnt/%s",filename);
  13119. if((access(FilePath,F_OK))!=-1)
  13120. {
  13121. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13122. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13123. system(rmFileCmd);
  13124. }
  13125. memset(ftpbuf, 0, sizeof(ftpbuf));
  13126. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13127. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13128. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13129. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13130. systemresult = system(ftpbuf);
  13131. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13132. if(systemresult != 0)
  13133. {
  13134. printf("wget error!\n");
  13135. return FALSE;
  13136. }
  13137. return TRUE;
  13138. }
  13139. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13140. {
  13141. char rmFileCmd[100]={0};
  13142. char FilePath[100]={0};
  13143. char ftpbuf[200];
  13144. char filenametemp[60]={0};
  13145. int systemresult;
  13146. //DEBUG_INFO("filename=%s\n",filename);
  13147. //DEBUG_INFO("url=%s\n",url);
  13148. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13149. if((access(FilePath,F_OK))!=-1)
  13150. {
  13151. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13152. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13153. system(rmFileCmd);
  13154. }
  13155. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13156. if(fp == NULL)
  13157. {
  13158. DEBUG_INFO("log is NULL\n");
  13159. return FALSE;
  13160. }
  13161. else
  13162. {
  13163. fprintf(fp, "%s\n", url);
  13164. sscanf(filename, "%*2[.]%s", filenametemp);
  13165. fprintf(fp, "%s\n", filenametemp);
  13166. fclose(fp);
  13167. }
  13168. memset(ftpbuf, 0, sizeof(ftpbuf));
  13169. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13170. systemresult = system(ftpbuf);
  13171. DEBUG_INFO("systemresult=%d\n",systemresult);
  13172. if(systemresult != 0)
  13173. {
  13174. DEBUG_INFO("http upload error!\n");
  13175. return FALSE;
  13176. }
  13177. return TRUE;
  13178. }
  13179. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13180. {
  13181. struct hostent* server;
  13182. char *IPbuffer;
  13183. char ftpbuf[200];
  13184. int systemresult;
  13185. // To retrieve host information
  13186. server = gethostbyname(location);
  13187. // To convert an Internet network
  13188. // address into ASCII string
  13189. IPbuffer = inet_ntoa(*((struct in_addr*)
  13190. server->h_addr_list[0]));
  13191. memset(ftpbuf, 0, sizeof(ftpbuf));
  13192. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13193. /* format : ftpput -u username -p passwd IP target source*/
  13194. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13195. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13196. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13197. systemresult = system(ftpbuf);
  13198. DEBUG_INFO("systemresult=%d\n",systemresult);
  13199. if(systemresult != 0)
  13200. {
  13201. DEBUG_INFO("ftpput error!\n");
  13202. return FALSE;
  13203. }
  13204. return TRUE;
  13205. }
  13206. int SettingChargingRecord(int target, int transactionId)
  13207. {
  13208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13209. {
  13210. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13211. {
  13212. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13213. {
  13214. addBuff(target, transactionId, 0);
  13215. return TRUE;
  13216. }
  13217. }
  13218. for (int index = 0; index < CCS_QUANTITY; index++)
  13219. {
  13220. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13221. {
  13222. addBuff(target, transactionId, 0);
  13223. return TRUE;
  13224. }
  13225. }
  13226. for (int index = 0; index < GB_QUANTITY; index++)
  13227. {
  13228. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13229. {
  13230. addBuff(target, transactionId, 0);
  13231. return TRUE;
  13232. }
  13233. }
  13234. }
  13235. else
  13236. {
  13237. for (int index = 0; index < AC_QUANTITY; index++)
  13238. {
  13239. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13240. {
  13241. addBuff(target, transactionId, 0);
  13242. return TRUE;
  13243. }
  13244. }
  13245. }
  13246. return FALSE;
  13247. }
  13248. int addBuff(int gun_idx, int user_id, int cmd_sn)
  13249. {
  13250. int isSuccess = FALSE;
  13251. //char *query = NULL;
  13252. sqlite3_stmt *stmt;
  13253. int rc; // return code
  13254. char str[20];
  13255. sprintf(str,"%d",user_id);
  13256. 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 */
  13257. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  13258. rc = sqlite3_step(stmt); /* 3 */
  13259. if (rc != SQLITE_DONE) {
  13260. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  13261. goto out;
  13262. }
  13263. sqlite3_finalize(stmt);
  13264. // free(query);
  13265. out:
  13266. //----------------------
  13267. // close SQLite database
  13268. //----------------------
  13269. sqlite3_close(db);
  13270. printf("database closed.\n");
  13271. return isSuccess;
  13272. }
  13273. /**
  13274. * Place the contents of the specified file into a memory buffer
  13275. *
  13276. * @param[in] filename The path and name of the file to read
  13277. * @param[out] filebuffer A pointer to the contents in memory
  13278. * @return status 0 success, 1 on failure
  13279. */
  13280. int get_file_contents(const char* filename, char** outbuffer) {
  13281. FILE* file = NULL;
  13282. long filesize;
  13283. const int blocksize = 1;
  13284. size_t readsize;
  13285. char* filebuffer;
  13286. // Open the file
  13287. file = fopen(filename, "r");
  13288. if (NULL == file)
  13289. {
  13290. printf("'%s' not opened\n", filename);
  13291. exit(EXIT_FAILURE);
  13292. }
  13293. // Determine the file size
  13294. fseek(file, 0, SEEK_END);
  13295. filesize = ftell(file);
  13296. rewind (file);
  13297. // Allocate memory for the file contents
  13298. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13299. *outbuffer = filebuffer;
  13300. if (filebuffer == NULL)
  13301. {
  13302. fputs ("malloc out-of-memory", stderr);
  13303. exit(EXIT_FAILURE);
  13304. }
  13305. // Read in the file
  13306. readsize = fread(filebuffer, blocksize, filesize, file);
  13307. if (readsize != filesize)
  13308. {
  13309. fputs ("didn't read file completely",stderr);
  13310. exit(EXIT_FAILURE);
  13311. }
  13312. // Clean exit
  13313. fclose(file);
  13314. return EXIT_SUCCESS;
  13315. }
  13316. static int selectSqlCount = 0;
  13317. static int callback(void *data, int argc, char **argv, char **azColName){
  13318. int i;
  13319. //printf("%s: ", (const char*)data);
  13320. selectSqlCount = argc;
  13321. for(i = 0; i<argc; i++){
  13322. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13323. }
  13324. //printf("\n");
  13325. return 0;
  13326. }
  13327. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13328. //int i;
  13329. //printf("%s:\n", (const char*)data);
  13330. localversion = argv[5] ? atoi(argv[5]) : 0;
  13331. //printf("localversion=%d\n", localversion);
  13332. return 0;
  13333. }
  13334. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13335. //int i;
  13336. //printf("%s:\n", (const char*)data);
  13337. //idTag
  13338. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13339. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13340. //parentIdTag
  13341. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13342. //expir_date
  13343. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13344. //status
  13345. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13346. //version
  13347. idTagQuery.listVersionInt = atoi(argv[5]);
  13348. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13349. return 0;
  13350. }
  13351. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  13352. #if 0
  13353. int i;
  13354. //printf("%s:\n", (const char*)data);
  13355. for(i=0; i<argc; i++){
  13356. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  13357. }
  13358. //printf("");
  13359. #endif
  13360. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13361. // printf("localversion=%d\n", localversion);
  13362. return 0;
  13363. }
  13364. /** sqlite3_exec的回调。
  13365. *
  13366. * 向控制台打印查询的结果。
  13367. *
  13368. * @param in data 传递给回调函数的数据。
  13369. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  13370. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  13371. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  13372. * @return 状态码。
  13373. */
  13374. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13375. {
  13376. for (int i = 0; i < n_columns; i++)
  13377. {
  13378. DEBUG_INFO("%s/t", col_values[i]);
  13379. }
  13380. DEBUG_INFO("/n");
  13381. return 0;
  13382. }
  13383. void OCPP_getListVerion()
  13384. {
  13385. int rc = 0;
  13386. // const char* data = "Callback function called";
  13387. char sql[100];
  13388. char zErrMsg[100];
  13389. memset(sql, 0, 100);
  13390. memset(zErrMsg, 0, 100);
  13391. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  13392. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13393. /* Execute SQL statement */
  13394. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13395. DEBUG_INFO("rc=%d\n",rc);
  13396. if( rc != SQLITE_OK ){
  13397. DEBUG_INFO("SQL error: %s", zErrMsg);
  13398. //sqlite3_free(zErrMsg);
  13399. }
  13400. }
  13401. void OCPP_getIdTag(char idTag[])
  13402. {
  13403. int rc = 0;
  13404. // const char* data = "Callback function called";
  13405. char sql[100];
  13406. char zErrMsg[100];
  13407. memset(sql, 0, 100);
  13408. memset(zErrMsg, 0, 100);
  13409. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  13410. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13411. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13412. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13413. /* Execute SQL statement */
  13414. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13415. if( rc != SQLITE_OK ){
  13416. DEBUG_INFO("SQL error: %s", zErrMsg);
  13417. //sqlite3_free(zErrMsg);
  13418. }
  13419. //return ver;
  13420. }
  13421. void OCPP_get_TableAuthlocalAllData(void)
  13422. {
  13423. int rc = 0;
  13424. // const char* data = "Callback function called";
  13425. char sql[100];
  13426. char zErrMsg[100];
  13427. memset(sql, 0, 100);
  13428. memset(zErrMsg, 0, 100);
  13429. sprintf(sql,"select * from ocpp_auth_local ");
  13430. /* Execute SQL statement */
  13431. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13432. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  13433. if( rc != SQLITE_OK ){
  13434. DEBUG_INFO("SQL error: %s", zErrMsg);
  13435. //sqlite3_free(zErrMsg);
  13436. }
  13437. //return ver;
  13438. }
  13439. int OCPP_cleanLocalList()
  13440. {
  13441. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13442. char *errMsg = 0;
  13443. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13444. if (SQLITE_OK != rc)
  13445. {
  13446. DEBUG_INFO("%s\n",errMsg);
  13447. return FALSE;
  13448. }
  13449. else
  13450. {
  13451. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  13452. }
  13453. return TRUE;
  13454. }
  13455. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13456. {
  13457. int isSuccess = FALSE;
  13458. int ret = 0;
  13459. //const char* data = "Callback function called";
  13460. char sql[300];
  13461. char zErrMsg[200];
  13462. memset(sql, 0, 300);
  13463. memset(zErrMsg, 0, 200);
  13464. 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);
  13465. //* Execute SQL statement */
  13466. //zErrMsg = 0;
  13467. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13468. if( ret != SQLITE_OK ){
  13469. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13470. // free(zErrMsg);
  13471. // free(sql);
  13472. return isSuccess;
  13473. }
  13474. memset(sql, 0, 300);
  13475. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13476. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13477. if( ret != SQLITE_OK ){
  13478. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13479. // free(zErrMsg);
  13480. // free(sql);
  13481. return isSuccess;
  13482. }
  13483. // DEBUG_INFO("successfully Insert records created\n");
  13484. isSuccess = TRUE;
  13485. return isSuccess;
  13486. }
  13487. void OCPP_deleteIdTag(char idTag[])
  13488. {
  13489. //int ver = 0;
  13490. //int isSuccess = FALSE;
  13491. int rc = 0;
  13492. char sql[100];
  13493. char zErrMsg[100];
  13494. memset(sql, 0, 100);
  13495. memset(zErrMsg, 0, 100);
  13496. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13497. //* Execute SQL statement */
  13498. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13499. if( rc != SQLITE_OK ){
  13500. DEBUG_INFO("SQL error: %s", zErrMsg);
  13501. //sqlite3_free(zErrMsg);
  13502. }
  13503. }
  13504. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13505. {
  13506. int isSuccess = FALSE;
  13507. int ret = 0;
  13508. const char* data = "Callback function called";
  13509. char sql[200];
  13510. char zErrMsg[100];
  13511. memset(sql, 0, 200);
  13512. memset(zErrMsg, 0, 100);
  13513. //* selectFromTable */
  13514. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  13515. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13516. //* Execute SQL statement */
  13517. selectSqlCount = 0;
  13518. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13519. if( ret != SQLITE_OK ){
  13520. printf("Error SQL: %s\n", zErrMsg);
  13521. }
  13522. printf("successfully select operation done\n");
  13523. memset(sql, 0, 200);
  13524. memset(zErrMsg, 0, 100);
  13525. if(selectSqlCount == 0)
  13526. {
  13527. //Insert
  13528. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  13529. 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);
  13530. DEBUG_INFO("sql:%s\n", sql);
  13531. //* Execute SQL statement */
  13532. //zErrMsg = 0;
  13533. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  13534. if( ret != SQLITE_OK ){
  13535. printf("SQL error: %s\n", zErrMsg);
  13536. return isSuccess;
  13537. }
  13538. DEBUG_INFO("successfully Insert records created\n");
  13539. isSuccess = TRUE;
  13540. }
  13541. else
  13542. {
  13543. //Update
  13544. //* Create merged SQL statement */
  13545. 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);
  13546. /* Execute SQL statement */
  13547. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13548. if( ret != SQLITE_OK ){
  13549. printf("SQL error: %s\n", zErrMsg);
  13550. //sqlite3_free(zErrMsg);
  13551. //sqlite3_free(sql);
  13552. return isSuccess;
  13553. }
  13554. DEBUG_INFO("Successfully operation done \n");
  13555. isSuccess = TRUE;
  13556. }
  13557. return isSuccess;
  13558. }
  13559. int GetOcppServerURL()
  13560. {
  13561. int result = FALSE;
  13562. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  13563. memset(OcppHost, 0, sizeof(OcppHost));
  13564. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  13565. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13566. {
  13567. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  13568. #if 1
  13569. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13570. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13571. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13572. #endif
  13573. #if 0
  13574. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13575. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  13576. OcppProtocol, OcppHost, OcppTempPath);
  13577. OcppPort = 443;
  13578. #endif
  13579. result = TRUE;
  13580. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13581. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13582. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13583. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13584. goto End;
  13585. }
  13586. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13587. {
  13588. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  13589. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13590. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13591. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13592. result = TRUE;
  13593. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13594. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13595. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13596. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13597. goto End;
  13598. }
  13599. else
  13600. {
  13601. strcpy(OcppHost,"");
  13602. }
  13603. End:
  13604. return result;
  13605. }
  13606. int GetOcppPath()
  13607. {
  13608. int result = FALSE;
  13609. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13610. {
  13611. if(OcppTempPath == NULL)
  13612. {
  13613. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13614. }
  13615. else
  13616. {
  13617. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13618. }
  13619. result = TRUE;
  13620. goto End;
  13621. }
  13622. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13623. {
  13624. if(OcppTempPath == NULL)
  13625. {
  13626. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13627. }
  13628. else
  13629. {
  13630. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13631. }
  13632. result = TRUE;
  13633. goto End;
  13634. }
  13635. else
  13636. {
  13637. strcpy(OcppPath,"");
  13638. }
  13639. End:
  13640. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  13641. return result;
  13642. }
  13643. int GetOcppPort()
  13644. {
  13645. return OcppPort;
  13646. }
  13647. int GetOcppConnStatus(void)
  13648. {
  13649. return ShmOCPP16Data->OcppConnStatus;
  13650. }
  13651. void SetOcppConnStatus(uint8_t status)
  13652. {
  13653. ShmOCPP16Data->OcppConnStatus = status;
  13654. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13655. #if 0
  13656. if(status == FALSE)
  13657. {
  13658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13659. {
  13660. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  13661. }
  13662. else
  13663. {
  13664. SystemInitial = AC_QUANTITY;
  13665. }
  13666. }
  13667. #endif
  13668. }
  13669. int GetHeartBeatWithNOResponse(void)
  13670. {
  13671. return HeartBeatWithNOResponse;
  13672. }
  13673. void SetHeartBeatWithNOResponse(void)
  13674. {
  13675. HeartBeatWithNOResponse = 0;
  13676. }
  13677. void splitstring(char *src,const char *separator,char **dest,int *num) {
  13678. /*
  13679. src 源字串的首地址(buf的地址)
  13680. separator 指定的分割字元
  13681. dest 接收子字串的陣列
  13682. num 分割後子字串的個數
  13683. */
  13684. char *pNext;
  13685. int count = 0;
  13686. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  13687. return;
  13688. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  13689. return;
  13690. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  13691. while(pNext != NULL) {
  13692. *dest++ = pNext;
  13693. ++count;
  13694. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  13695. }
  13696. *num = count;
  13697. }
  13698. int GetTransactionId(int gunindex, unsigned char idTag[])
  13699. {
  13700. char ch;
  13701. FILE *fptr1;
  13702. int temptransactionId;
  13703. char str[100]={0};
  13704. temptransactionId = 0;
  13705. /*------ Read the file ----------------*/
  13706. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13707. if (!fptr1)
  13708. {
  13709. //printf(" File not found or unable to open the input file!!\n");
  13710. return temptransactionId;
  13711. }
  13712. ch=fgetc(fptr1);
  13713. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13714. rewind(fptr1);
  13715. if(ch!=EOF)
  13716. {
  13717. // printf("%c",ch);
  13718. while (fgets(str, 100, fptr1) != NULL)
  13719. {
  13720. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13721. if(str[0]=='\0')
  13722. {
  13723. break;
  13724. }
  13725. char *revbuf[8] = {0}; //存放分割後的子字串
  13726. int num = 0;//分割後子字串的個數
  13727. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13728. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13729. {
  13730. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13731. {
  13732. temptransactionId = atoi(revbuf[2]);
  13733. break;
  13734. }
  13735. }
  13736. }
  13737. }
  13738. fclose(fptr1);
  13739. /*------- End of reading ---------------*/
  13740. return temptransactionId;
  13741. }
  13742. void SetTransactionIdZero(int transactionId)
  13743. {
  13744. //TransactionId[gunindex] = 0;
  13745. char ch;
  13746. FILE *fptr1, *fptr2;
  13747. int temptransactionId = 0;
  13748. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13749. printf("\n Delete a specific line from a file :\n");
  13750. printf("-----------------------------------------\n");
  13751. //scanf("%s",fname);
  13752. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13753. if (!fptr1)
  13754. {
  13755. //printf(" File not found or unable to open the input file!!\n");
  13756. return ;
  13757. }
  13758. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13759. if (!fptr2)
  13760. {
  13761. printf("Unable to open a temporary file to write!!\n");
  13762. fclose(fptr1);
  13763. return ;
  13764. }
  13765. ch=fgetc(fptr1);
  13766. //printf(" Now the content of the file %s is : \n",fname);
  13767. rewind(fptr1);
  13768. if(ch!=EOF)
  13769. {
  13770. // copy all contents to the temporary file except the specific line
  13771. while (fgets(str, 100, fptr1) != NULL)
  13772. {
  13773. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13774. if(str[0]=='\0')
  13775. {
  13776. break;
  13777. }
  13778. char *revbuf[8] = {0}; //存放分割後的子字串
  13779. int num = 0;//分割後子字串的個數
  13780. strcpy(strtemp, str);
  13781. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13782. if(revbuf[2][0] != '\0')
  13783. {
  13784. temptransactionId = atoi(revbuf[2]);
  13785. if(transactionId != temptransactionId)
  13786. {
  13787. fprintf(fptr2, "%s", strtemp);
  13788. }
  13789. }
  13790. }
  13791. }
  13792. fclose(fptr1);
  13793. fclose(fptr2);
  13794. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13795. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13796. printf("\n Delete a specific line from a file End\n");
  13797. printf("-----------------------------------------\n");
  13798. /*------ Read the file ----------------*/
  13799. }
  13800. int InternetDisconnect(void)
  13801. {
  13802. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13803. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13804. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13805. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13806. }
  13807. void GetChargingProfileRequest(int gunindex)
  13808. {
  13809. mtrace();
  13810. //int connectorIdInt, durationInt;
  13811. //char chargingRateUnitStr[4]={0};
  13812. int tempdurationInt = 0;
  13813. int tempchargingProfileId = 0;
  13814. int tempstackLevel = 0;
  13815. int temptransactionId = 0;
  13816. float tempminChargingRateFloat = 0.0;
  13817. char tempchargingProfilePurposeStr[24]={0};
  13818. char tempchargingProfileKindStr[12]={0};
  13819. char temprecurrencyKindStr[8]={0};
  13820. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13821. char tempvalidToStr[28]={0};
  13822. int tempStartPeriodInt = 0;
  13823. float tempLimitInt = 0.0;//0.1;
  13824. int tempNumberPhasesInt=0;
  13825. char fname[200];
  13826. //char comfirmstr[20];
  13827. float MinChargingRate =0.0;
  13828. double diff_t;
  13829. struct tm tp;
  13830. FILE *fptr1;//, *fptr2;
  13831. int c = 0;
  13832. char * pch;
  13833. char *loc;
  13834. char sstr[200]={ 0 };
  13835. int n_chargingProfile = 0;
  13836. int n_SchedulePeriods = 0;
  13837. char SchedulePeriodList[10][200]={0};
  13838. char sLineWord[1600]={0};
  13839. char word[1000]={0};
  13840. int confirmPeriods = 0;
  13841. struct StructProfile ChargePointMaxProfile;
  13842. struct StructProfile TxDefaultProfile;
  13843. struct StructProfile TxProfile;
  13844. struct StructProfile TxDefaultProfiletemp[2]={0};
  13845. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13846. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13847. struct StructChargingProfile TxProfile_TEMP={0};
  13848. int TxDefaultProfileFileIsNull=FALSE;
  13849. int ChargePointMaxProfileIsNull=FALSE;
  13850. int TxProfileIsNull=FALSE;
  13851. // int CompositeSceduleIndex = 0;
  13852. char ChargePointMaxProfileScheduleStr[30]={0};
  13853. char TxDefaultProfileScheduleStr[30]={0};
  13854. char TxProfileScheduleStr[30]={0};
  13855. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13856. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13857. memset(&TxProfile,0,sizeof(struct StructProfile));
  13858. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13859. DEBUG_INFO("GetChargingProfileRequest\n");
  13860. //*****************************ChargePointMaxProfile******************************************/
  13861. strcpy(fname, ChargePointMaxProfile_JSON);
  13862. ChargePointMaxProfileIsNull=TRUE;
  13863. DEBUG_INFO("test 1\n");
  13864. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13865. {
  13866. fptr1 = fopen(fname, "r");
  13867. int c;
  13868. c = fgetc(fptr1);
  13869. //DEBUG_INFO("c:%d\n",c);
  13870. rewind(fptr1);
  13871. if(c == EOF)
  13872. {
  13873. DEBUG_INFO("\n End of file reached.");
  13874. ChargePointMaxProfileIsNull=TRUE;
  13875. fclose(fptr1);
  13876. }
  13877. else
  13878. {
  13879. DEBUG_INFO("test 2\n");
  13880. ChargePointMaxProfileIsNull=FALSE;
  13881. while(fscanf(fptr1, "%s", word) != EOF)
  13882. {
  13883. if(strcmp(word, "chargingProfileId") == 0)
  13884. {
  13885. n_chargingProfile = n_chargingProfile + 1;
  13886. }
  13887. }
  13888. rewind(fptr1);
  13889. //search Charging Profile Element
  13890. int i = 0;
  13891. int j = 0;
  13892. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13893. //***********chargingProfileId**************/
  13894. c = 0;
  13895. loc = strstr(sLineWord, "chargingProfileId");
  13896. //DEBUG_INFO("loc=%s\n",loc);
  13897. memset(sstr ,0, sizeof(sstr) );
  13898. if(loc != NULL)
  13899. {
  13900. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13901. {
  13902. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13903. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13904. c++;
  13905. }
  13906. sstr[c] = '\0';
  13907. tempchargingProfileId = atoi(sstr);
  13908. }
  13909. else
  13910. {
  13911. tempchargingProfileId = 0;
  13912. }
  13913. //***********stackLevel**************/
  13914. c = 0;
  13915. loc = strstr(sLineWord, "stackLevel");
  13916. //DEBUG_INFO("loc=%s\n",loc);
  13917. memset(sstr ,0, sizeof(sstr) );
  13918. if(loc != NULL)
  13919. {
  13920. while (loc[2+strlen("stackLevel")+c] != '\"')
  13921. {
  13922. sstr[c] = loc[2+strlen("stackLevel")+c];
  13923. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13924. c++;
  13925. }
  13926. sstr[c] = '\0';
  13927. tempstackLevel = atoi(sstr);
  13928. }
  13929. else
  13930. {
  13931. tempstackLevel = 0;
  13932. }
  13933. //***********chargingProfilePurpose **************/
  13934. c = 0;
  13935. loc = strstr(sLineWord, "chargingProfilePurpose");
  13936. //DEBUG_INFO("loc=%s\n",loc);
  13937. memset(sstr ,0, sizeof(sstr) );
  13938. if(loc != NULL)
  13939. {
  13940. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13941. {
  13942. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13944. c++;
  13945. }
  13946. sstr[c] = '\0';
  13947. strcpy(tempchargingProfilePurposeStr,sstr);
  13948. }
  13949. else
  13950. {
  13951. strcpy(tempchargingProfilePurposeStr,"");
  13952. }
  13953. //***********chargingProfileKind **************/
  13954. c = 0;
  13955. loc = strstr(sLineWord, "chargingProfileKind");
  13956. //DEBUG_INFO("loc=%s\n",loc);
  13957. memset(sstr ,0, sizeof(sstr) );
  13958. if(loc != NULL)
  13959. {
  13960. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13961. {
  13962. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13963. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13964. c++;
  13965. }
  13966. sstr[c] = '\0';
  13967. strcpy(tempchargingProfileKindStr,sstr);
  13968. }
  13969. else
  13970. {
  13971. strcpy(tempchargingProfileKindStr,"");
  13972. }
  13973. //***********recurrencyKind **************/
  13974. c = 0;
  13975. loc = strstr(sLineWord, "recurrencyKind");
  13976. //DEBUG_INFO("loc=%s\n",loc);
  13977. memset(sstr ,0, sizeof(sstr) );
  13978. if(loc != NULL)
  13979. {
  13980. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13981. {
  13982. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13983. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13984. c++;
  13985. }
  13986. sstr[c] = '\0';
  13987. strcpy(temprecurrencyKindStr,sstr);
  13988. }
  13989. else
  13990. {
  13991. strcpy(temprecurrencyKindStr,"");
  13992. }
  13993. //***********validFrom**************/
  13994. c = 0;
  13995. loc = strstr(sLineWord, "validFrom");
  13996. //DEBUG_INFO("loc=%s\n",loc);
  13997. memset(sstr ,0, sizeof(sstr) );
  13998. if(loc != NULL)
  13999. {
  14000. while (loc[3+strlen("validFrom")+c] != '\"')
  14001. {
  14002. sstr[c] = loc[3+strlen("validFrom")+c];
  14003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14004. c++;
  14005. }
  14006. sstr[c] = '\0';
  14007. strcpy(tempvalidFromStr,sstr);
  14008. }
  14009. else
  14010. {
  14011. strcpy(tempvalidFromStr,"");
  14012. }
  14013. //***********validTo **************/
  14014. c = 0;
  14015. loc = strstr(sLineWord, "validTo");
  14016. //DEBUG_INFO("loc=%s\n",loc);
  14017. memset(sstr ,0, sizeof(sstr) );
  14018. if(loc != NULL)
  14019. {
  14020. while (loc[3+strlen("validTo")+c] != '\"')
  14021. {
  14022. sstr[c] = loc[3+strlen("validTo")+c];
  14023. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14024. c++;
  14025. }
  14026. sstr[c] = '\0';
  14027. strcpy(tempvalidToStr,sstr);
  14028. }
  14029. else
  14030. {
  14031. strcpy(tempvalidToStr,"");
  14032. }
  14033. //***********validFrom**************/
  14034. c = 0;
  14035. loc = strstr(sLineWord, "validFrom");
  14036. if(loc != NULL)
  14037. {
  14038. memset(sstr ,0, sizeof(sstr) );
  14039. while (loc[3+strlen("validFrom")+c] != '\"')
  14040. {
  14041. sstr[c] = loc[3+strlen("validFrom")+c];
  14042. c++;
  14043. }
  14044. sstr[c] = '\0';
  14045. strcpy(tempvalidFromStr,sstr);
  14046. }
  14047. else
  14048. {
  14049. strcpy(tempvalidFromStr,"");
  14050. }
  14051. //***********validTo **************/
  14052. c = 0;
  14053. loc = strstr(sLineWord, "validTo");
  14054. if(loc != NULL)
  14055. {
  14056. memset(sstr ,0, sizeof(sstr) );
  14057. while (loc[3+strlen("validTo")+c] != '\"')
  14058. {
  14059. sstr[c] = loc[3+strlen("validTo")+c];
  14060. c++;
  14061. }
  14062. sstr[c] = '\0';
  14063. strcpy(tempvalidToStr,sstr);
  14064. }
  14065. else
  14066. {
  14067. strcpy(tempvalidToStr,"");
  14068. }
  14069. //***********duration**************/
  14070. c = 0;
  14071. loc = strstr(sLineWord, "duration");
  14072. if(loc != NULL)
  14073. {
  14074. memset(sstr ,0, sizeof(sstr) );
  14075. while (loc[2+strlen("duration")+c] != ',')
  14076. {
  14077. sstr[c] = loc[2+strlen("duration")+c];
  14078. c++;
  14079. }
  14080. sstr[c] = '\0';
  14081. tempdurationInt = atoi(sstr);
  14082. }
  14083. else
  14084. {
  14085. tempdurationInt = 0;
  14086. }
  14087. //**********startSchedule**********/
  14088. c = 0;
  14089. loc = strstr(sLineWord, "startSchedule");
  14090. if(loc != NULL)
  14091. {
  14092. memset(sstr ,0, sizeof(sstr) );
  14093. while (loc[3+strlen("startSchedule")+c] != '\"')
  14094. {
  14095. sstr[c] = loc[3+strlen("startSchedule")+c];
  14096. c++;
  14097. }
  14098. sstr[c] = '\0';
  14099. strcpy(tempstartScheduleStr, sstr);
  14100. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  14101. }
  14102. else
  14103. {
  14104. strcpy(tempstartScheduleStr, "");
  14105. strcpy(ChargePointMaxProfileScheduleStr, "");
  14106. }
  14107. //**********chargingRateUnit**********/
  14108. c = 0;
  14109. loc = strstr(sLineWord, "chargingRateUnit");
  14110. memset(sstr ,0, sizeof(sstr) );
  14111. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14112. {
  14113. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14114. c++;
  14115. }
  14116. sstr[c] = '\0';
  14117. strcpy(tempchargingRateUnitStr, sstr);
  14118. //**********minChargingRate*******/
  14119. c = 0;
  14120. loc = strstr(sLineWord, "minChargingRate");
  14121. if(loc != NULL)
  14122. {
  14123. memset(sstr ,0, sizeof(sstr) );
  14124. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14125. {
  14126. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14127. c++;
  14128. }
  14129. sstr[c] = '\0';
  14130. tempminChargingRateFloat = atof(sstr);
  14131. }
  14132. else
  14133. {
  14134. tempminChargingRateFloat = 0.0;
  14135. }
  14136. //
  14137. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14138. tp.tm_isdst = -1;
  14139. time_t utc = mktime(&tp);
  14140. time_t t = time(NULL);
  14141. diff_t = difftime(t, utc);
  14142. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14143. //parsing strings to words
  14144. i = 0;
  14145. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14146. loc = loc+3+strlen("chargingSchedulePeriod");
  14147. pch = strtok(loc ,"{");
  14148. while (pch != NULL)
  14149. {
  14150. strcpy(SchedulePeriodList[i], pch);
  14151. pch = strtok (NULL, "{");
  14152. i = i + 1;
  14153. }
  14154. n_SchedulePeriods = i;
  14155. for(int i=0;i<n_SchedulePeriods;i++)
  14156. {
  14157. //*************startPeriod****************/
  14158. c = 0;
  14159. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14160. memset(sstr ,0, sizeof(sstr) );
  14161. while (loc[strlen("startPeriod")+2+c] != ',')
  14162. {
  14163. sstr[c] = loc[strlen("startPeriod")+2+c];
  14164. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14165. c++;
  14166. }
  14167. sstr[c] = '\0';
  14168. tempStartPeriodInt = atoi(sstr);
  14169. //*************limit****************/
  14170. c = 0;
  14171. loc = strstr(SchedulePeriodList[i], "limit");
  14172. memset(sstr ,0, sizeof(sstr) );
  14173. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14174. {
  14175. sstr[c] = loc[strlen("limit")+2+c];
  14176. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14177. c++;
  14178. }
  14179. sstr[c] = '\0';
  14180. tempLimitInt = atof(sstr);
  14181. //*************numberPhases****************/
  14182. c = 0;
  14183. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14184. memset(sstr ,0, sizeof(sstr) );
  14185. if(loc != NULL)
  14186. {
  14187. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14188. {
  14189. sstr[c] = loc[strlen("numberPhases")+2+c];
  14190. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14191. c++;
  14192. }
  14193. sstr[c] = '\0';
  14194. tempNumberPhasesInt = atoi(sstr);
  14195. }
  14196. else
  14197. {
  14198. tempNumberPhasesInt = 0;
  14199. }
  14200. if(j == 0)
  14201. {
  14202. ChargePointMaxProfile.Duration = tempdurationInt;
  14203. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  14204. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  14205. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14206. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14207. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14208. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  14209. ChargePointMaxProfile_TEMP.TransactionId = 0;
  14210. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14211. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14212. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14213. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14214. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14215. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14216. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14217. }
  14218. }
  14219. if(MinChargingRate < tempminChargingRateFloat)
  14220. {
  14221. MinChargingRate = tempminChargingRateFloat;
  14222. }
  14223. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14224. if(confirmPeriods < n_SchedulePeriods)
  14225. {
  14226. confirmPeriods = n_SchedulePeriods;
  14227. }
  14228. j = j + 1;
  14229. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14230. fclose(fptr1);
  14231. }// end else
  14232. }// the end of access file ChargePointMaxProfile
  14233. DEBUG_INFO("test 3\n");
  14234. //****************************TxDefaultProfile************************************************/
  14235. memset(fname, 0, sizeof fname);
  14236. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  14237. TxDefaultProfileFileIsNull=TRUE;
  14238. if((access(fname,F_OK))!=-1)
  14239. {
  14240. fptr1 = fopen(fname, "r");
  14241. c = 0;
  14242. c = fgetc(fptr1);
  14243. //DEBUG_INFO("c:%d\n",c);
  14244. rewind(fptr1);
  14245. if(c == EOF)
  14246. {
  14247. DEBUG_INFO("\n End of file reached.");
  14248. TxDefaultProfileFileIsNull=TRUE;
  14249. fclose(fptr1);
  14250. }
  14251. else
  14252. {
  14253. TxDefaultProfileFileIsNull=FALSE;
  14254. while(fscanf(fptr1, "%s", word) != EOF)
  14255. {
  14256. if(strcmp(word, "chargingProfileId") == 0)
  14257. {
  14258. n_chargingProfile = n_chargingProfile + 1;
  14259. }
  14260. }
  14261. rewind(fptr1);
  14262. //search Charging Profile Element
  14263. int i = 0;
  14264. int j = 0;
  14265. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14266. {
  14267. #if 0
  14268. //***********connectorId****************/
  14269. c = 0;
  14270. loc = strstr(sLineWord, "connectorId");
  14271. memset(sstr ,0, sizeof(sstr) );
  14272. while (loc[strlen("connectorId")+2+c] != ',')
  14273. {
  14274. sstr[c] = loc[strlen("connectorId")+2+c];
  14275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14276. c++;
  14277. }
  14278. sstr[c] = '\0';
  14279. tempconnectorIdInt = atoi(sstr);
  14280. #endif
  14281. //***********chargingProfileId**************/
  14282. c = 0;
  14283. loc = strstr(sLineWord, "chargingProfileId");
  14284. //DEBUG_INFO("loc=%s\n",loc);
  14285. memset(sstr ,0, sizeof(sstr) );
  14286. if(loc != NULL)
  14287. {
  14288. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14289. {
  14290. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14292. c++;
  14293. }
  14294. sstr[c] = '\0';
  14295. tempchargingProfileId = atoi(sstr);
  14296. }
  14297. else
  14298. {
  14299. tempchargingProfileId = 0;
  14300. }
  14301. //***********stackLevel**************/
  14302. c = 0;
  14303. loc = strstr(sLineWord, "stackLevel");
  14304. //DEBUG_INFO("loc=%s\n",loc);
  14305. memset(sstr ,0, sizeof(sstr) );
  14306. if(loc != NULL)
  14307. {
  14308. while (loc[2+strlen("stackLevel")+c] != '\"')
  14309. {
  14310. sstr[c] = loc[2+strlen("stackLevel")+c];
  14311. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14312. c++;
  14313. }
  14314. sstr[c] = '\0';
  14315. tempstackLevel = atoi(sstr);
  14316. }
  14317. else
  14318. {
  14319. tempstackLevel = 0;
  14320. }
  14321. //***********chargingProfilePurpose **************/
  14322. c = 0;
  14323. loc = strstr(sLineWord, "chargingProfilePurpose");
  14324. //DEBUG_INFO("loc=%s\n",loc);
  14325. memset(sstr ,0, sizeof(sstr) );
  14326. if(loc != NULL)
  14327. {
  14328. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14329. {
  14330. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14331. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14332. c++;
  14333. }
  14334. sstr[c] = '\0';
  14335. strcpy(tempchargingProfilePurposeStr,sstr);
  14336. }
  14337. else
  14338. {
  14339. strcpy(tempchargingProfilePurposeStr,"");
  14340. }
  14341. //***********chargingProfileKind **************/
  14342. c = 0;
  14343. loc = strstr(sLineWord, "chargingProfileKind");
  14344. //DEBUG_INFO("loc=%s\n",loc);
  14345. memset(sstr ,0, sizeof(sstr) );
  14346. if(loc != NULL)
  14347. {
  14348. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14349. {
  14350. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14351. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14352. c++;
  14353. }
  14354. sstr[c] = '\0';
  14355. strcpy(tempchargingProfileKindStr,sstr);
  14356. }
  14357. else
  14358. {
  14359. strcpy(tempchargingProfileKindStr,"");
  14360. }
  14361. //***********recurrencyKind **************/
  14362. c = 0;
  14363. loc = strstr(sLineWord, "recurrencyKind");
  14364. //DEBUG_INFO("loc=%s\n",loc);
  14365. memset(sstr ,0, sizeof(sstr) );
  14366. if(loc != NULL)
  14367. {
  14368. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14369. {
  14370. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14371. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14372. c++;
  14373. }
  14374. sstr[c] = '\0';
  14375. strcpy(temprecurrencyKindStr,sstr);
  14376. }
  14377. else
  14378. {
  14379. strcpy(temprecurrencyKindStr,"");
  14380. }
  14381. //***********validFrom**************/
  14382. c = 0;
  14383. loc = strstr(sLineWord, "validFrom");
  14384. if(loc != NULL)
  14385. {
  14386. memset(sstr ,0, sizeof(sstr) );
  14387. while (loc[3+strlen("validFrom")+c] != '\"')
  14388. {
  14389. sstr[c] = loc[3+strlen("validFrom")+c];
  14390. c++;
  14391. }
  14392. sstr[c] = '\0';
  14393. strcpy(tempvalidFromStr,sstr);
  14394. }
  14395. else
  14396. {
  14397. strcpy(tempvalidFromStr,"");
  14398. }
  14399. //***********validTo **************/
  14400. c = 0;
  14401. loc = strstr(sLineWord, "validTo");
  14402. if(loc != NULL)
  14403. {
  14404. memset(sstr ,0, sizeof(sstr) );
  14405. while (loc[3+strlen("validTo")+c] != '\"')
  14406. {
  14407. sstr[c] = loc[3+strlen("validTo")+c];
  14408. c++;
  14409. }
  14410. sstr[c] = '\0';
  14411. strcpy(tempvalidToStr,sstr);
  14412. }
  14413. else
  14414. {
  14415. strcpy(tempvalidToStr,"");
  14416. }
  14417. //***********duration**************/
  14418. c = 0;
  14419. loc = strstr(sLineWord, "duration");
  14420. if(loc != NULL)
  14421. {
  14422. memset(sstr ,0, sizeof(sstr) );
  14423. while (loc[2+strlen("duration")+c] != ',')
  14424. {
  14425. sstr[c] = loc[2+strlen("duration")+c];
  14426. c++;
  14427. }
  14428. sstr[c] = '\0';
  14429. tempdurationInt = atoi(sstr);
  14430. }
  14431. else
  14432. {
  14433. tempdurationInt = 0;
  14434. }
  14435. //**********startSchedule**********/
  14436. c = 0;
  14437. loc = strstr(sLineWord, "startSchedule");
  14438. if(loc != NULL)
  14439. {
  14440. memset(sstr ,0, sizeof(sstr) );
  14441. while (loc[3+strlen("startSchedule")+c] != '\"')
  14442. {
  14443. sstr[c] = loc[3+strlen("startSchedule")+c];
  14444. c++;
  14445. }
  14446. sstr[c] = '\0';
  14447. strcpy(tempstartScheduleStr, sstr);
  14448. strcpy(TxDefaultProfileScheduleStr, sstr);
  14449. }
  14450. else
  14451. {
  14452. strcpy(tempstartScheduleStr, "");
  14453. strcpy(TxDefaultProfileScheduleStr, "");
  14454. }
  14455. //**********chargingRateUnit**********/
  14456. c = 0;
  14457. loc = strstr(sLineWord, "chargingRateUnit");
  14458. memset(sstr ,0, sizeof(sstr) );
  14459. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14460. {
  14461. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14462. c++;
  14463. }
  14464. sstr[c] = '\0';
  14465. strcpy(tempchargingRateUnitStr, sstr);
  14466. //**********minChargingRate*******/
  14467. c = 0;
  14468. loc = strstr(sLineWord, "minChargingRate");
  14469. if(loc != NULL)
  14470. {
  14471. memset(sstr ,0, sizeof(sstr) );
  14472. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14473. {
  14474. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14475. c++;
  14476. }
  14477. sstr[c] = '\0';
  14478. tempminChargingRateFloat = atof(sstr);
  14479. }
  14480. else
  14481. {
  14482. tempminChargingRateFloat = 0.0;
  14483. }
  14484. //
  14485. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14486. tp.tm_isdst = -1;
  14487. time_t utc = mktime(&tp);
  14488. time_t t = time(NULL);
  14489. diff_t = difftime(t, utc);
  14490. printf("diff between startScheduleStr and now =%f\n",diff_t);
  14491. //parsing strings to words
  14492. i = 0;
  14493. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14494. loc = loc+3+strlen("chargingSchedulePeriod");
  14495. pch = strtok(loc ,"{");
  14496. while (pch != NULL)
  14497. {
  14498. strcpy(SchedulePeriodList[i], pch);
  14499. pch = strtok (NULL, "{");
  14500. i = i + 1;
  14501. }
  14502. n_SchedulePeriods = i;
  14503. for(int i=0;i<n_SchedulePeriods;i++)
  14504. {
  14505. //*************startPeriod****************/
  14506. c = 0;
  14507. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14508. memset(sstr ,0, sizeof(sstr) );
  14509. while (loc[strlen("startPeriod")+2+c] != ',')
  14510. {
  14511. sstr[c] = loc[strlen("startPeriod")+2+c];
  14512. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14513. c++;
  14514. }
  14515. sstr[c] = '\0';
  14516. tempStartPeriodInt = atoi(sstr);
  14517. //*************limit****************/
  14518. c = 0;
  14519. loc = strstr(SchedulePeriodList[i], "limit");
  14520. memset(sstr ,0, sizeof(sstr) );
  14521. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14522. {
  14523. sstr[c] = loc[strlen("limit")+2+c];
  14524. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14525. c++;
  14526. }
  14527. sstr[c] = '\0';
  14528. tempLimitInt = atof(sstr);
  14529. //*************numberPhases****************/
  14530. c = 0;
  14531. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14532. memset(sstr ,0, sizeof(sstr) );
  14533. if(loc != NULL)
  14534. {
  14535. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14536. {
  14537. sstr[c] = loc[strlen("numberPhases")+2+c];
  14538. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14539. c++;
  14540. }
  14541. sstr[c] = '\0';
  14542. tempNumberPhasesInt = atoi(sstr);
  14543. }
  14544. else
  14545. {
  14546. tempNumberPhasesInt = 0;
  14547. }
  14548. if(j == 0)
  14549. {
  14550. TxDefaultProfile.Duration = tempdurationInt;
  14551. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  14552. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  14553. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14554. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14555. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14556. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  14557. TxDefaultProfile_TEMP.TransactionId = 0;
  14558. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14559. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14560. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14561. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14562. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14563. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14564. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14565. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14566. }
  14567. else
  14568. {
  14569. //other stack level charging Profile
  14570. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  14571. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  14572. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  14573. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  14574. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  14575. }
  14576. }
  14577. if(MinChargingRate < tempminChargingRateFloat)
  14578. {
  14579. MinChargingRate = tempminChargingRateFloat;
  14580. }
  14581. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14582. if(confirmPeriods < n_SchedulePeriods)
  14583. confirmPeriods = n_SchedulePeriods;
  14584. j = j + 1;
  14585. }
  14586. fclose(fptr1);
  14587. //Stacking Charging Profiles
  14588. for(int l=0; l <(j-1) ;l++)
  14589. {
  14590. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  14591. {
  14592. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  14593. {
  14594. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  14595. {
  14596. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  14597. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  14598. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  14599. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14600. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14601. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14602. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14603. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14604. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14605. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14606. }
  14607. else
  14608. {
  14609. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14610. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14611. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14612. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14613. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14614. }
  14615. }
  14616. }
  14617. }//end of Stacking Charging Profiles
  14618. }// end else
  14619. }// the end of ACCESS TxDefaultProfile
  14620. //****************************TxProfile************************************************/
  14621. memset(fname, 0, sizeof fname);
  14622. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  14623. TxProfileIsNull=TRUE;
  14624. if((access(fname,F_OK))!=-1)
  14625. {
  14626. fptr1 = fopen(fname, "r");
  14627. c = 0;
  14628. c = fgetc(fptr1);
  14629. //DEBUG_INFO("c:%d\n",c);
  14630. rewind(fptr1);
  14631. if(c == EOF)
  14632. {
  14633. DEBUG_INFO("\n End of file reached.");
  14634. TxProfileIsNull=TRUE;
  14635. fclose(fptr1);
  14636. }
  14637. else
  14638. {
  14639. TxProfileIsNull=FALSE;
  14640. while(fscanf(fptr1, "%s", word) != EOF)
  14641. {
  14642. if(strcmp(word, "chargingProfileId") == 0)
  14643. {
  14644. n_chargingProfile = n_chargingProfile + 1;
  14645. }
  14646. }
  14647. rewind(fptr1);
  14648. //search Charging Profile Element
  14649. int i= 0;
  14650. int j= 0;
  14651. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14652. #if 0
  14653. /***********connectorId****************/
  14654. c = 0;
  14655. loc = strstr(sLineWord, "connectorId");
  14656. memset(sstr ,0, sizeof(sstr) );
  14657. while (loc[strlen("connectorId")+2+c] != ',')
  14658. {
  14659. sstr[c] = loc[strlen("connectorId")+2+c];
  14660. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14661. c++;
  14662. }
  14663. sstr[c] = '\0';
  14664. tempconnectorIdInt = atoi(sstr);
  14665. #endif
  14666. //***********chargingProfileId**************/
  14667. c = 0;
  14668. loc = strstr(sLineWord, "chargingProfileId");
  14669. memset(sstr ,0, sizeof(sstr) );
  14670. if(loc != NULL)
  14671. {
  14672. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14673. {
  14674. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14676. c++;
  14677. }
  14678. sstr[c] = '\0';
  14679. tempchargingProfileId = atoi(sstr);
  14680. }
  14681. else
  14682. {
  14683. tempchargingProfileId = 0;
  14684. }
  14685. //***********transactionId **************/
  14686. c = 0;
  14687. loc = strstr(sLineWord, "transactionId");
  14688. //DEBUG_INFO("loc=%s\n",loc);
  14689. memset(sstr ,0, sizeof(sstr) );
  14690. if(loc != NULL)
  14691. {
  14692. while (loc[2+strlen("transactionId")+c] != '\"')
  14693. {
  14694. sstr[c] = loc[2+strlen("transactionId")+c];
  14695. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14696. c++;
  14697. }
  14698. sstr[c] = '\0';
  14699. temptransactionId = atoi(sstr);
  14700. }
  14701. else
  14702. {
  14703. temptransactionId = 0;
  14704. }
  14705. //***********stackLevel**************/
  14706. c = 0;
  14707. loc = strstr(sLineWord, "stackLevel");
  14708. //DEBUG_INFO("loc=%s\n",loc);
  14709. memset(sstr ,0, sizeof(sstr) );
  14710. if(loc != NULL)
  14711. {
  14712. while (loc[2+strlen("stackLevel")+c] != '\"')
  14713. {
  14714. sstr[c] = loc[2+strlen("stackLevel")+c];
  14715. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14716. c++;
  14717. }
  14718. sstr[c] = '\0';
  14719. tempstackLevel = atoi(sstr);
  14720. }
  14721. else
  14722. {
  14723. tempstackLevel = 0;
  14724. }
  14725. //***********chargingProfilePurpose **************/
  14726. c = 0;
  14727. loc = strstr(sLineWord, "chargingProfilePurpose");
  14728. //DEBUG_INFO("loc=%s\n",loc);
  14729. memset(sstr ,0, sizeof(sstr) );
  14730. if(loc != NULL)
  14731. {
  14732. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14733. {
  14734. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14735. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14736. c++;
  14737. }
  14738. sstr[c] = '\0';
  14739. strcpy(tempchargingProfilePurposeStr,sstr);
  14740. }
  14741. else
  14742. {
  14743. strcpy(tempchargingProfilePurposeStr,"");
  14744. }
  14745. //***********chargingProfileKind **************/
  14746. c = 0;
  14747. loc = strstr(sLineWord, "chargingProfileKind");
  14748. //DEBUG_INFO("loc=%s\n",loc);
  14749. memset(sstr ,0, sizeof(sstr) );
  14750. if(loc != NULL)
  14751. {
  14752. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14753. {
  14754. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14755. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14756. c++;
  14757. }
  14758. sstr[c] = '\0';
  14759. strcpy(tempchargingProfileKindStr,sstr);
  14760. }
  14761. else
  14762. {
  14763. strcpy(tempchargingProfileKindStr,"");
  14764. }
  14765. //***********recurrencyKind **************/
  14766. c = 0;
  14767. loc = strstr(sLineWord, "recurrencyKind");
  14768. //DEBUG_INFO("loc=%s\n",loc);
  14769. memset(sstr ,0, sizeof(sstr) );
  14770. if(loc != NULL)
  14771. {
  14772. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14773. {
  14774. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14776. c++;
  14777. }
  14778. sstr[c] = '\0';
  14779. strcpy(temprecurrencyKindStr,sstr);
  14780. }
  14781. else
  14782. {
  14783. strcpy(temprecurrencyKindStr,"");
  14784. }
  14785. //***********validFrom**************/
  14786. c = 0;
  14787. loc = strstr(sLineWord, "validFrom");
  14788. if(loc != NULL)
  14789. {
  14790. memset(sstr ,0, sizeof(sstr) );
  14791. while (loc[3+strlen("validFrom")+c] != '\"')
  14792. {
  14793. sstr[c] = loc[3+strlen("validFrom")+c];
  14794. c++;
  14795. }
  14796. sstr[c] = '\0';
  14797. strcpy(tempvalidFromStr,sstr);
  14798. }
  14799. else
  14800. {
  14801. strcpy(tempvalidFromStr,"");
  14802. }
  14803. //***********validTo**************/
  14804. c = 0;
  14805. loc = strstr(sLineWord, "validTo");
  14806. if(loc != NULL)
  14807. {
  14808. memset(sstr ,0, sizeof(sstr) );
  14809. while (loc[3+strlen("validTo")+c] != '\"')
  14810. {
  14811. sstr[c] = loc[3+strlen("validTo")+c];
  14812. c++;
  14813. }
  14814. sstr[c] = '\0';
  14815. strcpy(tempvalidToStr,sstr);
  14816. }
  14817. else
  14818. {
  14819. strcpy(tempvalidToStr,"");
  14820. }
  14821. //***********duration**************/
  14822. c = 0;
  14823. loc = strstr(sLineWord, "duration");
  14824. //DEBUG_INFO("loc=%s\n",loc);
  14825. memset(sstr ,0, sizeof(sstr) );
  14826. if(loc != NULL)
  14827. {
  14828. while (loc[2+strlen("duration")+c] != '\"')
  14829. {
  14830. sstr[c] = loc[2+strlen("duration")+c];
  14831. c++;
  14832. }
  14833. sstr[c] = '\0';
  14834. tempdurationInt = atoi(sstr);
  14835. }
  14836. else
  14837. {
  14838. tempdurationInt = 0;
  14839. }
  14840. //**********startSchedule**********/
  14841. c = 0;
  14842. loc = strstr(sLineWord, "startSchedule");
  14843. if(loc != NULL)
  14844. {
  14845. memset(sstr ,0, sizeof(sstr) );
  14846. while (loc[3+strlen("startSchedule")+c] != '\"')
  14847. {
  14848. sstr[c] = loc[3+strlen("startSchedule")+c];
  14849. c++;
  14850. }
  14851. sstr[c] = '\0';
  14852. strcpy(tempstartScheduleStr, sstr);
  14853. strcpy(TxProfileScheduleStr, sstr);
  14854. }
  14855. else
  14856. {
  14857. strcpy(tempstartScheduleStr, "");
  14858. strcpy(TxProfileScheduleStr, "");
  14859. }
  14860. //**********chargingRateUnit**********/
  14861. c = 0;
  14862. loc = strstr(sLineWord, "chargingRateUnit");
  14863. memset(sstr ,0, sizeof(sstr) );
  14864. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14865. {
  14866. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14867. c++;
  14868. }
  14869. sstr[c] = '\0';
  14870. strcpy(tempchargingRateUnitStr, sstr);
  14871. //**********minChargingRate*******/
  14872. c = 0;
  14873. loc = strstr(sLineWord, "minChargingRate");
  14874. if(loc != NULL)
  14875. {
  14876. memset(sstr ,0, sizeof(sstr) );
  14877. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14878. {
  14879. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14880. c++;
  14881. }
  14882. sstr[c] = '\0';
  14883. tempminChargingRateFloat = atof(sstr);
  14884. }
  14885. else
  14886. {
  14887. tempminChargingRateFloat = 0.0;
  14888. }
  14889. //
  14890. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14891. tp.tm_isdst = -1;
  14892. time_t utc = mktime(&tp);
  14893. time_t t = time(NULL);
  14894. diff_t = difftime(t, utc);
  14895. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14896. //parsing strings to words
  14897. i = 0;
  14898. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14899. loc = loc+3+strlen("chargingSchedulePeriod");
  14900. pch = strtok(loc ,"{");
  14901. while (pch != NULL)
  14902. {
  14903. strcpy(SchedulePeriodList[i], pch);
  14904. pch = strtok (NULL, "{");
  14905. i = i + 1;
  14906. }
  14907. n_SchedulePeriods = i;
  14908. for(int i=0;i<n_SchedulePeriods;i++)
  14909. {
  14910. //*************startPeriod****************/
  14911. c = 0;
  14912. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14913. memset(sstr ,0, sizeof(sstr) );
  14914. while (loc[strlen("startPeriod")+2+c] != ',')
  14915. {
  14916. sstr[c] = loc[strlen("startPeriod")+2+c];
  14917. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14918. c++;
  14919. }
  14920. sstr[c] = '\0';
  14921. tempStartPeriodInt = atoi(sstr);
  14922. //*************limit****************/
  14923. c = 0;
  14924. loc = strstr(SchedulePeriodList[i], "limit");
  14925. memset(sstr ,0, sizeof(sstr) );
  14926. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14927. {
  14928. sstr[c] = loc[strlen("limit")+2+c];
  14929. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14930. c++;
  14931. }
  14932. sstr[c] = '\0';
  14933. tempLimitInt = atof(sstr);
  14934. //*************numberPhases****************/
  14935. c = 0;
  14936. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14937. memset(sstr ,0, sizeof(sstr) );
  14938. if(loc != NULL)
  14939. {
  14940. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14941. {
  14942. sstr[c] = loc[strlen("numberPhases")+2+c];
  14943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14944. c++;
  14945. }
  14946. sstr[c] = '\0';
  14947. tempNumberPhasesInt = atoi(sstr);
  14948. }
  14949. else
  14950. {
  14951. tempNumberPhasesInt = 0;
  14952. }
  14953. //TxProfile.Duration = durationInt;
  14954. TxProfile.TotalPeriod = n_SchedulePeriods;
  14955. TxProfile.Period[i].Limit = tempLimitInt;
  14956. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14957. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14958. }
  14959. if(MinChargingRate < tempminChargingRateFloat)
  14960. {
  14961. MinChargingRate = tempminChargingRateFloat;
  14962. }
  14963. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14964. if(confirmPeriods < n_SchedulePeriods)
  14965. confirmPeriods = n_SchedulePeriods;
  14966. if(j == 0)
  14967. {
  14968. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14969. TxProfile_TEMP.StackLevel = tempstackLevel;
  14970. TxProfile_TEMP.TransactionId = 0;
  14971. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14972. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14973. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14974. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14975. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14976. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14977. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14978. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14979. }
  14980. }
  14981. fclose(fptr1);
  14982. }
  14983. }// the end of ACCESS TxProfile
  14984. //-----------------------------------------------CompositeSchedule--------------------------//
  14985. int period=0;
  14986. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14987. {
  14988. //TxProfile
  14989. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14990. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14991. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14992. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14993. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14994. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14995. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14996. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14997. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14998. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14999. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15000. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15001. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15002. for(int k=0; k < TxProfile.TotalPeriod;k++)
  15003. {
  15004. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  15005. {
  15006. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15007. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15008. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15009. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15010. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15011. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15012. period = period + 1;
  15013. }
  15014. else
  15015. {
  15016. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  15017. {
  15018. }
  15019. else
  15020. {
  15021. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15022. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15023. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15024. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15025. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15026. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15027. period = period + 1;
  15028. }
  15029. }
  15030. }
  15031. struct tm tp;
  15032. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15033. tp.tm_isdst = -1;
  15034. time_t utc = mktime(&tp);
  15035. time_t t = time(NULL);
  15036. double diff_f = difftime(t, utc);
  15037. int diff_i;// = (int)diff_f;
  15038. int quotient; // = diff_i / 86400;//86400 seconds/day
  15039. if(diff_f >= 0)
  15040. {
  15041. diff_i = (int)diff_f;
  15042. quotient = diff_i / 86400;//86400 seconds/day
  15043. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15044. {
  15045. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  15046. {
  15047. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15048. {
  15049. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15050. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15051. }
  15052. else
  15053. {
  15054. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15055. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15056. }
  15057. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15058. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15059. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15060. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15061. period = period + 1;
  15062. }
  15063. }
  15064. }// end of if(diff_f >= 0)
  15065. }
  15066. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15067. {
  15068. //TxDefaultProfile
  15069. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15070. struct tm tp;
  15071. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15072. tp.tm_isdst = -1;
  15073. time_t utc = mktime(&tp);
  15074. time_t t = time(NULL);
  15075. double diff_f = difftime(t, utc);
  15076. int diff_i;// = (int)diff_f;
  15077. int quotient; // = diff_i / 86400;//86400 seconds/day
  15078. int remainder;
  15079. //---- Define StartSchedule----/
  15080. struct tm *gtime;
  15081. time_t now;
  15082. char buf[28];
  15083. //---Read the current system time---/
  15084. time(&now);
  15085. //---Convert the system time to GMT (now UTC)---/
  15086. gtime = gmtime(&now);
  15087. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15088. if(diff_f >= 0)
  15089. {
  15090. diff_i = (int)diff_f;
  15091. quotient = diff_i / 86400;//86400 seconds/day
  15092. remainder = diff_i % 86400;
  15093. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15094. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15095. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15096. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  15097. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15098. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15099. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15100. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15101. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15102. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15103. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15104. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15105. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  15106. {
  15107. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15108. {
  15109. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15110. {
  15111. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15112. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15113. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15114. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15115. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15116. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15117. period = period + 1;
  15118. }
  15119. else
  15120. {
  15121. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15122. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15123. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15124. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  15125. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15126. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15127. period = period + 1;
  15128. }
  15129. }
  15130. }
  15131. } // end of diff_f >= 0
  15132. }
  15133. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  15134. {
  15135. //TxDefaultProfile
  15136. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15137. struct tm tp;
  15138. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15139. tp.tm_isdst = -1;
  15140. time_t utc = mktime(&tp);
  15141. time_t t = time(NULL);
  15142. double diff_f = difftime(t, utc);
  15143. int diff_i;// = (int)diff_f;
  15144. int quotient; // = diff_i / 86400;//86400 seconds/day
  15145. int remainder;
  15146. //---- Define StartSchedule----/
  15147. struct tm *gtime;
  15148. time_t now;
  15149. char buf[28];
  15150. //---Read the current system time---/
  15151. time(&now);
  15152. //---Convert the system time to GMT (now UTC)---/
  15153. gtime = gmtime(&now);
  15154. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15155. if(diff_f >= 0)
  15156. {
  15157. diff_i = (int)diff_f;
  15158. quotient = diff_i / 86400;//86400 seconds/day
  15159. remainder = diff_i % 86400;
  15160. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15161. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15162. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15163. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  15164. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15165. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15166. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15167. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15168. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15169. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  15170. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15171. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15172. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15173. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15174. {
  15175. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15176. {
  15177. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15178. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15179. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15180. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15181. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15182. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15183. period = period + 1;
  15184. }
  15185. }
  15186. } //end of diff_f >= 0
  15187. }
  15188. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15189. {
  15190. //ChargePointMaxProfile
  15191. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  15192. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  15193. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15194. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  15195. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  15196. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15197. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15198. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  15199. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  15200. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  15201. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  15202. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  15203. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  15204. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  15205. {
  15206. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  15207. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  15208. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  15209. period = period + 1;
  15210. }
  15211. }
  15212. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  15213. {
  15214. //TxProfile Daily
  15215. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  15216. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  15217. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  15218. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  15219. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15220. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15221. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15222. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15223. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15224. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15225. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15226. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15227. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15228. for(int l=0; l< TxProfile.TotalPeriod; l++)
  15229. {
  15230. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  15231. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  15232. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  15233. }
  15234. }
  15235. confirmPeriods = period;
  15236. if(confirmPeriods != 0)
  15237. {
  15238. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  15239. 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,"
  15240. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  15241. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  15242. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  15243. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  15244. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  15245. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  15246. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  15247. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  15248. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  15249. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  15250. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  15251. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  15252. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  15253. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  15254. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  15255. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  15256. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  15257. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  15258. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  15259. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  15260. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  15261. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  15262. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  15263. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  15264. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  15265. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  15266. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  15267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  15268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  15269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  15270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  15271. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  15272. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  15273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  15274. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  15275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  15276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  15277. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  15278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  15279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  15280. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  15281. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  15282. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  15283. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  15284. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  15285. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  15286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  15287. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  15288. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  15289. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  15290. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  15291. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  15292. }
  15293. }
  15294. void storeTempStopTransaction(int gun_index)
  15295. {
  15296. //int result = FAIL;
  15297. //char message[1500]={0};
  15298. char guid[37]={0};
  15299. int tempIndex = 0;
  15300. //char tempdata[65]={0};
  15301. //int idx_sample=0;
  15302. DEBUG_ERROR("sendStopTransactionRequest \n");
  15303. memset(queuedata, 0, sizeof(queuedata));
  15304. //ENERGY_ACTIVE_IMPORT_REGISTER
  15305. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15306. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  15317. {
  15318. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15319. {
  15320. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  15321. }
  15322. }// END OF CHAdeMO_QUANTITY
  15323. }
  15324. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  15335. {
  15336. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15337. {
  15338. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  15339. }
  15340. }// END OF CCS_QUANTITY
  15341. }
  15342. else if(gunType[gun_index] == 'G')
  15343. {
  15344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15345. {
  15346. tempIndex = ((gun_index==2) ? 1: 0);
  15347. }
  15348. else
  15349. {
  15350. tempIndex = gun_index;
  15351. }
  15352. for (int index = 0; index < GB_QUANTITY; index++)
  15353. {
  15354. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15355. {
  15356. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  15357. }
  15358. }// END OF GB_QUANTITY
  15359. }
  15360. else
  15361. {
  15362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15363. {
  15364. tempIndex = 2;
  15365. }
  15366. else
  15367. {
  15368. tempIndex = gun_index;
  15369. }
  15370. for (int index = 0; index < AC_QUANTITY; index++)
  15371. {
  15372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15373. {
  15374. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  15375. }
  15376. }// END OF AC_QUANTITY
  15377. }
  15378. //Stop Transaction Time
  15379. struct timeval tmnow;
  15380. struct tm *tm;
  15381. char buf[28];//, usec_buf[6];
  15382. gettimeofday(&tmnow, NULL);
  15383. time_t t;
  15384. t = time(NULL);
  15385. /*UTC time and date*/
  15386. tm = gmtime(&t);
  15387. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15389. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15390. random_uuid(guid);
  15391. /***********************************transactionData******************************************************/
  15392. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  15393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15394. //=================================
  15395. // Transaction_Begin
  15396. //=================================
  15397. // Energy.Active.Export.Interval
  15398. //idx_sample=0;
  15399. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  15400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15402. 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*/]);
  15403. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15404. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15405. {
  15406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15407. }
  15408. else
  15409. {
  15410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15411. }
  15412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15414. //=================================
  15415. // Transaction_End
  15416. //=================================
  15417. //Current.Export
  15418. //idx_sample=1;
  15419. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15420. if(gunType[gun_index] == 'J')
  15421. {
  15422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15423. {
  15424. tempIndex = ((gun_index==2) ? 1: 0);
  15425. }
  15426. else
  15427. {
  15428. tempIndex = gun_index;
  15429. }
  15430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15431. {
  15432. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15433. {
  15434. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15435. }
  15436. }// End of for CHAdeMO_QUANTITY
  15437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15438. }
  15439. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15440. {
  15441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15442. {
  15443. tempIndex = ((gun_index==2) ? 1: 0);
  15444. }
  15445. else
  15446. {
  15447. tempIndex = gun_index;
  15448. }
  15449. for (int index = 0; index < CCS_QUANTITY; index++)
  15450. {
  15451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15452. {
  15453. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15454. }
  15455. }// End of for CCS_QUANTITY
  15456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15457. }
  15458. else if(gunType[gun_index] == 'G')
  15459. {
  15460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15461. {
  15462. tempIndex = ((gun_index==2) ? 1: 0);
  15463. }
  15464. else
  15465. {
  15466. tempIndex = gun_index;
  15467. }
  15468. for (int index = 0; index < GB_QUANTITY; index++)
  15469. {
  15470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15471. {
  15472. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15473. }
  15474. }// End of for GB_QUANTITY
  15475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15476. }
  15477. else
  15478. {
  15479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15480. {
  15481. tempIndex = 2;
  15482. }
  15483. else
  15484. {
  15485. tempIndex = gun_index;
  15486. }
  15487. for (int index = 0; index < AC_QUANTITY; index++)
  15488. {
  15489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15490. {
  15491. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15492. }
  15493. }// End of for AC_QUANTITY
  15494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15495. }
  15496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15499. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15502. //Energy.Active.Export.Interval
  15503. //idx_sample=2;
  15504. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15505. if(gunType[gun_index] == 'J')
  15506. {
  15507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15508. {
  15509. tempIndex = ((gun_index==2) ? 1: 0);
  15510. }
  15511. else
  15512. {
  15513. tempIndex = gun_index;
  15514. }
  15515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15516. {
  15517. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15518. {
  15519. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15520. }
  15521. }// END OF CHAdeMO_QUANTITY
  15522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15523. }
  15524. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15525. {
  15526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15527. {
  15528. tempIndex = ((gun_index==2) ? 1: 0);
  15529. }
  15530. else
  15531. {
  15532. tempIndex = gun_index;
  15533. }
  15534. for (int index = 0; index < CCS_QUANTITY; index++)
  15535. {
  15536. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15537. {
  15538. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15539. }
  15540. }// END OF CCS_QUANTITY
  15541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15542. }
  15543. else if(gunType[gun_index] == 'G')
  15544. {
  15545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15546. {
  15547. tempIndex = ((gun_index==2) ? 1: 0);
  15548. }
  15549. else
  15550. {
  15551. tempIndex = gun_index;
  15552. }
  15553. for (int index = 0; index < GB_QUANTITY; index++)
  15554. {
  15555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15556. {
  15557. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15558. }
  15559. }// END OF GB_QUANTITY
  15560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15561. }
  15562. else
  15563. {
  15564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15565. {
  15566. tempIndex = 2;
  15567. }
  15568. else
  15569. {
  15570. tempIndex = gun_index;
  15571. }
  15572. for (int index = 0; index < AC_QUANTITY; index++)
  15573. {
  15574. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15575. {
  15576. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15577. }
  15578. }// END OF AC_QUANTITY
  15579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15580. }
  15581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15584. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15587. //Power.Active.Export
  15588. //idx_sample=3;
  15589. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15590. if(gunType[gun_index] == 'J')
  15591. {
  15592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15593. {
  15594. tempIndex = ((gun_index==2) ? 1: 0);
  15595. }
  15596. else
  15597. {
  15598. tempIndex = gun_index;
  15599. }
  15600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15601. {
  15602. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15603. {
  15604. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15605. }
  15606. } // End for CHAdeMO_QUANTITY
  15607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15608. }
  15609. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15610. {
  15611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15612. {
  15613. tempIndex = ((gun_index==2) ? 1: 0);
  15614. }
  15615. else
  15616. {
  15617. tempIndex = gun_index;
  15618. }
  15619. for (int index = 0; index < CCS_QUANTITY; index++)
  15620. {
  15621. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15622. {
  15623. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15624. }
  15625. } // END for CCS_QUANTITY
  15626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15627. }
  15628. else if(gunType[gun_index] == 'G')
  15629. {
  15630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15631. {
  15632. tempIndex = ((gun_index==2) ? 1: 0);
  15633. }
  15634. else
  15635. {
  15636. tempIndex = gun_index;
  15637. }
  15638. for (int index = 0; index < GB_QUANTITY; index++)
  15639. {
  15640. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15641. {
  15642. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15643. }
  15644. }// END for GB_QUANTITY
  15645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15646. }
  15647. else
  15648. {
  15649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15650. {
  15651. tempIndex = 2;
  15652. }
  15653. else
  15654. {
  15655. tempIndex = gun_index;
  15656. }
  15657. for (int index = 0; index < AC_QUANTITY; index++)
  15658. {
  15659. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15660. {
  15661. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15662. }
  15663. } // END for AC_QUANTITY
  15664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15665. }
  15666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15669. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15672. //Voltage
  15673. //idx_sample=4;
  15674. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15675. if(gunType[gun_index] == 'J')
  15676. {
  15677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15678. {
  15679. tempIndex = ((gun_index==2) ? 1: 0);
  15680. }
  15681. else
  15682. {
  15683. tempIndex = gun_index;
  15684. }
  15685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15686. {
  15687. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15688. {
  15689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15690. }
  15691. } // END OF FOR CHAdeMO_QUANTITY
  15692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15693. }
  15694. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15695. {
  15696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15697. {
  15698. tempIndex = ((gun_index==2) ? 1: 0);
  15699. }
  15700. else
  15701. {
  15702. tempIndex = gun_index;
  15703. }
  15704. for (int index = 0; index < CCS_QUANTITY; index++)
  15705. {
  15706. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15707. {
  15708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15709. }
  15710. } // END OF FOR CCS_QUANTITY
  15711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15712. }
  15713. else if(gunType[gun_index] == 'G')
  15714. {
  15715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15716. {
  15717. tempIndex = ((gun_index==2) ? 1: 0);
  15718. }
  15719. else
  15720. {
  15721. tempIndex = gun_index;
  15722. }
  15723. for (int index = 0; index < GB_QUANTITY; index++)
  15724. {
  15725. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15726. {
  15727. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15728. }
  15729. } // END OF FOR GB_QUANTITY
  15730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15731. }
  15732. else
  15733. {
  15734. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15735. {
  15736. tempIndex = 2;
  15737. }
  15738. else
  15739. {
  15740. tempIndex = gun_index;
  15741. }
  15742. for (int index = 0; index < AC_QUANTITY; index++)
  15743. {
  15744. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15745. {
  15746. 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
  15747. }
  15748. } // END OF FOR AC_QUANTITY
  15749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15750. }
  15751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15754. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15757. //SoC
  15758. //idx_sample=5;
  15759. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15760. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15761. {
  15762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15763. {
  15764. tempIndex = ((gun_index==2) ? 1: 0);
  15765. }
  15766. else
  15767. {
  15768. tempIndex = gun_index;
  15769. }
  15770. if(gunType[gun_index] == 'J')
  15771. {
  15772. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15773. {
  15774. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15775. {
  15776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15777. }
  15778. }
  15779. }
  15780. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15781. {
  15782. for (int index = 0; index < CCS_QUANTITY; index++)
  15783. {
  15784. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15785. {
  15786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15787. }
  15788. }
  15789. }
  15790. else if(gunType[gun_index] == 'G')
  15791. {
  15792. for (int index = 0; index < GB_QUANTITY; index++)
  15793. {
  15794. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15795. {
  15796. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15797. }
  15798. }
  15799. }
  15800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  15805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15806. } // END FOR DC CASE
  15807. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15808. {
  15809. 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\"}]}]}]"
  15810. ,MESSAGE_TYPE_CALL
  15811. ,guid
  15812. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15813. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15814. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15816. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  15817. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  15854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  15855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  15856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  15857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  15858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  15859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  15860. );
  15861. }
  15862. else
  15863. {
  15864. 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\"}]}]}]"
  15865. ,MESSAGE_TYPE_CALL
  15866. ,guid
  15867. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15868. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15869. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15871. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  15872. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15908. );
  15909. }
  15910. // Check File "TempStopTransaction" Exist
  15911. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  15912. {
  15913. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15914. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  15915. }
  15916. else
  15917. {
  15918. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15919. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  15920. if(log == NULL)
  15921. {
  15922. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15923. return ;
  15924. }
  15925. else
  15926. {
  15927. fclose(log);
  15928. }
  15929. }
  15930. //Add TempStopTransaction | Update TempStopTransaction
  15931. // open file for writing
  15932. FILE *outfile;
  15933. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  15934. DEBUG_INFO("data=%s\n",queuedata);
  15935. fputs(queuedata, outfile);
  15936. fputs("\n", outfile);
  15937. fclose (outfile);
  15938. #if 0
  15939. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15940. if(hashmap_operation(0, guid, tempdata) == 1)
  15941. {
  15942. result = PASS;
  15943. DEBUG_INFO("StopTransaction mapitem pass\n");
  15944. }
  15945. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  15946. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  15947. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  15948. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  15949. {
  15950. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  15951. }
  15952. #endif
  15953. }
  15954. void checkTempStopTransaction(int gun_index)
  15955. {
  15956. FILE *fptr1;
  15957. char ch;
  15958. char str[100]={0};
  15959. char guid[37]={0};
  15960. char tempdata[65]={0};
  15961. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15962. if (!fptr1)
  15963. {
  15964. //printf(" File not found or unable to open the input file!!\n");
  15965. return ;
  15966. }
  15967. ch=fgetc(fptr1);
  15968. //printf(" Now the content of the file %s is : \n",fname);
  15969. rewind(fptr1);
  15970. if(ch!=EOF)
  15971. {
  15972. // copy all contents to the temporary file except the specific line
  15973. while (fgets(str, 1200, fptr1) != NULL)
  15974. {
  15975. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15976. if(str[0]=='\0')
  15977. {
  15978. break;
  15979. }
  15980. random_uuid(guid);
  15981. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15982. if(hashmap_operation(0, guid, tempdata) == 1)
  15983. {
  15984. DEBUG_INFO("StopTransaction mapitem pass\n");
  15985. }
  15986. queue_operation(4, guid, str );//addq(guid, queuedata); ---> remove temporally
  15987. if(GetTransactionQueueNum() == 1)
  15988. {
  15989. LWS_Send(str);
  15990. }
  15991. }
  15992. }
  15993. fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15994. fclose(fptr1);
  15995. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  15996. }
  15997. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15998. {
  15999. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16000. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16001. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16002. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16003. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16004. }
  16005. int GetWebSocketPingInterval(void)
  16006. {
  16007. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16008. }
  16009. int GetServerSign(void)
  16010. {
  16011. return server_sign;
  16012. }
  16013. void SetServerSign(int value)
  16014. {
  16015. server_sign = value;
  16016. }
  16017. int GetBootNotificationInterval(void)
  16018. {
  16019. return BootNotificationInterval;
  16020. }
  16021. int GetInternetConn(void)
  16022. {
  16023. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16024. }
  16025. void InitialSystemValue(void)
  16026. {
  16027. int connectorIndex = 0;
  16028. //int valueASCII = 0;
  16029. server_cycle_Status = 120;
  16030. gunTotalNumber=0;
  16031. SystemInitial = 0;
  16032. localversion=0;
  16033. BootNotificationInterval = 0;
  16034. authorizeRetryTimes = 0;
  16035. GunStatusInterval = 10;
  16036. TransactionMessageAttemptsValue = 0;
  16037. TransactionMessageRetryIntervalValue = 0;
  16038. HeartBeatWithNOResponse = 0;
  16039. HeartBeatCountPerHour = 0;
  16040. HeartBeatWaitTime = 10;
  16041. FirstHeartBeat = 0;
  16042. FirmwareStatusNotificationStatus = 3; // Idle
  16043. DiagnosticsStatusNotificationStatus = 0; // Idle
  16044. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  16045. memset(statusModeChage, 0, sizeof(statusModeChage));
  16046. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  16047. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  16048. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  16049. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  16050. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  16051. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  16052. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  16053. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  16054. memset(gunType, 0, sizeof(gunType));
  16055. //gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  16056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16057. {
  16058. //check connector / socket type (index: 8, 9, 10)
  16059. for(int index=7; index <10 ; index++)
  16060. {
  16061. if(index != 8)
  16062. {
  16063. // DC Connector
  16064. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  16065. {
  16066. SystemInitial = SystemInitial + 1;
  16067. gunTotalNumber = gunTotalNumber + 1;
  16068. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16069. connectorIndex = connectorIndex + 1;
  16070. }
  16071. }
  16072. else
  16073. {
  16074. // AC Connector
  16075. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16076. {
  16077. SystemInitial = SystemInitial + 1;
  16078. gunTotalNumber = gunTotalNumber + 1;
  16079. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16080. connectorIndex = connectorIndex + 1;
  16081. }
  16082. }
  16083. }
  16084. //SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  16085. //gunTotalNumber =
  16086. //DEBUG_INFO("DC ...\n");
  16087. }
  16088. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16089. {
  16090. //check connector / socket type (index: 8, 9, 10)
  16091. for(int index=7; index <10 ; index++)
  16092. {
  16093. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16094. {
  16095. SystemInitial = SystemInitial + 1;
  16096. gunTotalNumber = gunTotalNumber + 1;
  16097. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16098. connectorIndex = connectorIndex + 1;
  16099. DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16100. }
  16101. }
  16102. DEBUG_INFO("gunTotalNumber: %d\n", gunTotalNumber);
  16103. DEBUG_INFO("connectorIndex: %d\n", connectorIndex);
  16104. //SystemInitial = AC_QUANTITY;
  16105. //gunTotalNumber =
  16106. //DEBUG_INFO("AC ...\n");
  16107. }
  16108. //Status / ConnectorPlugIn Setting
  16109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16110. {
  16111. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16112. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16113. }
  16114. for (int index = 0; index < CCS_QUANTITY; index++)
  16115. {
  16116. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16117. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16118. }
  16119. for (int index = 0; index < GB_QUANTITY; index++)
  16120. {
  16121. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16122. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16123. }
  16124. for (int index = 0; index < AC_QUANTITY; index++)
  16125. {
  16126. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16127. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16128. }
  16129. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16130. {
  16131. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16132. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16133. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16134. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  16135. }
  16136. // Charger PRE_SYS_MODE
  16137. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  16138. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16139. clientTime.Heartbeat=time((time_t*)NULL);
  16140. sleep(1);
  16141. }
  16142. void LWS_Send(char * str)
  16143. {
  16144. //=====================================================
  16145. // Check InternetConn 0: disconnected, 1: connected
  16146. //====================================================
  16147. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  16148. {
  16149. DEBUG_INFO("\n offline now !!!\n");
  16150. return;
  16151. }
  16152. pthread_mutex_lock(&lock);
  16153. memset(SendBuffer,0,SendBufLen);
  16154. sprintf((char *)SendBuffer, "%s", str);
  16155. pthread_mutex_unlock(&lock);
  16156. lws_callback_on_writable(wsi_client);
  16157. lws_service(context, 10000);//timeout_ms
  16158. }