MessageHandler.c 670 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683
  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 int TempMeterValueInterval = 0;
  154. static struct OCPPAuthLocalElemet
  155. {
  156. int listVersionInt;
  157. char idTagstr[20];
  158. char parentIdTag[20];
  159. char expiryDate[30];
  160. char idTagstatus[16];
  161. }idTagQuery;
  162. //=============================================
  163. // OCPP HeartBeat Response Not Receive Counts
  164. //============================================
  165. static int HeartBeatWithNOResponse = 0;
  166. static int HeartBeatCountPerHour = 0;
  167. extern struct lws *wsi_client;
  168. extern struct lws_context *context;
  169. extern unsigned char SendBuffer[4096];
  170. extern int SendBufLen;
  171. extern char *random_uuid( char buf[37] );
  172. extern void split(char **arr, char *str, const char *del);
  173. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  174. extern int GetTransactionQueueNum(void);
  175. extern pthread_mutex_t mutex1;
  176. extern struct Charger_Info Charger;
  177. extern sqlite3 *db;
  178. int TransactionMessageAttemptsGet(void);
  179. int TransactionMessageRetryIntervalGet(void);
  180. int GetOcppConnStatus(void);
  181. void SetOcppConnStatus(uint8_t status);
  182. int updateSetting(char *key, char *value);
  183. int setKeyValue(char *key, char *value);
  184. void OCPP_get_TableAuthlocalAllData(void);
  185. void processUnkownKey(void);
  186. struct StructOCPPMeterValue
  187. {
  188. unsigned char TimeStamp[28];
  189. struct StructSampledValue SampledValue[10];
  190. };
  191. struct ClientTime
  192. {
  193. unsigned int Heartbeat;
  194. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  195. unsigned int StartTransaction;
  196. unsigned int StopTransaction;
  197. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  198. }clientTime;
  199. typedef union
  200. {
  201. //Operations Initiated by Central System
  202. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  203. struct
  204. {
  205. //CsMsgValue[0]
  206. unsigned char StatusNotificationReq :1; //bit 0,
  207. unsigned char StatusNotificationConf :1; //bit 0,
  208. unsigned char :6; //bit 2~7
  209. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  210. }CpinitiateMsg;
  211. CpinitiateMsg cpinitateMsg;
  212. //==========================================
  213. // Init all Enumeration & Mapping String
  214. //==========================================
  215. /*ChargePointErrorCode*/
  216. typedef enum {
  217. ConnectorLockFailure,
  218. EVCommunicationError,
  219. GroundFailure,
  220. HighTemperature,
  221. InternalError,
  222. LocalListConflict,
  223. NoError,
  224. OtherError,
  225. OverCurrentFailure,
  226. OverVoltage,
  227. PowerMeterFailure,
  228. PowerSwitchFailure,
  229. ReaderFailure,
  230. ResetFailure,
  231. UnderVoltage,
  232. WeakSignal
  233. } ChargePointErrorCode;
  234. #if 0
  235. static char *ChargePointErrorCodeStr[] = {
  236. MACROSTR(ConnectorLockFailure),
  237. MACROSTR(EVCommunicationError),
  238. MACROSTR(GroundFailure),
  239. MACROSTR(HighTemperature),
  240. MACROSTR(InternalError),
  241. MACROSTR(LocalListConflict),
  242. MACROSTR(NoError),
  243. MACROSTR(OtherError),
  244. MACROSTR(OverCurrentFailure),
  245. MACROSTR(OverVoltage),
  246. MACROSTR(PowerMeterFailure),
  247. MACROSTR(PowerSwitchFailure),
  248. MACROSTR(ReaderFailure),
  249. MACROSTR(ResetFailure),
  250. MACROSTR(UnderVoltage),
  251. MACROSTR(WeakSignal)
  252. };
  253. #endif
  254. /*ChargePointStatus*/
  255. typedef enum {
  256. Available =0,
  257. Preparing,
  258. Charging,
  259. SuspendedEVSE,
  260. SuspendedEV,
  261. Finishing,
  262. Reserved,
  263. Unavailable,
  264. Faulted
  265. } ChargePointStatus;
  266. static char * ChargePointStatusStr[] = {
  267. MACROSTR(Available),
  268. MACROSTR(Preparing),
  269. MACROSTR(Charging),
  270. MACROSTR(SuspendedEVSE),
  271. MACROSTR(SuspendedEV),
  272. MACROSTR(Finishing),
  273. MACROSTR(Reserved),
  274. MACROSTR(Unavailable),
  275. MACROSTR(Faulted)
  276. };
  277. /*AvailabilityType*/
  278. typedef enum {
  279. RegistrationStatus_Accepted,
  280. RegistrationStatus_Pending,
  281. RegistrationStatus_Rejected
  282. } RegistrationStatus;
  283. static char *RegistrationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Pending),
  286. MACROSTR(Rejected)
  287. };
  288. /*AvailabilityType*/
  289. typedef enum {
  290. Inoperative,
  291. Operative
  292. } AvailabilityType;
  293. static char *AvailabilityTypeStr[] = {
  294. MACROSTR(Inoperative),
  295. MACROSTR(Operative)
  296. };
  297. /*AvailabilityStatus*/
  298. typedef enum {
  299. Accepted,
  300. Rejected,
  301. Scheduled
  302. } AvailabilityStatus;
  303. static char *AvailabilityStatusStr[] = {
  304. MACROSTR(Accepted),
  305. MACROSTR(Rejected),
  306. MACROSTR(Scheduled)
  307. };
  308. /*ConfigurationStatus*/
  309. typedef enum {
  310. ConfigurationStatus_Accepted,
  311. ConfigurationStatus_Rejected,
  312. RebootRequired,
  313. NotSupported
  314. } ConfigurationStatus;
  315. static char *ConfigurationStatusStr[] = {
  316. MACROSTR(Accepted),
  317. MACROSTR(Rejected),
  318. MACROSTR(RebootRequired),
  319. MACROSTR(NotSupported)
  320. };
  321. /*ClearCacheStatus*/
  322. typedef enum {
  323. ClearCacheStatus_Accepted,
  324. ClearCacheStatus_Rejected
  325. } ClearCacheStatus;
  326. static char *ClearCacheStatusStr[] = {
  327. MACROSTR(Accepted),
  328. MACROSTR(Rejected)
  329. };
  330. /*ChargingProfilePurposeType*/
  331. typedef enum {
  332. ChargePointMaxProfile,
  333. TxDefaultProfile,
  334. TxProfile
  335. } ChargingProfilePurposeType;
  336. static char *ChargingProfilePurposeTypeStr[] = {
  337. MACROSTR(ChargePointMaxProfile),
  338. MACROSTR(TxDefaultProfile),
  339. MACROSTR(TxProfile)
  340. };
  341. /*ChargingProfileStatus*/
  342. typedef enum {
  343. ChargingProfileStatus_Accepted,
  344. ChargingProfileStatus_Rejected,
  345. ChargingProfileStatus_NotSupported
  346. } ChargingProfileStatus;
  347. static char *ChargingProfileStatusStr[] = {
  348. MACROSTR(Accepted),
  349. MACROSTR(Rejected),
  350. MACROSTR(NotSupported)
  351. };
  352. /*ClearChargingProfileStatus*/
  353. typedef enum {
  354. ClearChargingProfileStatus_Accepted,
  355. ClearChargingProfileStatus_Unknown
  356. } ClearChargingProfileStatus;
  357. static char *ClearChargingProfileStatusStr[] = {
  358. MACROSTR(Accepted),
  359. MACROSTR(Unknown)
  360. };
  361. /*GetCompositeScheduleStatus*/
  362. typedef enum {
  363. GetCompositeScheduleStatus_Accepted,
  364. GetCompositeScheduleStatus_Rejected
  365. } GetCompositeScheduleStatus;
  366. static char *GetCompositeScheduleStatusStr[] = {
  367. MACROSTR(Accepted),
  368. MACROSTR(Rejected)
  369. };
  370. /*ChargingRateUnitType*/
  371. typedef enum {
  372. ChargingRateUnitType_W,
  373. ChargingRateUnitType_A
  374. } ChargingRateUnitType;
  375. /*AuthorizationStatus*/
  376. typedef enum {
  377. AuthorizationStatus_Accepted ,
  378. AuthorizationStatus_Blocked ,
  379. AuthorizationStatus_Expired ,
  380. AuthorizationStatus_Invalid ,
  381. AuthorizationStatus_ConcurrentTx
  382. } AuthorizationStatus;
  383. /*UpdateType*/
  384. typedef enum {
  385. Differential ,
  386. Full
  387. } UpdateType;
  388. static char *UpdateTypeStr[] = {
  389. MACROSTR(Differential),
  390. MACROSTR(Full)
  391. };
  392. /*UpdateStatus*/
  393. typedef enum {
  394. UpdateStatus_Accepted ,
  395. UpdateStatus_Failed ,
  396. UpdateStatus_NotSupported ,
  397. UpdateStatus_VersionMismatch
  398. } UpdateStatus;
  399. static char *UpdateStatusStr[] = {
  400. MACROSTR(Accepted),
  401. MACROSTR(Failed),
  402. MACROSTR(NotSupported),
  403. MACROSTR(VersionMismatch)
  404. };
  405. /*RemoteStartStopStatus*/
  406. typedef enum {
  407. RemoteStartStopStatus_Accepted,
  408. RemoteStartStopStatus_Rejected
  409. } RemoteStartStopStatus;
  410. static char *RemoteStartStopStatusStr[] = {
  411. MACROSTR(Accepted),
  412. MACROSTR(Rejected)
  413. };
  414. /*ReservationStatus*/
  415. typedef enum {
  416. ReservationStatus_Accepted,
  417. ReservationStatus_Faulted,
  418. ReservationStatus_Occupied,
  419. ReservationStatus_Rejected,
  420. ReservationStatus_Unavailable
  421. } ReservationStatus;
  422. static char *ReservationStatusStr[] = {
  423. MACROSTR(Accepted),
  424. MACROSTR(Faulted),
  425. MACROSTR(Occupied),
  426. MACROSTR(Rejected),
  427. MACROSTR(Unavailable)
  428. };
  429. /*ResetType*/
  430. typedef enum {
  431. Hard,
  432. Soft
  433. } ResetType;
  434. static char *ResetTypeStr[] = {
  435. MACROSTR(Hard),
  436. MACROSTR(Soft)
  437. };
  438. /*ResetStatus*/
  439. typedef enum {
  440. ResetStatus_Accepted,
  441. ResetStatus_Rejected
  442. } ResetStatus;
  443. static char *ResetStatusStr[] = {
  444. MACROSTR(Accepted),
  445. MACROSTR(Rejected)
  446. };
  447. /*DiagnosticsStatus*/
  448. typedef enum {
  449. DiagnosticsStatus_Idle,
  450. DiagnosticsStatus_Uploaded,
  451. DiagnosticsStatus_UploadFailed,
  452. DiagnosticsStatus_Uploading
  453. } DiagnosticsStatus;
  454. static char * DiagnosticsStatusStr[] = {
  455. MACROSTR(Idle),
  456. MACROSTR(Uploaded),
  457. MACROSTR(UploadFailed),
  458. MACROSTR(Uploading)
  459. };
  460. /*FirmwareStatus*/
  461. typedef enum {
  462. FirmwareStatus_Downloaded,
  463. FirmwareStatus_DownloadFailed,
  464. FirmwareStatus_Downloading,
  465. FirmwareStatus_Idle,
  466. FirmwareStatus_InstallationFailed,
  467. FirmwareStatus_Installing,
  468. FirmwareStatus_Installed
  469. } FirmwareStatus;
  470. static char * FirmwareStatusStr[] = {
  471. MACROSTR(Downloaded),
  472. MACROSTR(DownloadFailed),
  473. MACROSTR(Downloading),
  474. MACROSTR(Idle),
  475. MACROSTR(InstallationFailed),
  476. MACROSTR(Installing),
  477. MACROSTR(Installed)
  478. };
  479. /*MessageTrigger*/
  480. typedef enum {
  481. BootNotification,
  482. DiagnosticsStatusNotification,
  483. FirmwareStatusNotification,
  484. Heartbeat,
  485. MeterValues,
  486. StatusNotification
  487. } MessageTrigger;
  488. static char * MessageTriggerStr[] = {
  489. MACROSTR(BootNotification),
  490. MACROSTR(DiagnosticsStatusNotification),
  491. MACROSTR(FirmwareStatusNotification),
  492. MACROSTR(Heartbeat),
  493. MACROSTR(MeterValues),
  494. MACROSTR(StatusNotification)
  495. };
  496. /*TriggerMessageStatus*/
  497. typedef enum {
  498. TriggerMessageStatus_Accepted ,
  499. TriggerMessageStatus_Rejected ,
  500. TriggerMessageStatus_NotImplemented
  501. } TriggerMessageStatus;
  502. static char * TriggerMessageStatusStr[] = {
  503. MACROSTR(Accepted),
  504. MACROSTR(Rejected),
  505. MACROSTR(NotImplemented)
  506. };
  507. /*UnlockStatus*/
  508. typedef enum {
  509. Unlocked,
  510. UnlockFailed,
  511. UnlockStatus_NotSupported
  512. } UnlockStatus;
  513. static char * UnlockStatusStr[] = {
  514. MACROSTR(Unlocked),
  515. MACROSTR(UnlockFailed),
  516. MACROSTR(NotSupported)
  517. };
  518. /*StopTransactionReason*/
  519. typedef enum {
  520. EmergencyStop,
  521. EVDisconnected,
  522. HardReset,
  523. Local,
  524. Other,
  525. PowerLoss,
  526. Reboot,
  527. Remote,
  528. SoftReset,
  529. UnlockCommand,
  530. DeAuthorized
  531. } StopTransactionReason;
  532. #if 0
  533. static char * StopTransactionReasonStr[] = {
  534. MACROSTR(EmergencyStop),
  535. MACROSTR(EVDisconnected),
  536. MACROSTR(HardReset),
  537. MACROSTR(Local),
  538. MACROSTR(Other),
  539. MACROSTR(PowerLoss),
  540. MACROSTR(Reboot),
  541. MACROSTR(Remote),
  542. MACROSTR(SoftReset),
  543. MACROSTR(UnlockCommand),
  544. MACROSTR(DeAuthorized)
  545. };
  546. #endif
  547. /*CancelReservationStatus*/
  548. typedef enum {
  549. CancelReservationStatus_Accepted,
  550. CancelReservationStatus_Rejected
  551. } CancelReservationStatus;
  552. static char * CancelReservationStatusStr[] = {
  553. MACROSTR(Accepted),
  554. MACROSTR(Rejected)
  555. };
  556. /*ReadingContext*/
  557. typedef enum {
  558. ReadingContext_Interruption_Begin,
  559. ReadingContext_Interruption_End,
  560. ReadingContext_Other,
  561. ReadingContext_Sample_Clock,
  562. ReadingContext_Sample_Periodic ,
  563. ReadingContext_Transaction_Begin ,
  564. ReadingContext_Transaction_End,
  565. ReadingContext_Trigger
  566. } ReadingContext;
  567. static char * ReadingContextStr[] = {
  568. MACROSTR(Interruption.Begin),
  569. MACROSTR(Interruption.End),
  570. MACROSTR(Other),
  571. MACROSTR(Sample.Clock),
  572. MACROSTR(Sample.Periodic),
  573. MACROSTR(Transaction.Begin),
  574. MACROSTR(Transaction.End),
  575. MACROSTR(Trigger)
  576. };
  577. /*ValueFormat*/
  578. typedef enum {
  579. Raw,
  580. SignedData
  581. } ValueFormat;
  582. static char * ValueFormatStr[] = {
  583. MACROSTR(Raw),
  584. MACROSTR(SignedData)
  585. };
  586. /*Measurand*/
  587. typedef enum {
  588. Current_Export ,
  589. Current_Import,
  590. Current_Offered,
  591. Energy_Active_Export_Register,
  592. Energy_Active_Import_Register,
  593. Energy_Reactive_Export_Register,
  594. Energy_Reactive_Import_Register,
  595. Energy_Active_Export_Interval,
  596. Energy_Active_Import_Interval,
  597. Energy_Reactive_Export_Interval,
  598. Energy_Reactive_Import_Interval,
  599. Frequency,
  600. Power_Active_Export ,
  601. Power_Active_Import,
  602. Power_Factor,
  603. Power_Offered,
  604. Power_Reactive_Export,
  605. Power_Reactive_Import,
  606. RPM,
  607. SoC,
  608. Temperature ,
  609. Voltage
  610. } Measurand;
  611. static char * MeasurandStr[] = {
  612. MACROSTR(Current.Export),
  613. MACROSTR(Current.Import),
  614. MACROSTR(Current.Offered),
  615. MACROSTR(Energy.Active.Export.Register),
  616. MACROSTR(Energy.Active.Import.Register),
  617. MACROSTR(Energy.Reactive.Export.Register),
  618. MACROSTR(Energy.Reactive.Import.Register),
  619. MACROSTR(Energy.Active.Export.Interval),
  620. MACROSTR(Energy.Active.Import.Interval),
  621. MACROSTR(Energy.Reactive.Export.Interval),
  622. MACROSTR(Energy.Reactive.Import.Interval),
  623. MACROSTR(Frequency),
  624. MACROSTR(Power.Active.Export),
  625. MACROSTR(Power.Active.Import),
  626. MACROSTR(Power.Factor),
  627. MACROSTR(Power.Offered),
  628. MACROSTR(Power.Reactive.ExportMACROSTR),
  629. MACROSTR(Power.Reactive.Import),
  630. MACROSTR(RPM),
  631. MACROSTR(SoC),
  632. MACROSTR(Temperature),
  633. MACROSTR(Voltage)
  634. };
  635. /*Location*/
  636. typedef enum {
  637. Location_Body,
  638. Location_Cable,
  639. Location_EV,
  640. Location_Inlet ,
  641. Location_Outlet
  642. } Location;
  643. static char * LocationStr[] = {
  644. MACROSTR(Body),
  645. MACROSTR(Cable),
  646. MACROSTR(EV),
  647. MACROSTR(Inlet),
  648. MACROSTR(Outlet)
  649. };
  650. /*Phase*/
  651. typedef enum {
  652. L1,
  653. L2,
  654. L3,
  655. N,
  656. L1_N,
  657. L2_N,
  658. L3_N,
  659. L1_L2,
  660. L2_L3,
  661. L3_L1
  662. } Phase;
  663. static char * PhaseStr[] = {
  664. MACROSTR(L1),
  665. MACROSTR(L2),
  666. MACROSTR(L3),
  667. MACROSTR(N),
  668. MACROSTR(L1-N),
  669. MACROSTR(L2-N),
  670. MACROSTR(L3-N),
  671. MACROSTR(L1-L2),
  672. MACROSTR(L2-L3),
  673. MACROSTR(L3-L1)
  674. };
  675. /*UnitOfMeasure*/
  676. typedef enum {
  677. UnitOfMeasure_Wh,
  678. UnitOfMeasure_kWh ,
  679. UnitOfMeasure_varh ,
  680. UnitOfMeasure_kvarh ,
  681. UnitOfMeasure_W ,
  682. UnitOfMeasure_kW ,
  683. UnitOfMeasure_VA ,
  684. UnitOfMeasure_kVA ,
  685. UnitOfMeasure_var ,
  686. UnitOfMeasure_kvar ,
  687. UnitOfMeasure_A ,
  688. UnitOfMeasure_V ,
  689. UnitOfMeasure_Celsius ,
  690. UnitOfMeasure_Fahrenheit ,
  691. UnitOfMeasure_K ,
  692. UnitOfMeasure_Percent
  693. } UnitOfMeasure;
  694. static char * UnitOfMeasureStr[] = {
  695. MACROSTR(Wh),
  696. MACROSTR(kWh),
  697. MACROSTR(varh),
  698. MACROSTR(kvarh),
  699. MACROSTR(W),
  700. MACROSTR(kW),
  701. MACROSTR(VA),
  702. MACROSTR(kVA),
  703. MACROSTR(var),
  704. MACROSTR(kvar),
  705. MACROSTR(A),
  706. MACROSTR(V),
  707. MACROSTR(Celsius),
  708. MACROSTR(Fahrenheit),
  709. MACROSTR(K),
  710. MACROSTR(Percent)
  711. };
  712. #if 0
  713. /*Configuration enum*/
  714. enum CoreProfile {
  715. AllowOfflineTxForUnknownId=0,
  716. AuthorizationCacheEnabled,
  717. AuthorizeRemoteTxRequests,
  718. BlinkRepeat,
  719. ClockAlignedDataInterval,
  720. ConnectionTimeOut,
  721. GetConfigurationMaxKeys,
  722. HeartbeatInterval,
  723. LightIntensity,
  724. LocalAuthorizeOffline,
  725. LocalPreAuthorize,
  726. MaxEnergyOnInvalidId,
  727. MeterValuesAlignedData,
  728. MeterValuesAlignedDataMaxLength,
  729. MeterValuesSampledData,
  730. MeterValuesSampledDataMaxLength,
  731. MeterValueSampleInterval,
  732. MinimumStatusDuration,
  733. NumberOfConnectors,
  734. ResetRetries,
  735. ConnectorPhaseRotation,
  736. ConnectorPhaseRotationMaxLength,
  737. StopTransactionOnEVSideDisconnect,
  738. StopTransactionOnInvalidId,
  739. StopTxnAlignedData,
  740. StopTxnAlignedDataMaxLength,
  741. StopTxnSampledData,
  742. StopTxnSampledDataMaxLength,
  743. SupportedFeatureProfiles,
  744. SupportedFeatureProfilesMaxLength,
  745. TransactionMessageAttempts,
  746. TransactionMessageRetryInterval,
  747. UnlockConnectorOnEVSideDisconnect,
  748. WebSocketPingInterval,
  749. _CoreProfile_CNT
  750. };
  751. #endif
  752. enum LocalAuthListManagementProfile{
  753. LocalAuthListEnabled=0,
  754. LocalAuthListMaxLength,
  755. SendLocalListMaxLength,
  756. _LocalAuthListManagementProfile_CNT
  757. };
  758. enum ReservationProfile{
  759. ReserveConnectorZeroSupported
  760. };
  761. enum SmartChargingProfile{
  762. ChargeProfileMaxStackLevel,
  763. ChargingScheduleAllowedChargingRateUnit,
  764. ChargingScheduleMaxPeriods,
  765. ConnectorSwitch3to1PhaseSupported,
  766. MaxChargingProfilesInstalled
  767. };
  768. enum ChargerSystemStatus{
  769. ChargerSystemStatus_Booting,
  770. ChargerSystemStatus_Idle,
  771. ChargerSystemStatus_Authorizing,
  772. ChargerSystemStatus_Preparing,
  773. ChargerSystemStatus_Charging,
  774. ChargerSystemStatus_Terminating,
  775. ChargerSystemStatus_Alarm,
  776. ChargerSystemStatus_Fault
  777. };
  778. enum GetConfigurationKey {
  779. GetConfiguration_AllowOfflineTxForUnknownId=0,
  780. GetConfiguration_AuthorizationCacheEnabled,
  781. GetConfiguration_AuthorizeRemoteTxRequests,
  782. GetConfiguration_BlinkRepeat,
  783. GetConfiguration_ClockAlignedDataInterval,
  784. GetConfiguration_ConnectionTimeOut,
  785. GetConfiguration_GetConfigurationMaxKeys,
  786. GetConfiguration_HeartbeatInterval,
  787. GetConfiguration_LightIntensity,
  788. GetConfiguration_LocalAuthorizeOffline,
  789. GetConfiguration_LocalPreAuthorize,
  790. GetConfiguration_MaxEnergyOnInvalidId,
  791. GetConfiguration_MeterValuesAlignedData,
  792. GetConfiguration_MeterValuesAlignedDataMaxLength,
  793. GetConfiguration_MeterValuesSampledData,
  794. GetConfiguration_MeterValuesSampledDataMaxLength,
  795. GetConfiguration_MeterValueSampleInterval,
  796. GetConfiguration_MinimumStatusDuration,
  797. GetConfiguration_NumberOfConnectors,
  798. GetConfiguration_ResetRetries,
  799. GetConfiguration_ConnectorPhaseRotation,
  800. GetConfiguration_ConnectorPhaseRotationMaxLength,
  801. GetConfiguration_StopTransactionOnEVSideDisconnect,
  802. GetConfiguration_StopTransactionOnInvalidId,
  803. GetConfiguration_StopTxnAlignedData,
  804. GetConfiguration_StopTxnAlignedDataMaxLength,
  805. GetConfiguration_StopTxnSampledData,
  806. GetConfiguration_StopTxnSampledDataMaxLength,
  807. GetConfiguration_SupportedFeatureProfiles,
  808. GetConfiguration_SupportedFeatureProfilesMaxLength,
  809. GetConfiguration_TransactionMessageAttempts,
  810. GetConfiguration_TransactionMessageRetryInterval,
  811. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  812. GetConfiguration_WebSocketPingInterval,
  813. GetConfiguration_LocalAuthListEnabled,
  814. GetConfiguration_LocalAuthListMaxLength,
  815. GetConfiguration_SendLocalListMaxLength,
  816. GetConfiguration_ReserveConnectorZeroSupported,
  817. GetConfiguration_ChargeProfileMaxStackLevel,
  818. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  819. GetConfiguration_ChargingScheduleMaxPeriods,
  820. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  821. GetConfiguration_MaxChargingProfilesInstalled,
  822. };
  823. //GetConfiguration Array
  824. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  825. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  826. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  827. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  828. //==========================================
  829. // Init all share memory
  830. //==========================================
  831. int InitShareMemory()
  832. {
  833. int result = PASS;
  834. int MeterSMId;
  835. //creat ShmSysConfigAndInfo
  836. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  837. {
  838. #ifdef SystemLogMessage
  839. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  840. #endif
  841. result = FAIL;
  842. }
  843. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  844. {
  845. #ifdef SystemLogMessage
  846. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  847. #endif
  848. result = FAIL;
  849. }
  850. else
  851. {}
  852. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  853. {
  854. #ifdef SystemLogMessage
  855. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  856. #endif
  857. result = FAIL;
  858. }
  859. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  860. {
  861. #ifdef SystemLogMessage
  862. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  863. #endif
  864. result = FAIL;
  865. }
  866. else
  867. {}
  868. //creat ShmPsuData
  869. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  870. {
  871. #ifdef SystemLogMessage
  872. DEBUG_ERROR("shmget ShmPsuData NG\n");
  873. #endif
  874. result = FAIL;
  875. }
  876. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  877. {
  878. #ifdef SystemLogMessage
  879. DEBUG_ERROR("shmat ShmPsuData NG\n");
  880. #endif
  881. result = FAIL;
  882. }
  883. else
  884. {}
  885. //creat ShmOCPP16Data
  886. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  887. {
  888. #ifdef SystemLogMessage
  889. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  890. #endif
  891. result = FAIL;
  892. }
  893. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  894. {
  895. #ifdef SystemLogMessage
  896. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  897. #endif
  898. result = FAIL;
  899. }
  900. else
  901. {}
  902. /****************************** For Initial Settings************************************************/
  903. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  904. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  905. // allocate Configuration memory address
  906. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  907. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  908. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  909. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  910. //offline MeterValue Interval
  911. TempMeterValueInterval = 0;
  912. return result;
  913. }
  914. int ProcessShareMemory()
  915. {
  916. if(InitShareMemory() == FAIL)
  917. {
  918. #ifdef SystemLogMessage
  919. DEBUG_ERROR("InitShareMemory NG\n");
  920. #endif
  921. if(ShmStatusCodeData!=NULL)
  922. {
  923. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  924. }
  925. sleep(5);
  926. return FAIL;
  927. }
  928. return PASS;
  929. }
  930. //---------------------common routine---------------------------//
  931. char * stringtrim( char * s )
  932. {
  933. char * p1 = s;
  934. char * p2 = s;
  935. while(*p1 != '\0')
  936. {
  937. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  938. {
  939. if(*p1 != ',')
  940. {
  941. p1 ++;
  942. }
  943. else
  944. {
  945. break;
  946. }
  947. }
  948. if(*p1 != ',')
  949. {
  950. * p2 ++ = *p1 ++;
  951. //printf("p2=%s\n",p2);
  952. }
  953. else
  954. {
  955. break;
  956. }
  957. }
  958. *p2 = '\0';
  959. return (s);
  960. }
  961. char * stringtrimspace( char * s )
  962. {
  963. char * p1 = s;
  964. char * p2 = s;
  965. while(*p1 != '\0')
  966. {
  967. while(*p1 == ' ') //while(*p1 == ' ' || *p1 == '\t' || *p1 == '\n' || *p1 == '\r')
  968. {
  969. p1 ++;
  970. }
  971. * p2 ++ = *p1 ++;
  972. //printf("p2=%s\n",p2);
  973. }
  974. *p2 = '\0';
  975. return (s);
  976. }
  977. int isOFFline(void)
  978. {
  979. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  980. {
  981. if(TempMeterValueInterval >= 10 )
  982. {
  983. TempMeterValueInterval = 0;
  984. return TRUE;
  985. }
  986. else
  987. {
  988. TempMeterValueInterval = TempMeterValueInterval+ 1;
  989. return FALSE;
  990. }
  991. }
  992. else
  993. {
  994. return FALSE;
  995. }
  996. }
  997. //---------------------------------------------
  998. // new:
  999. // enum SYSTEM_STATUS
  1000. // {
  1001. // SYS_MODE_BOOTING = 0,
  1002. // SYS_MODE_IDLE = 1,
  1003. // SYS_MODE_AUTHORIZING = 2,
  1004. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1005. // SYS_MODE_REASSIGN = 4,
  1006. // SYS_MODE_PREPARING = 5,
  1007. // SYS_MODE_PREPARE_FOR_EV = 6,
  1008. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1009. // SYS_MODE_CHARGING = 8,
  1010. // SYS_MODE_TERMINATING = 9,
  1011. // SYS_MODE_COMPLETE = 10,
  1012. // SYS_MODE_ALARM = 11,
  1013. // SYS_MODE_FAULT = 12,
  1014. // SYS_MODE_RESERVATION = 13,
  1015. // SYS_MODE_BOOKING = 14,
  1016. // SYS_MODE_MAINTAIN = 15,
  1017. // SYS_MODE_DEBUG = 16,
  1018. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1019. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1020. // SYS_MODE_UPDATE = 19
  1021. // };
  1022. //
  1023. //
  1024. //-----------------------------------------
  1025. void CheckSystemValue(void)
  1026. {
  1027. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1028. //int IdleModeCnt = 0;
  1029. char filenmae[100]={0};
  1030. char str[100]={0};
  1031. //===============================
  1032. // send Heartbeat
  1033. //===============================
  1034. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1035. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1036. {
  1037. clientTime.Heartbeat=time((time_t*)NULL);
  1038. if(server_sign == TRUE)
  1039. {
  1040. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1041. }
  1042. else
  1043. {
  1044. HeartBeatWaitTime = 10;
  1045. }
  1046. }
  1047. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1048. {
  1049. DEBUG_INFO("Heartbeat !!!\n");
  1050. //parameter for test
  1051. sendHeartbeatRequest(0);
  1052. //==============================================
  1053. // Reset Waiting Time
  1054. //==============================================
  1055. clientTime.Heartbeat=time((time_t*)NULL);
  1056. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1057. }
  1058. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1059. {
  1060. //===============================
  1061. // CSU Trigger Reset Conf
  1062. //===============================
  1063. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1064. {
  1065. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1066. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1067. {
  1068. server_sign = FALSE;
  1069. }
  1070. }
  1071. //===============================
  1072. // CSU Trigger Authorize Request
  1073. //===============================
  1074. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1075. {
  1076. sendAuthorizeRequest(0);
  1077. authorizeRetryTimes = authorizeRetryTimes + 1;
  1078. if(authorizeRetryTimes < 3)
  1079. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1080. }
  1081. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1082. {
  1083. authorizeRetryTimes = 0;
  1084. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1085. server_sign = FALSE;
  1086. }
  1087. 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))
  1088. {
  1089. sendAuthorizeRequest(0);
  1090. }
  1091. //===============================
  1092. // CSU Trigger Smart Charging Profilw
  1093. //===============================
  1094. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1095. {
  1096. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1097. GetChargingProfileRequest(gun_index);
  1098. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1099. }
  1100. //==============================================
  1101. // Charger start transaction
  1102. //==============================================
  1103. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1104. {
  1105. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1106. sendStartTransactionRequest(gun_index);
  1107. clientTime.StartTransaction = time((time_t*)NULL);
  1108. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1109. }
  1110. //==============================================
  1111. // Charger stop transaction
  1112. //==============================================
  1113. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1114. {
  1115. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1116. sendStopTransactionRequest(gun_index);
  1117. clientTime.StopTransaction = time((time_t*)NULL);
  1118. }
  1119. //==============================================
  1120. // Charger status report
  1121. //==============================================
  1122. //--- Check Mode Change ---//
  1123. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1124. if(gunType[gun_index] == 'J')
  1125. {
  1126. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1127. {
  1128. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1129. {
  1130. 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]*/ )
  1131. {
  1132. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1133. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1134. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1135. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1136. statusModeChage[gun_index] = TRUE;
  1137. }
  1138. #if 1 // for TempStopTransaction
  1139. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1140. {
  1141. checkTempStopTransaction(gun_index);
  1142. }
  1143. #endif
  1144. }
  1145. }
  1146. }
  1147. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1148. {
  1149. for (int index = 0; index < CCS_QUANTITY; index++)
  1150. {
  1151. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1152. {
  1153. 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]*/ )
  1154. {
  1155. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1156. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1157. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1158. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1159. statusModeChage[gun_index] = TRUE;
  1160. }
  1161. #if 1 // for TempStopTransaction
  1162. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1163. {
  1164. checkTempStopTransaction(gun_index);
  1165. }
  1166. #endif
  1167. }
  1168. }
  1169. }
  1170. else if(gunType[gun_index] == 'G')
  1171. {
  1172. for (int index = 0; index < GB_QUANTITY; index++)
  1173. {
  1174. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1175. {
  1176. 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]*/ )
  1177. {
  1178. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1179. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1180. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1181. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1182. statusModeChage[gun_index] = TRUE;
  1183. }
  1184. #if 1 // for TempStopTransaction
  1185. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1186. {
  1187. checkTempStopTransaction(gun_index);
  1188. }
  1189. #endif
  1190. }
  1191. }
  1192. }
  1193. else
  1194. {
  1195. for (int index = 0; index < AC_QUANTITY; index++)
  1196. {
  1197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1198. {
  1199. 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]*/ )
  1200. {
  1201. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1202. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1203. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1204. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1205. statusModeChage[gun_index] = TRUE;
  1206. }
  1207. #if 1 // for TempStopTransaction
  1208. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1209. {
  1210. checkTempStopTransaction(gun_index);
  1211. }
  1212. #endif
  1213. }
  1214. }// END
  1215. }
  1216. if(((SystemInitial > 0)&& (server_sign == TRUE))||
  1217. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1218. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1219. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1220. {
  1221. if(SystemInitial > 0)
  1222. SystemInitial = SystemInitial -1;
  1223. sendStatusNotificationRequest(gun_index);
  1224. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1225. statusModeChage[gun_index] = FALSE;
  1226. DEBUG_INFO("SystemInitial=%d !!!\n",SystemInitial);
  1227. //DEBUG_INFO("difftime(time((time_t*)NULL), clientTime.Heartbeat)=%d !!!\n",difftime(time((time_t*)NULL), clientTime.Heartbeat));
  1228. //DEBUG_INFO("HeartBeatWaitTime=%d !!!\n",HeartBeatWaitTime);
  1229. //DEBUG_INFO("ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval=%d !!!\n",ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  1230. }
  1231. //==============================================
  1232. // Meter report
  1233. //==============================================
  1234. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) || ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1235. {
  1236. DEBUG_INFO("Sent Meter Value\n");
  1237. //check Transaction active
  1238. if(gunType[gun_index] == 'J')
  1239. {
  1240. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1241. {
  1242. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1243. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1244. {
  1245. meterValueSend[gun_index] =1;
  1246. }
  1247. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1248. {
  1249. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1250. if((access(filenmae,F_OK))!=-1)
  1251. {
  1252. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1253. sprintf(str,"rm -f %s",filenmae);
  1254. system(str);
  1255. }
  1256. }
  1257. }// End for CHAdeMO
  1258. }
  1259. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1260. {
  1261. for (int index = 0; index < CCS_QUANTITY; index++)
  1262. {
  1263. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1264. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1265. {
  1266. meterValueSend[gun_index] =1;
  1267. }
  1268. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1269. {
  1270. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1271. if((access(filenmae,F_OK))!=-1)
  1272. {
  1273. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1274. sprintf(str,"rm -f %s",filenmae);
  1275. system(str);
  1276. }
  1277. }
  1278. } // End for CCS
  1279. }
  1280. else if(gunType[gun_index] == 'G')
  1281. {
  1282. for (int index = 0; index < GB_QUANTITY; index++)
  1283. {
  1284. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1285. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1286. {
  1287. meterValueSend[gun_index] =1;
  1288. }
  1289. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1290. {
  1291. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1292. if((access(filenmae,F_OK))!=-1)
  1293. {
  1294. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1295. sprintf(str,"rm -f %s",filenmae);
  1296. system(str);
  1297. }
  1298. }
  1299. }// End for GB
  1300. }
  1301. else
  1302. {
  1303. for (int index = 0; index < AC_QUANTITY; index++)
  1304. {
  1305. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1306. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1307. {
  1308. meterValueSend[gun_index] =1;
  1309. }
  1310. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1311. {
  1312. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1313. if((access(filenmae,F_OK))!=-1)
  1314. {
  1315. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1316. sprintf(str,"rm -f %s",filenmae);
  1317. system(str);
  1318. }
  1319. }
  1320. }//End for AC
  1321. }
  1322. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1323. if(meterValueSend[gun_index] == 1)
  1324. {
  1325. sendMeterValuesRequest(gun_index);
  1326. #if 1 // for TempStopTransaction
  1327. storeTempStopTransaction(gun_index);
  1328. #endif
  1329. }
  1330. }
  1331. //==============================================
  1332. // Check Connector reserved
  1333. //==============================================
  1334. //===============================
  1335. // Check if Reserve is expired
  1336. //===============================
  1337. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1338. {
  1339. double diff_t;
  1340. struct tm tp;
  1341. // current time
  1342. time_t t = time(NULL);
  1343. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1344. tp.tm_isdst = -1;
  1345. time_t utc = mktime(&tp);
  1346. diff_t = difftime(utc, t);
  1347. if(diff_t <= 0)
  1348. {
  1349. DEBUG_INFO("reserve expired !!! \n");
  1350. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1351. }
  1352. }//END OF Check if Reserve is expired
  1353. //==========================================
  1354. // csu trigger FirmwareStatusNotificationReq
  1355. //==========================================
  1356. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1357. {
  1358. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1359. }
  1360. //==========================================
  1361. // csu trigger CancelReservationConf
  1362. //==========================================
  1363. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1364. {
  1365. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1366. }
  1367. //==========================================
  1368. // csu trigger ChangeAvailabilityConf
  1369. //==========================================
  1370. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1371. {
  1372. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1373. }
  1374. //==========================================
  1375. // csu trigger UnlockConnectorConf
  1376. //==========================================
  1377. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1378. {
  1379. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1380. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1381. }
  1382. //==========================================
  1383. // csu trigger ReserveNowConf
  1384. //==========================================
  1385. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1386. {
  1387. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1388. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1389. }
  1390. //==========================================
  1391. // csu trigger DataTransferReq
  1392. //==========================================
  1393. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1394. {
  1395. sendDataTransferRequest(gun_index);
  1396. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1397. }
  1398. }
  1399. }
  1400. //==========================================
  1401. // send request routine
  1402. //==========================================
  1403. int sendAuthorizeRequest(int gun_index)
  1404. {
  1405. mtrace();
  1406. int result = FAIL;
  1407. char message[100]={0};
  1408. char guid[37];
  1409. char tempdata[65]={0};
  1410. DEBUG_INFO("sendAuthorizeRequest \n");
  1411. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1412. //Local Authorize
  1413. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1414. {
  1415. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1416. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1417. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1418. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1419. result = PASS;
  1420. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1421. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1422. authorizeRetryTimes = 0;
  1423. return result;
  1424. }
  1425. 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))||
  1426. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1427. {
  1428. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1429. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1430. {
  1431. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1432. {
  1433. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1434. }
  1435. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1436. {
  1437. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1438. }
  1439. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1440. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1441. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1442. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1443. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1444. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1445. authorizeRetryTimes = 0;
  1446. return result;
  1447. }
  1448. else
  1449. {
  1450. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1451. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1452. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1453. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1454. result = PASS;
  1455. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1456. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1457. authorizeRetryTimes = 0;
  1458. return result;
  1459. }
  1460. }
  1461. //initailize struct Authorize
  1462. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1463. //get data from shared memory
  1464. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1465. random_uuid(guid);
  1466. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1467. LWS_Send(message);
  1468. sprintf(tempdata, "Authorize,%d", gun_index);
  1469. if(hashmap_operation(0, guid, tempdata) == 1)
  1470. {
  1471. result = PASS;
  1472. DEBUG_ERROR("Authorize mapItem pass\n");
  1473. }
  1474. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1475. return result;
  1476. }
  1477. int sendBootNotificationRequest(void)
  1478. {
  1479. mtrace();
  1480. int result = FAIL;
  1481. char message[500]={0}, payload[700]={0};
  1482. char guid[37]={0};
  1483. char tempdata[65]={0};
  1484. int IsGunCharging = FALSE;
  1485. //check Transaction active
  1486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1487. {
  1488. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1489. {
  1490. IsGunCharging = TRUE;
  1491. }
  1492. }
  1493. for (int index = 0; index < CCS_QUANTITY; index++)
  1494. {
  1495. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1496. {
  1497. IsGunCharging = TRUE;
  1498. }
  1499. }
  1500. for (int index = 0; index < GB_QUANTITY; index++)
  1501. {
  1502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1503. {
  1504. IsGunCharging = TRUE;
  1505. }
  1506. }
  1507. for (int index = 0; index < AC_QUANTITY; index++)
  1508. {
  1509. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1510. {
  1511. IsGunCharging = TRUE;
  1512. }
  1513. }
  1514. if(IsGunCharging == TRUE)
  1515. {
  1516. server_sign = TRUE;
  1517. return result;
  1518. }
  1519. // Fill BootNotification fields
  1520. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1521. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1522. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1523. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1524. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1525. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1526. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1527. #if 0
  1528. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1529. ShmOCPP16Data->ChargeBoxId
  1530. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1531. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1532. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1533. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1534. ,ShmOCPP16Data->BootNotification.CpIccid
  1535. ,ShmOCPP16Data->BootNotification.CpImsi
  1536. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1537. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1538. #endif
  1539. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1540. ShmOCPP16Data->ChargeBoxId
  1541. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1542. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1543. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1544. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1545. ,ShmOCPP16Data->BootNotification.CpIccid
  1546. ,ShmOCPP16Data->BootNotification.CpImsi);
  1547. random_uuid(guid);
  1548. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1549. LWS_Send(message);
  1550. sprintf(tempdata, "BootNotification,0");
  1551. 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*/)
  1552. {
  1553. result = PASS;
  1554. }
  1555. memset(queuedata, 0, sizeof(queuedata));
  1556. strcpy(queuedata,message);
  1557. return result;
  1558. }
  1559. int sendDataTransferRequest(int gun_index)
  1560. {
  1561. mtrace();
  1562. char message[1000]={0};
  1563. char guid[37]={0};
  1564. char tempdata[65]={0};
  1565. int result = FAIL;
  1566. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1567. random_uuid(guid);
  1568. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1569. MESSAGE_TYPE_CALL,
  1570. guid,
  1571. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1572. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1573. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1574. LWS_Send(message);
  1575. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1576. 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*/)
  1577. {
  1578. result = PASS;
  1579. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1580. }
  1581. return result;
  1582. }
  1583. int sendDiagnosticsStatusNotificationRequest(char *status)
  1584. {
  1585. mtrace();
  1586. int result = FAIL;
  1587. char message[110]={0};
  1588. char guid[37]={0};
  1589. char tempdata[65]={0};
  1590. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1591. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1592. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1593. random_uuid(guid);
  1594. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1595. LWS_Send(message);
  1596. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1597. if(hashmap_operation(0, guid, tempdata) == 1)
  1598. {
  1599. result = PASS;
  1600. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1601. }
  1602. //#ifdef SystemLogMessage
  1603. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1604. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1605. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1606. //#endif
  1607. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1608. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1609. //record status
  1610. if(strcmp(status,"Idle")==0)
  1611. {
  1612. DiagnosticsStatusNotificationStatus = 0;
  1613. }
  1614. else if(strcmp(status,"Uploaded")==0)
  1615. {
  1616. DiagnosticsStatusNotificationStatus = 1;
  1617. }
  1618. else if(strcmp(status,"UploadFailed")==0)
  1619. {
  1620. DiagnosticsStatusNotificationStatus = 2;
  1621. }
  1622. else if(strcmp(status,"Uploading")==0)
  1623. {
  1624. DiagnosticsStatusNotificationStatus = 3;
  1625. }
  1626. return result;
  1627. }
  1628. int sendFirmwareStatusNotificationRequest(char *status)
  1629. {
  1630. mtrace();
  1631. int result = FAIL;
  1632. char message[110]={0};
  1633. char guid[37]={0};
  1634. char tempdata[65]={0};
  1635. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1636. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1637. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1638. random_uuid(guid);
  1639. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1640. LWS_Send(message);
  1641. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1642. 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*/)
  1643. {
  1644. result = PASS;
  1645. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1646. }
  1647. //#ifdef SystemLogMessage
  1648. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1649. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1650. //#endif
  1651. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1652. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1653. //record status
  1654. if(strcmp(status,"Downloaded")==0)
  1655. {
  1656. FirmwareStatusNotificationStatus = 0;
  1657. }
  1658. else if(strcmp(status,"DownloadFailed")==0)
  1659. {
  1660. FirmwareStatusNotificationStatus = 1;
  1661. }
  1662. else if(strcmp(status,"Downloading")==0)
  1663. {
  1664. FirmwareStatusNotificationStatus = 2;
  1665. }
  1666. else if(strcmp(status,"Idle")==0)
  1667. {
  1668. FirmwareStatusNotificationStatus = 3;
  1669. }
  1670. else if(strcmp(status,"InstallationFailed")==0)
  1671. {
  1672. FirmwareStatusNotificationStatus = 4;
  1673. }
  1674. else if(strcmp(status,"Installing")==0)
  1675. {
  1676. FirmwareStatusNotificationStatus = 5;
  1677. }
  1678. else if(strcmp(status,"Installed")==0)
  1679. {
  1680. FirmwareStatusNotificationStatus = 6;
  1681. }
  1682. return result;
  1683. }
  1684. int sendHeartbeatRequest(int gun_index)
  1685. {
  1686. mtrace();
  1687. int result = FAIL;
  1688. char message[80]={0};
  1689. char guid[37]={0};
  1690. char tempdata[65]={0};
  1691. random_uuid(guid);
  1692. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1693. , MESSAGE_TYPE_CALL
  1694. , guid );
  1695. LWS_Send(message);
  1696. sprintf(tempdata, "Heartbeat,%d", 0);
  1697. 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*/)
  1698. {
  1699. result = PASS;
  1700. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1701. }
  1702. return result;
  1703. }
  1704. int sendStartTransactionRequest(int gun_index)
  1705. {
  1706. mtrace();
  1707. int result = FAIL;
  1708. char message[250]={0};
  1709. char guid[37]={0};
  1710. struct timeval tmnow;
  1711. struct tm *tm;
  1712. char buf[28];//, usec_buf[6];
  1713. char tempdata[65]={0};
  1714. int tempIndex = 0;
  1715. DEBUG_INFO("sendStartTransactionRequest...");
  1716. gettimeofday(&tmnow, NULL);
  1717. time_t t;
  1718. t = time(NULL);
  1719. /*UTC time and date*/
  1720. tm = gmtime(&t);
  1721. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1722. #if 0 // remove temporally
  1723. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1724. strcat(buf,".");
  1725. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1726. strcat(buf,usec_buf);
  1727. #endif
  1728. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1729. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1730. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1731. // clear StartTransaction Response
  1732. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1733. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1734. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1735. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1736. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1737. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  1748. {
  1749. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  1750. {
  1751. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1752. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1753. }
  1754. }
  1755. }
  1756. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  1767. {
  1768. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1769. {
  1770. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1771. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1772. }
  1773. }
  1774. }
  1775. else if(gunType[gun_index] == 'G')
  1776. {
  1777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1778. {
  1779. tempIndex = ((gun_index==2) ? 1: 0);
  1780. }
  1781. else
  1782. {
  1783. tempIndex = gun_index;
  1784. }
  1785. for (int index = 0; index < GB_QUANTITY; index++)
  1786. {
  1787. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1788. {
  1789. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1790. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1791. }
  1792. }
  1793. }
  1794. else
  1795. {
  1796. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1797. {
  1798. tempIndex = 2;
  1799. }
  1800. else
  1801. {
  1802. tempIndex = gun_index;
  1803. }
  1804. for (int index = 0; index < AC_QUANTITY; index++)
  1805. {
  1806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1807. {
  1808. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  1809. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1810. }
  1811. }
  1812. }
  1813. random_uuid(guid);
  1814. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1815. , MESSAGE_TYPE_CALL
  1816. , guid
  1817. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1818. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1819. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1820. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1821. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1822. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1823. 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*/)
  1824. {
  1825. result = PASS;
  1826. }
  1827. strcpy(queuedata, message);
  1828. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1829. if(GetTransactionQueueNum() == 1)
  1830. {
  1831. LWS_Send(message);
  1832. }
  1833. return result;
  1834. }
  1835. int sendStatusNotificationRequest(int gun_index)
  1836. {
  1837. mtrace();
  1838. int result = FAIL;
  1839. char message[600]={0};
  1840. char guid[37];
  1841. int currentStatus = 0;
  1842. struct timeval tmnow;
  1843. struct tm *tm;
  1844. char buf[28];//, usec_buf[6];
  1845. char tempdata[65]={0};
  1846. int tempIndex = 0;
  1847. gettimeofday(&tmnow, NULL);
  1848. time_t t;
  1849. t = time(NULL);
  1850. /*UTC time and date*/
  1851. tm = gmtime(&t);
  1852. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1853. #if 0 // remove temporally
  1854. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1855. strcat(buf,".");
  1856. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1857. strcat(buf,usec_buf);
  1858. #endif
  1859. printf("%s",buf);
  1860. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1861. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1862. // it's option
  1863. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1864. /*
  1865. enum _SYSTEM_STATUS
  1866. {
  1867. S_BOOTING = 0,
  1868. S_IDLE, = 1
  1869. S_AUTHORIZING, =2
  1870. S_REASSIGN_CHECK, =3
  1871. S_REASSIGN, =4
  1872. S_PRECHARGE, =5
  1873. S_PREPARING_FOR_EV, =6
  1874. S_PREPARING_FOR_EVSE, =7
  1875. S_CHARGING, =8
  1876. S_TERMINATING, =9
  1877. S_COMPLETE, =10
  1878. S_ALARM, =11
  1879. S_FAULT =12
  1880. }
  1881. */
  1882. //check Transaction active
  1883. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1884. if(gunType[gun_index] == 'J')
  1885. {
  1886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1887. {
  1888. tempIndex = ((gun_index==2) ? 1: 0);
  1889. }
  1890. else
  1891. {
  1892. tempIndex = gun_index;
  1893. }
  1894. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1895. {
  1896. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1897. {
  1898. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  1899. {
  1900. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1901. {
  1902. currentStatus = 1; //OCPP Status: Preparing
  1903. }
  1904. else
  1905. {
  1906. currentStatus = 0; //OCPP Status: Available
  1907. }
  1908. }
  1909. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1910. {
  1911. currentStatus = 1; //OCPP Status: Preparing
  1912. }
  1913. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1914. {
  1915. currentStatus = 2; //OCPP Status: Charging
  1916. }
  1917. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1918. {
  1919. currentStatus = 5; //OCPP Status: Finishing
  1920. }
  1921. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  1922. {
  1923. currentStatus = 4; //OCPP Status: SuspendedEV
  1924. }
  1925. 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
  1926. {
  1927. currentStatus = 7; //OCPP Status: Unavailable
  1928. }
  1929. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  1930. {
  1931. currentStatus = 8; //OCPP Status: Faulted
  1932. }
  1933. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1934. {
  1935. currentStatus = 6; //OCPP Status: Reserved
  1936. }
  1937. } //end of the same index
  1938. }//end of for CHAdeMO_QUANTITY
  1939. }
  1940. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1941. {
  1942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1943. {
  1944. tempIndex = ((gun_index==2) ? 1: 0);
  1945. }
  1946. else
  1947. {
  1948. tempIndex = gun_index;
  1949. }
  1950. for (int index = 0; index < CCS_QUANTITY; index++)
  1951. {
  1952. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1953. {
  1954. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1955. {
  1956. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1957. {
  1958. currentStatus = 1; //OCPP Status: Preparing
  1959. }
  1960. else
  1961. {
  1962. currentStatus = 0; //OCPP Status: Available
  1963. }
  1964. }
  1965. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1966. {
  1967. currentStatus = 1; //OCPP Status: Preparing
  1968. }
  1969. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1970. {
  1971. currentStatus = 2; //OCPP Status: Charging
  1972. }
  1973. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1974. {
  1975. currentStatus = 5; //OCPP Status: Finishing
  1976. }
  1977. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  1978. {
  1979. currentStatus = 4; //OCPP Status: SuspendedEV
  1980. }
  1981. 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
  1982. {
  1983. currentStatus = 7; //OCPP Status : Unavailable
  1984. }
  1985. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  1986. {
  1987. currentStatus = 8; //OCPP Status: Faulted
  1988. }
  1989. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1990. {
  1991. currentStatus = 6; //OCPP Status: Reserved
  1992. }
  1993. } //end of the same index
  1994. } // end of for CCS_QUANTITY
  1995. }
  1996. else if(gunType[gun_index] == 'G')
  1997. {
  1998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1999. {
  2000. tempIndex = ((gun_index==2) ? 1: 0);
  2001. }
  2002. else
  2003. {
  2004. tempIndex = gun_index;
  2005. }
  2006. for (int index = 0; index < GB_QUANTITY; index++)
  2007. {
  2008. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2009. {
  2010. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2011. {
  2012. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2013. {
  2014. currentStatus = 1; //OCPP Status: Preparing
  2015. }
  2016. else
  2017. {
  2018. currentStatus = 0; //OCPP Status: Available
  2019. }
  2020. }
  2021. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  2022. {
  2023. currentStatus = 1; //OCPP Status: Preparing
  2024. }
  2025. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2026. {
  2027. currentStatus = 2; //OCPP Status: Charging
  2028. }
  2029. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2030. {
  2031. currentStatus = 5; //OCPP Status: Finishing
  2032. }
  2033. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2034. {
  2035. currentStatus = 4; //OCPP Status: SuspendedEV
  2036. }
  2037. 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
  2038. {
  2039. currentStatus = 7; //OCPP Status: Unavailable
  2040. }
  2041. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2042. {
  2043. currentStatus = 8; //OCPP Status: Faulted
  2044. }
  2045. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2046. {
  2047. currentStatus = 6; //OCPP Status: Reserved
  2048. }
  2049. } //end of the same index
  2050. } // end of for GB_QUANTITY
  2051. }
  2052. else
  2053. {
  2054. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2055. {
  2056. tempIndex = 2;
  2057. }
  2058. else
  2059. {
  2060. tempIndex = gun_index;
  2061. }
  2062. for (int index = 0; index < AC_QUANTITY; index++)
  2063. {
  2064. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2065. {
  2066. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  2067. {
  2068. 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))
  2069. {
  2070. currentStatus = 1; //OCPP Status: Preparing
  2071. }
  2072. else
  2073. {
  2074. currentStatus = 0; //OCPP Status: Available
  2075. }
  2076. }
  2077. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  2078. {
  2079. currentStatus = 1; //OCPP Status: Preparing
  2080. }
  2081. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  2082. {
  2083. currentStatus = 2; //OCPP Status: Charging
  2084. }
  2085. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  2086. {
  2087. currentStatus = 5; //OCPP Status: Finishing
  2088. }
  2089. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2090. {
  2091. currentStatus = 4; //OCPP Status: SuspendedEV
  2092. }
  2093. 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
  2094. {
  2095. currentStatus = 7; //OCPP Status: Unavailable
  2096. }
  2097. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2098. {
  2099. currentStatus = 8; //OCPP Status: Faulted
  2100. }
  2101. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2102. {
  2103. currentStatus = 6; //OCPP Status: Reserved
  2104. }
  2105. }//end of the same index
  2106. }//end of for AC_QUANTITY
  2107. }
  2108. //it's option
  2109. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2110. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2111. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2112. random_uuid(guid);
  2113. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2114. , MESSAGE_TYPE_CALL
  2115. , guid
  2116. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2117. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2118. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2119. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2120. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2121. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2122. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2123. LWS_Send(message);
  2124. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2125. 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*/)
  2126. {
  2127. //DEBUG_ERROR("statusNotification mapitem pass");
  2128. result = PASS;
  2129. }
  2130. return result;
  2131. }
  2132. int sendStopTransactionRequest(int gun_index)
  2133. {
  2134. mtrace();
  2135. int result = FAIL;
  2136. //char message[1500]={0};
  2137. char guid[37]={0};
  2138. char tempdata[65]={0};
  2139. int tempIndex = 0;
  2140. //int idx_sample=0;
  2141. DEBUG_ERROR("sendStopTransactionRequest \n");
  2142. memset(queuedata, 0, sizeof(queuedata));
  2143. //ENERGY_ACTIVE_IMPORT_REGISTER
  2144. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2145. if(gunType[gun_index] == 'J')
  2146. {
  2147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2148. {
  2149. tempIndex = ((gun_index==2) ? 1: 0);
  2150. }
  2151. else
  2152. {
  2153. tempIndex = gun_index;
  2154. }
  2155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2156. {
  2157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2158. {
  2159. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2160. }
  2161. }// END OF CHAdeMO_QUANTITY
  2162. }
  2163. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2164. {
  2165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2166. {
  2167. tempIndex = ((gun_index==2) ? 1: 0);
  2168. }
  2169. else
  2170. {
  2171. tempIndex = gun_index;
  2172. }
  2173. for (int index = 0; index < CCS_QUANTITY; index++)
  2174. {
  2175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2176. {
  2177. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2178. }
  2179. }// END OF CCS_QUANTITY
  2180. }
  2181. else if(gunType[gun_index] == 'G')
  2182. {
  2183. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2184. {
  2185. tempIndex = ((gun_index==2) ? 1: 0);
  2186. }
  2187. else
  2188. {
  2189. tempIndex = gun_index;
  2190. }
  2191. for (int index = 0; index < GB_QUANTITY; index++)
  2192. {
  2193. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2194. {
  2195. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2196. }
  2197. }// END OF GB_QUANTITY
  2198. }
  2199. else
  2200. {
  2201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2202. {
  2203. tempIndex = 2;
  2204. }
  2205. else
  2206. {
  2207. tempIndex = gun_index;
  2208. }
  2209. for (int index = 0; index < AC_QUANTITY; index++)
  2210. {
  2211. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2212. {
  2213. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  2214. }
  2215. }// END OF AC_QUANTITY
  2216. }
  2217. //Stop Transaction Time
  2218. struct timeval tmnow;
  2219. struct tm *tm;
  2220. char buf[28];//, usec_buf[6];
  2221. gettimeofday(&tmnow, NULL);
  2222. time_t t;
  2223. t = time(NULL);
  2224. /*UTC time and date*/
  2225. tm = gmtime(&t);
  2226. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2228. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2229. random_uuid(guid);
  2230. /***********************************transactionData******************************************************/
  2231. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2233. //=================================
  2234. // Transaction_Begin
  2235. //=================================
  2236. // Energy.Active.Export.Interval
  2237. //idx_sample=0;
  2238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  2239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2241. 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*/]);
  2242. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2243. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2244. {
  2245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2246. }
  2247. else
  2248. {
  2249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2250. }
  2251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2253. //=================================
  2254. // Transaction_End
  2255. //=================================
  2256. //Current.Export
  2257. //idx_sample=1;
  2258. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  2259. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  2270. {
  2271. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2272. {
  2273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2274. }
  2275. }// End of for CHAdeMO_QUANTITY
  2276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2277. }
  2278. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  2289. {
  2290. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2291. {
  2292. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2293. }
  2294. }// End of for CCS_QUANTITY
  2295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2296. }
  2297. else if(gunType[gun_index] == 'G')
  2298. {
  2299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2300. {
  2301. tempIndex = ((gun_index==2) ? 1: 0);
  2302. }
  2303. else
  2304. {
  2305. tempIndex = gun_index;
  2306. }
  2307. for (int index = 0; index < GB_QUANTITY; index++)
  2308. {
  2309. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2310. {
  2311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2312. }
  2313. }// End of for GB_QUANTITY
  2314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2315. }
  2316. else
  2317. {
  2318. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2319. {
  2320. tempIndex = 2;
  2321. }
  2322. else
  2323. {
  2324. tempIndex = gun_index;
  2325. }
  2326. for (int index = 0; index < AC_QUANTITY; index++)
  2327. {
  2328. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2329. {
  2330. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2331. }
  2332. }// End of for AC_QUANTITY
  2333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2334. }
  2335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  2338. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2341. //Energy.Active.Export.Interval
  2342. //idx_sample=2;
  2343. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2344. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  2355. {
  2356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2357. {
  2358. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2359. }
  2360. }// END OF CHAdeMO_QUANTITY
  2361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2362. }
  2363. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  2374. {
  2375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2376. {
  2377. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2378. }
  2379. }// END OF CCS_QUANTITY
  2380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2381. }
  2382. else if(gunType[gun_index] == 'G')
  2383. {
  2384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2385. {
  2386. tempIndex = ((gun_index==2) ? 1: 0);
  2387. }
  2388. else
  2389. {
  2390. tempIndex = gun_index;
  2391. }
  2392. for (int index = 0; index < GB_QUANTITY; index++)
  2393. {
  2394. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2395. {
  2396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2397. }
  2398. }// END OF GB_QUANTITY
  2399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2400. }
  2401. else
  2402. {
  2403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2404. {
  2405. tempIndex = 2;
  2406. }
  2407. else
  2408. {
  2409. tempIndex = gun_index;
  2410. }
  2411. for (int index = 0; index < AC_QUANTITY; index++)
  2412. {
  2413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2414. {
  2415. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2416. }
  2417. }// END OF AC_QUANTITY
  2418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2419. }
  2420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  2423. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2426. //Power.Active.Export
  2427. //idx_sample=3;
  2428. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2429. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  2440. {
  2441. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2442. {
  2443. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2444. }
  2445. } // End for CHAdeMO_QUANTITY
  2446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2447. }
  2448. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  2459. {
  2460. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2461. {
  2462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2463. }
  2464. } // END for CCS_QUANTITY
  2465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2466. }
  2467. else if(gunType[gun_index] == 'G')
  2468. {
  2469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2470. {
  2471. tempIndex = ((gun_index==2) ? 1: 0);
  2472. }
  2473. else
  2474. {
  2475. tempIndex = gun_index;
  2476. }
  2477. for (int index = 0; index < GB_QUANTITY; index++)
  2478. {
  2479. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2480. {
  2481. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2482. }
  2483. }// END for GB_QUANTITY
  2484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2485. }
  2486. else
  2487. {
  2488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2489. {
  2490. tempIndex = 2;
  2491. }
  2492. else
  2493. {
  2494. tempIndex = gun_index;
  2495. }
  2496. for (int index = 0; index < AC_QUANTITY; index++)
  2497. {
  2498. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2499. {
  2500. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2501. }
  2502. } // END for AC_QUANTITY
  2503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2504. }
  2505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  2508. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2511. //Voltage
  2512. //idx_sample=4;
  2513. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2514. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  2525. {
  2526. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2527. {
  2528. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2529. }
  2530. } // END OF FOR CHAdeMO_QUANTITY
  2531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2532. }
  2533. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  2544. {
  2545. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2546. {
  2547. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2548. }
  2549. } // END OF FOR CCS_QUANTITY
  2550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2551. }
  2552. else if(gunType[gun_index] == 'G')
  2553. {
  2554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2555. {
  2556. tempIndex = ((gun_index==2) ? 1: 0);
  2557. }
  2558. else
  2559. {
  2560. tempIndex = gun_index;
  2561. }
  2562. for (int index = 0; index < GB_QUANTITY; index++)
  2563. {
  2564. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2565. {
  2566. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2567. }
  2568. } // END OF FOR GB_QUANTITY
  2569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2570. }
  2571. else
  2572. {
  2573. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2574. {
  2575. tempIndex = 2;
  2576. }
  2577. else
  2578. {
  2579. tempIndex = gun_index;
  2580. }
  2581. for (int index = 0; index < AC_QUANTITY; index++)
  2582. {
  2583. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2584. {
  2585. 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
  2586. }
  2587. } // END OF FOR AC_QUANTITY
  2588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2589. }
  2590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2593. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2596. //SoC
  2597. //idx_sample=5;
  2598. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2599. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2600. {
  2601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2602. {
  2603. tempIndex = ((gun_index==2) ? 1: 0);
  2604. }
  2605. else
  2606. {
  2607. tempIndex = gun_index;
  2608. }
  2609. if(gunType[gun_index] == 'J')
  2610. {
  2611. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2612. {
  2613. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2614. {
  2615. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2616. }
  2617. }
  2618. }
  2619. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2620. {
  2621. for (int index = 0; index < CCS_QUANTITY; index++)
  2622. {
  2623. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2624. {
  2625. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2626. }
  2627. }
  2628. }
  2629. else if(gunType[gun_index] == 'G')
  2630. {
  2631. for (int index = 0; index < GB_QUANTITY; index++)
  2632. {
  2633. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2634. {
  2635. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2636. }
  2637. }
  2638. }
  2639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2645. } // END FOR DC CASE
  2646. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2647. {
  2648. 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\"}]}]}]"
  2649. ,MESSAGE_TYPE_CALL
  2650. ,guid
  2651. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2652. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2653. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2654. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2655. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2656. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2657. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2658. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2659. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2660. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2661. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2662. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2663. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2664. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2665. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2666. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2667. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2668. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2669. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2670. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2671. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2672. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2673. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2674. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2675. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2676. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2677. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2678. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2679. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2680. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2681. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2682. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2683. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2684. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2686. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2687. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2699. );
  2700. }
  2701. else
  2702. {
  2703. 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\"}]}]}]"
  2704. ,MESSAGE_TYPE_CALL
  2705. ,guid
  2706. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2707. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2708. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2709. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2710. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2711. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2712. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2722. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2723. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2724. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2725. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2726. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2727. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2728. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2729. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2730. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2731. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2732. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2733. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2734. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2735. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2747. );
  2748. }
  2749. #if 1 // for TempStopTransaction
  2750. //Delete TempStopTransaction
  2751. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  2752. {
  2753. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  2754. }
  2755. #endif
  2756. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2757. if(hashmap_operation(0, guid, tempdata) == 1)
  2758. {
  2759. result = PASS;
  2760. DEBUG_INFO("StopTransaction mapitem pass\n");
  2761. }
  2762. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2763. if(GetTransactionQueueNum() == 1)
  2764. {
  2765. LWS_Send(queuedata);
  2766. }
  2767. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2768. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2769. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2770. {
  2771. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2772. }
  2773. //for test
  2774. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2775. return result;
  2776. }
  2777. int sendMeterValuesRequest(int gun_index)
  2778. {
  2779. mtrace();
  2780. int result = FAIL;
  2781. // char message[1500]={0};
  2782. char guid[37]={0};
  2783. //int idx_sample=0;
  2784. //int length = 0;
  2785. char tempdata[65]={0};
  2786. int tempIndex = 0;
  2787. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2788. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2789. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2790. {
  2791. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2792. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2793. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2794. return result;
  2795. }
  2796. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2797. {
  2798. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2799. }
  2800. memset(queuedata, 0, sizeof(queuedata));
  2801. //set value
  2802. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2803. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2804. random_uuid(guid);
  2805. //UTC Date time
  2806. struct timeval tmnow;
  2807. struct tm *tm;
  2808. char buf[28];//, usec_buf[6];
  2809. gettimeofday(&tmnow, NULL);
  2810. time_t t;
  2811. t = time(NULL);
  2812. /*UTC time and date*/
  2813. tm = gmtime(&t);
  2814. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2816. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2817. //idx_sample=0;
  2818. //********************************(1)Current.Export************************************************/
  2819. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2820. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  2831. {
  2832. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2833. {
  2834. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  2850. {
  2851. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2852. {
  2853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2854. }
  2855. }
  2856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2857. }
  2858. else if(gunType[gun_index] == 'G')
  2859. {
  2860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2861. {
  2862. tempIndex = ((gun_index==2) ? 1: 0);
  2863. }
  2864. else
  2865. {
  2866. tempIndex = gun_index;
  2867. }
  2868. for (int index = 0; index < GB_QUANTITY; index++)
  2869. {
  2870. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2871. {
  2872. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2873. }
  2874. }
  2875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2876. }
  2877. else
  2878. {
  2879. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2880. {
  2881. tempIndex = 2;
  2882. }
  2883. else
  2884. {
  2885. tempIndex = gun_index;
  2886. }
  2887. for (int index = 0; index < AC_QUANTITY; index++)
  2888. {
  2889. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2890. {
  2891. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2892. }
  2893. }
  2894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2895. }
  2896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  2899. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2902. //idx_sample=1;
  2903. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2904. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2905. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  2916. {
  2917. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2918. {
  2919. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2920. }
  2921. } // END OF FOR CHAdeMO_QUANTITY
  2922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2923. }
  2924. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2925. {
  2926. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2927. {
  2928. tempIndex = ((gun_index==2) ? 1: 0);
  2929. }
  2930. else
  2931. {
  2932. tempIndex = gun_index;
  2933. }
  2934. for (int index = 0; index < CCS_QUANTITY; index++)
  2935. {
  2936. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2937. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2938. {
  2939. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2940. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2941. }
  2942. } // END OF CCS_QUANTITY
  2943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2944. }
  2945. else if(gunType[gun_index] == 'G')
  2946. {
  2947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2948. {
  2949. tempIndex = ((gun_index==2) ? 1: 0);
  2950. }
  2951. else
  2952. {
  2953. tempIndex = gun_index;
  2954. }
  2955. for (int index = 0; index < GB_QUANTITY; index++)
  2956. {
  2957. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2958. {
  2959. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2960. }
  2961. } // END OF GB_QUANTITY
  2962. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2963. }
  2964. else
  2965. {
  2966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2967. {
  2968. tempIndex = 2;
  2969. }
  2970. else
  2971. {
  2972. tempIndex = gun_index;
  2973. }
  2974. for (int index = 0; index < AC_QUANTITY; index++)
  2975. {
  2976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2977. {
  2978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2979. }
  2980. }
  2981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2982. }
  2983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  2986. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2988. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2989. //idx_sample=2;
  2990. //********************************(4)Power.Active.Export************************************************/
  2991. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2992. if(gunType[gun_index] == 'J')
  2993. {
  2994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2995. {
  2996. tempIndex = ((gun_index==2) ? 1: 0);
  2997. }
  2998. else
  2999. {
  3000. tempIndex = gun_index;
  3001. }
  3002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3003. {
  3004. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3005. {
  3006. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  3007. }
  3008. } // END OF FOR
  3009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3010. }
  3011. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3012. {
  3013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3014. {
  3015. tempIndex = ((gun_index==2) ? 1: 0);
  3016. }
  3017. else
  3018. {
  3019. tempIndex = gun_index;
  3020. }
  3021. for (int index = 0; index < CCS_QUANTITY; index++)
  3022. {
  3023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3024. {
  3025. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  3026. }
  3027. }
  3028. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3029. }
  3030. else if(gunType[gun_index] == 'G')
  3031. {
  3032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3033. {
  3034. tempIndex = ((gun_index==2) ? 1: 0);
  3035. }
  3036. else
  3037. {
  3038. tempIndex = gun_index;
  3039. }
  3040. for (int index = 0; index < GB_QUANTITY; index++)
  3041. {
  3042. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3043. {
  3044. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  3045. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  3046. }
  3047. }
  3048. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3049. }
  3050. else
  3051. {
  3052. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3053. {
  3054. tempIndex = 2;
  3055. }
  3056. else
  3057. {
  3058. tempIndex = gun_index;
  3059. }
  3060. for (int index = 0; index < AC_QUANTITY; index++)
  3061. {
  3062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3063. {
  3064. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  3065. }
  3066. }
  3067. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3068. }
  3069. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3070. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  3071. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Import]);
  3072. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3073. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  3074. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  3075. //idx_sample=3;
  3076. //***********************************************(5)VOLTAGE******************************************************/
  3077. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3078. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  3089. {
  3090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3091. {
  3092. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  3108. {
  3109. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3110. {
  3111. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  3112. }
  3113. }
  3114. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3115. }
  3116. else if(gunType[gun_index] == 'G')
  3117. {
  3118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3119. {
  3120. tempIndex = ((gun_index==2) ? 1: 0);
  3121. }
  3122. else
  3123. {
  3124. tempIndex = gun_index;
  3125. }
  3126. for (int index = 0; index < GB_QUANTITY; index++)
  3127. {
  3128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3129. {
  3130. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  3131. }
  3132. }
  3133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3134. }
  3135. else
  3136. {
  3137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3138. {
  3139. tempIndex = 2;
  3140. }
  3141. else
  3142. {
  3143. tempIndex = gun_index;
  3144. }
  3145. for (int index = 0; index < AC_QUANTITY; index++)
  3146. {
  3147. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3148. {
  3149. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  3150. }
  3151. }
  3152. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3153. }
  3154. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3155. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  3156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  3157. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3158. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  3159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3160. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3161. {
  3162. //idx_sample=4;
  3163. //sampledValue = NULL;
  3164. //***********************************************(6)SOC******************************************************/
  3165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3166. {
  3167. tempIndex = ((gun_index==2) ? 1: 0);
  3168. }
  3169. else
  3170. {
  3171. tempIndex = gun_index;
  3172. }
  3173. if(gunType[gun_index] == 'J')
  3174. {
  3175. //tempIndex = ((gun_index==2) ? 1: 0);
  3176. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3177. {
  3178. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3179. {
  3180. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  3181. }
  3182. }
  3183. }
  3184. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3185. {
  3186. //tempIndex = ((gun_index==2) ? 1: 0);
  3187. for (int index = 0; index < CCS_QUANTITY; index++)
  3188. {
  3189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3190. {
  3191. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  3192. }
  3193. }
  3194. }
  3195. else if(gunType[gun_index] == 'G')
  3196. {
  3197. //tempIndex = ((gun_index==2) ? 1: 0);
  3198. for (int index = 0; index < GB_QUANTITY; index++)
  3199. {
  3200. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3201. {
  3202. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  3203. }
  3204. }
  3205. }
  3206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3207. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  3208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  3209. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3210. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  3211. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  3212. }
  3213. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3214. {
  3215. 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\"}]}]}]"
  3216. ,MESSAGE_TYPE_CALL
  3217. ,guid
  3218. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3219. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3220. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3221. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3222. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3223. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3224. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3225. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3226. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3227. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3228. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3229. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3230. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3231. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3232. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3233. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3234. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3235. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3236. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3237. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3238. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3239. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3240. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3241. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3242. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3243. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3244. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3245. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3246. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3247. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3248. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3249. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  3250. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  3251. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  3252. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  3253. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  3254. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  3255. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  3256. );
  3257. }
  3258. else
  3259. {
  3260. 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\"}]}]}]"
  3261. ,MESSAGE_TYPE_CALL
  3262. ,guid
  3263. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3264. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3265. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3266. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3267. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3268. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3269. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3270. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3271. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3272. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3273. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3274. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3275. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3276. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3277. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3278. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3279. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3280. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3281. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3282. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3283. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3284. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3285. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3286. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3287. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3288. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3289. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3290. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3291. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3292. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3293. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3294. );
  3295. }
  3296. // Put request guid to hash map
  3297. sprintf(tempdata, "MeterValues,%d", (gun_index));
  3298. 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*/)
  3299. {
  3300. result = PASS;
  3301. DEBUG_INFO("MeterValues mapitem pass\n");
  3302. }
  3303. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3304. if(GetTransactionQueueNum() == 1)
  3305. {
  3306. LWS_Send(queuedata);
  3307. }
  3308. return result;
  3309. }
  3310. //==========================================
  3311. // send confirm routine
  3312. //==========================================
  3313. int sendCancelReservationConfirmation(char *uuid,char *payload)
  3314. {
  3315. mtrace();
  3316. int result = FAIL;
  3317. char message[100]={0};
  3318. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  3319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3320. LWS_Send(message);
  3321. result = TRUE;
  3322. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  3323. return result;
  3324. }
  3325. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  3326. {
  3327. mtrace();
  3328. int result = FAIL;
  3329. char message[100]={0};
  3330. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  3331. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3332. LWS_Send(message);
  3333. result = TRUE;
  3334. return result;
  3335. }
  3336. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  3337. {
  3338. mtrace();
  3339. int result = FAIL;
  3340. char message[100]={0};
  3341. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  3342. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3343. LWS_Send(message);
  3344. result = TRUE;
  3345. return result;
  3346. }
  3347. int sendClearCacheConfirmation(char *uuid,char *payload)
  3348. {
  3349. mtrace();
  3350. int result = FAIL;
  3351. char message[500]={0};
  3352. // int count = 0;
  3353. // int gun_index = 0;
  3354. // char guid[37];
  3355. // [ 3, "1570592744204", { "status": "Accepted" } ]
  3356. DEBUG_ERROR("sendClearCacheConfirmation\n");
  3357. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3358. LWS_Send(message);
  3359. return result;
  3360. }
  3361. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  3362. {
  3363. mtrace();
  3364. int result = FAIL;
  3365. char message[500]={0};
  3366. // [ 3, "1571284268200", { "status": "Unknown" } ]
  3367. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  3368. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3369. LWS_Send(message);
  3370. return result;
  3371. }
  3372. int sendDataTransferConfirmation(char *uuid,char *payload)
  3373. {
  3374. mtrace();
  3375. char statusStr[20]={0};
  3376. char dataStr[10]={0};
  3377. char sstr[20]={0};
  3378. int c = 0;
  3379. char *loc;
  3380. int result = FAIL;
  3381. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3382. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3383. /**********************status**************************/
  3384. loc = strstr(payload, "status");
  3385. memset(sstr ,0, sizeof(sstr) );
  3386. c = 0;
  3387. while (loc[3+strlen("status")+c] != '\"')
  3388. {
  3389. sstr[c] = loc[3+strlen("status")+c];
  3390. c++;
  3391. }
  3392. sstr[c] = '\0';
  3393. strcpy(statusStr, sstr);
  3394. /**********************data**************************/
  3395. loc = strstr(payload, "data");
  3396. memset(sstr ,0, sizeof(sstr) );
  3397. c = 0;
  3398. while (loc[3+strlen("data")+c] != '\"')
  3399. {
  3400. sstr[c] = loc[3+strlen("data")+c];
  3401. c++;
  3402. }
  3403. sstr[c] = '\0';
  3404. strcpy(dataStr, sstr);
  3405. return result;
  3406. }
  3407. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3408. {
  3409. mtrace();
  3410. int result = FAIL;
  3411. char message[1000]={0};
  3412. double diff_f = 0.0;
  3413. int diff_i = 0;
  3414. int diffSeconds = 0;
  3415. struct tm tp;
  3416. int TimeZero = FALSE;
  3417. int CompositeScheduleIndex = 0;
  3418. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  3419. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  3420. {
  3421. TimeZero = TRUE;
  3422. }
  3423. else
  3424. {
  3425. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3426. }
  3427. if(TimeZero == FALSE)
  3428. {
  3429. tp.tm_isdst = -1;
  3430. time_t utc = mktime(&tp);
  3431. time_t t = time(NULL);
  3432. diff_f = difftime(t, utc);
  3433. diff_i = (int)diff_f;
  3434. diffSeconds = diff_i % 86400;//86400 seconds/day
  3435. }
  3436. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3437. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3438. #if 0 //remove temporally
  3439. 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}"
  3440. ,MESSAGE_TYPE_CALLRESULT
  3441. ,uuid
  3442. ,payload
  3443. ,connectorIdInt
  3444. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3445. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3446. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3447. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3448. #endif
  3449. if(nPeriod == 0)
  3450. {
  3451. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  3452. {
  3453. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  3454. ,MESSAGE_TYPE_CALLRESULT
  3455. ,uuid
  3456. ,payload
  3457. ,connectorIdInt);
  3458. }
  3459. else
  3460. {
  3461. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3462. ,MESSAGE_TYPE_CALLRESULT
  3463. ,uuid
  3464. ,payload
  3465. ,connectorIdInt
  3466. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3467. }
  3468. }
  3469. else
  3470. {
  3471. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3472. ,MESSAGE_TYPE_CALLRESULT
  3473. ,uuid
  3474. ,payload
  3475. ,connectorIdInt
  3476. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3477. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3478. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3479. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3480. int len = nPeriod;
  3481. //Last Period StartPriod is less than diffSeconds
  3482. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds) || (diffSeconds == 0))
  3483. {
  3484. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3485. , 0
  3486. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3487. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3488. }
  3489. else
  3490. {
  3491. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3492. {
  3493. 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)
  3494. {
  3495. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3496. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3497. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3498. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3499. }
  3500. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3501. {
  3502. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3503. , ((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*/))
  3504. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3505. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3506. }
  3507. }
  3508. }
  3509. sprintf(message + strlen(message), "]}}]");
  3510. }
  3511. LWS_Send(message);
  3512. result = TRUE;
  3513. return result;
  3514. }
  3515. int sendGetConfigurationConfirmation(char *uuid)
  3516. {
  3517. mtrace();
  3518. int result = FAIL;
  3519. int MaxKeySupported = 0;
  3520. int sentConfigurationNumber= 0;
  3521. int sentunConfigurationNumber= 0;
  3522. char message[4000]={0};
  3523. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3524. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3525. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3526. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3527. ,MESSAGE_TYPE_CALLRESULT
  3528. ,uuid );
  3529. //configuration key
  3530. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3531. {
  3532. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3533. {
  3534. if (sentConfigurationNumber == 0)
  3535. {
  3536. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3537. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3538. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3539. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3540. }
  3541. else
  3542. {
  3543. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3544. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3545. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3546. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3547. }
  3548. sentConfigurationNumber = sentConfigurationNumber + 1;
  3549. }
  3550. }
  3551. sprintf(message + strlen(message), "]");
  3552. if(UnknownKeynum != 0)
  3553. {
  3554. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3555. //unkown key
  3556. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3557. {
  3558. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3559. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3560. if(sentunConfigurationNumber == 0)
  3561. {
  3562. sprintf(message + strlen(message), "\"%s\""
  3563. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3564. }
  3565. else
  3566. {
  3567. sprintf(message + strlen(message), ",\"%s\""
  3568. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3569. }
  3570. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3571. }
  3572. sprintf(message + strlen(message), "]");
  3573. }
  3574. sprintf(message + strlen(message), "}]");
  3575. LWS_Send(message);
  3576. return result;
  3577. }
  3578. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3579. {
  3580. mtrace();
  3581. int result = FAIL;
  3582. char message[400]={0};
  3583. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3584. if(strcmp(payload,"")==0)
  3585. {
  3586. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3587. }
  3588. else
  3589. {
  3590. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3591. }
  3592. LWS_Send(message);
  3593. result = TRUE;
  3594. return result;
  3595. }
  3596. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3597. {
  3598. mtrace();
  3599. int result = FAIL;
  3600. char message[80]={0};
  3601. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3602. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3603. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3604. LWS_Send(message);
  3605. result = TRUE;
  3606. return result;
  3607. }
  3608. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3609. {
  3610. mtrace();
  3611. int result = FAIL;
  3612. char message[80]={0};
  3613. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3614. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3615. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3616. LWS_Send(message);
  3617. result = TRUE;
  3618. return result;
  3619. }
  3620. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3621. {
  3622. mtrace();
  3623. int result = FAIL;
  3624. char message[80]={0};
  3625. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3626. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3627. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3628. LWS_Send(message);
  3629. result = TRUE;
  3630. return result;
  3631. }
  3632. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3633. {
  3634. mtrace();
  3635. int result = FAIL;
  3636. char message[80]={0};
  3637. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3638. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3639. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3640. LWS_Send(message);
  3641. result = TRUE;
  3642. return result;
  3643. }
  3644. int sendResetConfirmation(char *uuid,char *payload)
  3645. {
  3646. mtrace();
  3647. int result = FAIL;
  3648. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3649. char message[80]={0};
  3650. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3651. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3652. LWS_Send(message);
  3653. result = TRUE;
  3654. return result;
  3655. }
  3656. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3657. {
  3658. mtrace();
  3659. int result = FAIL;
  3660. char message[500]={0};
  3661. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3662. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3663. LWS_Send(message);
  3664. result = TRUE;
  3665. return result;
  3666. }
  3667. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3668. {
  3669. mtrace();
  3670. int result = FAIL;
  3671. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3672. char message[80]={0};
  3673. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3674. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3675. LWS_Send(message);
  3676. result = TRUE;
  3677. return result;
  3678. }
  3679. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3680. {
  3681. mtrace();
  3682. int result = FAIL;
  3683. char message[80]={0};
  3684. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3685. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3686. LWS_Send(message);
  3687. result = TRUE;
  3688. return result;
  3689. }
  3690. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3691. {
  3692. mtrace();
  3693. int result = FAIL;
  3694. char message[80]={0};
  3695. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3696. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3697. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3698. LWS_Send(message);
  3699. result = TRUE;
  3700. return result;
  3701. }
  3702. int sendUpdateFirmwareConfirmation(char *uuid)
  3703. {
  3704. mtrace();
  3705. int result = FAIL;
  3706. char message[60]={0};
  3707. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3708. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3709. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3710. LWS_Send(message);
  3711. result = TRUE;
  3712. return result;
  3713. }
  3714. //==========================================
  3715. // send CallError routine
  3716. //==========================================
  3717. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3718. {
  3719. mtrace();
  3720. //int result = FAIL;
  3721. char message[220]={0};
  3722. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3723. #ifdef SystemLogMessage
  3724. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3725. uniqueId, action, errorCode, errorDescription);
  3726. #endif
  3727. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3728. LWS_Send(message);
  3729. //result = TRUE;
  3730. }
  3731. //==========================================
  3732. // Handle server request routine Start
  3733. //==========================================
  3734. #define GUN_NUM 1
  3735. int handleCancelReservationRequest(char *uuid, char *payload)
  3736. {
  3737. mtrace();
  3738. int result = FAIL;
  3739. int gunNO = 0;
  3740. int reservationIdInt =0;
  3741. char comfirmstr[20];
  3742. int c = 0;
  3743. int copyTo = 0;
  3744. char *loc;
  3745. char sstr[100]={0};
  3746. DEBUG_INFO("handle CancelReservationRequest\n");
  3747. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3748. c = 0;
  3749. copyTo = 0;
  3750. loc = strstr(payload, "reservationId");
  3751. memset(sstr ,0, sizeof(sstr) );
  3752. while (loc[strlen("reservationId")+2+c] != '}')
  3753. {
  3754. if(loc[strlen("interval")+2+c] != ' ')
  3755. {
  3756. sstr[copyTo] = loc[strlen("reservationId")+2+c];
  3757. copyTo = copyTo + 1;
  3758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3759. }
  3760. c++;
  3761. }
  3762. sstr[copyTo] = '\0';
  3763. reservationIdInt = atoi(sstr);
  3764. memset(comfirmstr, 0, sizeof comfirmstr);
  3765. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3766. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3767. //check Transaction active
  3768. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3769. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3770. {
  3771. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3772. {
  3773. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3774. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3775. if(gunType[2] == 'J')
  3776. {
  3777. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  3778. }
  3779. else
  3780. {
  3781. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3782. }
  3783. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3784. goto end;
  3785. }
  3786. }
  3787. for (int index = 0; index < CCS_QUANTITY; index++)
  3788. {
  3789. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3790. {
  3791. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3792. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3793. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  3794. {
  3795. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  3796. }
  3797. else
  3798. {
  3799. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3800. }
  3801. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3802. goto end;
  3803. }
  3804. }
  3805. for (int index = 0; index < GB_QUANTITY; index++)
  3806. {
  3807. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3808. {
  3809. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3810. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3811. if(gunType[2] == 'G')
  3812. {
  3813. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  3814. }
  3815. else
  3816. {
  3817. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3818. }
  3819. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3820. goto end;
  3821. }
  3822. }
  3823. for (int index = 0; index < AC_QUANTITY; index++)
  3824. {
  3825. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3826. {
  3827. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3828. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3829. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3830. {
  3831. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  3832. }
  3833. else
  3834. {
  3835. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3836. }
  3837. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3838. goto end;
  3839. }
  3840. }
  3841. //The reservationId does NOT match the reservationId
  3842. sendCancelReservationConfirmation(uuid, comfirmstr);
  3843. end:
  3844. // Fill in ocpp packet uuid
  3845. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3846. return result;
  3847. }
  3848. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3849. {
  3850. mtrace();
  3851. int result = FAIL;
  3852. int gunIndex = 0;
  3853. char sstr[90]={0},sstrtemp[50]={ 0 };
  3854. char typeStr[16]={0};
  3855. char comfirmstr[20];
  3856. int specificId = FALSE;
  3857. char *loc;
  3858. //int intervalInt = 0;
  3859. int c = 0;
  3860. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3861. strcpy(sstrtemp, stringtrimspace(payload));
  3862. /*** connectorId ****/
  3863. loc = strstr(sstrtemp, "connectorId");
  3864. memset(sstr ,0, sizeof(sstr) );
  3865. c = 0;
  3866. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') ) // 2: ":
  3867. {
  3868. sstr[c] = loc[strlen("connectorId")+2+c];
  3869. c++;
  3870. }
  3871. sstr[c] = '\0';
  3872. gunIndex = atoi(sstr);
  3873. /***type ****/
  3874. loc = strstr(sstrtemp, "type");
  3875. memset(sstr ,0, sizeof(sstr) );
  3876. c = 0;
  3877. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3878. {
  3879. sstr[c] = loc[3+strlen("type")+c];
  3880. c++;
  3881. }
  3882. sstr[c] = '\0';
  3883. strcpy(typeStr, sstr);
  3884. if(gunIndex != 0)
  3885. {
  3886. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3887. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3888. }
  3889. else
  3890. {
  3891. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3892. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3893. }
  3894. memset(comfirmstr, 0, sizeof comfirmstr);
  3895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3896. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3897. {
  3898. specificId = TRUE;
  3899. }
  3900. if(specificId == FALSE)
  3901. goto end;
  3902. if(gunIndex != 0)
  3903. {
  3904. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3905. }
  3906. else
  3907. {
  3908. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3909. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3910. }
  3911. /*
  3912. enum SYSTEM_STATUS
  3913. {
  3914. SYS_MODE_BOOTING = 0,
  3915. SYS_MODE_IDLE = 1,
  3916. SYS_MODE_AUTHORIZING = 2,
  3917. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3918. SYS_MODE_REASSIGN = 4,
  3919. SYS_MODE_PREPARING = 5,
  3920. SYS_MODE_PREPARE_FOR_EV = 6,
  3921. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3922. SYS_MODE_CHARGING = 8,
  3923. SYS_MODE_TERMINATING = 9,
  3924. SYS_MODE_COMPLETE = 10,
  3925. SYS_MODE_ALARM = 11,
  3926. SYS_MODE_FAULT = 12,
  3927. SYS_MODE_RESERVATION = 13,
  3928. SYS_MODE_BOOKING = 14,
  3929. SYS_MODE_MAINTAIN = 15,
  3930. SYS_MODE_DEBUG = 16,
  3931. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3932. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3933. SYS_MODE_UPDATE = 19
  3934. };
  3935. */
  3936. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3937. {
  3938. //check Transaction active
  3939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3940. {
  3941. if ((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')))
  3942. {
  3943. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3944. {
  3945. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3946. }
  3947. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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 CHAdeMO_QUANTITY
  3958. for (int index = 0; index < CCS_QUANTITY; index++)
  3959. {
  3960. if ((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))))
  3961. {
  3962. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3963. {
  3964. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3965. }
  3966. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[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 CCS_QUANTITY
  3977. for (int index = 0; index < GB_QUANTITY; index++)
  3978. {
  3979. if ((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))
  3980. {
  3981. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3982. {
  3983. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3984. }
  3985. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[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 GB_QUANTITY
  3996. for (int index = 0; index < AC_QUANTITY; index++)
  3997. {
  3998. if ((gunIndex == 0) || ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))))
  3999. {
  4000. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  4001. {
  4002. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4003. }
  4004. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4005. {
  4006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4007. }
  4008. else
  4009. {
  4010. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4011. }
  4012. goto end;
  4013. }
  4014. }//END FOR AC_QUANTITY
  4015. }//END FOR AvailabilityTypeStr[Inoperative]
  4016. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  4017. {
  4018. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  4019. //check Transaction active
  4020. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4021. {
  4022. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4023. {
  4024. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4025. goto end;
  4026. }
  4027. }//END FOR CHAdeMO_QUANTITY
  4028. for (int index = 0; index < CCS_QUANTITY; index++)
  4029. {
  4030. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4031. {
  4032. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4033. goto end;
  4034. }
  4035. }//END FOR CCS_QUANTITY
  4036. for (int index = 0; index < GB_QUANTITY; index++)
  4037. {
  4038. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4039. {
  4040. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  4041. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4042. goto end;
  4043. }
  4044. }// END FOR GB_QUANTITY
  4045. for (int index = 0; index < AC_QUANTITY; index++)
  4046. {
  4047. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4048. {
  4049. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4050. goto end;
  4051. }
  4052. }//END FOR CHAdeMO_QUANTITY
  4053. }//END FOR AvailabilityTypeStr[Operative]
  4054. end:
  4055. if(gunIndex != 0)
  4056. {
  4057. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  4058. }
  4059. else
  4060. {
  4061. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  4062. }
  4063. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  4064. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  4065. return result;
  4066. }
  4067. int handleChangeConfigurationRequest(char *uuid, char *payload)
  4068. {
  4069. mtrace();
  4070. int result = FAIL;
  4071. char sstr[100]={0},sstrtemp[160]={ 0 };
  4072. char keystr[40]={0};
  4073. char valuestr[100]={0};
  4074. char *loc;
  4075. int c = 0;
  4076. char comfirmstr[20]={0};
  4077. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  4078. strcpy(sstrtemp, stringtrimspace(payload));
  4079. /***key ****/
  4080. loc = strstr(sstrtemp, "key");
  4081. memset(sstr ,0, sizeof(sstr) );
  4082. c = 0;
  4083. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  4084. {
  4085. sstr[c] = loc[3+strlen("key")+c];
  4086. c++;
  4087. }
  4088. sstr[c] = '\0';
  4089. strcpy(keystr, sstr);
  4090. //DEBUG_INFO( "keystr=%s\n",keystr);
  4091. /***value ****/
  4092. loc = strstr(sstrtemp, "value");
  4093. memset(sstr ,0, sizeof(sstr) );
  4094. c = 0;
  4095. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  4096. {
  4097. sstr[c] = loc[3+strlen("value")+c];
  4098. c++;
  4099. }
  4100. sstr[c] = '\0';
  4101. strcpy(valuestr, sstr);
  4102. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  4103. if((uuid==NULL) || (payload ==NULL) )
  4104. {
  4105. #ifdef Debug
  4106. DEBUG_INFO("payload is null\n");
  4107. #endif
  4108. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4109. }
  4110. else
  4111. {
  4112. int status = setKeyValue(keystr, valuestr);
  4113. switch(status)
  4114. {
  4115. case ConfigurationStatus_Accepted:
  4116. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  4117. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  4118. StoreConfigurationTable();
  4119. break;
  4120. case ConfigurationStatus_Rejected:
  4121. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4122. break;
  4123. case RebootRequired:
  4124. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  4125. StoreConfigurationTable();
  4126. break;
  4127. case NotSupported:
  4128. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  4129. break;
  4130. default:
  4131. break;
  4132. }
  4133. }
  4134. //confirmation.setStatus(ConfigurationStatus.Rejected);
  4135. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  4136. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  4137. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  4138. {
  4139. ChageWebSocketPingInterval(atoi(valuestr));
  4140. }
  4141. return result;
  4142. }
  4143. int handleClearCacheRequest(char *uuid, char *payload)
  4144. {
  4145. mtrace();
  4146. int result = FAIL;
  4147. char comfirmstr[20];
  4148. int fd;
  4149. char rmFileCmd[100]={0};
  4150. struct stat stats;
  4151. DEBUG_INFO("handle ClearCacheRequest\n");
  4152. stat("/Storage/OCPP", &stats);
  4153. // Check for directory existence
  4154. if (S_ISDIR(stats.st_mode) == 1)
  4155. {
  4156. //DEBUG_ERROR("\n OCPP directory exist \n");
  4157. }
  4158. else
  4159. {
  4160. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  4161. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  4162. system(rmFileCmd);
  4163. }
  4164. memset(rmFileCmd, 0, sizeof rmFileCmd);
  4165. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  4166. {
  4167. DEBUG_INFO("AuthorizationCache file exist.\n");
  4168. }
  4169. else
  4170. {
  4171. DEBUG_INFO("AuthorizationCache file not exist\n");
  4172. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  4173. if(log == NULL)
  4174. {
  4175. DEBUG_INFO("AuthorizationCache file is NULL\n");
  4176. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4177. goto end;
  4178. }
  4179. else
  4180. {
  4181. fclose(log);
  4182. }
  4183. }
  4184. fd = open(AuthorizationCache_JSON,O_RDWR);
  4185. if(fd < 0)
  4186. {
  4187. DEBUG_INFO("open AuthorizationCache file failed\n");
  4188. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4189. }
  4190. else
  4191. {
  4192. DEBUG_INFO("open AuthorizationCache file successful\n");
  4193. //* 清空? 件 */
  4194. ftruncate(fd,0);
  4195. //* ? 新设置? 件? 移??*/
  4196. lseek(fd,0,SEEK_SET);
  4197. close(fd);
  4198. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  4199. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  4200. }
  4201. end:
  4202. sendClearCacheConfirmation(uuid, comfirmstr);
  4203. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  4204. return result;
  4205. }
  4206. int handleClearChargingProfileRequest(char *uuid, char *payload)
  4207. {
  4208. mtrace();
  4209. int result = FAIL;
  4210. int resultRename;
  4211. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  4212. char chargingProfilePurposeStr[26]={0};
  4213. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  4214. char tempchargingProfilePurposeStr[26]={0};
  4215. char sstr[160]={0},sstrtemp[160]={ 0 };//sstr[200]={ 0 };
  4216. char str[100]={0};
  4217. int c = 0;
  4218. //int i = 0;
  4219. //char * pch;
  4220. char *loc;
  4221. char fname[200]={0};
  4222. char comfirmstr[20]={0};
  4223. char word[1600]={0};
  4224. int clearflag = FALSE;
  4225. int chargingProfileIdIsNULL = FALSE;
  4226. int connectorIsNULL = FALSE;
  4227. int chargingProfilePurposeIsNULL = FALSE;
  4228. int stackLevelIsNULL = FALSE;
  4229. //int GotoEnd = FALSE;
  4230. FILE *fptr1, *fptr2;
  4231. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  4232. int n_chargingProfile=0;
  4233. int isEmptyFile = FALSE;
  4234. char sLineWord[1600]={0};
  4235. char chargingProfiles[10][100]={0};
  4236. int ChargeProfileCount = 0;
  4237. char ch;
  4238. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  4239. strcpy(sstrtemp, stringtrimspace(payload));
  4240. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  4241. //***id ****/
  4242. c = 0;
  4243. loc = strstr(sstrtemp, "id");
  4244. memset(sstr ,0, sizeof(sstr) );
  4245. if(loc == NULL)
  4246. {
  4247. chargingProfileIdIsNULL = TRUE;
  4248. }
  4249. else
  4250. {
  4251. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  4252. {
  4253. sstr[c] = loc[strlen("id")+2+c];
  4254. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4255. c++;
  4256. }
  4257. sstr[c] = '\0';
  4258. chargingProfileIdInt = atoi(sstr);
  4259. }
  4260. //***connectorId ****/
  4261. c=0;
  4262. loc = strstr(sstrtemp, "connectorId");
  4263. memset(sstr ,0, sizeof(sstr) );
  4264. if(loc == NULL)
  4265. {
  4266. connectorIsNULL = TRUE;
  4267. }
  4268. else
  4269. {
  4270. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  4271. {
  4272. sstr[c] = loc[strlen("connectorId")+2+c];
  4273. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4274. c++;
  4275. }
  4276. sstr[c] = '\0';
  4277. connectorIdInt = atoi(sstr);
  4278. }
  4279. //***chargingProfilePurpose ****/
  4280. loc = strstr(sstrtemp, "chargingProfilePurpose");
  4281. memset(sstr ,0, sizeof(sstr) );
  4282. c = 0;
  4283. if(loc == NULL)
  4284. {
  4285. chargingProfilePurposeIsNULL = TRUE;
  4286. }
  4287. else
  4288. {
  4289. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  4290. {
  4291. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4292. c++;
  4293. }
  4294. sstr[c] = '\0';
  4295. strcpy(chargingProfilePurposeStr, sstr);
  4296. }
  4297. //***stackLevel ****/
  4298. c=0;
  4299. loc = strstr(sstrtemp, "stackLevel");
  4300. memset(sstr ,0, sizeof(sstr) );
  4301. if(loc == NULL)
  4302. {
  4303. stackLevelIsNULL = TRUE;
  4304. }
  4305. else
  4306. {
  4307. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  4308. {
  4309. sstr[c] = loc[strlen("stackLevel")+2+c];
  4310. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4311. c++;
  4312. }
  4313. sstr[c] = '\0';
  4314. stackLevelInt = atoi(sstr);
  4315. }
  4316. if(connectorIsNULL == FALSE)
  4317. {
  4318. switch(connectorIdInt)
  4319. {
  4320. case 0:
  4321. if(chargingProfilePurposeIsNULL == TRUE)
  4322. {
  4323. int l = 0;
  4324. strcpy(fname, ChargePointMaxProfile_JSON);
  4325. if((access(fname,F_OK))!=-1)
  4326. {
  4327. strcpy(chargingProfiles[l], fname);
  4328. l = l + 1;
  4329. }
  4330. strcpy(fname, TxDefaultProfile_0_JSON);
  4331. if((access(fname,F_OK))!=-1)
  4332. {
  4333. strcpy(chargingProfiles[l], fname);
  4334. l = l + 1;
  4335. }
  4336. ChargeProfileCount = l;
  4337. }
  4338. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  4339. {
  4340. strcpy(fname, ChargePointMaxProfile_JSON);
  4341. if((access(fname,F_OK))!=-1)
  4342. {
  4343. strcpy(chargingProfiles[0], fname);
  4344. ChargeProfileCount = 1;
  4345. }
  4346. }
  4347. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4348. {
  4349. strcpy(fname, TxDefaultProfile_0_JSON);
  4350. if((access(fname,F_OK))!=-1)
  4351. {
  4352. strcpy(chargingProfiles[0], fname);
  4353. ChargeProfileCount = 1;
  4354. }
  4355. }
  4356. break;
  4357. default:
  4358. if(chargingProfilePurposeIsNULL == TRUE)
  4359. {
  4360. int m = 0;
  4361. memset(fname, 0, sizeof fname);
  4362. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4363. if((access(fname,F_OK))!=-1)
  4364. {
  4365. strcpy(chargingProfiles[m], fname);
  4366. m = m + 1;
  4367. }
  4368. memset(fname, 0, sizeof fname);
  4369. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4370. if((access(fname,F_OK))!=-1)
  4371. {
  4372. strcpy(chargingProfiles[m], fname);
  4373. m = m + 1;
  4374. }
  4375. ChargeProfileCount = m;
  4376. }
  4377. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4378. {
  4379. //strcpy(fname, TxDefaultProfile_1_JSON);
  4380. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4381. if((access(fname,F_OK))!=-1)
  4382. {
  4383. strcpy(chargingProfiles[0], fname);
  4384. ChargeProfileCount = 1;
  4385. }
  4386. }
  4387. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  4388. {
  4389. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4390. if((access(fname,F_OK))!=-1)
  4391. {
  4392. strcpy(chargingProfiles[0], fname);
  4393. ChargeProfileCount = 1;
  4394. }
  4395. //strcpy(fname, TxProfile_1_JSON);
  4396. }
  4397. //strcpy(fname, ChargePointMaxProfile_JSON );
  4398. break;
  4399. }
  4400. }
  4401. else // Check all Charging Profiles
  4402. {
  4403. int i = 0;
  4404. char fnametemp[200]={0};
  4405. ChargeProfileCount = 0;
  4406. //Check ChargePointMaxProfile.json exit
  4407. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  4408. {
  4409. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  4410. i = i + 1;
  4411. }
  4412. //Check TxDefaultProfile_0.json exit
  4413. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  4414. {
  4415. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  4416. i = i + 1;
  4417. }
  4418. //Check TxDefaultProfile_%d.json
  4419. for(int j=1; j <= gunTotalNumber; j++)
  4420. {
  4421. memset(fnametemp, 0, sizeof fnametemp);
  4422. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  4423. if((access(fnametemp,F_OK))!=-1)
  4424. {
  4425. strcpy(chargingProfiles[i], fnametemp);
  4426. i = i + 1;
  4427. }
  4428. }
  4429. //Check TxProfile_%d.json
  4430. for(int j=1; j <= gunTotalNumber; j++)
  4431. {
  4432. memset(fnametemp, 0, sizeof fnametemp);
  4433. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  4434. if((access(fnametemp,F_OK))!=-1)
  4435. {
  4436. strcpy(chargingProfiles[i], fnametemp);
  4437. i = i + 1;
  4438. }
  4439. }
  4440. ChargeProfileCount = i;
  4441. }// End connectorIsNULL is TRUE
  4442. if(ChargeProfileCount == 0)
  4443. {
  4444. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4445. goto end;
  4446. }
  4447. #if 0
  4448. fptr1 = fopen(fname, "r");
  4449. if (!fptr1)
  4450. {
  4451. //file not exist
  4452. DEBUG_INFO("Unable to open the input file!!\n");
  4453. fptr1 = fopen(fname, "w+");
  4454. }
  4455. fclose(fptr1);
  4456. #endif
  4457. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  4458. {
  4459. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4460. goto end;
  4461. }
  4462. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  4463. {
  4464. memset(str, 0, sizeof str);
  4465. // clear temp file
  4466. sprintf(str,"rm -f %s",temp);
  4467. system(str);
  4468. for(int k=0; k < ChargeProfileCount; k++)
  4469. {
  4470. memset(str, 0, sizeof str);
  4471. //clear file in C
  4472. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4473. system(str);
  4474. }
  4475. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4476. goto end;
  4477. }
  4478. else if(connectorIsNULL == TRUE)
  4479. {
  4480. for(int k=0; k < ChargeProfileCount; k++)
  4481. {
  4482. fptr1 = fopen(chargingProfiles[k], "r");
  4483. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  4484. //Check Charging Profile Count
  4485. while(fscanf(fptr1, "%s", word) != EOF)
  4486. {
  4487. //DEBUG_INFO("word=%s\n",word);
  4488. if(strstr(word, "chargingProfileId")!= NULL)
  4489. {
  4490. //DEBUG_INFO("test chargingProfileId \n");
  4491. n_chargingProfile = n_chargingProfile + 1;
  4492. //DEBUG_INFO("chargingProfileId Found\n");
  4493. }
  4494. }
  4495. rewind(fptr1);
  4496. //search Charging Profile Element
  4497. //int i= 0;
  4498. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4499. {
  4500. //------------------------tempconnectorIdInt------------------------//
  4501. loc = strstr(sLineWord, "connectorId");
  4502. c = 0;
  4503. memset(sstr ,0, sizeof(sstr) );
  4504. while (loc[strlen("connectorId")+2+c] != ',')
  4505. {
  4506. sstr[c] = loc[strlen("connectorId")+2+c];
  4507. c++;
  4508. }
  4509. sstr[c] = '\0';
  4510. tempconnectorIdInt = atoi(sstr);
  4511. printf("file's gun number is %d\n", tempconnectorIdInt);
  4512. //--------------------------chargingProfileId--------------------//
  4513. c = 0;
  4514. loc = strstr(sLineWord, "chargingProfileId");
  4515. memset(sstr ,0, sizeof(sstr) );
  4516. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4517. {
  4518. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4520. c++;
  4521. }
  4522. sstr[c] = '\0';
  4523. tempchargingProfileIdInt = atoi(sstr);
  4524. //stackLevel
  4525. c = 0;
  4526. loc = strstr(sLineWord, "stackLevel");
  4527. memset(sstr ,0, sizeof(sstr) );
  4528. while (loc[strlen("stackLevel")+2+c] != ',')
  4529. {
  4530. sstr[c] = loc[strlen("stackLevel")+2+c];
  4531. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4532. c++;
  4533. }
  4534. sstr[c] = '\0';
  4535. tempstackLevelInt = atoi(sstr);
  4536. c = 0;
  4537. loc = strstr(sLineWord, "chargingProfilePurpose");
  4538. memset(sstr ,0, sizeof(sstr) );
  4539. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4540. {
  4541. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4542. c++;
  4543. }
  4544. sstr[c] = '\0';
  4545. strcpy(tempchargingProfilePurposeStr, sstr);
  4546. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4547. {
  4548. //------- not write to fptr2-------//
  4549. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4550. //clearflag = TRUE;
  4551. }
  4552. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4553. {
  4554. //------- not write to fptr2-------//
  4555. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4556. }
  4557. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4558. {
  4559. //------- not write to fptr2-------//
  4560. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4561. }
  4562. else
  4563. {
  4564. fprintf(fptr2, sLineWord);//writing data into file
  4565. }
  4566. memset(sLineWord, 0, sizeof sLineWord);
  4567. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4568. if(clearflag == TRUE)
  4569. {
  4570. fclose(fptr1);
  4571. fclose(fptr2);
  4572. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4573. system(str);
  4574. // clear temp file
  4575. sprintf(str,"rm -f %s",temp);
  4576. system(str);
  4577. }
  4578. else
  4579. {
  4580. fclose(fptr1);
  4581. fclose(fptr2);
  4582. memset(str, 0, sizeof str);
  4583. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4584. system(str);
  4585. resultRename = rename(temp, chargingProfiles[k]);
  4586. if(resultRename == 0)
  4587. {
  4588. DEBUG_INFO("File ChargingProfile renamed successfully");
  4589. }
  4590. else
  4591. {
  4592. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4593. }
  4594. if(comfirmstr[0]== 0)
  4595. {
  4596. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4597. }
  4598. //Check chargingProfile is empty file
  4599. /*------ Read the file ----------------*/
  4600. fptr1=fopen(chargingProfiles[k],"r");
  4601. ch=fgetc(fptr1);
  4602. rewind(fptr1);
  4603. memset(sLineWord, 0, sizeof sLineWord);
  4604. if(ch!=EOF)
  4605. {
  4606. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4607. {
  4608. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4609. if(sLineWord[0]=='\0')
  4610. {
  4611. isEmptyFile = TRUE;
  4612. break;
  4613. }
  4614. else
  4615. {
  4616. isEmptyFile = FALSE;
  4617. break;
  4618. }
  4619. }
  4620. }
  4621. fclose(fptr1);
  4622. if(isEmptyFile == TRUE)
  4623. {
  4624. memset(str, 0, sizeof str);
  4625. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4626. system(str);
  4627. }
  4628. }
  4629. }// End of while(int k=0; k < ChargePointCount; k++)
  4630. }
  4631. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4632. {
  4633. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4634. for(int k=0; k < ChargeProfileCount; k++)
  4635. {
  4636. fptr1 = fopen(chargingProfiles[k], "r");
  4637. fptr2 = fopen(temp, "w+");
  4638. //Check Charging Profile Count
  4639. while(fscanf(fptr1, "%s", word) != EOF)
  4640. {
  4641. //DEBUG_INFO("word=%s\n",word);
  4642. if(strstr(word, "chargingProfileId")!= NULL)
  4643. {
  4644. //DEBUG_INFO("test chargingProfileId \n");
  4645. n_chargingProfile = n_chargingProfile + 1;
  4646. //DEBUG_INFO("chargingProfileId Found\n");
  4647. }
  4648. }
  4649. rewind(fptr1);
  4650. //search Charging Profile Element
  4651. //int i= 0;
  4652. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4653. {
  4654. //*************************tempconnectorIdInt*********************************/
  4655. loc = strstr(sLineWord, "connectorId");
  4656. c = 0;
  4657. memset(sstr ,0, sizeof(sstr) );
  4658. while (loc[strlen("connectorId")+2+c] != ',')
  4659. {
  4660. sstr[c] = loc[strlen("connectorId")+2+c];
  4661. c++;
  4662. }
  4663. sstr[c] = '\0';
  4664. tempconnectorIdInt = atoi(sstr);
  4665. //chargingProfileId
  4666. c = 0;
  4667. loc = strstr(sLineWord, "chargingProfileId");
  4668. memset(sstr ,0, sizeof(sstr) );
  4669. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4670. {
  4671. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4672. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4673. c++;
  4674. }
  4675. sstr[c] = '\0';
  4676. tempchargingProfileIdInt = atoi(sstr);
  4677. //stackLevel
  4678. c = 0;
  4679. loc = strstr(sLineWord, "stackLevel");
  4680. memset(sstr ,0, sizeof(sstr) );
  4681. while (loc[strlen("stackLevel")+2+c] != ',')
  4682. {
  4683. sstr[c] = loc[strlen("stackLevel")+2+c];
  4684. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4685. c++;
  4686. }
  4687. sstr[c] = '\0';
  4688. tempstackLevelInt = atoi(sstr);
  4689. c = 0;
  4690. loc = strstr(sLineWord, "chargingProfilePurpose");
  4691. memset(sstr ,0, sizeof(sstr) );
  4692. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4693. {
  4694. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4695. c++;
  4696. }
  4697. sstr[c] = '\0';
  4698. strcpy(tempchargingProfilePurposeStr, sstr);
  4699. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4700. {
  4701. //------- not write to fptr2-------//
  4702. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4703. //clearflag = TRUE;
  4704. }
  4705. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4706. {
  4707. //------- not write to fptr2-------//
  4708. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4709. }
  4710. else if(stackLevelIsNULL == TRUE)
  4711. {
  4712. //Clear Whole File
  4713. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4714. clearflag = TRUE;
  4715. break;
  4716. }
  4717. else
  4718. {
  4719. fprintf(fptr2, sLineWord);//writing data into file
  4720. }
  4721. memset(sLineWord, 0, sizeof sLineWord);
  4722. }
  4723. if(clearflag == TRUE)
  4724. {
  4725. fclose(fptr1);
  4726. fclose(fptr2);
  4727. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4728. system(str);
  4729. // clear temp file
  4730. sprintf(str,"rm -f %s",temp);
  4731. system(str);
  4732. }
  4733. else
  4734. {
  4735. fclose(fptr1);
  4736. fclose(fptr2);
  4737. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4738. system(str);
  4739. resultRename = rename(temp, chargingProfiles[k]);
  4740. if(resultRename == 0)
  4741. {
  4742. DEBUG_INFO("File ChargingProfile renamed successfully");
  4743. }
  4744. else
  4745. {
  4746. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4747. }
  4748. if(comfirmstr[0]== 0)
  4749. {
  4750. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4751. }
  4752. //Check chargingProfile is empty file
  4753. /*------ Read the file ----------------*/
  4754. fptr1=fopen(chargingProfiles[k],"r");
  4755. ch=fgetc(fptr1);
  4756. rewind(fptr1);
  4757. memset(sLineWord, 0, sizeof sLineWord);
  4758. if(ch!=EOF)
  4759. {
  4760. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4761. {
  4762. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4763. if(sLineWord[0]=='\0')
  4764. {
  4765. isEmptyFile = TRUE;
  4766. break;
  4767. }
  4768. else
  4769. {
  4770. isEmptyFile = FALSE;
  4771. break;
  4772. }
  4773. }
  4774. }
  4775. fclose(fptr1);
  4776. if(isEmptyFile == TRUE)
  4777. {
  4778. memset(str, 0, sizeof str);
  4779. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4780. system(str);
  4781. }
  4782. /*------- End of reading ---------------*/
  4783. }
  4784. } // while(int k=0; k < ChargeProfileCount; k++)
  4785. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4786. end:
  4787. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4788. return result;
  4789. }
  4790. int handleDataTransferRequest(char *uuid, char *payload)
  4791. {
  4792. mtrace();
  4793. int result = FAIL;
  4794. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4795. char tempvendorId[255]={0};
  4796. char tempmessageId[50]={0};
  4797. char tempdata[50]={0};
  4798. char sstr[160]={0};//sstr[200]={ 0 };
  4799. char message[80]={0};
  4800. int c = 0;
  4801. char *loc;
  4802. DEBUG_INFO("handle DataTransferRequest\n");
  4803. if((uuid != NULL) && (payload != NULL))
  4804. {
  4805. //===============================
  4806. // vendorId
  4807. //===============================
  4808. c = 0;
  4809. loc = strstr(payload, "vendorId");
  4810. while (loc[strlen("vendorId")+3+c] != '\"')
  4811. {
  4812. sstr[c] = loc[strlen("vendorId")+3+c];
  4813. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4814. c++;
  4815. }
  4816. sstr[c] = '\0';
  4817. strcpy(tempvendorId,sstr);
  4818. //===============================
  4819. // messageId
  4820. //===============================
  4821. memset(sstr ,0, sizeof(sstr) );
  4822. c = 0;
  4823. loc = strstr(payload, "messageId");
  4824. while (loc[strlen("messageId")+3+c] != '\"')
  4825. {
  4826. sstr[c] = loc[strlen("messageId")+3+c];
  4827. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4828. c++;
  4829. }
  4830. sstr[c] = '\0';
  4831. strcpy(tempmessageId,sstr);
  4832. //===============================
  4833. // data
  4834. //===============================
  4835. memset(sstr ,0, sizeof(sstr) );
  4836. c = 0;
  4837. loc = strstr(payload, "data");
  4838. printf("loc=%s\n",loc);
  4839. while (loc[strlen("data")+3+c] != '\"')
  4840. {
  4841. sstr[c] = loc[strlen("data")+3+c];
  4842. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4843. c++;
  4844. }
  4845. sstr[c] = '\0';
  4846. strcpy(tempdata,sstr);
  4847. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4848. }
  4849. else
  4850. {
  4851. char guid[37]={0};
  4852. random_uuid(guid);
  4853. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4854. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4855. }
  4856. LWS_Send(message);
  4857. return result;
  4858. }
  4859. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4860. {
  4861. mtrace();
  4862. int result = FAIL;
  4863. int connectorIdInt, durationInt;
  4864. char chargingRateUnitStr[4]={0};
  4865. //int tempconnectorIdInt,
  4866. int tempdurationInt;
  4867. float tempminChargingRateFloat = 0.0;
  4868. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4869. int tempStartPeriodInt=0;
  4870. float tempLimitInt=0.0;//0.1;
  4871. int tempNumberPhasesInt=0;
  4872. char fname[200];
  4873. char comfirmstr[20];
  4874. //float totallimit =0.0;
  4875. float MinChargingRate =0.0;
  4876. //double diff_t;
  4877. //struct tm tp;
  4878. FILE *fptr1;
  4879. int c = 0;
  4880. //int i = 0;
  4881. char * pch;
  4882. char *loc;
  4883. char sstr[200]={ 0 },sstrtemp[50]={ 0 };
  4884. int n_chargingProfile = 0;
  4885. int n_SchedulePeriods = 0;
  4886. char SchedulePeriodList[10][200]={0};
  4887. char sLineWord[1600]={0};
  4888. //int n_periods = 0;
  4889. char word[1000]={0};
  4890. int confirmPeriods = 0;
  4891. struct StructProfile ChargePointMaxProfile;
  4892. struct StructProfile TxDefaultProfile;
  4893. struct StructProfile TxProfile;
  4894. struct StructProfile TxDefaultProfiletemp[2]={0};
  4895. int TxDefaultProfileFileIsNull=FALSE;
  4896. int ChargePointMaxProfileIsNull=FALSE;
  4897. int TxProfileIsNull=FALSE;
  4898. int CompositeSceduleIndex = 0;
  4899. char ChargePointMaxProfileScheduleStr[30]={0};
  4900. char TxDefaultProfileScheduleStr[30]={0};
  4901. char TxProfileScheduleStr[30]={0};
  4902. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4903. strcpy(sstrtemp, stringtrimspace(payload));
  4904. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4905. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4906. memset(&TxProfile,0,sizeof(struct StructProfile));
  4907. c=0;
  4908. loc = strstr(sstrtemp, "connectorId");
  4909. memset(sstr ,0, sizeof(sstr) );
  4910. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4911. {
  4912. sstr[c] = loc[strlen("connectorId")+2+c];
  4913. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4914. c++;
  4915. }
  4916. sstr[c] = '\0';
  4917. connectorIdInt = atoi(sstr);
  4918. c=0;
  4919. loc = strstr(sstrtemp, "duration");
  4920. memset(sstr ,0, sizeof(sstr) );
  4921. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4922. {
  4923. sstr[c] = loc[strlen("duration")+2+c];
  4924. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4925. c++;
  4926. }
  4927. sstr[c] = '\0';
  4928. durationInt = atoi(sstr);
  4929. c = 0;
  4930. loc = strstr(sstrtemp, "chargingRateUnit");
  4931. memset(sstr ,0, sizeof(sstr) );
  4932. if(loc == NULL)
  4933. {
  4934. }
  4935. else
  4936. {
  4937. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4938. {
  4939. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4940. c++;
  4941. }
  4942. sstr[c] = '\0';
  4943. strcpy(chargingRateUnitStr, sstr);
  4944. }
  4945. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4946. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4947. if(connectorIdInt==0) // connectorId is 0
  4948. {
  4949. //******************************ChargePointMaxProfile*****************************************************/
  4950. strcpy(fname, ChargePointMaxProfile_JSON );
  4951. char word[30]={0};
  4952. char sLineWord[1060]={0};
  4953. int n_chargingProfile=0;
  4954. ChargePointMaxProfileIsNull=TRUE;
  4955. if((access(fname,F_OK))!=-1)
  4956. {
  4957. fptr1 = fopen(fname, "r");
  4958. int c;
  4959. c = fgetc(fptr1);
  4960. //DEBUG_INFO("c:%d\n",c);
  4961. rewind(fptr1);
  4962. if(c == EOF)
  4963. {
  4964. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4965. ChargePointMaxProfileIsNull=TRUE;
  4966. fclose(fptr1);
  4967. }
  4968. else
  4969. {
  4970. ChargePointMaxProfileIsNull=FALSE;
  4971. while(fscanf(fptr1, "%s", word) != EOF)
  4972. {
  4973. if(strcmp(word, "chargingProfileId") == 0)
  4974. {
  4975. n_chargingProfile = n_chargingProfile + 1;
  4976. printf("Found\n");
  4977. }
  4978. }
  4979. rewind(fptr1);
  4980. //search Charging Profile Element
  4981. int i= 0;
  4982. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4983. #if 0
  4984. /***********connectorId****************/
  4985. c = 0;
  4986. loc = strstr(sLineWord, "connectorId");
  4987. // printf("loc=%s\n",loc);
  4988. memset(sstr ,0, sizeof(sstr) );
  4989. while (loc[strlen("connectorId")+2+c] != ',')
  4990. {
  4991. sstr[c] = loc[strlen("connectorId")+2+c];
  4992. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4993. c++;
  4994. }
  4995. sstr[c] = '\0';
  4996. tempconnectorIdInt = atoi(sstr);
  4997. #endif
  4998. //***********validFrom**************/
  4999. c = 0;
  5000. loc = strstr(sLineWord, "validFrom");
  5001. //DEBUG_INFO("loc=%s\n",loc);
  5002. memset(sstr ,0, sizeof(sstr) );
  5003. if(loc != NULL)
  5004. {
  5005. while (loc[3+strlen("validFrom")+c] != '\"')
  5006. {
  5007. sstr[c] = loc[3+strlen("validFrom")+c];
  5008. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5009. c++;
  5010. }
  5011. sstr[c] = '\0';
  5012. DEBUG_INFO("validFrom=%s\n",sstr);
  5013. strcpy(tempvalidFromStr,sstr);
  5014. }
  5015. else
  5016. {
  5017. strcpy(tempvalidFromStr,"");
  5018. }
  5019. //**********startSchedule**********/
  5020. c = 0;
  5021. loc = strstr(sLineWord, "startSchedule");
  5022. //DEBUG_INFO("loc=%s\n",loc);
  5023. memset(sstr ,0, sizeof(sstr) );
  5024. if(loc != NULL)
  5025. {
  5026. while (loc[3+strlen("startSchedule")+c] != '\"')
  5027. {
  5028. sstr[c] = loc[3+strlen("startSchedule")+c];
  5029. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5030. c++;
  5031. }
  5032. sstr[c] = '\0';
  5033. strcpy(tempstartScheduleStr, sstr);
  5034. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5035. }
  5036. else
  5037. {
  5038. strcpy(tempstartScheduleStr, "");
  5039. strcpy(ChargePointMaxProfileScheduleStr, "");
  5040. }
  5041. //**********chargingRateUnit**********/
  5042. c = 0;
  5043. loc = strstr(sLineWord, "chargingRateUnit");
  5044. memset(sstr ,0, sizeof(sstr) );
  5045. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5046. {
  5047. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5048. c++;
  5049. }
  5050. sstr[c] = '\0';
  5051. strcpy(tempchargingRateUnitStr, sstr);
  5052. //**********minChargingRate*******/
  5053. c = 0;
  5054. loc = strstr(sLineWord, "minChargingRate");
  5055. //printf("loc=%s\n",loc);
  5056. if(loc != NULL)
  5057. {
  5058. memset(sstr ,0, sizeof(sstr) );
  5059. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5060. {
  5061. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5062. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5063. c++;
  5064. }
  5065. sstr[c] = '\0';
  5066. tempminChargingRateFloat = atof(sstr);
  5067. }
  5068. else
  5069. {
  5070. tempminChargingRateFloat = 0.0;
  5071. }
  5072. //
  5073. #if 0
  5074. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5075. tp.tm_isdst = -1;
  5076. time_t utc = mktime(&tp);
  5077. // current time
  5078. time_t t = time(NULL);
  5079. #endif
  5080. //diff_t = difftime(t, utc);
  5081. //parsing strings to words
  5082. i = 0;
  5083. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5084. loc = loc+3+strlen("chargingSchedulePeriod");
  5085. pch = strtok(loc ,"{");
  5086. while (pch != NULL)
  5087. {
  5088. strcpy(SchedulePeriodList[i], pch);
  5089. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5090. //printf ("%s\n",pch);
  5091. pch = strtok (NULL, "{");
  5092. i = i + 1;
  5093. }
  5094. n_SchedulePeriods = i;
  5095. for(int i=0;i<n_SchedulePeriods;i++)
  5096. {
  5097. //*************startPeriod****************/
  5098. c = 0;
  5099. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5100. memset(sstr ,0, sizeof(sstr) );
  5101. while (loc[strlen("startPeriod")+2+c] != ',')
  5102. {
  5103. sstr[c] = loc[strlen("startPeriod")+2+c];
  5104. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5105. c++;
  5106. }
  5107. sstr[c] = '\0';
  5108. tempStartPeriodInt = atoi(sstr);
  5109. //*************limit****************/
  5110. c = 0;
  5111. loc = strstr(SchedulePeriodList[i], "limit");
  5112. memset(sstr ,0, sizeof(sstr) );
  5113. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5114. {
  5115. sstr[c] = loc[strlen("limit")+2+c];
  5116. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5117. c++;
  5118. }
  5119. sstr[c] = '\0';
  5120. tempLimitInt = atof(sstr);
  5121. //*************numberPhases****************/
  5122. c = 0;
  5123. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5124. memset(sstr ,0, sizeof(sstr) );
  5125. if(loc != NULL)
  5126. {
  5127. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5128. {
  5129. sstr[c] = loc[strlen("numberPhases")+2+c];
  5130. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5131. c++;
  5132. }
  5133. sstr[c] = '\0';
  5134. tempNumberPhasesInt = atoi(sstr);
  5135. }
  5136. else
  5137. {
  5138. tempNumberPhasesInt = 0;
  5139. }
  5140. ChargePointMaxProfile.Duration = durationInt;
  5141. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5142. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5143. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5144. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5145. }
  5146. if(MinChargingRate < tempminChargingRateFloat)
  5147. MinChargingRate = tempminChargingRateFloat;
  5148. }
  5149. }// End of file ChargingProfile
  5150. } //THE END OF ACCESS ChargePointMaxProfile
  5151. //******************************TxDefaultProfile***********************************************/
  5152. strcpy(fname, TxDefaultProfile_0_JSON);
  5153. memset(word, 0, 30);
  5154. memset(sLineWord, 0, 1060);
  5155. //char word[30]={0};
  5156. //char sLineWord[1060]={0};
  5157. n_chargingProfile=0;
  5158. TxDefaultProfileFileIsNull=TRUE;
  5159. if((access(fname,F_OK))!=-1)
  5160. {
  5161. fptr1 = fopen(fname, "r");
  5162. c = 0;
  5163. c = fgetc(fptr1);
  5164. //DEBUG_INFO("c:%d\n",c);
  5165. rewind(fptr1);
  5166. if(c == EOF)
  5167. {
  5168. DEBUG_INFO("\n End of file ChargingProfile reached.");
  5169. TxDefaultProfileFileIsNull=TRUE;
  5170. fclose(fptr1);
  5171. }
  5172. else
  5173. {
  5174. TxDefaultProfileFileIsNull=FALSE;
  5175. while(fscanf(fptr1, "%s", word) != EOF)
  5176. {
  5177. if(strcmp(word, "chargingProfileId") == 0)
  5178. {
  5179. n_chargingProfile = n_chargingProfile + 1;
  5180. printf("Found\n");
  5181. }
  5182. }
  5183. rewind(fptr1);
  5184. //search Charging Profile Element
  5185. int i= 0;
  5186. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5187. #if 0
  5188. /***********connectorId****************/
  5189. c = 0;
  5190. loc = strstr(sLineWord, "connectorId");
  5191. // printf("loc=%s\n",loc);
  5192. memset(sstr ,0, sizeof(sstr) );
  5193. while (loc[strlen("connectorId")+2+c] != ',')
  5194. {
  5195. sstr[c] = loc[strlen("connectorId")+2+c];
  5196. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5197. c++;
  5198. }
  5199. sstr[c] = '\0';
  5200. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  5201. tempconnectorIdInt = atoi(sstr);
  5202. #endif
  5203. //***********validFrom**************/
  5204. c = 0;
  5205. loc = strstr(sLineWord, "validFrom");
  5206. //DEBUG_INFO("loc=%s\n",loc);
  5207. memset(sstr ,0, sizeof(sstr) );
  5208. if(loc != NULL)
  5209. {
  5210. while (loc[3+strlen("validFrom")+c] != '\"')
  5211. {
  5212. sstr[c] = loc[3+strlen("validFrom")+c];
  5213. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5214. c++;
  5215. }
  5216. sstr[c] = '\0';
  5217. DEBUG_INFO("validFrom=%s\n",sstr);
  5218. strcpy(tempvalidFromStr,sstr);
  5219. }
  5220. else
  5221. {
  5222. strcpy(tempvalidFromStr,"");
  5223. }
  5224. //**********startSchedule**********/
  5225. c = 0;
  5226. loc = strstr(sLineWord, "startSchedule");
  5227. //DEBUG_INFO("loc=%s\n",loc);
  5228. memset(sstr ,0, sizeof(sstr) );
  5229. if(loc != NULL)
  5230. {
  5231. while (loc[3+strlen("startSchedule")+c] != '\"')
  5232. {
  5233. sstr[c] = loc[3+strlen("startSchedule")+c];
  5234. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5235. c++;
  5236. }
  5237. sstr[c] = '\0';
  5238. strcpy(tempstartScheduleStr, sstr);
  5239. strcpy(TxDefaultProfileScheduleStr, sstr);
  5240. }
  5241. else
  5242. {
  5243. strcpy(tempstartScheduleStr, "");
  5244. strcpy(TxDefaultProfileScheduleStr, "");
  5245. }
  5246. //**********chargingRateUnit**********/
  5247. c = 0;
  5248. loc = strstr(sLineWord, "chargingRateUnit");
  5249. memset(sstr ,0, sizeof(sstr) );
  5250. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5251. {
  5252. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5253. c++;
  5254. }
  5255. sstr[c] = '\0';
  5256. strcpy(tempchargingRateUnitStr, sstr);
  5257. //**********minChargingRate*******/
  5258. c = 0;
  5259. loc = strstr(sLineWord, "minChargingRate");
  5260. //printf("loc=%s\n",loc);
  5261. if(loc != NULL)
  5262. {
  5263. memset(sstr ,0, sizeof(sstr) );
  5264. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5265. {
  5266. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5267. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5268. c++;
  5269. }
  5270. sstr[c] = '\0';
  5271. tempminChargingRateFloat = atof(sstr);
  5272. }
  5273. else
  5274. {
  5275. tempminChargingRateFloat = 0.0;
  5276. }
  5277. #if 0
  5278. //
  5279. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5280. tp.tm_isdst = -1;
  5281. time_t utc = mktime(&tp);
  5282. // current time
  5283. time_t t = time(NULL);
  5284. //diff_t = difftime(t, utc);
  5285. #endif
  5286. //parsing strings to words
  5287. i = 0;
  5288. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5289. loc = loc+3+strlen("chargingSchedulePeriod");
  5290. pch = strtok(loc ,"{");
  5291. while (pch != NULL)
  5292. {
  5293. strcpy(SchedulePeriodList[i], pch);
  5294. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5295. //printf ("%s\n",pch);
  5296. pch = strtok (NULL, "{");
  5297. i = i + 1;
  5298. }
  5299. n_SchedulePeriods = i;
  5300. for(int i=0;i<n_SchedulePeriods;i++)
  5301. {
  5302. //*************startPeriod****************/
  5303. c = 0;
  5304. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5305. memset(sstr ,0, sizeof(sstr) );
  5306. while (loc[strlen("startPeriod")+2+c] != ',')
  5307. {
  5308. sstr[c] = loc[strlen("startPeriod")+2+c];
  5309. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5310. c++;
  5311. }
  5312. sstr[c] = '\0';
  5313. tempStartPeriodInt = atoi(sstr);
  5314. //*************limit****************/
  5315. c = 0;
  5316. loc = strstr(SchedulePeriodList[i], "limit");
  5317. memset(sstr ,0, sizeof(sstr) );
  5318. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5319. {
  5320. sstr[c] = loc[strlen("limit")+2+c];
  5321. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5322. c++;
  5323. }
  5324. sstr[c] = '\0';
  5325. tempLimitInt = atof(sstr);
  5326. //*************numberPhases****************/
  5327. c = 0;
  5328. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5329. memset(sstr ,0, sizeof(sstr) );
  5330. if(loc != NULL)
  5331. {
  5332. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5333. {
  5334. sstr[c] = loc[strlen("numberPhases")+2+c];
  5335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5336. c++;
  5337. }
  5338. sstr[c] = '\0';
  5339. tempNumberPhasesInt = atoi(sstr);
  5340. }
  5341. else
  5342. {
  5343. tempNumberPhasesInt = 0;
  5344. }
  5345. TxDefaultProfile.Duration = durationInt;
  5346. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5347. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5348. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5349. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5350. }
  5351. if(MinChargingRate < tempminChargingRateFloat)
  5352. MinChargingRate = tempminChargingRateFloat;
  5353. }
  5354. }
  5355. }// the end of ACCESS TxDefaultProfile
  5356. //--------------------- Composite Schedule-----------------------------//
  5357. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  5358. {
  5359. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5360. struct tm tp;
  5361. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5362. tp.tm_isdst = -1;
  5363. time_t utc = mktime(&tp);
  5364. time_t t = time(NULL);
  5365. double diff_f = difftime(t, utc);
  5366. int diff_i; //= (int)diff_f;
  5367. int quotient; //= diff_i / 86400;//86400 seconds/day
  5368. int period = 0;
  5369. if(diff_f >= 0)
  5370. {
  5371. diff_i = (int)diff_f;
  5372. quotient = diff_i / 86400;
  5373. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5374. {
  5375. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5376. {
  5377. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  5378. {
  5379. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5380. }
  5381. else
  5382. {
  5383. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5384. }
  5385. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5386. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5387. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5388. period = period + 1;
  5389. }
  5390. }
  5391. }
  5392. confirmPeriods = period;
  5393. }
  5394. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  5395. {
  5396. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5397. struct tm tp;
  5398. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5399. tp.tm_isdst = -1;
  5400. time_t utc = mktime(&tp);
  5401. time_t t = time(NULL);
  5402. double diff_f = difftime(t, utc);
  5403. int diff_i; // = (int)diff_f;
  5404. int quotient; // = diff_i / 86400;//86400 seconds/day
  5405. int period = 0;
  5406. if(diff_f >= 0)
  5407. {
  5408. diff_i = (int)diff_f;
  5409. quotient = diff_i / 86400;//86400 seconds/day
  5410. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5411. {
  5412. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5413. {
  5414. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5415. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5416. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5417. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5418. period = period + 1;
  5419. }
  5420. }
  5421. }
  5422. confirmPeriods = period;
  5423. }
  5424. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  5425. {
  5426. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  5427. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  5428. {
  5429. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  5430. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  5431. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  5432. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5433. }
  5434. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  5435. }
  5436. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  5437. {
  5438. confirmPeriods = 0;
  5439. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5440. //goto end;
  5441. }
  5442. //* Define temporary variables */
  5443. struct tm *gtime;
  5444. time_t now;
  5445. char buf[28];
  5446. /* Read the current system time */
  5447. time(&now);
  5448. /* Convert the system time to GMT (now UTC) */
  5449. gtime = gmtime(&now);
  5450. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5451. // make .conf
  5452. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5453. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5454. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5455. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5456. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5457. }
  5458. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  5459. {
  5460. //*****************************ChargePointMaxProfile******************************************/
  5461. strcpy(fname, ChargePointMaxProfile_JSON);
  5462. ChargePointMaxProfileIsNull=TRUE;
  5463. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  5464. {
  5465. fptr1 = fopen(fname, "r");
  5466. int c;
  5467. c = fgetc(fptr1);
  5468. //DEBUG_INFO("c:%d\n",c);
  5469. rewind(fptr1);
  5470. if(c == EOF)
  5471. {
  5472. DEBUG_INFO("\n End of file reached.");
  5473. ChargePointMaxProfileIsNull=TRUE;
  5474. fclose(fptr1);
  5475. }
  5476. else
  5477. {
  5478. ChargePointMaxProfileIsNull=FALSE;
  5479. while(fscanf(fptr1, "%s", word) != EOF)
  5480. {
  5481. if(strcmp(word, "chargingProfileId") == 0)
  5482. {
  5483. n_chargingProfile = n_chargingProfile + 1;
  5484. }
  5485. }
  5486. rewind(fptr1);
  5487. //search Charging Profile Element
  5488. int i = 0;
  5489. int j = 0;
  5490. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5491. #if 0
  5492. /***********connectorId****************/
  5493. c = 0;
  5494. loc = strstr(sLineWord, "connectorId");
  5495. memset(sstr ,0, sizeof(sstr) );
  5496. while (loc[strlen("connectorId")+2+c] != ',')
  5497. {
  5498. sstr[c] = loc[strlen("connectorId")+2+c];
  5499. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5500. c++;
  5501. }
  5502. sstr[c] = '\0';
  5503. tempconnectorIdInt = atoi(sstr);
  5504. #endif
  5505. //***********validFrom**************/
  5506. c = 0;
  5507. loc = strstr(sLineWord, "validFrom");
  5508. if(loc != NULL)
  5509. {
  5510. memset(sstr ,0, sizeof(sstr) );
  5511. while (loc[3+strlen("validFrom")+c] != '\"')
  5512. {
  5513. sstr[c] = loc[3+strlen("validFrom")+c];
  5514. c++;
  5515. }
  5516. sstr[c] = '\0';
  5517. strcpy(tempvalidFromStr,sstr);
  5518. }
  5519. else
  5520. {
  5521. strcpy(tempvalidFromStr,"");
  5522. }
  5523. //***********validFrom**************/
  5524. c = 0;
  5525. loc = strstr(sLineWord, "duration");
  5526. if(loc != NULL)
  5527. {
  5528. memset(sstr ,0, sizeof(sstr) );
  5529. while (loc[2+strlen("duration")+c] != ',')
  5530. {
  5531. sstr[c] = loc[2+strlen("duration")+c];
  5532. c++;
  5533. }
  5534. sstr[c] = '\0';
  5535. tempdurationInt = atoi(sstr);
  5536. }
  5537. else
  5538. {
  5539. tempdurationInt = 0;
  5540. }
  5541. //**********startSchedule**********/
  5542. c = 0;
  5543. loc = strstr(sLineWord, "startSchedule");
  5544. memset(sstr ,0, sizeof(sstr) );
  5545. if(loc != NULL)
  5546. {
  5547. while (loc[3+strlen("startSchedule")+c] != '\"')
  5548. {
  5549. sstr[c] = loc[3+strlen("startSchedule")+c];
  5550. c++;
  5551. }
  5552. sstr[c] = '\0';
  5553. strcpy(tempstartScheduleStr, sstr);
  5554. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5555. }
  5556. else
  5557. {
  5558. strcpy(tempstartScheduleStr, "");
  5559. strcpy(ChargePointMaxProfileScheduleStr, "");
  5560. }
  5561. //**********chargingRateUnit**********/
  5562. c = 0;
  5563. loc = strstr(sLineWord, "chargingRateUnit");
  5564. memset(sstr ,0, sizeof(sstr) );
  5565. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5566. {
  5567. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5568. c++;
  5569. }
  5570. sstr[c] = '\0';
  5571. strcpy(tempchargingRateUnitStr, sstr);
  5572. //**********minChargingRate*******/
  5573. c = 0;
  5574. loc = strstr(sLineWord, "minChargingRate");
  5575. if(loc != NULL)
  5576. {
  5577. memset(sstr ,0, sizeof(sstr) );
  5578. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5579. {
  5580. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5581. c++;
  5582. }
  5583. sstr[c] = '\0';
  5584. tempminChargingRateFloat = atof(sstr);
  5585. }
  5586. else
  5587. {
  5588. tempminChargingRateFloat = 0.0;
  5589. }
  5590. #if 0
  5591. //
  5592. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5593. tp.tm_isdst = -1;
  5594. time_t utc = mktime(&tp);
  5595. time_t t = time(NULL);
  5596. //diff_t = difftime(t, utc);
  5597. #endif
  5598. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5599. //DEBUG_INFO(" debug 5 -1\n");
  5600. //parsing strings to words
  5601. i = 0;
  5602. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5603. loc = loc+3+strlen("chargingSchedulePeriod");
  5604. pch = strtok(loc ,"{");
  5605. while (pch != NULL)
  5606. {
  5607. strcpy(SchedulePeriodList[i], pch);
  5608. pch = strtok (NULL, "{");
  5609. i = i + 1;
  5610. }
  5611. n_SchedulePeriods = i;
  5612. for(int i=0;i<n_SchedulePeriods;i++)
  5613. {
  5614. //*************startPeriod****************/
  5615. c = 0;
  5616. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5617. memset(sstr ,0, sizeof(sstr) );
  5618. while (loc[strlen("startPeriod")+2+c] != ',')
  5619. {
  5620. sstr[c] = loc[strlen("startPeriod")+2+c];
  5621. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5622. c++;
  5623. }
  5624. sstr[c] = '\0';
  5625. tempStartPeriodInt = atoi(sstr);
  5626. //*************limit****************/
  5627. c = 0;
  5628. loc = strstr(SchedulePeriodList[i], "limit");
  5629. memset(sstr ,0, sizeof(sstr) );
  5630. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5631. {
  5632. sstr[c] = loc[strlen("limit")+2+c];
  5633. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5634. c++;
  5635. }
  5636. sstr[c] = '\0';
  5637. tempLimitInt = atof(sstr);
  5638. //*************numberPhases****************/
  5639. c = 0;
  5640. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5641. memset(sstr ,0, sizeof(sstr) );
  5642. if(loc != NULL)
  5643. {
  5644. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5645. {
  5646. sstr[c] = loc[strlen("numberPhases")+2+c];
  5647. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5648. c++;
  5649. }
  5650. sstr[c] = '\0';
  5651. tempNumberPhasesInt = atoi(sstr);
  5652. }
  5653. else
  5654. {
  5655. tempNumberPhasesInt = 0;
  5656. }
  5657. if(j == 0)
  5658. {
  5659. ChargePointMaxProfile.Duration = tempdurationInt;
  5660. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5661. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5662. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5663. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5664. }
  5665. }
  5666. if(MinChargingRate < tempminChargingRateFloat)
  5667. {
  5668. MinChargingRate = tempminChargingRateFloat;
  5669. }
  5670. if(confirmPeriods < n_SchedulePeriods)
  5671. {
  5672. confirmPeriods = n_SchedulePeriods;
  5673. }
  5674. j = j + 1;
  5675. }
  5676. fclose(fptr1);
  5677. }
  5678. }// the end of access file ChargePointMaxProfile
  5679. //****************************TxDefaultProfile************************************************/
  5680. memset(fname, 0, sizeof fname);
  5681. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5682. TxDefaultProfileFileIsNull=TRUE;
  5683. if((access(fname,F_OK))!=-1)
  5684. {
  5685. fptr1 = fopen(fname, "r");
  5686. c = 0;
  5687. c = fgetc(fptr1);
  5688. //DEBUG_INFO("c:%d\n",c);
  5689. rewind(fptr1);
  5690. if(c == EOF)
  5691. {
  5692. DEBUG_INFO("\n End of file reached.");
  5693. TxDefaultProfileFileIsNull=TRUE;
  5694. fclose(fptr1);
  5695. }
  5696. else
  5697. {
  5698. TxDefaultProfileFileIsNull=FALSE;
  5699. while(fscanf(fptr1, "%s", word) != EOF)
  5700. {
  5701. if(strcmp(word, "chargingProfileId") == 0)
  5702. {
  5703. n_chargingProfile = n_chargingProfile + 1;
  5704. }
  5705. }
  5706. rewind(fptr1);
  5707. //search Charging Profile Element
  5708. int i = 0;
  5709. int j = 0;
  5710. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5711. //DEBUG_INFO(" 1-1\n");
  5712. #if 0
  5713. /***********connectorId****************/
  5714. c = 0;
  5715. loc = strstr(sLineWord, "connectorId");
  5716. memset(sstr ,0, sizeof(sstr) );
  5717. while (loc[strlen("connectorId")+2+c] != ',')
  5718. {
  5719. sstr[c] = loc[strlen("connectorId")+2+c];
  5720. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5721. c++;
  5722. }
  5723. sstr[c] = '\0';
  5724. tempconnectorIdInt = atoi(sstr);
  5725. #endif
  5726. //***********validFrom**************/
  5727. c = 0;
  5728. loc = strstr(sLineWord, "validFrom");
  5729. if(loc != NULL)
  5730. {
  5731. memset(sstr ,0, sizeof(sstr) );
  5732. while (loc[3+strlen("validFrom")+c] != '\"')
  5733. {
  5734. sstr[c] = loc[3+strlen("validFrom")+c];
  5735. c++;
  5736. }
  5737. sstr[c] = '\0';
  5738. strcpy(tempvalidFromStr,sstr);
  5739. }
  5740. else
  5741. {
  5742. strcpy(tempvalidFromStr,"");
  5743. }
  5744. //***********duration**************/
  5745. c = 0;
  5746. loc = strstr(sLineWord, "duration");
  5747. if(loc != NULL)
  5748. {
  5749. memset(sstr ,0, sizeof(sstr) );
  5750. while (loc[2+strlen("duration")+c] != ',')
  5751. {
  5752. sstr[c] = loc[2+strlen("duration")+c];
  5753. c++;
  5754. }
  5755. sstr[c] = '\0';
  5756. tempdurationInt = atoi(sstr);
  5757. }
  5758. else
  5759. {
  5760. tempdurationInt = 0;
  5761. }
  5762. //**********startSchedule**********/
  5763. c = 0;
  5764. loc = strstr(sLineWord, "startSchedule");
  5765. memset(sstr ,0, sizeof(sstr) );
  5766. if(loc != NULL)
  5767. {
  5768. while (loc[3+strlen("startSchedule")+c] != '\"')
  5769. {
  5770. sstr[c] = loc[3+strlen("startSchedule")+c];
  5771. c++;
  5772. }
  5773. sstr[c] = '\0';
  5774. strcpy(tempstartScheduleStr, sstr);
  5775. strcpy(TxDefaultProfileScheduleStr, sstr);
  5776. }
  5777. else
  5778. {
  5779. strcpy(tempstartScheduleStr, "");
  5780. strcpy(TxDefaultProfileScheduleStr, "");
  5781. }
  5782. //**********chargingRateUnit**********/
  5783. c = 0;
  5784. loc = strstr(sLineWord, "chargingRateUnit");
  5785. memset(sstr ,0, sizeof(sstr) );
  5786. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5787. {
  5788. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5789. c++;
  5790. }
  5791. sstr[c] = '\0';
  5792. strcpy(tempchargingRateUnitStr, sstr);
  5793. //**********minChargingRate*******/
  5794. c = 0;
  5795. loc = strstr(sLineWord, "minChargingRate");
  5796. if(loc != NULL)
  5797. {
  5798. memset(sstr ,0, sizeof(sstr) );
  5799. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5800. {
  5801. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5802. c++;
  5803. }
  5804. sstr[c] = '\0';
  5805. tempminChargingRateFloat = atof(sstr);
  5806. }
  5807. else
  5808. {
  5809. tempminChargingRateFloat = 0.0;
  5810. }
  5811. #if 0
  5812. //
  5813. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5814. tp.tm_isdst = -1;
  5815. time_t utc = mktime(&tp);
  5816. time_t t = time(NULL);
  5817. //diff_t = difftime(t, utc);
  5818. #endif
  5819. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5820. //parsing strings to words
  5821. i = 0;
  5822. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5823. loc = loc+3+strlen("chargingSchedulePeriod");
  5824. pch = strtok(loc ,"{");
  5825. while (pch != NULL)
  5826. {
  5827. strcpy(SchedulePeriodList[i], pch);
  5828. pch = strtok (NULL, "{");
  5829. i = i + 1;
  5830. }
  5831. n_SchedulePeriods = i;
  5832. for(int i=0;i<n_SchedulePeriods;i++)
  5833. {
  5834. //*************startPeriod****************/
  5835. c = 0;
  5836. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5837. memset(sstr ,0, sizeof(sstr) );
  5838. while (loc[strlen("startPeriod")+2+c] != ',')
  5839. {
  5840. sstr[c] = loc[strlen("startPeriod")+2+c];
  5841. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5842. c++;
  5843. }
  5844. sstr[c] = '\0';
  5845. tempStartPeriodInt = atoi(sstr);
  5846. //*************limit****************/
  5847. c = 0;
  5848. loc = strstr(SchedulePeriodList[i], "limit");
  5849. memset(sstr ,0, sizeof(sstr) );
  5850. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5851. {
  5852. sstr[c] = loc[strlen("limit")+2+c];
  5853. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5854. c++;
  5855. }
  5856. sstr[c] = '\0';
  5857. tempLimitInt = atof(sstr);
  5858. //*************numberPhases****************/
  5859. c = 0;
  5860. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5861. memset(sstr ,0, sizeof(sstr) );
  5862. if(loc != NULL)
  5863. {
  5864. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5865. {
  5866. sstr[c] = loc[strlen("numberPhases")+2+c];
  5867. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5868. c++;
  5869. }
  5870. sstr[c] = '\0';
  5871. tempNumberPhasesInt = atoi(sstr);
  5872. }
  5873. else
  5874. {
  5875. tempNumberPhasesInt = 0;
  5876. }
  5877. if(j == 0)
  5878. {
  5879. TxDefaultProfile.Duration = tempdurationInt;
  5880. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5881. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5882. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5883. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5884. }
  5885. else
  5886. {
  5887. //other stack level charging Profile
  5888. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5889. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5890. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5891. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5892. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5893. }
  5894. }
  5895. if(MinChargingRate < tempminChargingRateFloat)
  5896. MinChargingRate = tempminChargingRateFloat;
  5897. if(confirmPeriods < n_SchedulePeriods)
  5898. confirmPeriods = n_SchedulePeriods;
  5899. j = j + 1;
  5900. //DEBUG_INFO(" 1-2\n");
  5901. }
  5902. fclose(fptr1);
  5903. //Stacking Charging Profiles
  5904. for(int l=0; l <(j-1) ;l++)
  5905. {
  5906. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5907. {
  5908. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5909. {
  5910. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5911. {
  5912. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5913. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5914. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5915. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5916. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5917. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5918. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5919. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5920. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5921. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5922. }
  5923. else
  5924. {
  5925. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5926. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5927. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5928. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5929. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5930. }
  5931. }
  5932. }
  5933. }
  5934. //end of Stacking Charging Profiles
  5935. }
  5936. }// the end of ACCESS TxDefaultProfile
  5937. //****************************TxProfile************************************************/
  5938. memset(fname, 0, sizeof fname);
  5939. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5940. TxProfileIsNull=TRUE;
  5941. if((access(fname,F_OK))!=-1)
  5942. {
  5943. fptr1 = fopen(fname, "r");
  5944. c = 0;
  5945. c = fgetc(fptr1);
  5946. //DEBUG_INFO("c:%d\n",c);
  5947. rewind(fptr1);
  5948. if(c == EOF)
  5949. {
  5950. DEBUG_INFO("\n End of file reached.");
  5951. TxProfileIsNull=TRUE;
  5952. fclose(fptr1);
  5953. }
  5954. else
  5955. {
  5956. TxProfileIsNull=FALSE;
  5957. while(fscanf(fptr1, "%s", word) != EOF)
  5958. {
  5959. if(strcmp(word, "chargingProfileId") == 0)
  5960. {
  5961. n_chargingProfile = n_chargingProfile + 1;
  5962. }
  5963. }
  5964. rewind(fptr1);
  5965. //search Charging Profile Element
  5966. int i= 0;
  5967. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5968. #if 0
  5969. /***********connectorId****************/
  5970. c = 0;
  5971. loc = strstr(sLineWord, "connectorId");
  5972. memset(sstr ,0, sizeof(sstr) );
  5973. while (loc[strlen("connectorId")+2+c] != ',')
  5974. {
  5975. sstr[c] = loc[strlen("connectorId")+2+c];
  5976. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5977. c++;
  5978. }
  5979. sstr[c] = '\0';
  5980. tempconnectorIdInt = atoi(sstr);
  5981. #endif
  5982. //***********validFrom**************/
  5983. c = 0;
  5984. loc = strstr(sLineWord, "validFrom");
  5985. if(loc != NULL)
  5986. {
  5987. memset(sstr ,0, sizeof(sstr) );
  5988. while (loc[3+strlen("validFrom")+c] != '\"')
  5989. {
  5990. sstr[c] = loc[3+strlen("validFrom")+c];
  5991. c++;
  5992. }
  5993. sstr[c] = '\0';
  5994. strcpy(tempvalidFromStr,sstr);
  5995. }
  5996. else
  5997. {
  5998. strcpy(tempvalidFromStr,"");
  5999. }
  6000. //**********startSchedule**********/
  6001. c = 0;
  6002. loc = strstr(sLineWord, "startSchedule");
  6003. memset(sstr ,0, sizeof(sstr) );
  6004. if(loc != NULL)
  6005. {
  6006. while (loc[3+strlen("startSchedule")+c] != '\"')
  6007. {
  6008. sstr[c] = loc[3+strlen("startSchedule")+c];
  6009. c++;
  6010. }
  6011. sstr[c] = '\0';
  6012. strcpy(tempstartScheduleStr, sstr);
  6013. strcpy(TxProfileScheduleStr, sstr);
  6014. }
  6015. else
  6016. {
  6017. strcpy(tempstartScheduleStr, "");
  6018. strcpy(TxProfileScheduleStr, "");
  6019. }
  6020. //**********chargingRateUnit**********/
  6021. c = 0;
  6022. loc = strstr(sLineWord, "chargingRateUnit");
  6023. memset(sstr ,0, sizeof(sstr) );
  6024. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6025. {
  6026. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6027. c++;
  6028. }
  6029. sstr[c] = '\0';
  6030. strcpy(tempchargingRateUnitStr, sstr);
  6031. //**********minChargingRate*******/
  6032. c = 0;
  6033. loc = strstr(sLineWord, "minChargingRate");
  6034. if(loc != NULL)
  6035. {
  6036. memset(sstr ,0, sizeof(sstr) );
  6037. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  6038. {
  6039. sstr[c] = loc[2+strlen("minChargingRate")+c];
  6040. c++;
  6041. }
  6042. sstr[c] = '\0';
  6043. tempminChargingRateFloat = atof(sstr);
  6044. }
  6045. else
  6046. {
  6047. tempminChargingRateFloat = 0.0;
  6048. }
  6049. #if 0
  6050. //
  6051. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6052. tp.tm_isdst = -1;
  6053. time_t utc = mktime(&tp);
  6054. time_t t = time(NULL);
  6055. //diff_t = difftime(t, utc);
  6056. #endif
  6057. //DEBUG_INFO("diff_t=%f\n",diff_t);
  6058. //parsing strings to words
  6059. i = 0;
  6060. loc = strstr(sLineWord, "chargingSchedulePeriod");
  6061. loc = loc+3+strlen("chargingSchedulePeriod");
  6062. pch = strtok(loc ,"{");
  6063. while (pch != NULL)
  6064. {
  6065. strcpy(SchedulePeriodList[i], pch);
  6066. pch = strtok (NULL, "{");
  6067. i = i + 1;
  6068. }
  6069. n_SchedulePeriods = i;
  6070. for(int i=0;i<n_SchedulePeriods;i++)
  6071. {
  6072. //*************startPeriod****************/
  6073. c = 0;
  6074. loc = strstr(SchedulePeriodList[i], "startPeriod");
  6075. memset(sstr ,0, sizeof(sstr) );
  6076. while (loc[strlen("startPeriod")+2+c] != ',')
  6077. {
  6078. sstr[c] = loc[strlen("startPeriod")+2+c];
  6079. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6080. c++;
  6081. }
  6082. sstr[c] = '\0';
  6083. tempStartPeriodInt = atoi(sstr);
  6084. //*************limit****************/
  6085. c = 0;
  6086. loc = strstr(SchedulePeriodList[i], "limit");
  6087. memset(sstr ,0, sizeof(sstr) );
  6088. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  6089. {
  6090. sstr[c] = loc[strlen("limit")+2+c];
  6091. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6092. c++;
  6093. }
  6094. sstr[c] = '\0';
  6095. tempLimitInt = atof(sstr);
  6096. //*************numberPhases****************/
  6097. c = 0;
  6098. loc = strstr(SchedulePeriodList[i], "numberPhases");
  6099. memset(sstr ,0, sizeof(sstr) );
  6100. if(loc != NULL)
  6101. {
  6102. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  6103. {
  6104. sstr[c] = loc[strlen("numberPhases")+2+c];
  6105. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6106. c++;
  6107. }
  6108. sstr[c] = '\0';
  6109. tempNumberPhasesInt = atoi(sstr);
  6110. }
  6111. else
  6112. {
  6113. tempNumberPhasesInt = 0;
  6114. }
  6115. TxProfile.Duration = durationInt;
  6116. TxProfile.TotalPeriod = n_SchedulePeriods;
  6117. TxProfile.Period[i].Limit = tempLimitInt;
  6118. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  6119. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  6120. }
  6121. if(MinChargingRate < tempminChargingRateFloat)
  6122. MinChargingRate = tempminChargingRateFloat;
  6123. if(confirmPeriods < n_SchedulePeriods)
  6124. confirmPeriods = n_SchedulePeriods;
  6125. }
  6126. fclose(fptr1);
  6127. }
  6128. }// the end of ACCESS TxProfile
  6129. //CompositeSchedule
  6130. int period=0;
  6131. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  6132. {
  6133. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  6134. struct tm tp;
  6135. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6136. tp.tm_isdst = -1;
  6137. time_t utc = mktime(&tp);
  6138. time_t t = time(NULL);
  6139. double diff_f = difftime(t, utc);
  6140. int diff_i; // = (int)diff_f;
  6141. int quotient; // = diff_i / 86400;//86400 seconds/day
  6142. //int remainder = diff_i % 86400;
  6143. for(int k=0; k < TxProfile.TotalPeriod;k++)
  6144. {
  6145. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  6146. {
  6147. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  6148. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6149. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6150. period = period + 1;
  6151. }
  6152. else
  6153. {
  6154. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  6155. {
  6156. }
  6157. else
  6158. {
  6159. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6160. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6161. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6162. period = period + 1;
  6163. }
  6164. }
  6165. }
  6166. if( diff_f >= 0)
  6167. {
  6168. diff_i = (int)diff_f;
  6169. quotient = diff_i / 86400;//86400 seconds/day
  6170. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6171. {
  6172. 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))
  6173. {
  6174. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6175. {
  6176. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6177. }
  6178. else
  6179. {
  6180. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6181. }
  6182. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6183. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  6184. period = period + 1;
  6185. }
  6186. }
  6187. // Check Last Period
  6188. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  6189. {
  6190. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6191. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  6192. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  6193. period = period + 1;
  6194. }
  6195. } // diff_f >= 0
  6196. }
  6197. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  6198. {
  6199. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6200. struct tm tp;
  6201. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6202. tp.tm_isdst = -1;
  6203. time_t utc = mktime(&tp);
  6204. time_t t = time(NULL);
  6205. double diff_f = difftime(t, utc);
  6206. int diff_i;// = (int)diff_f;
  6207. int quotient; // = diff_i / 86400;//86400 seconds/day
  6208. //int remainder = diff_i % 86400;
  6209. if(diff_f >= 0)
  6210. {
  6211. diff_i = (int)diff_f;
  6212. quotient = diff_i / 86400;//86400 seconds/day
  6213. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6214. {
  6215. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6216. {
  6217. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6218. {
  6219. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6220. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6221. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6222. period = period + 1;
  6223. }
  6224. else
  6225. {
  6226. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6227. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6228. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6229. period = period + 1;
  6230. }
  6231. }
  6232. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6233. {
  6234. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6235. {
  6236. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6237. {
  6238. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6239. {
  6240. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6241. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6242. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6243. period = period + 1;
  6244. }
  6245. else
  6246. {
  6247. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6248. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6249. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6250. period = period + 1;
  6251. }
  6252. }
  6253. }
  6254. }
  6255. }
  6256. } // end diff_f >= 0
  6257. }
  6258. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  6259. {
  6260. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6261. struct tm tp;
  6262. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6263. tp.tm_isdst = -1;
  6264. time_t utc = mktime(&tp);
  6265. time_t t = time(NULL);
  6266. double diff_f = difftime(t, utc);
  6267. int diff_i; // = (int)diff_f;
  6268. int quotient; // = diff_i / 86400;//86400 seconds/day
  6269. //int remainder = diff_i % 86400;
  6270. if(diff_f >= 0)
  6271. {
  6272. diff_i = (int)diff_f;
  6273. quotient = diff_i / 86400;//86400 seconds/day
  6274. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6275. {
  6276. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6277. {
  6278. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6279. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6280. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6281. period = period + 1;
  6282. }
  6283. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6284. {
  6285. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6286. {
  6287. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6288. {
  6289. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6290. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6291. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6292. period = period + 1;
  6293. }
  6294. }
  6295. }
  6296. }
  6297. } // diff_f >= 0
  6298. }
  6299. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  6300. {
  6301. confirmPeriods = 0;
  6302. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6303. //goto end;
  6304. }
  6305. confirmPeriods = period;
  6306. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  6307. //---- Define StartSchedule----/
  6308. struct tm *gtime;
  6309. time_t now;
  6310. char buf[28];
  6311. //---Read the current system time---/
  6312. time(&now);
  6313. //---Convert the system time to GMT (now UTC)---/
  6314. gtime = gmtime(&now);
  6315. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  6316. // make .conf
  6317. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  6318. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  6319. //DEBUG_INFO(" debug 11\n");
  6320. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  6321. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  6322. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6323. }
  6324. else
  6325. {
  6326. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6327. }
  6328. //end:
  6329. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  6330. return result;
  6331. }
  6332. int handleGetConfigurationRequest(char *uuid, char *payload)
  6333. {
  6334. mtrace();
  6335. int result = FAIL;
  6336. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  6337. //struct json_object *jsonitem;
  6338. int MaxKeySupported = 0;
  6339. int n_keys = 0;
  6340. char requestKey[43][50]={0};
  6341. char search[]="[";
  6342. char sstr[500]={ 0 },sstrtemp[60]={ 0 };
  6343. //int pos;
  6344. int l, c = 0;
  6345. int i = 0;
  6346. char *delim = "\",\"";
  6347. char * pch;
  6348. strcpy(sstrtemp, stringtrimspace(payload));
  6349. char *loc = strstr(sstrtemp, search);
  6350. //********************* Parsing String ***********************************/
  6351. if(loc == NULL) {
  6352. DEBUG_INFO("no key match in Configuration \n");
  6353. }
  6354. else {
  6355. //pos = loc - payload;
  6356. l = strlen(loc)-4;
  6357. while (c < l)
  6358. {
  6359. sstr[c] = loc[c+2];
  6360. c++;
  6361. }
  6362. sstr[c] = '\0';
  6363. //parsing strings to words
  6364. pch = strtok(sstr,delim);
  6365. if(pch == NULL)
  6366. {
  6367. strcpy(requestKey[0], sstr);
  6368. }
  6369. else
  6370. {
  6371. while (pch != NULL)
  6372. {
  6373. strcpy(requestKey[i], pch);
  6374. pch = strtok (NULL, delim);
  6375. i = i + 1;
  6376. }
  6377. n_keys = i;
  6378. }
  6379. }
  6380. UnknownKeynum = 0;
  6381. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  6382. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  6383. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6384. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6385. if(n_keys != 0)
  6386. {
  6387. for(int i=0;i<n_keys;i++)
  6388. {
  6389. getKeyValue(requestKey[i]);
  6390. //json_object_put(jsonitem);
  6391. }
  6392. }
  6393. else
  6394. {
  6395. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6396. getKeyValue("");
  6397. }
  6398. processUnkownKey();
  6399. sendGetConfigurationConfirmation(uuid);
  6400. return result;
  6401. }
  6402. static char fnamePlusPath[100]={0};
  6403. static char fnamePWithNoPath[60]={0};
  6404. void checkUploadLog(void)
  6405. {
  6406. FILE *fp;
  6407. /* Open the command for reading. */
  6408. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6409. if (fp == NULL) {
  6410. printf("Failed to run command\n" );
  6411. exit(1);
  6412. }
  6413. int ftppathlen = 0;
  6414. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6415. int i = 0;
  6416. /* Read the output a line at a time - output it. */
  6417. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6418. if(i==0)
  6419. {
  6420. ftppathlen = strlen(fnamePlusPath);
  6421. printf("%s\n", fnamePlusPath);
  6422. fnamePlusPath[ftppathlen]='\0';
  6423. break;
  6424. }
  6425. i= i+1;
  6426. }
  6427. /* close */
  6428. pclose(fp);
  6429. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6430. {
  6431. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6432. {
  6433. fnamePlusPath[k]='\0';
  6434. }
  6435. }
  6436. i=1;
  6437. //char fname[60]={0};
  6438. while(i < ftppathlen)
  6439. {
  6440. int len=ftppathlen-i;
  6441. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6442. {
  6443. printf("compare '/' all right\n");
  6444. break;
  6445. }
  6446. i=i+1;
  6447. }
  6448. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6449. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6450. fnamePWithNoPath[i+1] = '\0';
  6451. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6452. {
  6453. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6454. {
  6455. fnamePWithNoPath[j]='\0';
  6456. }
  6457. }
  6458. FILE* fp1 = fopen(fnamePlusPath, "r");
  6459. if (fp1)
  6460. {
  6461. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6462. // file exists
  6463. fclose(fp1);
  6464. }
  6465. else
  6466. {
  6467. // file doesn't exist
  6468. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6469. }
  6470. }
  6471. static char GetDiagnosticspayloadData[300]={0};
  6472. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6473. {
  6474. mtrace();
  6475. int result = FAIL;
  6476. pthread_t t; // pthread 變數
  6477. system("exec /root/logPackTools 'log' 6");
  6478. #if 0
  6479. //char buffer [128];
  6480. time (&rawtime);
  6481. //printf("%ld\n", rawtime);
  6482. timeinfo = localtime (&rawtime);
  6483. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6484. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6485. if((access(fnamePlusPath,F_OK))!=-1)
  6486. {
  6487. DEBUG_INFO("fnamePlusPath exist.\n");
  6488. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6489. }
  6490. else
  6491. {
  6492. DEBUG_INFO("fnamePlusPath not exist!\n");
  6493. }
  6494. #endif
  6495. checkUploadLog();
  6496. memset(GetDiagnosticspayloadData, 0, 300);
  6497. strcpy(GetDiagnosticspayloadData, stringtrimspace(payload));
  6498. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  6499. pthread_create(&t, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6500. return result;
  6501. }
  6502. void* GetDiagnosticsProcess(void* data)
  6503. {
  6504. pthread_detach(pthread_self());
  6505. mtrace();
  6506. int retriesInt=0, retryIntervalInt=0;
  6507. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6508. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6509. 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};
  6510. int port=0;
  6511. char sstr[260]={ 0 };//sstr[200]={ 0 };
  6512. int c = 0;
  6513. char *loc;
  6514. int isSuccess = FALSE;
  6515. char ftpbuf[200]={0};
  6516. //char temp[100]={0};
  6517. char * pch;
  6518. // [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"}]
  6519. char str[300]={ 0 };
  6520. strcpy(str,(const char*)GetDiagnosticspayloadData);
  6521. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6522. DEBUG_INFO("GetDiagnosticsProcess\n");
  6523. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6524. //****************location*******************/
  6525. c = 0;
  6526. memset(sstr ,0, sizeof(sstr) );
  6527. loc = strstr(str, "location");
  6528. while (loc[3+strlen("location")+c] != '\"')
  6529. {
  6530. sstr[c] = loc[3+strlen("location")+c];
  6531. c++;
  6532. }
  6533. sstr[c] = '\0';
  6534. strcpy(locationstr,sstr);
  6535. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6536. if(strcmp(locationstr,"")==0)
  6537. {
  6538. DEBUG_INFO("location is <Empty>!\n");
  6539. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6540. goto end;
  6541. }
  6542. //****************retries*******************/
  6543. c = 0;
  6544. loc = strstr(str, "retries");
  6545. if(loc == NULL)
  6546. {
  6547. retriesIsNULL = TRUE;
  6548. }
  6549. else
  6550. {
  6551. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6552. {
  6553. sstr[c] = loc[strlen("retries")+2+c];
  6554. c++;
  6555. }
  6556. sstr[c] = '\0';
  6557. retriesInt = atoi(sstr);
  6558. }
  6559. if(retriesIsNULL == TRUE)
  6560. {
  6561. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6562. }
  6563. //****************retryInterval*******************/
  6564. c = 0;
  6565. loc = strstr(str, "retryInterval");
  6566. if(loc == NULL)
  6567. {
  6568. retryIntervalIsNULL = TRUE;
  6569. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6570. }
  6571. else
  6572. {
  6573. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6574. {
  6575. sstr[c] = loc[strlen("retryInterval")+2+c];
  6576. c++;
  6577. }
  6578. sstr[c] = '\0';
  6579. retryIntervalInt = atoi(sstr);
  6580. }
  6581. //****************startTime*******************/
  6582. c = 0;
  6583. memset(sstr ,0, sizeof(sstr) );
  6584. loc = strstr(str, "startTime");
  6585. if(loc == NULL)
  6586. {
  6587. startTimeIsNULL = TRUE;
  6588. }
  6589. else
  6590. {
  6591. while (loc[3+strlen("startTime")+c] != '\"')
  6592. {
  6593. sstr[c] = loc[3+strlen("startTime")+c];
  6594. c++;
  6595. }
  6596. sstr[c] = '\0';
  6597. strcpy(startTimestr,sstr);
  6598. }
  6599. //****************stopTime*******************/
  6600. c = 0;
  6601. memset(sstr ,0, sizeof(sstr) );
  6602. loc = strstr(str, "stopTime");
  6603. if(loc == NULL)
  6604. {
  6605. stopTimeIsNULL = TRUE;
  6606. }
  6607. else
  6608. {
  6609. while (loc[3+strlen("stopTime")+c] != '\"')
  6610. {
  6611. sstr[c] = loc[3+strlen("stopTime")+c];
  6612. c++;
  6613. }
  6614. sstr[c] = '\0';
  6615. strcpy(stopTimestr,sstr);
  6616. }
  6617. memset(protocol, 0, sizeof(protocol));
  6618. memset(user, 0, sizeof(user) );
  6619. memset(password, 0, sizeof(password));
  6620. memset(host, 0, sizeof(host));
  6621. memset(path, 0, sizeof(path));
  6622. memset(ftppath, 0, sizeof(ftppath));
  6623. memset(host1, 0, sizeof(host1));
  6624. memset(path1, 0, sizeof(path1));
  6625. /*location: ftp://user:password@host:port/path*/
  6626. #if 0
  6627. time_t rawtime;
  6628. struct tm * timeinfo;
  6629. //char buffer [128];
  6630. time (&rawtime);
  6631. //printf("%ld\n", rawtime);
  6632. timeinfo = localtime (&rawtime);
  6633. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6634. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6635. #endif
  6636. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6637. if((access(fnamePlusPath,F_OK))!=-1)
  6638. {
  6639. DEBUG_INFO("fnamePlusPath exist.\n");
  6640. }
  6641. else
  6642. {
  6643. DEBUG_INFO("fnamePlusPath not exist!\n");
  6644. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6645. goto end;
  6646. }
  6647. pch=strchr(locationstr,'@');
  6648. if(pch==NULL)
  6649. {
  6650. sscanf(locationstr,
  6651. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6652. protocol, host, &port, path);
  6653. strcpy(user,"anonymous");
  6654. strcpy(password,"");
  6655. }
  6656. else
  6657. {
  6658. //DEBUG_INFO("pch=%s\n", pch);
  6659. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6660. protocol, user, password, host, &port, path);
  6661. }
  6662. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6663. {
  6664. DEBUG_INFO("protocol is not ftp/http ! \n");
  6665. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6666. goto end;
  6667. }
  6668. if(strncmp(locationstr,"http", 4) == 0)
  6669. {
  6670. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6671. sprintf(ftppath,"/%s", path);
  6672. do{
  6673. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6674. sleep(retryIntervalInt);
  6675. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6676. if(!isSuccess)
  6677. {
  6678. DEBUG_INFO("Diagnostics fail.\n");
  6679. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6680. }
  6681. else
  6682. {
  6683. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6684. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6685. }
  6686. }
  6687. else
  6688. {
  6689. sscanf(host,"%[^/]%s",host1, path1);
  6690. sprintf(ftppath,"%s", path1);
  6691. int ftppathlen=strlen(ftppath);
  6692. int i=1;
  6693. char filenametemp[50];
  6694. while(i < ftppathlen)
  6695. {
  6696. int len=ftppathlen-i;
  6697. if(ftppath[len]== 47) // '/' ascll code: 47
  6698. {
  6699. DEBUG_INFO("find '/' all right\n");
  6700. break;
  6701. }
  6702. i=i+1;
  6703. }
  6704. memset(filenametemp, 0, sizeof(filenametemp));
  6705. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6706. filenametemp[i+1] = 0;
  6707. memset(ftpbuf, 0, sizeof(ftpbuf));
  6708. if(port == 0)
  6709. port = 21;
  6710. do{
  6711. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6712. sleep(retryIntervalInt);
  6713. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6714. if(!isSuccess)
  6715. {
  6716. DEBUG_INFO("Diagnostics fail.\n");
  6717. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6718. }
  6719. else
  6720. {
  6721. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6722. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6723. }
  6724. }
  6725. end:
  6726. DiagnosticsStatusNotificationStatus = 0; //Idle
  6727. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6728. }
  6729. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6730. {
  6731. mtrace();
  6732. int result = FAIL;
  6733. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6734. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6735. {
  6736. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6737. localversion = -1;
  6738. }
  6739. else
  6740. {
  6741. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6742. OCPP_getListVerion();
  6743. }
  6744. //from db.OCPP_getListVerion
  6745. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6746. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6747. sendGetLocalListVersionConfirmation(uuid,"");
  6748. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6749. return result;
  6750. }
  6751. int handleRemoteStartRequest(char *uuid, char *payload)
  6752. {
  6753. mtrace();
  6754. int result = FAIL;
  6755. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6756. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6757. int tempIndex = 0;
  6758. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6759. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6760. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6761. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6762. int chargingSchedulePeriodCount = 0;
  6763. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6764. int c = 0;
  6765. char *loc;
  6766. char comfirmstr[20]={0};
  6767. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6768. if(server_pending == TRUE)
  6769. {
  6770. return 0;
  6771. }
  6772. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6773. strcpy(sstrtemp, stringtrimspace(payload));
  6774. //**********connectorId****************/
  6775. c = 0;
  6776. memset(sstr ,0, sizeof(sstr) );
  6777. loc = strstr(sstrtemp, "connectorId");
  6778. if(loc == NULL)
  6779. {
  6780. connectorIdIsNULL = TRUE;
  6781. }
  6782. else
  6783. {
  6784. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6785. {
  6786. sstr[c] = loc[strlen("connectorId")+2+c];
  6787. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6788. c++;
  6789. }
  6790. sstr[c] = '\0';
  6791. connectorIdInt = atoi(sstr);
  6792. }
  6793. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6794. {
  6795. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6796. goto end;
  6797. }
  6798. //****************idTag*******************/
  6799. c = 0;
  6800. memset(sstr ,0, sizeof(sstr) );
  6801. loc = strstr(sstrtemp, "idTag");
  6802. while (loc[3+strlen("idTag")+c] != '\"')
  6803. {
  6804. sstr[c] = loc[3+strlen("idTag")+c];
  6805. c++;
  6806. }
  6807. sstr[c] = '\0';
  6808. strcpy(idTagstr,sstr);
  6809. //****************chargingProfile*******************/
  6810. c = 0;
  6811. memset(sstr ,0, sizeof(sstr) );
  6812. loc = strstr(sstrtemp, "chargingProfile");
  6813. if(loc == NULL)
  6814. {
  6815. chargingProfileIsNULL = TRUE;
  6816. }
  6817. else
  6818. {
  6819. //****************chargingProfileId*******************/
  6820. c=0;
  6821. loc = strstr(sstrtemp, "chargingProfileId");
  6822. memset(sstr ,0, sizeof(sstr) );
  6823. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6824. {
  6825. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6826. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6827. c++;
  6828. }
  6829. sstr[c] = '\0';
  6830. chargingProfileIdInt = atoi(sstr);
  6831. //****************transactionId*******************/
  6832. loc = strstr(sstrtemp, "transactionId");
  6833. if(loc == NULL)
  6834. {
  6835. transactionIdIsNULL = TRUE;
  6836. }
  6837. else
  6838. {
  6839. c=0;
  6840. memset(sstr ,0, sizeof(sstr) );
  6841. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6842. {
  6843. sstr[c] = loc[strlen("transactionId")+2+c];
  6844. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6845. c++;
  6846. }
  6847. sstr[c] = '\0';
  6848. transactionIdInt = atoi(sstr);
  6849. }
  6850. //****************stackLevel*******************/
  6851. c=0;
  6852. loc = strstr(sstrtemp, "stackLevel");
  6853. memset(sstr ,0, sizeof(sstr) );
  6854. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6855. {
  6856. sstr[c] = loc[strlen("stackLevel")+2+c];
  6857. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6858. c++;
  6859. }
  6860. sstr[c] = '\0';
  6861. stackLevelInt = atoi(sstr);
  6862. //****************chargingProfilePurpose*******************/
  6863. c = 0;
  6864. memset(sstr ,0, sizeof(sstr) );
  6865. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6866. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6867. {
  6868. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6869. c++;
  6870. }
  6871. sstr[c] = '\0';
  6872. strcpy(chargingProfilePurposestr,sstr);
  6873. //****************chargingProfileKind*******************/
  6874. c = 0;
  6875. memset(sstr ,0, sizeof(sstr) );
  6876. loc = strstr(sstrtemp, "chargingProfileKind");
  6877. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6878. {
  6879. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6880. c++;
  6881. }
  6882. sstr[c] = '\0';
  6883. strcpy(chargingProfileKindstr,sstr);
  6884. //****************recurrencyKind*******************/
  6885. loc = strstr(sstrtemp, "recurrencyKind");
  6886. if(loc == NULL)
  6887. {
  6888. recurrencyKindIsNULL = TRUE;
  6889. }
  6890. else
  6891. {
  6892. c = 0;
  6893. memset(sstr ,0, sizeof(sstr) );
  6894. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6895. {
  6896. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6897. c++;
  6898. }
  6899. sstr[c] = '\0';
  6900. strcpy(recurrencyKindstr,sstr);
  6901. }
  6902. //****************validFrom*******************/
  6903. loc = strstr(sstrtemp, "validFrom");
  6904. if(loc == NULL)
  6905. {
  6906. validFromIsNULL = TRUE;
  6907. }
  6908. else
  6909. {
  6910. c = 0;
  6911. memset(sstr ,0, sizeof(sstr) );
  6912. while (loc[3+strlen("validFrom")+c] != '\"')
  6913. {
  6914. sstr[c] = loc[3+strlen("validFrom")+c];
  6915. c++;
  6916. }
  6917. sstr[c] = '\0';
  6918. strcpy(validFromstr,sstr);
  6919. }
  6920. //****************validTo*******************/
  6921. loc = strstr(sstrtemp, "validTo");
  6922. if(loc == NULL)
  6923. {
  6924. validToIsNULL = TRUE;
  6925. }
  6926. else
  6927. {
  6928. c = 0;
  6929. memset(sstr ,0, sizeof(sstr) );
  6930. while (loc[3+strlen("validTo")+c] != '\"')
  6931. {
  6932. sstr[c] = loc[3+strlen("validTo")+c];
  6933. c++;
  6934. }
  6935. sstr[c] = '\0';
  6936. strcpy(validTostr,sstr);
  6937. }
  6938. //****************chargingSchedule*******************/
  6939. loc = strstr(sstrtemp, "chargingSchedule");
  6940. if(loc != NULL)
  6941. {
  6942. //****************duration*******************/
  6943. loc = strstr(sstrtemp, "duration");
  6944. if(loc == NULL)
  6945. {
  6946. durationIsNULL = TRUE;
  6947. }
  6948. else
  6949. {
  6950. c=0;
  6951. memset(sstr ,0, sizeof(sstr) );
  6952. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6953. {
  6954. sstr[c] = loc[strlen("duration")+2+c];
  6955. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6956. c++;
  6957. }
  6958. sstr[c] = '\0';
  6959. durationInt = atoi(sstr);
  6960. }
  6961. //****************startSchedule******************/
  6962. loc = strstr(sstrtemp, "startSchedule");
  6963. if(loc == NULL)
  6964. {
  6965. startScheduleIsNULL = TRUE;
  6966. }
  6967. else
  6968. {
  6969. c = 0;
  6970. memset(sstr ,0, sizeof(sstr) );
  6971. while (loc[3+strlen("startSchedule")+c] != '\"')
  6972. {
  6973. sstr[c] = loc[3+strlen("startSchedule")+c];
  6974. c++;
  6975. }
  6976. sstr[c] = '\0';
  6977. strcpy(startSchedulestr,sstr);
  6978. }
  6979. //****************chargingRateUnit*******************/
  6980. c = 0;
  6981. memset(sstr ,0, sizeof(sstr) );
  6982. loc = strstr(sstrtemp, "chargingRateUnit");
  6983. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6984. {
  6985. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6986. c++;
  6987. }
  6988. sstr[c] = '\0';
  6989. strcpy(chargingRateUnitstr,sstr);
  6990. //****************minChargingRate*******************/
  6991. loc = strstr(sstrtemp, "minChargingRate");
  6992. if(loc == NULL)
  6993. {
  6994. minChargingRateIsNULL = TRUE;
  6995. }
  6996. else
  6997. {
  6998. c=0;
  6999. memset(sstr ,0, sizeof(sstr) );
  7000. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  7001. {
  7002. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7004. c++;
  7005. }
  7006. sstr[c] = '\0';
  7007. minChargingRateflaot = atof(sstr);
  7008. }
  7009. //****************chargingSchedulePeriod count*******************/
  7010. int what_len = strlen("startPeriod");
  7011. char *where = sstrtemp;
  7012. while ((where = strstr(where, "startPeriod"))) {
  7013. where += what_len;
  7014. chargingSchedulePeriodCount++;
  7015. }
  7016. where = sstrtemp;
  7017. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7018. {
  7019. //****************startPeriod*******************/
  7020. c=0;
  7021. loc = strstr(where, "startPeriod");
  7022. memset(sstr ,0, sizeof(sstr) );
  7023. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7024. {
  7025. sstr[c] = loc[strlen("startPeriod")+2+c];
  7026. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7027. c++;
  7028. }
  7029. sstr[c] = '\0';
  7030. startPeriodInt[periodNums] = atoi(sstr);
  7031. //****************limit*******************/
  7032. c=0;
  7033. loc = strstr(where, "limit");
  7034. memset(sstr ,0, sizeof(sstr) );
  7035. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7036. {
  7037. sstr[c] = loc[strlen("limit")+2+c];
  7038. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7039. c++;
  7040. }
  7041. sstr[c] = '\0';
  7042. limitflaot[periodNums] = atof(sstr);
  7043. //****************numberPhases*******************/
  7044. loc = strstr(where, "numberPhases");
  7045. if(loc == NULL)
  7046. {
  7047. numberPhasesIsNULL = TRUE;
  7048. }
  7049. else
  7050. {
  7051. c=0;
  7052. memset(sstr ,0, sizeof(sstr) );
  7053. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7054. {
  7055. sstr[c] = loc[strlen("numberPhases")+2+c];
  7056. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7057. c++;
  7058. }
  7059. sstr[c] = '\0';
  7060. numberPhasesInt[periodNums] = atoi(sstr);
  7061. }
  7062. where = loc;
  7063. } // END FOR chargingSchedulePeriodCount
  7064. }// END IF chargingSchedule
  7065. } // END chargingProfile
  7066. /*
  7067. enum _SYSTEM_STATUS
  7068. {
  7069. S_BOOTING = 0,
  7070. S_IDLE, = 1
  7071. S_AUTHORIZING, =2
  7072. S_REASSIGN_CHECK, =3
  7073. S_REASSIGN, =4
  7074. S_PRECHARGE, =5
  7075. S_PREPARING_FOR_EV, =6
  7076. S_PREPARING_FOR_EVSE, =7
  7077. S_CHARGING, =8
  7078. S_TERMINATING, =9
  7079. S_COMPLETE, =10
  7080. S_ALARM, =11
  7081. S_FAULT =12
  7082. }
  7083. */
  7084. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7085. {
  7086. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7087. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7088. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7089. //check Transaction active
  7090. if(gunType[connectorIdInt -1] == 'J')
  7091. {
  7092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7093. {
  7094. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7095. }
  7096. else
  7097. {
  7098. tempIndex = connectorIdInt -1;
  7099. }
  7100. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7101. {
  7102. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7103. {
  7104. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7105. {
  7106. //Reserved
  7107. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7108. }
  7109. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7110. {
  7111. //Reserved
  7112. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7113. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7114. goto end;
  7115. }
  7116. else
  7117. {
  7118. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7119. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7120. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7121. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7122. {
  7123. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7124. goto end;
  7125. }
  7126. }//END FOR ELSE
  7127. }
  7128. }// END FOR CHAdeMO_QUANTITY
  7129. }
  7130. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7131. {
  7132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7133. {
  7134. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7135. }
  7136. else
  7137. {
  7138. tempIndex = connectorIdInt -1;
  7139. }
  7140. for (int index = 0; index < CCS_QUANTITY; index++)
  7141. {
  7142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7143. {
  7144. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7145. {
  7146. //Reserved
  7147. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7148. }
  7149. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7150. {
  7151. //Reserved
  7152. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7153. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7154. goto end;
  7155. }
  7156. else
  7157. {
  7158. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7159. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7160. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7161. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7162. {
  7163. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7164. goto end;
  7165. }
  7166. }// END FOR ELSE
  7167. }
  7168. }// END FOR CCS_QUANTITY
  7169. }
  7170. else if(gunType[connectorIdInt -1] == 'G')
  7171. {
  7172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7173. {
  7174. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7175. }
  7176. else
  7177. {
  7178. tempIndex = connectorIdInt -1;
  7179. }
  7180. for (int index = 0; index < GB_QUANTITY; index++)
  7181. {
  7182. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7183. {
  7184. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7185. {
  7186. //Reserved
  7187. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7188. }
  7189. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7190. {
  7191. //Reserved
  7192. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7193. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7194. goto end;
  7195. }
  7196. else
  7197. {
  7198. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7200. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7201. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7202. {
  7203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7204. goto end;
  7205. }
  7206. }// END FOR ELSE
  7207. }
  7208. } // END FOR GB_QUANTITY
  7209. }
  7210. else
  7211. {
  7212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7213. {
  7214. tempIndex = 2;
  7215. }
  7216. else
  7217. {
  7218. tempIndex = connectorIdInt -1;
  7219. }
  7220. for (int index = 0; index < AC_QUANTITY; index++)
  7221. {
  7222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7223. {
  7224. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7225. {
  7226. //Reserved
  7227. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7228. }
  7229. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7230. {
  7231. //Reserved
  7232. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7233. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7234. goto end;
  7235. }
  7236. else
  7237. {
  7238. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7239. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7240. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7241. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7242. {
  7243. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7244. goto end;
  7245. }
  7246. }//END FOR ELSE
  7247. }
  7248. }// END FOR AC_QUANTITY
  7249. }
  7250. if(chargingProfileIsNULL == FALSE)
  7251. {
  7252. //ChargingProfile
  7253. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7254. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7255. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7256. if(recurrencyKindIsNULL == FALSE) //OPTION
  7257. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7258. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7259. if(transactionIdIsNULL == FALSE) // OPTION
  7260. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7261. if(validFromIsNULL == FALSE) // OPTION
  7262. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7263. if(validToIsNULL == FALSE) //OPTION
  7264. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7265. //ChargingSchedule
  7266. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7267. if(durationIsNULL == FALSE) //OPTION
  7268. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7269. if(minChargingRateIsNULL == FALSE) //OPTION
  7270. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7271. if(startScheduleIsNULL == FALSE) //OPTION
  7272. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7273. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7274. {
  7275. //ChargingSchedulePeriod
  7276. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7277. if(numberPhasesIsNULL == FALSE)
  7278. {
  7279. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7280. }
  7281. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7282. }
  7283. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7284. {
  7285. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7286. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7287. //memset idTag
  7288. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7289. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7290. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7291. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7292. }
  7293. else
  7294. {
  7295. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7296. }
  7297. }
  7298. else
  7299. {
  7300. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7301. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7302. //memset idTag
  7303. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7304. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7305. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7306. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7307. }
  7308. }
  7309. else
  7310. {
  7311. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7312. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7313. }
  7314. end:
  7315. if(connectorIdIsNULL == FALSE)
  7316. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7317. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7318. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7319. //OCPP send RemoteStartConfirmation by first.
  7320. sendRemoteStartConfirmation(uuid, comfirmstr);
  7321. return result;
  7322. }
  7323. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7324. {
  7325. mtrace();
  7326. int result = FAIL;
  7327. int match = FALSE;
  7328. int GunNO = 0;
  7329. int tempIndex = 0;
  7330. int transactionIdInt=0;
  7331. int transactionIdIsNULL= FALSE;
  7332. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7333. int c = 0;
  7334. char *loc;
  7335. char comfirmstr[20];
  7336. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7337. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7338. if(server_pending == TRUE)
  7339. {
  7340. return 0;
  7341. }
  7342. strcpy(sstrtemp, stringtrimspace(payload));
  7343. c=0;
  7344. loc = strstr(sstrtemp, "transactionId");
  7345. if(loc == NULL)
  7346. {
  7347. transactionIdIsNULL= TRUE;
  7348. }
  7349. else
  7350. {
  7351. memset(sstr ,0, sizeof(sstr) );
  7352. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7353. {
  7354. sstr[c] = loc[strlen("transactionId")+2+c];
  7355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7356. c++;
  7357. }
  7358. sstr[c] = '\0';
  7359. transactionIdInt = atoi(sstr);
  7360. }
  7361. if(transactionIdIsNULL == FALSE)
  7362. {
  7363. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7364. {
  7365. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7366. {
  7367. //check Transaction active
  7368. if(gunType[gun_index] == 'J')
  7369. {
  7370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7371. {
  7372. tempIndex = ((gun_index==2) ? 1: 0);
  7373. }
  7374. else
  7375. {
  7376. tempIndex = gun_index;
  7377. }
  7378. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7379. {
  7380. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7381. {
  7382. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7383. {
  7384. match = TRUE;
  7385. GunNO = gun_index;
  7386. }
  7387. }
  7388. }// END FOR CHAdeMO_QUANTITY
  7389. }
  7390. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7391. {
  7392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7393. {
  7394. tempIndex = ((gun_index==2) ? 1: 0);
  7395. }
  7396. else
  7397. {
  7398. tempIndex = gun_index;
  7399. }
  7400. for (int index = 0; index < CCS_QUANTITY; index++)
  7401. {
  7402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7403. {
  7404. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7405. {
  7406. match = TRUE;
  7407. GunNO = gun_index;
  7408. }
  7409. }
  7410. }// END FOR CCS_QUANTITY
  7411. }
  7412. else if(gunType[gun_index] == 'G')
  7413. {
  7414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7415. {
  7416. tempIndex = ((gun_index==2) ? 1: 0);
  7417. }
  7418. else
  7419. {
  7420. tempIndex = gun_index;
  7421. }
  7422. for (int index = 0; index < GB_QUANTITY; index++)
  7423. {
  7424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7425. {
  7426. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7427. {
  7428. match = TRUE;
  7429. GunNO = gun_index;
  7430. }
  7431. }
  7432. }// END FOR GB_QUANTITY
  7433. }
  7434. else
  7435. {
  7436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7437. {
  7438. tempIndex = 2;
  7439. }
  7440. else
  7441. {
  7442. tempIndex = gun_index;
  7443. }
  7444. for (int index = 0; index < AC_QUANTITY; index++)
  7445. {
  7446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7447. {
  7448. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7449. {
  7450. match = TRUE;
  7451. GunNO = gun_index;
  7452. }
  7453. }
  7454. }// END FOR CHAdeMO_QUANTITY
  7455. } // END FOR AC ELSE
  7456. }// CHECK IF ResponseTransactionId == transactionIdInt
  7457. }//END FOR
  7458. if( match == TRUE)
  7459. {
  7460. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7461. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7462. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7463. }
  7464. else
  7465. {
  7466. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7467. }
  7468. }
  7469. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7470. return result;
  7471. }
  7472. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7473. {
  7474. mtrace();
  7475. int result = FAIL;
  7476. int connectorIdInt=0, reservationIdInt=0;
  7477. int tempIndex = 0;
  7478. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7479. char comfirmstr[20]={0};
  7480. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7481. int c = 0;
  7482. char *loc;
  7483. //char *ptr;
  7484. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  7485. strcpy(sstrtemp, stringtrimspace(payload));
  7486. //***(1)connectorId ****/
  7487. c=0;
  7488. loc = strstr(sstrtemp, "connectorId");
  7489. memset(sstr ,0, sizeof(sstr) );
  7490. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7491. {
  7492. sstr[c] = loc[strlen("connectorId")+2+c];
  7493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7494. c++;
  7495. }
  7496. sstr[c] = '\0';
  7497. connectorIdInt = atoi(sstr);
  7498. //***(2)expiryDate ****/
  7499. loc = strstr(sstrtemp, "expiryDate");
  7500. memset(sstr ,0, sizeof(sstr) );
  7501. c = 0;
  7502. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7503. {
  7504. sstr[c] = loc[3+strlen("expiryDate")+c];
  7505. c++;
  7506. }
  7507. sstr[c] = '\0';
  7508. strcpy(expiryDatestr, sstr);
  7509. //***(3)idTag ****/
  7510. loc = strstr(sstrtemp, "idTag");
  7511. memset(sstr ,0, sizeof(sstr) );
  7512. c = 0;
  7513. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7514. {
  7515. sstr[c] = loc[3+strlen("idTag")+c];
  7516. c++;
  7517. }
  7518. sstr[c] = '\0';
  7519. strcpy(idTagstr, sstr);
  7520. //***(4)parentIdTag ****/
  7521. loc = strstr(sstrtemp, "parentIdTag");
  7522. memset(sstr ,0, sizeof(sstr) );
  7523. c = 0;
  7524. if(loc == NULL)
  7525. {
  7526. strcpy(parentIdTagstr, "");
  7527. }
  7528. else
  7529. {
  7530. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7531. {
  7532. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7533. c++;
  7534. }
  7535. sstr[c] = '\0';
  7536. strcpy(parentIdTagstr, sstr);
  7537. }
  7538. //***(5)reservationId ****/
  7539. c=0;
  7540. loc = strstr(sstrtemp, "reservationId");
  7541. memset(sstr ,0, sizeof(sstr) );
  7542. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7543. {
  7544. sstr[c] = loc[strlen("reservationId")+2+c];
  7545. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7546. c++;
  7547. }
  7548. sstr[c] = '\0';
  7549. reservationIdInt = atoi(sstr);
  7550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7551. /*
  7552. enum SYSTEM_STATUS
  7553. {
  7554. SYS_MODE_BOOTING = 0,
  7555. SYS_MODE_IDLE = 1,
  7556. SYS_MODE_AUTHORIZING = 2,
  7557. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7558. SYS_MODE_REASSIGN = 4,
  7559. SYS_MODE_PREPARING = 5,
  7560. SYS_MODE_PREPARE_FOR_EV = 6,
  7561. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7562. SYS_MODE_CHARGING = 8,
  7563. SYS_MODE_TERMINATING = 9,
  7564. SYS_MODE_COMPLETE = 10,
  7565. SYS_MODE_ALARM = 11,
  7566. SYS_MODE_FAULT = 12,
  7567. SYS_MODE_RESERVATION = 13,
  7568. SYS_MODE_BOOKING = 14,
  7569. SYS_MODE_MAINTAIN = 15,
  7570. SYS_MODE_DEBUG = 16,
  7571. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7572. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7573. SYS_MODE_UPDATE = 19
  7574. };
  7575. */
  7576. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7577. {
  7578. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7579. goto end;
  7580. }
  7581. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7582. {
  7583. //check Transaction active
  7584. if(gunType[connectorIdInt -1] == 'J')
  7585. {
  7586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7587. {
  7588. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7589. }
  7590. else
  7591. {
  7592. tempIndex = connectorIdInt -1;
  7593. }
  7594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7595. {
  7596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7597. {
  7598. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7599. {
  7600. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7601. {
  7602. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7603. {
  7604. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7606. }
  7607. 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'))
  7608. {
  7609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7610. }
  7611. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7612. {
  7613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7614. }
  7615. else
  7616. {
  7617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7618. }
  7619. }
  7620. 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
  7621. {
  7622. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7623. }
  7624. }
  7625. else
  7626. {
  7627. //replace reservation
  7628. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7630. }
  7631. }
  7632. } // END FOR CHAdeMO_QUANTITY
  7633. }
  7634. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7635. {
  7636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7637. {
  7638. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7639. }
  7640. else
  7641. {
  7642. tempIndex = connectorIdInt -1;
  7643. }
  7644. for (int index = 0; index < CCS_QUANTITY; index++)
  7645. {
  7646. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7647. {
  7648. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7649. {
  7650. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7651. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7652. {
  7653. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7654. {
  7655. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7657. }
  7658. 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'))
  7659. {
  7660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7661. }
  7662. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7663. {
  7664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7665. }
  7666. else
  7667. {
  7668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7669. }
  7670. }
  7671. 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
  7672. {
  7673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7674. }
  7675. }
  7676. else
  7677. {
  7678. //replace reservation
  7679. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7681. }
  7682. }
  7683. } // END FOR CCS_QUANTITY
  7684. }
  7685. else if(gunType[connectorIdInt -1] == 'G')
  7686. {
  7687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7688. {
  7689. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7690. }
  7691. else
  7692. {
  7693. tempIndex = connectorIdInt -1;
  7694. }
  7695. for (int index = 0; index < GB_QUANTITY; index++)
  7696. {
  7697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7698. {
  7699. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7700. {
  7701. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7702. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7703. {
  7704. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7705. {
  7706. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7708. }
  7709. 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'))
  7710. {
  7711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7712. }
  7713. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7714. {
  7715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7716. }
  7717. else
  7718. {
  7719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7720. }
  7721. }
  7722. 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
  7723. {
  7724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7725. }
  7726. }
  7727. else
  7728. {
  7729. //replace reservation
  7730. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7732. }
  7733. }
  7734. }// END FOR GB_QUANTITY
  7735. }
  7736. else
  7737. {
  7738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7739. {
  7740. tempIndex = 2;
  7741. }
  7742. else
  7743. {
  7744. tempIndex = (connectorIdInt -1);
  7745. }
  7746. for (int index = 0; index < AC_QUANTITY; index++)
  7747. {
  7748. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7749. {
  7750. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7751. {
  7752. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7753. {
  7754. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7755. {
  7756. 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))
  7757. {
  7758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7759. }
  7760. else
  7761. {
  7762. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7764. }
  7765. }
  7766. 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'))
  7767. {
  7768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7769. }
  7770. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7771. {
  7772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7773. }
  7774. else
  7775. {
  7776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7777. }
  7778. }
  7779. 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
  7780. {
  7781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7782. }
  7783. }
  7784. else
  7785. {
  7786. //replace reservation
  7787. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7789. }
  7790. }
  7791. } // END FOR AC_QUANTITY
  7792. }
  7793. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7794. }
  7795. else if(connectorIdInt == 0)
  7796. {
  7797. //check Transaction active
  7798. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7799. {
  7800. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7801. {
  7802. 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'))
  7803. {
  7804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7805. goto end;
  7806. }
  7807. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7808. {
  7809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7810. goto end;
  7811. }
  7812. 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
  7813. {
  7814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7815. goto end;
  7816. }
  7817. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7818. {
  7819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7820. goto end;
  7821. }
  7822. }
  7823. }// END FOR CHAdeMO_QUANTITY
  7824. for (int index = 0; index < CCS_QUANTITY; index++)
  7825. {
  7826. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7827. {
  7828. 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'))
  7829. {
  7830. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7831. goto end;
  7832. }
  7833. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7834. {
  7835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7836. goto end;
  7837. }
  7838. 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
  7839. {
  7840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7841. goto end;
  7842. }
  7843. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7844. {
  7845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7846. goto end;
  7847. }
  7848. }
  7849. } // END FOR CCS_QUANTITY
  7850. for (int index = 0; index < GB_QUANTITY; index++)
  7851. {
  7852. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7853. {
  7854. 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'))
  7855. {
  7856. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7857. goto end;
  7858. }
  7859. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7860. {
  7861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7862. goto end;
  7863. }
  7864. 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
  7865. {
  7866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7867. goto end;
  7868. }
  7869. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7870. {
  7871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7872. goto end;
  7873. }
  7874. }
  7875. } // END FOR GB_QUANTITY
  7876. for (int index = 0; index < AC_QUANTITY; index++)
  7877. {
  7878. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7879. {
  7880. 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'))
  7881. {
  7882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7883. goto end;
  7884. }
  7885. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7886. {
  7887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7888. goto end;
  7889. }
  7890. 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
  7891. {
  7892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7893. goto end;
  7894. }
  7895. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7896. {
  7897. 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))
  7898. {
  7899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7900. goto end;
  7901. }
  7902. }
  7903. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7904. {
  7905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7906. goto end;
  7907. }
  7908. }
  7909. }// END FOR AC_QUANTITY
  7910. //The connectorId is 0
  7911. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7913. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7914. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7915. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7916. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7917. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7918. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7919. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7920. result = TRUE;
  7921. return result;
  7922. }
  7923. else
  7924. {
  7925. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7926. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7927. }
  7928. if(strcmp(comfirmstr,"Accepted") == 0)
  7929. {
  7930. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7931. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7932. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7933. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7934. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7935. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7936. result = TRUE;
  7937. return result;
  7938. }
  7939. end:
  7940. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7941. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7942. return result;
  7943. }
  7944. int handleResetRequest(char *uuid, char *payload)
  7945. {
  7946. mtrace();
  7947. int result = FAIL;
  7948. char sstr[10]={0},sstrtemp[30]={ 0 };
  7949. char typestr[10]={0};
  7950. char comfirmstr[20]={0};
  7951. int c = 0;
  7952. char *loc;
  7953. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7954. DEBUG_INFO("handleResetRequest ...\n");
  7955. strcpy(sstrtemp, stringtrimspace(payload));
  7956. loc = strstr(sstrtemp, "type");
  7957. memset(sstr ,0, sizeof(sstr) );
  7958. c = 0;
  7959. while (loc[3+strlen("type")+c] != '\"')
  7960. {
  7961. sstr[c] = loc[3+strlen("type")+c];
  7962. c++;
  7963. }
  7964. sstr[c] = '\0';
  7965. strcpy(typestr,sstr);
  7966. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7967. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7968. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7969. {
  7970. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7971. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7972. result = TRUE;
  7973. return result;
  7974. }
  7975. else
  7976. {
  7977. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7978. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7979. goto errorend;
  7980. }
  7981. errorend:
  7982. sendResetConfirmation(uuid, comfirmstr);
  7983. return result;
  7984. }
  7985. int handleSendLocalListRequest(char *uuid, char *payload)
  7986. {
  7987. mtrace();
  7988. int result = FAIL;
  7989. int listVersionInt;
  7990. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7991. char listsearch[]="listVersion";
  7992. char updateTypesearch[]="updateType";
  7993. char localAuthorizationListsearch[]="localAuthorizationList";
  7994. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7995. char CardList[500][160]={0};
  7996. char updateTypestr[15]={0};
  7997. char idTagstr[20]={0};
  7998. char parentIdTag[20]={0};
  7999. char expiryDate[30]={0};
  8000. char idTagstatus[16]={0};
  8001. int c = 0;
  8002. int i = 0;
  8003. char *delim1 = "}";
  8004. char * pch;
  8005. char *loc;
  8006. //char *ptr;
  8007. char comfirmstr[20];
  8008. //int n_localAuthorizations = 0;
  8009. int checkState_Faulted = FALSE;
  8010. DEBUG_INFO("handleSendLocalListRequest\n");
  8011. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8012. {
  8013. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8014. goto end;
  8015. }
  8016. //check Charge Point state
  8017. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8018. {
  8019. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8020. {
  8021. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8022. }
  8023. }
  8024. for (int index = 0; index < CCS_QUANTITY; index++)
  8025. {
  8026. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8027. {
  8028. checkState_Faulted = TRUE; //OCPP Status
  8029. }
  8030. }
  8031. for (int index = 0; index < GB_QUANTITY; index++)
  8032. {
  8033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8034. {
  8035. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8036. }
  8037. }
  8038. //check Charge Point state
  8039. for (int index = 0; index < AC_QUANTITY; index++)
  8040. {
  8041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8042. {
  8043. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8044. }
  8045. }
  8046. if(checkState_Faulted == TRUE)
  8047. {
  8048. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8049. goto end;
  8050. }
  8051. //Filter payload space
  8052. strcpy(sstrtemp, stringtrimspace(payload));
  8053. //listVersion
  8054. c = 0;
  8055. loc = strstr(sstrtemp, listsearch);
  8056. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8057. {
  8058. sstr[c] = loc[strlen("listVersion")+2+c];
  8059. c++;
  8060. }
  8061. sstr[c] = '\0';
  8062. listVersionInt = atoi(sstr);
  8063. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8064. //updateType
  8065. loc = strstr(sstrtemp, updateTypesearch);
  8066. c = 0;
  8067. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8068. {
  8069. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8070. c++;
  8071. }
  8072. sstr[c] = '\0';
  8073. strcpy(updateTypestr, sstr);
  8074. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8075. //localAuthorizationList
  8076. memset(sstr ,0, sizeof(sstr) );
  8077. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8078. if(loc != NULL) // localAuthorizationList is not NULL
  8079. {
  8080. //Check UpdateType
  8081. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8082. {
  8083. //Local list full update
  8084. printf("Local list full update.\n");
  8085. OCPP_getListVerion();
  8086. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8087. {
  8088. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8089. goto end;
  8090. }
  8091. OCPP_cleanLocalList();
  8092. }
  8093. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8094. {
  8095. //Local list different update
  8096. printf("Local list different update.\n");
  8097. OCPP_getListVerion();
  8098. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8099. {
  8100. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8101. goto end;
  8102. }
  8103. }
  8104. else
  8105. {
  8106. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8107. goto end;
  8108. }
  8109. c = 0;
  8110. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8111. {
  8112. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8114. c++;
  8115. }
  8116. sstr[c] = '\0';
  8117. //DEBUG_INFO("sstr=%s\n", sstr);
  8118. //parsing strings to words
  8119. i = 0;
  8120. pch = strtok(sstr,delim1);
  8121. while (pch != NULL)
  8122. {
  8123. strcpy(CardList[i], pch);
  8124. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8125. pch = strtok (NULL, delim1);
  8126. i = i + 1;
  8127. }
  8128. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8129. //local Authorizations List Numbers
  8130. //n_localAuthorizations = i;
  8131. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8132. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8133. c= 0;
  8134. while(c < i) // i is CardList Number
  8135. {
  8136. //Search "IdToken"
  8137. memset(sstr ,0, sizeof(sstr) );
  8138. loc = strstr(CardList[c], "idTag");
  8139. int j = 0;
  8140. while (loc[3+strlen("idTag")+j] != '\"')
  8141. {
  8142. sstr[j] = loc[3+strlen("idTag")+j];
  8143. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8144. j++;
  8145. }
  8146. sstr[j] = '\0';
  8147. strcpy(idTagstr, sstr);
  8148. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8149. //Search "expiryDate"
  8150. memset(sstr ,0, sizeof(sstr) );
  8151. loc = strstr(CardList[c], "expiryDate");
  8152. j = 0;
  8153. if(loc != NULL)
  8154. {
  8155. while (loc[3+strlen("expiryDate")+j] != '\"')
  8156. {
  8157. sstr[j] = loc[3+strlen("expiryDate")+j];
  8158. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8159. j++;
  8160. }
  8161. sstr[j] = '\0';
  8162. strcpy(expiryDate, sstr);
  8163. }
  8164. else
  8165. {
  8166. strcpy(expiryDate, "");
  8167. }
  8168. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8169. //Search "parentIdTag"
  8170. memset(sstr ,0, sizeof(sstr) );
  8171. loc = strstr(CardList[c], "parentIdTag");
  8172. j = 0;
  8173. if(loc != NULL)
  8174. {
  8175. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8176. {
  8177. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8178. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8179. j++;
  8180. }
  8181. sstr[j] = '\0';
  8182. strcpy(parentIdTag, sstr);
  8183. }
  8184. else
  8185. {
  8186. strcpy(parentIdTag, "");
  8187. }
  8188. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8189. //Search "status"
  8190. memset(sstr ,0, sizeof(sstr) );
  8191. loc = strstr(CardList[c], "status");
  8192. j = 0;
  8193. while (loc[3+strlen("status")+j] != '\"')
  8194. {
  8195. sstr[j] = loc[3+strlen("status")+j];
  8196. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8197. j++;
  8198. }
  8199. sstr[j] = '\0';
  8200. strcpy(idTagstatus, sstr);
  8201. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8202. OCPP_getIdTag(idTagstr);
  8203. //OCPP_getIdTag("test"); For Test
  8204. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8205. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8206. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8207. {
  8208. //Local list full update
  8209. DEBUG_INFO("Local list full update.\n");
  8210. // update list
  8211. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8212. //DEBUG_INFO("Local list full update. 1\n");
  8213. //OCPP_get_TableAuthlocalAllData();
  8214. //DEBUG_INFO("Local list full update. 2\n");
  8215. }
  8216. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8217. {
  8218. #if 0
  8219. if(strcmp(idTagstr, idTagAuthorization) == 0)
  8220. {
  8221. //OCPP_deleteIdTag(idTagstr);
  8222. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  8223. }
  8224. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  8225. {
  8226. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  8227. }
  8228. #endif
  8229. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8230. }
  8231. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8232. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8233. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8234. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8235. c++;
  8236. }
  8237. }
  8238. else
  8239. {
  8240. //Check UpdateType
  8241. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8242. {
  8243. //Local list full update
  8244. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8245. OCPP_cleanLocalList();
  8246. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8247. goto end;
  8248. }
  8249. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8250. {
  8251. //Local list different update
  8252. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8253. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8254. goto end;
  8255. }
  8256. }
  8257. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8258. end:
  8259. sendSendLocalListConfirmation(uuid, comfirmstr);
  8260. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8261. return result;
  8262. }
  8263. #define MAX 200
  8264. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8265. {
  8266. mtrace();
  8267. int result = FAIL;
  8268. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8269. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8270. char chargingProfilePurposeStr[30]={0};
  8271. char chargingProfileKindStr[16]={0};
  8272. char recurrencyKindStr[10]={0};
  8273. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8274. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8275. int chargingSchedulePeriodCount = 0;
  8276. //int updateflag = FALSE;
  8277. char comfirmstr[20]={0};
  8278. int meet= FALSE;
  8279. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8280. int c = 0;
  8281. char *loc;
  8282. FILE *fptr1;//, *fptr2;
  8283. //int lno=0;//, linectr = 0;
  8284. //int modifyflag = FALSE;
  8285. char filename[MAX]={0};
  8286. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8287. //int resultRename=0;
  8288. char rmFileCmd[50]={0};
  8289. char tempchargingProfilePurposeStr[30]={0};
  8290. char word[1600]={0};
  8291. int n_chargingProfile = 0;
  8292. //[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}}}]
  8293. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8294. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8295. //Filter string space
  8296. strcpy(sstrtemp, stringtrimspace(payload));
  8297. //*********************connectorId***************************/
  8298. loc = strstr(sstrtemp, "connectorId");
  8299. c = 0;
  8300. memset(sstr ,0, sizeof(sstr) );
  8301. while (loc[strlen("connectorId")+2+c] != ',')
  8302. {
  8303. sstr[c] = loc[strlen("connectorId")+2+c];
  8304. c++;
  8305. }
  8306. sstr[c] = '\0';
  8307. connectorIdInt = atoi(sstr);
  8308. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8309. {
  8310. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8311. }
  8312. else
  8313. {
  8314. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8315. }
  8316. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8317. //*********************chargingProfileId***************************/
  8318. loc = strstr(sstrtemp, "chargingProfileId");
  8319. c = 0;
  8320. memset(sstr ,0, sizeof(sstr) );
  8321. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8322. {
  8323. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8324. c++;
  8325. }
  8326. sstr[c] = '\0';
  8327. chargingProfileIdInt = atoi(sstr);
  8328. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8329. {
  8330. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8331. }
  8332. else
  8333. {
  8334. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8335. }
  8336. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8337. //*********************transactionId***************************/
  8338. loc = strstr(sstrtemp, "transactionId");
  8339. if(loc != NULL)
  8340. {
  8341. c = 0;
  8342. memset(sstr ,0, sizeof(sstr) );
  8343. while (loc[strlen("transactionId")+2+c] != ',')
  8344. {
  8345. sstr[c] = loc[strlen("transactionId")+2+c];
  8346. c++;
  8347. }
  8348. sstr[c] = '\0';
  8349. transactionIdInt = atoi(sstr);
  8350. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8351. {
  8352. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8353. }
  8354. else
  8355. {
  8356. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8357. }
  8358. }
  8359. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8360. //*********************stackLevel***************************/
  8361. loc = strstr(sstrtemp, "stackLevel");
  8362. c = 0;
  8363. memset(sstr ,0, sizeof(sstr) );
  8364. while (loc[strlen("stackLevel")+2+c] != ',')
  8365. {
  8366. sstr[c] = loc[strlen("stackLevel")+2+c];
  8367. c++;
  8368. }
  8369. sstr[c] = '\0';
  8370. stackLevelInt = atoi(sstr);
  8371. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8372. {
  8373. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8374. }
  8375. else
  8376. {
  8377. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8378. }
  8379. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8380. //*********************chargingProfilePurpose***************************/
  8381. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8382. c = 0;
  8383. memset(sstr ,0, sizeof(sstr) );
  8384. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8385. {
  8386. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8387. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8388. c++;
  8389. }
  8390. sstr[c] = '\0';
  8391. strcpy(chargingProfilePurposeStr,sstr);
  8392. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8393. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8394. {
  8395. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8396. }
  8397. else
  8398. {
  8399. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8400. }
  8401. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8402. //*********************chargingProfileKind***************************/
  8403. loc = strstr(sstrtemp, "chargingProfileKind");
  8404. c = 0;
  8405. memset(sstr ,0, sizeof(sstr) );
  8406. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8407. {
  8408. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8409. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8410. c++;
  8411. }
  8412. sstr[c] = '\0';
  8413. strcpy(chargingProfileKindStr,sstr);
  8414. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8415. {
  8416. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8417. }
  8418. else
  8419. {
  8420. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8421. }
  8422. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8423. //*********************recurrencyKind***************************/
  8424. loc = strstr(sstrtemp, "recurrencyKind");
  8425. if(loc != NULL)
  8426. {
  8427. c = 0;
  8428. memset(sstr ,0, sizeof(sstr) );
  8429. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8430. {
  8431. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8432. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8433. c++;
  8434. }
  8435. sstr[c] = '\0';
  8436. strcpy(recurrencyKindStr,sstr);
  8437. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8438. {
  8439. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8440. }
  8441. else
  8442. {
  8443. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8444. }
  8445. }
  8446. else
  8447. {
  8448. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8449. {
  8450. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8451. }
  8452. else
  8453. {
  8454. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8455. }
  8456. }
  8457. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8458. //*********************validFrom***************************/
  8459. loc = strstr(sstrtemp, "validFrom");
  8460. if(loc != NULL)
  8461. {
  8462. c = 0;
  8463. memset(sstr ,0, sizeof(sstr) );
  8464. while (loc[3+strlen("validFrom")+c] != '\"')
  8465. {
  8466. sstr[c] = loc[3+strlen("validFrom")+c];
  8467. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8468. c++;
  8469. }
  8470. sstr[c] = '\0';
  8471. strcpy(validFromStr,sstr);
  8472. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8473. {
  8474. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8475. }
  8476. else
  8477. {
  8478. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8479. }
  8480. }
  8481. else
  8482. {
  8483. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8484. {
  8485. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8486. }
  8487. else
  8488. {
  8489. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8490. }
  8491. }
  8492. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8493. //*********************validTo***************************/
  8494. loc = strstr(sstrtemp, "validTo");
  8495. if(loc != NULL)
  8496. {
  8497. c = 0;
  8498. memset(sstr ,0, sizeof(sstr) );
  8499. while (loc[3+strlen("validTo")+c] != '\"')
  8500. {
  8501. sstr[c] = loc[3+strlen("validTo")+c];
  8502. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8503. c++;
  8504. }
  8505. sstr[c] = '\0';
  8506. strcpy(validToStr,sstr);
  8507. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8508. {
  8509. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8510. }
  8511. else
  8512. {
  8513. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8514. }
  8515. }
  8516. else
  8517. {
  8518. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8519. {
  8520. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8521. }
  8522. else
  8523. {
  8524. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8525. }
  8526. }
  8527. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8528. //*********************duration***************************/
  8529. loc = strstr(sstrtemp, "duration");
  8530. if(loc != NULL)
  8531. {
  8532. c = 0;
  8533. memset(sstr ,0, sizeof(sstr) );
  8534. while (loc[strlen("duration")+2+c] != ',')
  8535. {
  8536. sstr[c] = loc[strlen("duration")+2+c];
  8537. c++;
  8538. }
  8539. sstr[c] = '\0';
  8540. durationInt = atoi(sstr);
  8541. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8542. {
  8543. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8544. }
  8545. else
  8546. {
  8547. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8548. }
  8549. }
  8550. else
  8551. {
  8552. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8553. {
  8554. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8555. }
  8556. else
  8557. {
  8558. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8559. }
  8560. }
  8561. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8562. //*********************startSchedule***************************/
  8563. loc = strstr(sstrtemp, "startSchedule");
  8564. if(loc != NULL)
  8565. {
  8566. c = 0;
  8567. memset(sstr ,0, sizeof(sstr) );
  8568. while (loc[3+strlen("startSchedule")+c] != '\"')
  8569. {
  8570. sstr[c] = loc[3+strlen("startSchedule")+c];
  8571. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8572. c++;
  8573. }
  8574. sstr[c] = '\0';
  8575. strcpy(startScheduleStr,sstr);
  8576. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8577. {
  8578. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8579. }
  8580. else
  8581. {
  8582. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8583. }
  8584. }
  8585. else
  8586. {
  8587. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8588. {
  8589. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8590. }
  8591. else
  8592. {
  8593. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8594. }
  8595. }
  8596. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8597. //*********************chargingRateUnit***************************/
  8598. loc = strstr(sstrtemp, "chargingRateUnit");
  8599. if(loc != NULL)
  8600. {
  8601. c = 0;
  8602. memset(sstr ,0, sizeof(sstr) );
  8603. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8604. {
  8605. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8606. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8607. c++;
  8608. }
  8609. sstr[c] = '\0';
  8610. strcpy(chargingRateUnitStr,sstr);
  8611. #if 0
  8612. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8613. {
  8614. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8615. goto end;
  8616. }
  8617. #endif
  8618. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8619. {
  8620. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8621. }
  8622. else
  8623. {
  8624. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8625. }
  8626. }
  8627. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8628. //****************chargingSchedulePeriod count start*******************/
  8629. int what_len = strlen("startPeriod");
  8630. char tempChargingProfile[1600]={0};
  8631. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8632. char *where = tempChargingProfile;
  8633. if (what_len)
  8634. {
  8635. while ((where = strstr(where, "startPeriod"))) {
  8636. where += what_len;
  8637. chargingSchedulePeriodCount++;
  8638. }
  8639. }
  8640. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8641. {
  8642. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8643. goto end;
  8644. }
  8645. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8646. //where = payload;
  8647. int templength = 0;
  8648. //int searchstart = 0;
  8649. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8650. {
  8651. //****************startPeriod*******************/
  8652. c=0;
  8653. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8654. memset(sstr ,0, sizeof(sstr) );
  8655. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8656. {
  8657. sstr[c] = loc[strlen("startPeriod")+2+c];
  8658. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8659. c++;
  8660. }
  8661. sstr[c] = '\0';
  8662. startPeriodInt[periodNums] = atoi(sstr);
  8663. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8664. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8665. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8666. {
  8667. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8668. }
  8669. else
  8670. {
  8671. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8672. }
  8673. templength = strlen("startPeriod")+2+c;
  8674. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8675. //****************limit*******************/
  8676. c=0;
  8677. loc = strstr(tempChargingProfile + templength, "limit");
  8678. memset(sstr ,0, sizeof(sstr) );
  8679. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8680. {
  8681. sstr[c] = loc[strlen("limit")+2+c];
  8682. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8683. c++;
  8684. }
  8685. sstr[c] = '\0';
  8686. limitflaot[periodNums] = atof(sstr);
  8687. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8688. {
  8689. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8690. }
  8691. else
  8692. {
  8693. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8694. }
  8695. templength = templength + strlen("limit")+2+c;
  8696. //****************numberPhases*******************/
  8697. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8698. if(loc != NULL)
  8699. {
  8700. c=0;
  8701. memset(sstr ,0, sizeof(sstr) );
  8702. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8703. {
  8704. sstr[c] = loc[strlen("numberPhases")+2+c];
  8705. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8706. c++;
  8707. }
  8708. sstr[c] = '\0';
  8709. numberPhasesInt[periodNums] = atoi(sstr);
  8710. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8711. {
  8712. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8713. }
  8714. else
  8715. {
  8716. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8717. }
  8718. templength = templength + strlen("numberPhases")+2+c;
  8719. }
  8720. //where = loc;
  8721. }
  8722. //****************chargingSchedulePeriod count end*******************/
  8723. //*********************minChargingRate***************************/
  8724. loc = strstr(sstrtemp, "minChargingRate");
  8725. if(loc != NULL)
  8726. {
  8727. c = 0;
  8728. memset(sstr ,0, sizeof(sstr) );
  8729. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8730. {
  8731. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8732. c++;
  8733. }
  8734. sstr[c] = '\0';
  8735. minChargingRateFloat = atof(sstr);
  8736. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8737. {
  8738. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8739. }
  8740. else
  8741. {
  8742. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8743. }
  8744. }
  8745. else
  8746. {
  8747. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8748. {
  8749. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8750. }
  8751. else
  8752. {
  8753. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8754. }
  8755. }
  8756. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8757. {
  8758. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8759. if(connectorIdInt != 0)
  8760. {
  8761. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8762. goto end;
  8763. }
  8764. strcpy(filename, ChargePointMaxProfile_JSON );
  8765. fptr1 = fopen(filename, "r");
  8766. if (!fptr1)
  8767. {
  8768. //file not exist
  8769. DEBUG_INFO("Unable to open the input file!!\n");
  8770. fptr1 = fopen(filename, "w+");
  8771. }
  8772. else
  8773. {
  8774. //Check Charging Profile Count
  8775. while(fscanf(fptr1, "%s", word) != EOF)
  8776. {
  8777. //DEBUG_INFO("word=%s\n",word);
  8778. if(strstr(word, "chargingProfileId")!= NULL)
  8779. {
  8780. //DEBUG_INFO("test chargingProfileId \n");
  8781. n_chargingProfile = n_chargingProfile + 1;
  8782. //DEBUG_INFO("chargingProfileId Found\n");
  8783. }
  8784. }
  8785. }
  8786. fclose(fptr1);
  8787. }
  8788. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8789. {
  8790. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8791. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8792. {
  8793. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8794. goto end;
  8795. }
  8796. memset(filename, 0, sizeof filename);
  8797. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8798. fptr1 = fopen(filename, "r");
  8799. if (!fptr1)
  8800. {
  8801. //file not exist
  8802. //DEBUG_INFO("Unable to open the input file!!\n");
  8803. fptr1 = fopen(filename, "w+");
  8804. }
  8805. else
  8806. {
  8807. //Check Charging Profile Count
  8808. while(fscanf(fptr1, "%s", word) != EOF)
  8809. {
  8810. //DEBUG_INFO("word=%s\n",word);
  8811. if(strstr(word, "chargingProfileId")!= NULL)
  8812. {
  8813. //DEBUG_INFO("test chargingProfileId \n");
  8814. n_chargingProfile = n_chargingProfile + 1;
  8815. //DEBUG_INFO("chargingProfileId Found\n");
  8816. }
  8817. }
  8818. }
  8819. fclose(fptr1);
  8820. }
  8821. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8822. {
  8823. //printf("set chargingProfile 1-4\n");
  8824. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8825. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8826. if(connectorIdInt == 0)
  8827. {
  8828. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8829. goto end;
  8830. }
  8831. int tempIndex = 0;
  8832. //check Transaction active
  8833. if(gunType[connectorIdInt -1] == 'J')
  8834. {
  8835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8836. {
  8837. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8838. }
  8839. else
  8840. {
  8841. tempIndex = connectorIdInt -1;
  8842. }
  8843. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8844. {
  8845. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8846. {
  8847. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8848. {
  8849. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8850. {
  8851. meet = TRUE;
  8852. break;
  8853. }
  8854. }
  8855. }
  8856. }
  8857. }
  8858. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8859. {
  8860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8861. {
  8862. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8863. }
  8864. else
  8865. {
  8866. tempIndex = connectorIdInt -1;
  8867. }
  8868. for (int index = 0; index < CCS_QUANTITY; index++)
  8869. {
  8870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8871. {
  8872. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8873. {
  8874. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8875. {
  8876. meet = TRUE;
  8877. break;
  8878. }
  8879. }
  8880. }
  8881. }
  8882. }
  8883. else if(gunType[connectorIdInt -1] == 'G')
  8884. {
  8885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8886. {
  8887. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8888. }
  8889. else
  8890. {
  8891. tempIndex = connectorIdInt -1;
  8892. }
  8893. for (int index = 0; index < GB_QUANTITY; index++)
  8894. {
  8895. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8896. {
  8897. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8898. {
  8899. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8900. {
  8901. meet = TRUE;
  8902. break;
  8903. }
  8904. }
  8905. }
  8906. }
  8907. }
  8908. else
  8909. {
  8910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8911. {
  8912. tempIndex = 2;
  8913. }
  8914. else
  8915. {
  8916. tempIndex = (connectorIdInt -1);
  8917. }
  8918. for (int index = 0; index < AC_QUANTITY; index++)
  8919. {
  8920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8921. {
  8922. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8923. {
  8924. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8925. {
  8926. meet = TRUE;
  8927. break;
  8928. }
  8929. }
  8930. }
  8931. }
  8932. }
  8933. //check Transaction active
  8934. if(meet == FALSE)
  8935. {
  8936. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8937. goto end;
  8938. }
  8939. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8940. {
  8941. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8942. goto end;
  8943. }
  8944. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8945. fptr1 = fopen(filename, "r");
  8946. if (!fptr1)
  8947. {
  8948. //file not exist
  8949. DEBUG_INFO("Unable to open the input file!!\n");
  8950. fptr1 = fopen(filename, "w+");
  8951. }
  8952. else
  8953. {
  8954. //Check Charging Profile Count
  8955. while(fscanf(fptr1, "%s", word) != EOF)
  8956. {
  8957. //DEBUG_INFO("word=%s\n",word);
  8958. if(strstr(word, "chargingProfileId")!= NULL)
  8959. {
  8960. //DEBUG_INFO("test chargingProfileId \n");
  8961. n_chargingProfile = n_chargingProfile + 1;
  8962. //DEBUG_INFO("chargingProfileId Found\n");
  8963. }
  8964. }
  8965. }
  8966. fclose(fptr1);
  8967. }
  8968. // Check ChargeProfileMaxStackLevel
  8969. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8970. {
  8971. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8972. goto end;
  8973. }
  8974. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8975. {
  8976. int i = 0;
  8977. char fnametemp[200]={0};
  8978. n_chargingProfile = 0;
  8979. //Check ChargePointMaxProfile.json exit
  8980. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8981. {
  8982. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8983. //Check Charging Profile Count
  8984. while(fscanf(fptr1, "%s", word) != EOF)
  8985. {
  8986. //DEBUG_INFO("word=%s\n",word);
  8987. if(strstr(word, "chargingProfileId")!= NULL)
  8988. {
  8989. //DEBUG_INFO("test chargingProfileId \n");
  8990. n_chargingProfile = n_chargingProfile + 1;
  8991. i = i + 1;
  8992. //DEBUG_INFO("chargingProfileId Found\n");
  8993. }
  8994. memset(word, 0, sizeof word);
  8995. }
  8996. fclose(fptr1);
  8997. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8998. }
  8999. //Check TxDefaultProfile_0.json exit
  9000. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9001. {
  9002. i = 0;
  9003. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9004. //Check Charging Profile Count
  9005. while(fscanf(fptr1, "%s", word) != EOF)
  9006. {
  9007. //DEBUG_INFO("word=%s\n",word);
  9008. if(strstr(word, "chargingProfileId")!= NULL)
  9009. {
  9010. //DEBUG_INFO("test chargingProfileId \n");
  9011. n_chargingProfile = n_chargingProfile + 1;
  9012. i = i + 1;
  9013. //DEBUG_INFO("chargingProfileId Found\n");
  9014. }
  9015. memset(word, 0, sizeof word);
  9016. }
  9017. fclose(fptr1);
  9018. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9019. }
  9020. //Check TxDefaultProfile_%d.json
  9021. for(int j=1; j <= gunTotalNumber; j++)
  9022. {
  9023. memset(fnametemp, 0, sizeof fnametemp);
  9024. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9025. if((access(fnametemp,F_OK))!=-1)
  9026. {
  9027. i = 0;
  9028. fptr1 = fopen(fnametemp, "r");
  9029. //Check Charging Profile Count
  9030. while(fscanf(fptr1, "%s", word) != EOF)
  9031. {
  9032. //DEBUG_INFO("word=%s\n",word);
  9033. if(strstr(word, "chargingProfileId")!= NULL)
  9034. {
  9035. //DEBUG_INFO("test chargingProfileId \n");
  9036. n_chargingProfile = n_chargingProfile + 1;
  9037. i = i + 1;
  9038. //DEBUG_INFO("chargingProfileId Found\n");
  9039. }
  9040. memset(word, 0, sizeof word);
  9041. }
  9042. fclose(fptr1);
  9043. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9044. }
  9045. }
  9046. //Check TxProfile_%d.json
  9047. for(int j=1; j <= gunTotalNumber; j++)
  9048. {
  9049. memset(fnametemp, 0, sizeof fnametemp);
  9050. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9051. if((access(fnametemp,F_OK))!=-1)
  9052. {
  9053. i = 0;
  9054. fptr1 = fopen(fnametemp, "r");
  9055. //Check Charging Profile Count
  9056. while(fscanf(fptr1, "%s", word) != EOF)
  9057. {
  9058. //DEBUG_INFO("word=%s\n",word);
  9059. if(strstr(word, "chargingProfileId")!= NULL)
  9060. {
  9061. //DEBUG_INFO("test chargingProfileId \n");
  9062. n_chargingProfile = n_chargingProfile + 1;
  9063. i = i + 1;
  9064. //DEBUG_INFO("chargingProfileId Found\n");
  9065. }
  9066. memset(word, 0, sizeof word);
  9067. }
  9068. fclose(fptr1);
  9069. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9070. }
  9071. }
  9072. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9073. {
  9074. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9075. goto end;
  9076. }
  9077. }
  9078. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9079. //**********************************Write to File********************************************************/
  9080. FILE *infile;
  9081. FILE *outfile;
  9082. // open file for writing
  9083. infile = fopen (filename, "r");
  9084. outfile = fopen (tempfile, "w");
  9085. int d =0;
  9086. d = fgetc(infile);
  9087. //DEBUG_INFO("d:%d\n",d);
  9088. rewind(infile);
  9089. //*检测到文件结束标识返回1,否则返回0。*/
  9090. if(d == EOF)
  9091. {
  9092. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9093. fprintf(outfile,"%s\n",payload);
  9094. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9095. fclose(infile);
  9096. fclose(outfile);
  9097. sprintf(rmFileCmd,"rm -f %s",filename);
  9098. system(rmFileCmd);
  9099. rename(tempfile, filename);
  9100. sleep(1);
  9101. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9102. //system(rmFileCmd);
  9103. }
  9104. else
  9105. {
  9106. char buf[1000]={0};
  9107. int ChargingProfileAdded = FALSE;
  9108. while (fgets(buf, sizeof(buf), infile) != NULL)
  9109. {
  9110. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9111. //*************************tempconnectorIdInt*********************************/
  9112. loc = strstr(buf, "connectorId");
  9113. c = 0;
  9114. memset(sstr ,0, sizeof(sstr) );
  9115. while (loc[strlen("connectorId")+2+c] != ',')
  9116. {
  9117. sstr[c] = loc[strlen("connectorId")+2+c];
  9118. c++;
  9119. }
  9120. sstr[c] = '\0';
  9121. tempconnectorIdInt = atoi(sstr);
  9122. //*************************tempchargingProfileIdInt*********************************/
  9123. loc = strstr(buf, "chargingProfileId");
  9124. c = 0;
  9125. memset(sstr ,0, sizeof(sstr) );
  9126. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9127. {
  9128. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9129. c++;
  9130. }
  9131. sstr[c] = '\0';
  9132. tempchargingProfileIdInt = atoi(sstr);
  9133. //*************************tempstackLevelInt*********************************/
  9134. loc = strstr(buf, "stackLevel");
  9135. c = 0;
  9136. memset(sstr ,0, sizeof(sstr) );
  9137. while (loc[strlen("stackLevel")+2+c] != ',')
  9138. {
  9139. sstr[c] = loc[strlen("stackLevel")+2+c];
  9140. c++;
  9141. }
  9142. sstr[c] = '\0';
  9143. tempstackLevelInt = atoi(sstr);
  9144. //*************************tempchargingProfilePurposeStr*********************************/
  9145. loc = strstr(payload, "chargingProfilePurpose");
  9146. c = 0;
  9147. memset(sstr ,0, sizeof(sstr) );
  9148. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9149. {
  9150. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9152. c++;
  9153. }
  9154. sstr[c] = '\0';
  9155. strcpy(tempchargingProfilePurposeStr,sstr);
  9156. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9157. {
  9158. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9159. {
  9160. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9161. if(ChargingProfileAdded == FALSE)
  9162. {
  9163. fprintf(outfile,"%s\n",payload);
  9164. ChargingProfileAdded = TRUE;
  9165. }
  9166. }
  9167. else
  9168. {
  9169. if(tempstackLevelInt < stackLevelInt)
  9170. {
  9171. if(ChargingProfileAdded == FALSE)
  9172. {
  9173. fprintf(outfile,"%s\n",payload);
  9174. ChargingProfileAdded = TRUE;
  9175. fprintf(outfile,"%s\n",buf);
  9176. }
  9177. else
  9178. {
  9179. fprintf(outfile,"%s\n",buf);
  9180. }
  9181. }
  9182. else
  9183. {
  9184. if(ChargingProfileAdded == FALSE)
  9185. {
  9186. fprintf(outfile,"%s\n",buf);
  9187. fprintf(outfile,"%s\n",payload);
  9188. ChargingProfileAdded = TRUE;
  9189. }
  9190. else
  9191. {
  9192. fprintf(outfile,"%s\n",buf);
  9193. }
  9194. }
  9195. }
  9196. }
  9197. else
  9198. {
  9199. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9200. {
  9201. if(ChargingProfileAdded == FALSE)
  9202. {
  9203. fprintf(outfile,"%s\n",payload);
  9204. ChargingProfileAdded = TRUE;
  9205. fprintf(outfile,"%s\n",buf);
  9206. }
  9207. else
  9208. {
  9209. fprintf(outfile,"%s\n",buf);
  9210. }
  9211. }
  9212. else if(tempstackLevelInt < stackLevelInt)
  9213. {
  9214. if(ChargingProfileAdded == FALSE)
  9215. {
  9216. fprintf(outfile,"%s\n",payload);
  9217. ChargingProfileAdded = TRUE;
  9218. fprintf(outfile,"%s\n",buf);
  9219. }
  9220. else
  9221. {
  9222. fprintf(outfile,"%s\n",buf);
  9223. }
  9224. }
  9225. else
  9226. {
  9227. if(ChargingProfileAdded == FALSE)
  9228. {
  9229. fprintf(outfile,"%s\n",buf);
  9230. fprintf(outfile,"%s\n",payload);
  9231. ChargingProfileAdded = TRUE;
  9232. }
  9233. else
  9234. {
  9235. fprintf(outfile,"%s\n",buf);
  9236. }
  9237. }
  9238. }
  9239. } // end of while loop
  9240. fclose(infile);
  9241. fclose(outfile);
  9242. sprintf(rmFileCmd,"rm -f %s",filename);
  9243. system(rmFileCmd);
  9244. rename(tempfile, filename);
  9245. sleep(1);
  9246. result = TRUE;
  9247. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9248. }
  9249. end:
  9250. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9251. return result;
  9252. return result;
  9253. }
  9254. int handleTriggerMessageRequest(char *uuid, char *payload)
  9255. {
  9256. mtrace();
  9257. int result = FAIL;
  9258. int connectorIdIsNULL = FALSE;
  9259. int connectorIdInt =0;
  9260. char sstr[40]={0},sstrtemp[100]={ 0 };
  9261. char requestedMessagestr[40]={0};
  9262. char comfirmstr[20]={0};
  9263. int c = 0;
  9264. char *loc;
  9265. DEBUG_INFO("handleTriggerMessageRequest\n");
  9266. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9267. strcpy(sstrtemp, stringtrimspace(payload));
  9268. c = 0;
  9269. loc = strstr(sstrtemp, "requestedMessage");
  9270. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9271. {
  9272. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9273. c++;
  9274. }
  9275. sstr[c] = '\0';
  9276. strcpy(requestedMessagestr, sstr);
  9277. c = 0;
  9278. loc = strstr(sstrtemp, "connectorId");
  9279. if(loc == NULL)
  9280. {
  9281. connectorIdIsNULL = TRUE;
  9282. }
  9283. else
  9284. {
  9285. memset(sstr ,0, sizeof(sstr) );
  9286. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9287. {
  9288. sstr[c] = loc[strlen("connectorId")+2+c];
  9289. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9290. c++;
  9291. }
  9292. sstr[c] = '\0';
  9293. connectorIdInt = atoi(sstr);
  9294. }
  9295. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9296. {
  9297. //connectorIdInt = json_object_get_int(connectorId);
  9298. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9299. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9300. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9301. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9302. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9303. }
  9304. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9305. {
  9306. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9307. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9308. return TRUE;
  9309. }
  9310. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9311. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9312. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9313. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9314. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9315. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9316. {
  9317. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9318. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9319. return TRUE;
  9320. }
  9321. else
  9322. {
  9323. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9324. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9325. }
  9326. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9327. {
  9328. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  9329. {
  9330. FirmwareStatusNotificationStatus = 3;
  9331. }
  9332. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9333. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9334. }
  9335. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9336. {
  9337. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9338. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9339. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9340. }
  9341. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9342. {
  9343. sendBootNotificationRequest();
  9344. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9345. }
  9346. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9347. {
  9348. sendHeartbeatRequest(connectorIdInt);
  9349. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9350. }
  9351. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9352. {
  9353. if(connectorIdIsNULL == FALSE)
  9354. {
  9355. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9356. {
  9357. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9358. sendMeterValuesRequest(connectorIdInt -1);
  9359. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9360. }
  9361. }
  9362. else
  9363. {
  9364. for(int idx=0;idx< gunTotalNumber;idx++)
  9365. {
  9366. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9367. sendMeterValuesRequest(idx);
  9368. }
  9369. }
  9370. }
  9371. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9372. {
  9373. if(connectorIdIsNULL == FALSE)
  9374. {
  9375. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9376. {
  9377. sendStatusNotificationRequest(connectorIdInt -1);
  9378. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9379. }
  9380. }
  9381. else
  9382. {
  9383. for(int idx=0;idx< gunTotalNumber;idx++)
  9384. sendStatusNotificationRequest(idx);
  9385. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9386. }
  9387. }
  9388. return result;
  9389. }
  9390. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9391. {
  9392. mtrace();
  9393. int result = FAIL;
  9394. char sstr[6]={0},sstrtemp[50]={ 0 };
  9395. int connectorIdInt =0;
  9396. char comfirmstr[20]={0};
  9397. int c = 0;
  9398. int tempIndex = 0;
  9399. char *loc;
  9400. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9401. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9402. strcpy(sstrtemp, stringtrimspace(payload));
  9403. c = 0;
  9404. loc = strstr(sstrtemp, "connectorId");
  9405. memset(sstr ,0, sizeof(sstr) );
  9406. while (loc[strlen("connectorId")+2+c] != '}')
  9407. {
  9408. sstr[c] = loc[strlen("connectorId")+2+c];
  9409. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9410. c++;
  9411. }
  9412. sstr[c] = '\0';
  9413. connectorIdInt = atoi(sstr);
  9414. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9415. if(gunTotalNumber == 0)
  9416. {
  9417. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9418. goto end;
  9419. }
  9420. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9421. {
  9422. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9423. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9424. goto end;
  9425. }
  9426. else
  9427. {
  9428. //check Transaction active
  9429. if(gunType[connectorIdInt-1] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  9440. {
  9441. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  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 < CCS_QUANTITY; index++)
  9459. {
  9460. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9461. {
  9462. //stop Transaction
  9463. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9464. }
  9465. }
  9466. }
  9467. else if(gunType[connectorIdInt-1] == 'G')
  9468. {
  9469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9470. {
  9471. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9472. }
  9473. else
  9474. {
  9475. tempIndex = connectorIdInt -1;
  9476. }
  9477. for (int index = 0; index < GB_QUANTITY; index++)
  9478. {
  9479. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9480. {
  9481. //stop Transaction
  9482. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9483. }
  9484. }
  9485. }
  9486. else
  9487. {
  9488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9489. {
  9490. tempIndex = 2;
  9491. }
  9492. else
  9493. {
  9494. tempIndex = connectorIdInt-1;
  9495. }
  9496. for (int index = 0; index < AC_QUANTITY; index++)
  9497. {
  9498. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9499. {
  9500. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9501. }
  9502. }
  9503. }
  9504. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9505. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9506. result = TRUE;
  9507. return result;
  9508. }
  9509. end:
  9510. //json_object_put(obj); --- remove temporally
  9511. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9512. return result;
  9513. }
  9514. static char UpdateFirmwarepayloadData[300]={0};
  9515. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9516. {
  9517. mtrace();
  9518. int result = FAIL;
  9519. pthread_t t;
  9520. sendUpdateFirmwareConfirmation(uuid);
  9521. memset(UpdateFirmwarepayloadData, 0, 300);
  9522. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9523. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9524. ////pthread_join(t, NULL); //
  9525. //pthread_detach(t);
  9526. //sendUpdateFirmwareConfirmation(uuid);
  9527. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9528. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9529. return result;
  9530. }
  9531. void *UpdateFirmwareProcess(void *data)
  9532. {
  9533. pthread_detach(pthread_self());
  9534. mtrace();
  9535. int retriesInt =0, retryIntervalInt=0;
  9536. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9537. int port=0;
  9538. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9539. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9540. //char comfirmstr[20];
  9541. int isSuccess = 0;
  9542. char ftpbuf[200];
  9543. char temp[100];
  9544. char * pch;
  9545. int retriesISNULL=FALSE;
  9546. int retryInterval=FALSE;
  9547. int c = 0;
  9548. //int i = 0;
  9549. char *loc;
  9550. char sstr[300]={ 0 };
  9551. char str[300]={ 0 };
  9552. //char *str = (char*) data; // ? ?輸入資 ?
  9553. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9554. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9555. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9556. //***************location **************/
  9557. loc = strstr(str, "location");
  9558. memset(sstr ,0, sizeof(sstr) );
  9559. c = 0;
  9560. while (loc[3+strlen("location")+c] != '\"')
  9561. {
  9562. sstr[c] = loc[3+strlen("location")+c];
  9563. c++;
  9564. }
  9565. sstr[c] = '\0';
  9566. strcpy(locationstr, sstr);
  9567. //***************retries**************/
  9568. c = 0;
  9569. loc = strstr(str, "retries");
  9570. if(loc == NULL)
  9571. {
  9572. retriesISNULL=TRUE;
  9573. }
  9574. else
  9575. {
  9576. memset(sstr ,0, sizeof(sstr) );
  9577. while (loc[strlen("retries")+2+c] != ',')
  9578. {
  9579. sstr[c] = loc[strlen("retries")+2+c];
  9580. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9581. c++;
  9582. }
  9583. sstr[c] = '\0';
  9584. }
  9585. if(retriesISNULL == FALSE)
  9586. {
  9587. retriesInt = atoi(sstr);
  9588. }
  9589. //***************retrieveDate **************/
  9590. loc = strstr(str, "retrieveDate");
  9591. memset(sstr ,0, sizeof(sstr) );
  9592. c = 0;
  9593. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9594. {
  9595. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9596. c++;
  9597. }
  9598. sstr[c] = '\0';
  9599. strcpy(retrieveDatestr, sstr);
  9600. //***************retryInterval **************/
  9601. c = 0;
  9602. loc = strstr(str, "retryInterval");
  9603. memset(sstr ,0, sizeof(sstr) );
  9604. if(loc == NULL)
  9605. {
  9606. retryInterval=TRUE;
  9607. }
  9608. else
  9609. {
  9610. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9611. {
  9612. sstr[c] = loc[strlen("retryInterval")+2+c];
  9613. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9614. c++;
  9615. }
  9616. sstr[c] = '\0';
  9617. }
  9618. if(retryInterval==FALSE)
  9619. {
  9620. retryIntervalInt = atoi(sstr);
  9621. }
  9622. memset(ftppath, 0, sizeof(ftppath));
  9623. memset(path, 0, sizeof(path));
  9624. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9625. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9626. if(strncmp(locationstr,"http", 4) == 0)
  9627. {
  9628. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9629. protocol, host, path);
  9630. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9631. // protocol, user, password, host, path);
  9632. sprintf(ftppath,"/%s", path);
  9633. //DEBUG_INFO("protocol =%s\n",protocol);
  9634. //DEBUG_INFO("host =%s\n",host);
  9635. //DEBUG_INFO("path =%s\n",path);
  9636. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9637. int ftppathlen=strlen(ftppath);
  9638. int i=1;
  9639. char filenametemp[50];
  9640. while(i < ftppathlen)
  9641. {
  9642. int len=ftppathlen-i;
  9643. if(ftppath[len]== 47) // '/' ascll code: 47
  9644. {
  9645. DEBUG_INFO("compare '/' all right\n");
  9646. break;
  9647. }
  9648. i=i+1;
  9649. }
  9650. memset(filenametemp, 0, sizeof(filenametemp));
  9651. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9652. filenametemp[i+1] = 0;
  9653. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9654. do{
  9655. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9656. sleep(retryIntervalInt);
  9657. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9658. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9659. if(!isSuccess)
  9660. {
  9661. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9662. }
  9663. else
  9664. {
  9665. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9666. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9667. //isUpdateRequest = TRUE;
  9668. }
  9669. }
  9670. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9671. {
  9672. memset(ftpbuf, 0, sizeof(ftpbuf));
  9673. memset(temp, 0, sizeof(temp));
  9674. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9675. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9676. int ftppathlen=strlen(ftpbuf);
  9677. int i=1;
  9678. char filenametemp[50];
  9679. while(i < ftppathlen)
  9680. {
  9681. int len=ftppathlen-i;
  9682. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9683. {
  9684. DEBUG_INFO(" compare '/' all right\n");
  9685. break;
  9686. }
  9687. i=i+1;
  9688. }
  9689. memset(filenametemp, 0, sizeof(filenametemp));
  9690. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9691. filenametemp[i+1] = 0;
  9692. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9693. pch=strchr(temp,'@');
  9694. if(pch==NULL)
  9695. {
  9696. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9697. protocol, host, &port, path);
  9698. strcpy(user,"anonymous");
  9699. strcpy(password,"");
  9700. }
  9701. else
  9702. {
  9703. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9704. protocol, user, password, host, &port, path);
  9705. }
  9706. sscanf(host,"%[^/]%s",host1, path1);
  9707. sprintf(ftppath,"%s", path1);
  9708. //DEBUG_INFO("protocol =%s\n",protocol);
  9709. //DEBUG_INFO("user =%s\n",user);
  9710. //DEBUG_INFO("password =%s\n",password);
  9711. //DEBUG_INFO("host1 =%s\n",host1);
  9712. //DEBUG_INFO("port =%d\n",port);
  9713. //DEBUG_INFO("path1 =%s\n",path1);
  9714. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9715. //ftpFile(host, user, password, port, ftppath, fname);
  9716. //download firmware pthred
  9717. if(port == 0)
  9718. {
  9719. port = 21;
  9720. }
  9721. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9722. do{
  9723. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9724. sleep(retryIntervalInt);
  9725. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9726. if(!isSuccess)
  9727. {
  9728. //BulldogUtil.sleepMs(interval*1000);
  9729. DEBUG_INFO("Update firmware request and download file fail.\n");
  9730. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9731. }
  9732. else
  9733. {
  9734. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9735. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9736. //isUpdateRequest = TRUE;
  9737. }
  9738. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9739. }
  9740. else
  9741. {
  9742. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9743. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9744. }
  9745. pthread_exit(NULL);
  9746. }
  9747. //==========================================
  9748. // Handle server response routine
  9749. //==========================================
  9750. void handleAuthorizeResponse(char *payload, int gun_index)
  9751. {
  9752. mtrace();
  9753. char expiryDatestr[30]={0};
  9754. char parentIdTagstr[20]={0};
  9755. char statusstr[20]={0};
  9756. char expiryDatestrtemp[30]={0};
  9757. char parentIdTagstrtemp[20]={0};
  9758. char IdTagstrtemp[20]={0};
  9759. char statusstrtemp[20]={0};
  9760. int expiryDateISNULL=FALSE;
  9761. int parentIdTagISNULL=FALSE;
  9762. char sstr[160]={0},sstrtemp[160]={0};
  9763. char* filename = AuthorizationCache_JSON;
  9764. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9765. int c = 0;
  9766. char *loc;
  9767. int resultRename=0;
  9768. int responseIdTagInfoAsZero= 0;
  9769. char rmFileCmd[50]={0};
  9770. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9771. strcpy(sstrtemp, stringtrimspace(payload));
  9772. //***********expiryDate*************/
  9773. loc = strstr(sstrtemp, "expiryDate");
  9774. memset(sstr ,0, sizeof(sstr) );
  9775. c = 0;
  9776. if(loc == NULL)
  9777. {
  9778. expiryDateISNULL = TRUE;
  9779. }
  9780. else
  9781. {
  9782. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9783. {
  9784. sstr[c] = loc[3+strlen("expiryDate")+c];
  9785. c++;
  9786. }
  9787. sstr[c] = '\0';
  9788. strcpy(expiryDatestr, sstr);
  9789. }
  9790. //***********parentIdTag*************/
  9791. loc = strstr(sstrtemp, "parentIdTag");
  9792. memset(sstr ,0, sizeof(sstr) );
  9793. c = 0;
  9794. if(loc == NULL)
  9795. {
  9796. parentIdTagISNULL = TRUE;
  9797. }
  9798. else
  9799. {
  9800. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9801. {
  9802. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9803. c++;
  9804. }
  9805. sstr[c] = '\0';
  9806. strcpy(parentIdTagstr, sstr);
  9807. }
  9808. //***********status*************/
  9809. loc = strstr(sstrtemp, "status");
  9810. memset(sstr ,0, sizeof(sstr) );
  9811. c = 0;
  9812. while (loc[3+strlen("status")+c] != '\"')
  9813. {
  9814. sstr[c] = loc[3+strlen("status")+c];
  9815. c++;
  9816. }
  9817. sstr[c] = '\0';
  9818. strcpy(statusstr, sstr);
  9819. if(expiryDateISNULL == FALSE)
  9820. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9821. if(parentIdTagISNULL == FALSE)
  9822. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9823. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9824. //Update idTag information to authorization cache if supproted
  9825. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9826. {
  9827. if((access(filename,F_OK))!=-1)
  9828. {
  9829. printf("AuthorizationCache exist.\n");
  9830. }
  9831. else
  9832. {
  9833. printf("AuthorizationCache not exist\n");
  9834. FILE *log = fopen(filename, "w+");
  9835. if(log == NULL)
  9836. {
  9837. printf("log is NULL\n");
  9838. goto out;
  9839. }
  9840. else
  9841. {
  9842. fclose(log);
  9843. }
  9844. }
  9845. FILE *infile;
  9846. FILE *outfile;
  9847. // open file for writing
  9848. infile = fopen (filename, "r");
  9849. outfile = fopen (tempfile, "w");
  9850. //*检测到文件结束标识返回1,否则返回0。*/
  9851. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9852. int c;
  9853. c = fgetc(infile);
  9854. //DEBUG_INFO("c:%d\n",c);
  9855. rewind(infile);
  9856. if(c == EOF)
  9857. {
  9858. DEBUG_INFO("Orignal File is NULL\n");
  9859. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9860. {
  9861. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9862. }
  9863. else
  9864. {
  9865. strcpy(expiryDatestrtemp, "");
  9866. }
  9867. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9868. {
  9869. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9870. }
  9871. else
  9872. {
  9873. //write Authorize IdTag
  9874. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9875. }
  9876. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9877. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9878. fclose(infile);
  9879. fclose(outfile);
  9880. sprintf(rmFileCmd,"rm -f %s",filename);
  9881. system(rmFileCmd);
  9882. resultRename = rename(tempfile, filename);
  9883. if(resultRename == 0)
  9884. {
  9885. printf("File renamed successfully");
  9886. }
  9887. else
  9888. {
  9889. printf("Error: unable to rename the file");
  9890. }
  9891. }
  9892. else
  9893. {
  9894. char buf[160]={0};
  9895. while (fgets(buf, sizeof(buf), infile) != NULL)
  9896. {
  9897. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9898. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9899. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9900. memset(statusstr, 0, sizeof(statusstrtemp));
  9901. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9902. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9903. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9904. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9905. //------------------IdTag-----------------------
  9906. loc = strstr(buf, "idTag");
  9907. memset(sstr ,0, sizeof(sstr) );
  9908. c = 0;
  9909. while (loc[3+strlen("idTag")+c] != '\"')
  9910. {
  9911. sstr[c] = loc[3+strlen("idTag")+c];
  9912. c++;
  9913. }
  9914. sstr[c] = '\0';
  9915. strcpy(IdTagstrtemp,sstr);
  9916. //*********************expiryDate***************/
  9917. loc = strstr(buf, "expiryDate");
  9918. memset(sstr ,0, sizeof(sstr) );
  9919. c = 0;
  9920. while (loc[3+strlen("expiryDate")+c] != '\"')
  9921. {
  9922. sstr[c] = loc[3+strlen("expiryDate")+c];
  9923. c++;
  9924. }
  9925. sstr[c] = '\0';
  9926. strcpy(expiryDatestr,sstr);
  9927. //*********************parentIdTag***************/
  9928. loc = strstr(buf, "parentIdTag");
  9929. memset(sstr ,0, sizeof(sstr) );
  9930. c = 0;
  9931. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9932. {
  9933. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9934. c++;
  9935. }
  9936. sstr[c] = '\0';
  9937. strcpy(parentIdTagstr,sstr);
  9938. //*********************status***************/
  9939. loc = strstr(buf, "status");
  9940. memset(sstr ,0, sizeof(sstr) );
  9941. c = 0;
  9942. while (loc[3+strlen("status")+c] != '\"')
  9943. {
  9944. sstr[c] = loc[3+strlen("status")+c];
  9945. c++;
  9946. }
  9947. sstr[c] = '\0';
  9948. strcpy(statusstr,sstr);
  9949. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9950. {
  9951. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9952. responseIdTagInfoAsZero = 1;
  9953. }
  9954. else
  9955. {
  9956. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9957. }
  9958. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9959. {
  9960. //modify item
  9961. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9962. {
  9963. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9964. }
  9965. else
  9966. {
  9967. strcpy(expiryDatestrtemp, "");
  9968. }
  9969. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9970. {
  9971. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9972. }
  9973. else
  9974. {
  9975. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9976. }
  9977. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9978. }
  9979. else
  9980. {
  9981. //wrie original item
  9982. strcpy(expiryDatestrtemp, expiryDatestr);
  9983. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9984. strcpy(statusstrtemp, statusstr);
  9985. }
  9986. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9987. }
  9988. fclose(infile);
  9989. fclose(outfile);
  9990. sprintf(rmFileCmd,"rm -f %s",filename);
  9991. system(rmFileCmd);
  9992. resultRename = rename(tempfile, filename);
  9993. if(resultRename == 0)
  9994. {
  9995. DEBUG_INFO("File renamed successfully");
  9996. }
  9997. else
  9998. {
  9999. DEBUG_INFO("Error: unable to rename the file");
  10000. }
  10001. }
  10002. }
  10003. out:
  10004. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10005. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10006. authorizeRetryTimes = 0;
  10007. }
  10008. char * strtrimc( char * s )
  10009. {
  10010. char * p1 = s;
  10011. char * p2 = s;
  10012. while(*p1 != '\0')
  10013. {
  10014. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  10015. {
  10016. if(*p1 != ',')
  10017. {
  10018. p1 ++;
  10019. }
  10020. else
  10021. {
  10022. break;
  10023. }
  10024. }
  10025. if(*p1 != ',')
  10026. {
  10027. * p2 ++ = *p1 ++;
  10028. //printf("p2=%s\n",p2);
  10029. }
  10030. else
  10031. {
  10032. break;
  10033. }
  10034. }
  10035. *p2 = '\0';
  10036. return (s);
  10037. }
  10038. void handleBootNotificationResponse(char *payload, int gun_index)
  10039. {
  10040. mtrace();
  10041. char sstr[140]={0}, sstrtemp[140]={0};//sstr[200]={ 0 };
  10042. char statusStr[12]={0};
  10043. char currentTimeStr[30]={0};
  10044. char *loc;
  10045. int intervalInt = 0;
  10046. int c = 0;
  10047. //double diff_t;
  10048. struct tm tp;
  10049. char buf[28]={0};
  10050. char timebuf[50]={0};
  10051. DEBUG_INFO("handleBootNotificationResponse ...\n");
  10052. //Filter string space
  10053. strcpy(sstrtemp, stringtrimspace(payload));
  10054. //*** interval ****/
  10055. c = 0;
  10056. loc = strstr(sstrtemp, "interval");
  10057. //printf("loc=%s\n",loc);
  10058. memset(sstr ,0, sizeof(sstr) );
  10059. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  10060. {
  10061. sstr[c] = loc[strlen("interval")+2+c];
  10062. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10063. c++;
  10064. }
  10065. sstr[c] = '\0';
  10066. //DEBUG_INFO("id=%d\n",atoi(sstr));
  10067. intervalInt = atoi(sstr);
  10068. //***status ****/
  10069. loc = strstr(sstrtemp, "status");
  10070. memset(sstr ,0, sizeof(sstr) );
  10071. c = 0;
  10072. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  10073. {
  10074. sstr[c] = loc[3+strlen("status")+c];
  10075. c++;
  10076. }
  10077. sstr[c] = '\0';
  10078. strcpy(statusStr, sstr);
  10079. //***currentTime ****/
  10080. loc = strstr(sstrtemp, "currentTime");
  10081. //printf("loc=%s\n",loc);
  10082. memset(sstr ,0, sizeof(sstr) );
  10083. c = 0;
  10084. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  10085. {
  10086. sstr[c] = loc[3+strlen("currentTime")+c];
  10087. c++;
  10088. }
  10089. sstr[c] = '\0';
  10090. strcpy(currentTimeStr, sstr);
  10091. //BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10092. //HeartBeatWaitTime = BootNotificationInterval;
  10093. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10094. BootNotificationInterval = intervalInt;
  10095. HeartBeatWaitTime = intervalInt;
  10096. clientTime.Heartbeat=time((time_t*)NULL);
  10097. //write back to ShmOCPP16Data->BootNotification
  10098. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10099. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10100. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10101. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  10102. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  10103. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  10104. {
  10105. server_sign = TRUE;
  10106. server_pending =FALSE;
  10107. }
  10108. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10109. {
  10110. server_pending = TRUE;
  10111. }
  10112. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10113. tp.tm_isdst = -1;
  10114. //time_t utc = mktime(&tp);
  10115. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10116. memset(timebuf, 0, sizeof timebuf);
  10117. sprintf(timebuf,"date -s '%s'",buf);
  10118. //DEBUG_INFO("timebuf=%s\n",timebuf);
  10119. system(timebuf);
  10120. //==============================================
  10121. // RTC sync
  10122. //==============================================
  10123. system("/sbin/hwclock -w --systohc");
  10124. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10125. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10126. }
  10127. void handleDataTransferResponse(char *payload, int gun_index)
  10128. {
  10129. char sstr[160]={0};//sstr[200]={ 0 };
  10130. int c = 0;
  10131. char *loc;
  10132. DEBUG_INFO("handleDataTransferResponse ...\n");
  10133. loc = strstr(payload, "status");
  10134. printf("loc=%s\n",loc);
  10135. c = 0;
  10136. while (loc[3+strlen("status")+c] != '\"')
  10137. {
  10138. sstr[c] = loc[3+strlen("status")+c];
  10139. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10140. c++;
  10141. }
  10142. sstr[c] = '\0';
  10143. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10144. }
  10145. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10146. {
  10147. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10148. //struct json_object *obj;
  10149. // obj = json_tokener_parse(payload);
  10150. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10151. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10152. //No fields are defined.
  10153. }
  10154. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10155. {
  10156. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10157. //struct json_object *obj;
  10158. // obj = json_tokener_parse(payload);
  10159. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10160. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10161. //No fields are defined.
  10162. }
  10163. void handleHeartbeatResponse(char *payload, int gun_index)
  10164. {
  10165. mtrace();
  10166. //double diff_t;
  10167. struct tm tp;
  10168. char buf[28]={0};
  10169. char timebuf[50]={0},sstrtemp[100]={0};
  10170. char sstr[30]={ 0 };
  10171. int c = 0;
  10172. char *loc;
  10173. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  10174. if(FirstHeartBeat == 0)
  10175. {
  10176. FirstHeartBeat = 1;
  10177. DEBUG_INFO("FirstHeartBeat \n");
  10178. }
  10179. HeartBeatWithNOResponse = 0;
  10180. strcpy(sstrtemp, stringtrimspace(payload));
  10181. c = 0;
  10182. loc = strstr(sstrtemp, "currentTime");
  10183. memset(sstr ,0, sizeof(sstr) );
  10184. while (loc[3+strlen("currentTime")+c] != '\"')
  10185. {
  10186. sstr[c] = loc[3+strlen("currentTime")+c];
  10187. c++;
  10188. }
  10189. sstr[c] = '\0';
  10190. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  10191. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10192. tp.tm_isdst = -1;
  10193. //time_t utc = mktime(&tp);
  10194. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10195. memset(timebuf, 0, sizeof timebuf);
  10196. sprintf(timebuf,"date -s '%s'",buf);
  10197. system(timebuf);
  10198. //==============================================
  10199. // RTC sync
  10200. //==============================================
  10201. system("/sbin/hwclock -w --systohc");
  10202. //===============================================
  10203. //Print Out HeartBeat log
  10204. //===============================================
  10205. {
  10206. double diff_t;
  10207. struct tm tp,tp1;
  10208. // BootNotification Receive Time
  10209. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10210. tp.tm_isdst = -1;
  10211. time_t BootNotificationReceiveTime = mktime(&tp);
  10212. //HeartBeat Receive Time
  10213. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10214. tp1.tm_isdst = -1;
  10215. time_t HeartBeatReceiveTime = mktime(&tp1);
  10216. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10217. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10218. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10219. {
  10220. HeartBeatCountPerHour = (int)diff_t / 3600;
  10221. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10222. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10223. }
  10224. }
  10225. }
  10226. void handleMeterValuesResponse(char *payload, int gun_index)
  10227. {
  10228. mtrace();
  10229. //struct json_object *obj;
  10230. DEBUG_INFO("handleMeterValuesResponse ...\n");
  10231. //No fields are defined.
  10232. }
  10233. void handleStartTransactionResponse(char *payload, int gun_index)
  10234. {
  10235. mtrace();
  10236. char sstr[28]={ 0 },sstrtemp[200]={ 0 };
  10237. int c = 0;
  10238. int copyTo = 0;
  10239. char *loc;
  10240. //int transactionIdInt = 0;
  10241. FILE *outfile;
  10242. char data[100]={0};
  10243. //char *delim = ":";
  10244. //char requestKey[2][50]={0};
  10245. //char * pch;
  10246. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  10247. DEBUG_INFO("handleStartTransactionResponse\n");
  10248. //****************expiryDate********************/
  10249. strcpy(sstrtemp, stringtrimspace(payload));
  10250. loc = strstr(sstrtemp, "expiryDate");
  10251. if(loc == NULL)
  10252. {
  10253. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  10254. }
  10255. else
  10256. {
  10257. #if 0
  10258. c = 0;
  10259. memset(sstr ,0, sizeof(sstr) );
  10260. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10261. memset(requestKey ,0, sizeof(requestKey) );
  10262. strcpy(sstrtemp,loc+strlen("expiryDate")+2); // 2: ":
  10263. //printf("sstrtemp=%s\n",sstrtemp);
  10264. //parsing strings to words
  10265. pch = strtok(sstrtemp,",");
  10266. while (pch != NULL)
  10267. {
  10268. strcpy(requestKey[c], pch);
  10269. pch = strtok (NULL, ",");
  10270. c = c + 1;
  10271. }
  10272. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10273. //strcpy(currentTimeStr, strtrimc(requestKey[0]));
  10274. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", stringtrim(requestKey[0]));
  10275. #endif
  10276. #if 1
  10277. c = 0;
  10278. memset(sstr ,0, sizeof(sstr) );
  10279. while (loc[3+strlen("expiryDate")+c] != '\"')
  10280. {
  10281. sstr[c] = loc[3+strlen("expiryDate")+c];
  10282. c++;
  10283. }
  10284. sstr[c] = '\0';
  10285. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10286. #endif
  10287. }
  10288. //****************parentIdTag********************/
  10289. loc = strstr(sstrtemp, "parentIdTag");
  10290. if(loc == NULL)
  10291. {
  10292. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  10293. }
  10294. else
  10295. {
  10296. #if 0
  10297. c = 0;
  10298. memset(sstr ,0, sizeof(sstr) );
  10299. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10300. memset(requestKey ,0, sizeof(requestKey) );
  10301. strcpy(sstrtemp,loc);
  10302. //printf("sstrtemp=%s\n",sstrtemp);
  10303. //parsing strings to words
  10304. pch = strtok(sstrtemp,delim);
  10305. while (pch != NULL)
  10306. {
  10307. strcpy(requestKey[c], pch);
  10308. pch = strtok (NULL, delim);
  10309. c = c + 1;
  10310. }
  10311. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10312. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", strtrimc(requestKey[1]));
  10313. #endif
  10314. #if 1
  10315. c = 0;
  10316. memset(sstr ,0, sizeof(sstr) );
  10317. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10318. {
  10319. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10320. c++;
  10321. }
  10322. sstr[c] = '\0';
  10323. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10324. #endif
  10325. }
  10326. //****************status********************/
  10327. loc = strstr(sstrtemp, "status");
  10328. if(loc == NULL)
  10329. {
  10330. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  10331. }
  10332. else
  10333. {
  10334. #if 0
  10335. c = 0;
  10336. memset(sstr ,0, sizeof(sstr) );
  10337. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10338. memset(requestKey ,0, sizeof(requestKey) );
  10339. strcpy(sstrtemp,loc);
  10340. //printf("sstrtemp=%s\n",sstrtemp);
  10341. //parsing strings to words
  10342. pch = strtok(sstrtemp,delim);
  10343. while (pch != NULL)
  10344. {
  10345. strcpy(requestKey[c], pch);
  10346. pch = strtok (NULL, delim);
  10347. c = c + 1;
  10348. }
  10349. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10350. //strcpy(statusStr, strtrimc(requestKey[1]));
  10351. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", strtrimc(requestKey[1]));
  10352. #endif
  10353. #if 1
  10354. c = 0;
  10355. memset(sstr ,0, sizeof(sstr) );
  10356. while (loc[3+strlen("status")+c] != '\"')
  10357. {
  10358. sstr[c] = loc[3+strlen("status")+c];
  10359. c++;
  10360. }
  10361. sstr[c] = '\0';
  10362. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10363. #endif
  10364. }
  10365. //****************transactionId********************/
  10366. c=0;
  10367. copyTo = 0;
  10368. loc = strstr(sstrtemp, "transactionId");
  10369. memset(sstr ,0, sizeof(sstr) );
  10370. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  10371. {
  10372. if(loc[strlen("transactionId")+2+c] != ' ')
  10373. {
  10374. sstr[copyTo] = loc[strlen("transactionId")+2+c];
  10375. copyTo = copyTo + 1;
  10376. }
  10377. c++;
  10378. }
  10379. sstr[copyTo] = '\0';
  10380. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  10381. //transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  10382. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10383. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10384. //-----------Start : write to the Queue TransactionId file -----------------//
  10385. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10386. {
  10387. //DEBUG_INFO("QueueTransactionId exist.\n");
  10388. }
  10389. else
  10390. {
  10391. //DEBUG_INFO("QueueTransactionId not exist\n");
  10392. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10393. if(log == NULL)
  10394. {
  10395. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10396. return ;
  10397. }
  10398. else
  10399. {
  10400. fclose(log);
  10401. }
  10402. }
  10403. // open file for writing
  10404. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10405. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10406. {
  10407. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10408. //DEBUG_INFO("data=%s\n",data);
  10409. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10410. fputs(data, outfile);
  10411. //fputs("\n", outfile);
  10412. fclose (outfile);
  10413. }
  10414. //-------------End: write to the Queue TransactionId file------------------------------------------//
  10415. //TransactionId[gun_index] = transactionIdInt;
  10416. //DEBUG_INFO("gun_index: %d\n", gun_index);
  10417. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  10418. #ifdef SystemLogMessage
  10419. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10420. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10421. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10422. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10423. #endif
  10424. }
  10425. void handleStatusNotificationResponse(char *payload, int gun_index)
  10426. {
  10427. mtrace();
  10428. printf("handleStatusNotificationResponse\n");
  10429. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10430. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10431. }
  10432. void handleStopTransactionnResponse(char *payload, int gun_index)
  10433. {
  10434. mtrace();
  10435. char sstr[30]={ 0 },sstrtemp[140]={ 0 };
  10436. int c = 0;
  10437. char *loc;
  10438. //char *delim = ":";
  10439. //char requestKey[3][50]={0};
  10440. //char * pch;
  10441. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  10442. strcpy(sstrtemp, stringtrimspace(payload));
  10443. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10444. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10445. loc = strstr(sstrtemp, "idTagInfo");
  10446. //***********************idTagInfo************************/
  10447. if(loc != NULL)
  10448. {
  10449. //***********************expiryDate************************/
  10450. loc = strstr(sstrtemp, "expiryDate");
  10451. if(loc != NULL)
  10452. {
  10453. memset(sstr ,0, sizeof(sstr) );
  10454. c = 0;
  10455. while (loc[3+strlen("expiryDate")+c] != '\"')
  10456. {
  10457. sstr[c] = loc[3+strlen("expiryDate")+c];
  10458. c++;
  10459. }
  10460. sstr[c] = '\0';
  10461. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10462. }
  10463. //***********************parentIdTag************************/
  10464. loc = strstr(sstrtemp, "parentIdTag");
  10465. if(loc != NULL)
  10466. {
  10467. memset(sstr ,0, sizeof(sstr) );
  10468. c = 0;
  10469. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10470. {
  10471. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10472. c++;
  10473. }
  10474. sstr[c] = '\0';
  10475. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10476. }
  10477. //***********************status************************/
  10478. loc = strstr(sstrtemp, "status");
  10479. memset(sstr ,0, sizeof(sstr) );
  10480. c = 0;
  10481. while (loc[3+strlen("status")+c] != '\"')
  10482. {
  10483. sstr[c] = loc[3+strlen("status")+c];
  10484. c++;
  10485. }
  10486. sstr[c] = '\0';
  10487. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10488. }
  10489. #ifdef SystemLogMessage
  10490. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10491. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10492. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10493. #endif
  10494. }
  10495. //==========================================
  10496. // Handle Error routine
  10497. //==========================================
  10498. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10499. {
  10500. mtrace();
  10501. #ifdef SystemLogMessage
  10502. DEBUG_INFO("errorCode: %s\n", errorCode);
  10503. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10504. DEBUG_INFO("errorDetails: %s\n", payload);
  10505. #endif
  10506. }
  10507. //===============================================
  10508. // Common routine
  10509. //===============================================
  10510. int initialConfigurationTable(void)
  10511. {
  10512. //clock_t start_t, end_t, total_t;
  10513. FILE *fp;
  10514. FILE *outfile;
  10515. char str[200]={0};
  10516. char sstr[100]={0};
  10517. int c = 0;
  10518. char *loc;
  10519. printf("initialConfigurationTable \n");
  10520. //start_t = clock();
  10521. //printf("Starting of the program, start_t = %ld\n", start_t);
  10522. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10523. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10524. {
  10525. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10526. if(outfile == NULL) {
  10527. DEBUG_INFO("Error opening file");
  10528. return FALSE;
  10529. }
  10530. /*Core Profile*/
  10531. //AllowOfflineTxForUnknownId
  10532. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10533. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10537. //AuthorizationCacheEnabled
  10538. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10542. //AuthorizeRemoteTxRequests
  10543. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10547. //BlinkRepeat
  10548. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10552. //ClockAlignedDataInterval
  10553. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10557. //ConnectionTimeOut
  10558. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10562. //GetConfigurationMaxKeys
  10563. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10567. // HeartbeatInterval
  10568. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10572. // LightIntensity
  10573. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10577. // LocalAuthorizeOffline
  10578. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10582. // LocalPreAuthorize
  10583. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10587. // MaxEnergyOnInvalidId
  10588. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10591. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10593. // MeterValuesAlignedData
  10594. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10598. // MeterValuesAlignedDataMaxLength
  10599. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10603. // MeterValuesSampledData
  10604. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10608. // MeterValuesSampledDataMaxLength
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  10613. // MeterValueSampleInterval
  10614. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10618. // MinimumStatusDuration
  10619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10622. server_cycle_Status = 120; //StatusNotification cycle
  10623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10624. // NumberOfConnectors
  10625. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10628. {
  10629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10630. }
  10631. else
  10632. {
  10633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10634. }
  10635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10636. // ResetRetries
  10637. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10641. // ConnectorPhaseRotation
  10642. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10646. // ConnectorPhaseRotationMaxLength
  10647. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10651. // StopTransactionOnEVSideDisconnect
  10652. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10656. // StopTransactionOnInvalidId
  10657. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10661. // StopTxnAlignedData
  10662. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10666. // StopTxnAlignedDataMaxLength
  10667. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10671. // StopTxnSampledData
  10672. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10676. // StopTxnSampledDataMaxLength
  10677. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10680. {
  10681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10682. }
  10683. else
  10684. {
  10685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10686. }
  10687. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10689. // SupportedFeatureProfiles
  10690. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10694. // SupportedFeatureProfilesMaxLength
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10699. // TransactionMessageAttempts
  10700. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10703. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10705. // TransactionMessageRetryInterval
  10706. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10709. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10711. // UnlockConnectorOnEVSideDisconnect
  10712. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10716. // WebSocketPingInterval
  10717. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10721. //* Local Auth List Management Profile*/
  10722. #if 0
  10723. //For OCTT Test Case
  10724. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10727. #endif
  10728. #if 1
  10729. //LocalAuthListEnabled
  10730. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10734. #endif
  10735. //LocalAuthListMaxLength
  10736. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10740. //SendLocalListMaxLength
  10741. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10745. //ReserveConnectorZeroSupported
  10746. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10750. //* Smart Charging Profile */
  10751. //ChargeProfileMaxStackLevel
  10752. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10756. // ChargingScheduleAllowedChargingRateUnit
  10757. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10761. // ChargingScheduleMaxPeriods
  10762. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10766. // ConnectorSwitch3to1PhaseSupported
  10767. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10771. // MaxChargingProfilesInstalled
  10772. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10776. fclose(outfile);
  10777. }
  10778. else
  10779. {
  10780. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10781. char keystr[60]={0};
  10782. char readonlystr[10]={0};
  10783. char valuestr[100]={0};
  10784. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10785. if(fp == NULL) {
  10786. DEBUG_INFO("Error opening file");
  10787. return FALSE;
  10788. }
  10789. while( fgets (str, sizeof(str), fp)!=NULL )
  10790. {
  10791. //DEBUG_INFO("Get Configuration \n");
  10792. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10793. //*************************key*********************************/
  10794. loc = strstr(str, "key");
  10795. c = 0;
  10796. memset(sstr ,0, sizeof(sstr) );
  10797. while (loc[strlen("key")+3+c] != '\"')
  10798. {
  10799. sstr[c] = loc[strlen("key")+3+c];
  10800. c++;
  10801. }
  10802. sstr[c] = '\0';
  10803. strcpy(keystr,sstr);
  10804. //*************************readonly*********************************/
  10805. loc = strstr(str, "readonly");
  10806. c = 0;
  10807. memset(sstr ,0, sizeof(sstr) );
  10808. while (loc[strlen("readonly")+2+c] != ',')
  10809. {
  10810. sstr[c] = loc[strlen("readonly")+2+c];
  10811. c++;
  10812. }
  10813. sstr[c] = '\0';
  10814. strcpy(readonlystr,sstr);
  10815. //*************************value*********************************/
  10816. loc = strstr(str, "value");
  10817. c = 0;
  10818. memset(sstr ,0, sizeof(sstr) );
  10819. while (loc[strlen("value")+3+c] != '\"')
  10820. {
  10821. sstr[c] = loc[strlen("value")+3+c];
  10822. c++;
  10823. }
  10824. sstr[c] = '\0';
  10825. strcpy(valuestr,sstr);
  10826. // DEBUG_INFO("keystr=%s\n",keystr);
  10827. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10828. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10829. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10830. {
  10831. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10832. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10834. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10835. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10836. }
  10837. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10838. {
  10839. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10840. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10842. }
  10843. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10844. {
  10845. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10847. }
  10848. if(strcmp(keystr, "BlinkRepeat") == 0)
  10849. {
  10850. //Charger.BlinkRepeat = Integer.parseInt(value);
  10851. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10853. }
  10854. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10855. {
  10856. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10858. }
  10859. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10860. {
  10861. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10863. }
  10864. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10865. {
  10866. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10868. }
  10869. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10870. {
  10871. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10873. HeartBeatWaitTime = atoi(valuestr);
  10874. }
  10875. if(strcmp(keystr, "LightIntensity") == 0)
  10876. {
  10877. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10879. }
  10880. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10881. {
  10882. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10884. }
  10885. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10886. {
  10887. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10889. }
  10890. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10891. {
  10892. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10894. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10895. }
  10896. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10897. {
  10898. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10900. }
  10901. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10902. {
  10903. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10905. }
  10906. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10907. {
  10908. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10910. }
  10911. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10912. {
  10913. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10915. }
  10916. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10917. {
  10918. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10920. }
  10921. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10922. {
  10923. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10925. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10926. }
  10927. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10928. {
  10929. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10931. }
  10932. if(strcmp(keystr, "ResetRetries") == 0)
  10933. {
  10934. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10936. }
  10937. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10938. {
  10939. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10941. }
  10942. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10943. {
  10944. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10946. }
  10947. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10948. {
  10949. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10951. }
  10952. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10953. {
  10954. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10956. }
  10957. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10958. {
  10959. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10961. }
  10962. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10963. {
  10964. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10966. }
  10967. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10968. {
  10969. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10971. }
  10972. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10973. {
  10974. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10976. }
  10977. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10978. {
  10979. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10981. }
  10982. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10983. {
  10984. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10986. }
  10987. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10988. {
  10989. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10991. TransactionMessageAttemptsValue = atoi(valuestr);
  10992. }
  10993. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10994. {
  10995. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10997. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10998. }
  10999. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11000. {
  11001. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11003. }
  11004. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11005. {
  11006. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11008. }
  11009. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11010. {
  11011. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11013. }
  11014. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11015. {
  11016. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11018. }
  11019. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11020. {
  11021. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11023. }
  11024. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11025. {
  11026. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11028. }
  11029. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11030. {
  11031. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11033. }
  11034. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11035. {
  11036. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11038. }
  11039. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11040. {
  11041. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11043. }
  11044. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11045. {
  11046. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11048. }
  11049. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11050. {
  11051. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11053. }
  11054. }
  11055. fclose(fp);
  11056. }
  11057. //end_t = clock();
  11058. //printf("End of the big loop, end_t = %ld\n", end_t);
  11059. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  11060. //printf("Total time taken by CPU: %f\n", total_t );
  11061. return 0;
  11062. }
  11063. void StoreConfigurationTable(void)
  11064. {
  11065. FILE *outfile;
  11066. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11067. if(outfile == NULL)
  11068. {
  11069. DEBUG_INFO("Error opening file");
  11070. return ;
  11071. }
  11072. /*Core Profile*/
  11073. //AllowOfflineTxForUnknownId
  11074. /*
  11075. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11076. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11079. */
  11080. //DEBUG_INFO("data=%s\n",data);
  11081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11082. //AuthorizationCacheEnabled
  11083. /*
  11084. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11087. */
  11088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11089. //AuthorizeRemoteTxRequests
  11090. /*
  11091. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11094. */
  11095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11096. //BlinkRepeat
  11097. /*
  11098. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11101. */
  11102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11103. //ClockAlignedDataInterval
  11104. /*
  11105. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11108. */
  11109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11110. //ConnectionTimeOut
  11111. /*
  11112. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11115. */
  11116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11117. //GetConfigurationMaxKeys
  11118. /*
  11119. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11122. */
  11123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11124. // HeartbeatInterval
  11125. /*
  11126. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11129. */
  11130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11131. // LightIntensity
  11132. /*
  11133. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11136. */
  11137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11138. // LocalAuthorizeOffline
  11139. /*
  11140. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11143. */
  11144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11145. // LocalPreAuthorize
  11146. /*
  11147. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11150. */
  11151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11152. // MaxEnergyOnInvalidId
  11153. /*
  11154. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11157. */
  11158. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11160. // MeterValuesAlignedData
  11161. /*
  11162. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11165. */
  11166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11167. // MeterValuesAlignedDataMaxLength
  11168. /*
  11169. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11172. */
  11173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11174. // MeterValuesSampledData
  11175. /*
  11176. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11179. */
  11180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11181. // MeterValuesSampledDataMaxLength
  11182. /*
  11183. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11186. */
  11187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11188. // MeterValueSampleInterval
  11189. /*
  11190. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11193. */
  11194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11195. // MinimumStatusDuration
  11196. /*
  11197. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11200. */
  11201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11202. // NumberOfConnectors
  11203. /*
  11204. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11207. {
  11208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11209. }
  11210. else
  11211. {
  11212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11213. }
  11214. */
  11215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11216. // ResetRetries
  11217. /*
  11218. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11221. */
  11222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11223. // ConnectorPhaseRotation
  11224. /*
  11225. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11228. */
  11229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11230. // ConnectorPhaseRotationMaxLength
  11231. /*
  11232. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11235. */
  11236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11237. // StopTransactionOnEVSideDisconnect
  11238. /*
  11239. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11242. */
  11243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11244. // StopTransactionOnInvalidId
  11245. /*
  11246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11249. */
  11250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11251. // StopTxnAlignedData
  11252. /*
  11253. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11256. */
  11257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11258. // StopTxnAlignedDataMaxLength
  11259. /*
  11260. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11263. */
  11264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11265. // StopTxnSampledData
  11266. /*
  11267. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11270. */
  11271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11272. // StopTxnSampledDataMaxLength
  11273. /*
  11274. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11277. */
  11278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11279. // SupportedFeatureProfiles
  11280. /*
  11281. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11284. */
  11285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11286. // SupportedFeatureProfilesMaxLength
  11287. /*
  11288. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11291. */
  11292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11293. // TransactionMessageAttempts
  11294. /*
  11295. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11298. */
  11299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11300. // TransactionMessageRetryInterval
  11301. /*
  11302. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11305. */
  11306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11307. // UnlockConnectorOnEVSideDisconnect
  11308. /*
  11309. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11312. */
  11313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11314. // WebSocketPingInterval
  11315. /*
  11316. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11319. */
  11320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11321. //* Local Auth List Management Profile*/
  11322. //LocalAuthListEnabled
  11323. /*
  11324. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11327. */
  11328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11329. //LocalAuthListMaxLength
  11330. /*
  11331. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11334. */
  11335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11336. //SendLocalListMaxLength
  11337. /*
  11338. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11341. */
  11342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11343. //ReserveConnectorZeroSupported
  11344. /*
  11345. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11348. */
  11349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11350. //* Smart Charging Profile */
  11351. //ChargeProfileMaxStackLevel
  11352. /*
  11353. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11356. */
  11357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11358. // ChargingScheduleAllowedChargingRateUnit
  11359. /*
  11360. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11363. */
  11364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11365. // ChargingScheduleMaxPeriods
  11366. /*
  11367. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11370. */
  11371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11372. // ConnectorSwitch3to1PhaseSupported
  11373. /*
  11374. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11377. */
  11378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11379. // MaxChargingProfilesInstalled
  11380. /*
  11381. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11384. */
  11385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11386. fclose(outfile);
  11387. }
  11388. void getKeyValue(char *keyReq)
  11389. {
  11390. int isEmpty = FALSE;
  11391. int isKnowKey = FALSE;
  11392. //int unKnowIndex = 0;
  11393. DEBUG_INFO("getKeyValue \n");
  11394. DEBUG_INFO("keyReq=%s \n",keyReq);
  11395. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11396. isEmpty = TRUE;
  11397. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11398. {
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11404. }
  11405. else
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11408. }
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11410. isKnowKey = TRUE;
  11411. }
  11412. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11419. }
  11420. else
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11423. }
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11425. isKnowKey = TRUE;
  11426. }
  11427. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11434. }
  11435. else
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11438. }
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11440. isKnowKey = TRUE;
  11441. }
  11442. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11449. }
  11450. else
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11453. }
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11455. isKnowKey = TRUE;
  11456. }
  11457. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11464. }
  11465. else
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11468. }
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11470. isKnowKey = TRUE;
  11471. }
  11472. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11479. }
  11480. else
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11483. }
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11485. isKnowKey = TRUE;
  11486. }
  11487. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11494. }
  11495. else
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11498. }
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11500. isKnowKey = TRUE;
  11501. }
  11502. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11509. }
  11510. else
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11513. }
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11515. isKnowKey = TRUE;
  11516. }
  11517. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11524. }
  11525. else
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11528. }
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11530. isKnowKey = TRUE;
  11531. }
  11532. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11539. }
  11540. else
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11543. }
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11545. isKnowKey = TRUE;
  11546. }
  11547. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11554. }
  11555. else
  11556. {
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11558. }
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11560. isKnowKey = TRUE;
  11561. }
  11562. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11569. }
  11570. else
  11571. {
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11573. }
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11575. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11576. isKnowKey = TRUE;
  11577. }
  11578. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11582. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11585. }
  11586. else
  11587. {
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11589. }
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11591. isKnowKey = TRUE;
  11592. }
  11593. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11594. {
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11600. }
  11601. else
  11602. {
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11604. }
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11606. isKnowKey = TRUE;
  11607. }
  11608. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11612. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11615. }
  11616. else
  11617. {
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11619. }
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11621. isKnowKey = TRUE;
  11622. }
  11623. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11624. {
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11630. }
  11631. else
  11632. {
  11633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11634. }
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11636. isKnowKey = TRUE;
  11637. }
  11638. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11639. {
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11642. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11645. }
  11646. else
  11647. {
  11648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11649. }
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11651. isKnowKey = TRUE;
  11652. }
  11653. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11654. {
  11655. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11658. {
  11659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11660. }
  11661. else
  11662. {
  11663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11664. }
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11666. isKnowKey = TRUE;
  11667. }
  11668. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11669. {
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11673. {
  11674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11675. }
  11676. else
  11677. {
  11678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11679. }
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11681. isKnowKey = TRUE;
  11682. }
  11683. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11684. {
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11688. {
  11689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11690. }
  11691. else
  11692. {
  11693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11694. }
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11696. isKnowKey = TRUE;
  11697. }
  11698. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11699. {
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11703. {
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11705. }
  11706. else
  11707. {
  11708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11709. }
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11711. isKnowKey = TRUE;
  11712. }
  11713. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11714. {
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11718. {
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11720. }
  11721. else
  11722. {
  11723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11724. }
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11726. isKnowKey = TRUE;
  11727. }
  11728. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11729. {
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11733. {
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11735. }
  11736. else
  11737. {
  11738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11739. }
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11741. isKnowKey = TRUE;
  11742. }
  11743. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11744. {
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11748. {
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11750. }
  11751. else
  11752. {
  11753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11754. }
  11755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11756. isKnowKey = TRUE;
  11757. }
  11758. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11759. {
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11763. {
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11765. }
  11766. else
  11767. {
  11768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11769. }
  11770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11771. isKnowKey = TRUE;
  11772. }
  11773. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11774. {
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11778. {
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11780. }
  11781. else
  11782. {
  11783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11784. }
  11785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11786. isKnowKey = TRUE;
  11787. }
  11788. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11789. {
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11793. {
  11794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11795. }
  11796. else
  11797. {
  11798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11799. }
  11800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11801. isKnowKey = TRUE;
  11802. }
  11803. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11804. {
  11805. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11808. {
  11809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11810. }
  11811. else
  11812. {
  11813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11814. }
  11815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11816. isKnowKey = TRUE;
  11817. }
  11818. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11819. {
  11820. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11823. {
  11824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11825. }
  11826. else
  11827. {
  11828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11829. }
  11830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11831. isKnowKey = TRUE;
  11832. }
  11833. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11834. {
  11835. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11838. {
  11839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11840. }
  11841. else
  11842. {
  11843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11844. }
  11845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11846. isKnowKey = TRUE;
  11847. }
  11848. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11849. {
  11850. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11853. {
  11854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11855. }
  11856. else
  11857. {
  11858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11859. }
  11860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11861. isKnowKey = TRUE;
  11862. }
  11863. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11864. {
  11865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11868. {
  11869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11870. }
  11871. else
  11872. {
  11873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11874. }
  11875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11876. isKnowKey = TRUE;
  11877. }
  11878. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11879. {
  11880. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11883. {
  11884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11885. }
  11886. else
  11887. {
  11888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11889. }
  11890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11891. isKnowKey = TRUE;
  11892. }
  11893. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11894. {
  11895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11898. {
  11899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11900. }
  11901. else
  11902. {
  11903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11904. }
  11905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11906. isKnowKey = TRUE;
  11907. }
  11908. #if 0
  11909. //For OCTT Test Case
  11910. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11911. {
  11912. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11914. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11915. {
  11916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11917. }
  11918. else
  11919. {
  11920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11921. }
  11922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11923. isKnowKey = TRUE;
  11924. }
  11925. #endif
  11926. #if 1
  11927. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11928. {
  11929. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11931. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11932. {
  11933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11934. }
  11935. else
  11936. {
  11937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11938. }
  11939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11940. isKnowKey = TRUE;
  11941. }
  11942. #endif
  11943. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11944. {
  11945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11947. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11948. {
  11949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11950. }
  11951. else
  11952. {
  11953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11954. }
  11955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11956. isKnowKey = TRUE;
  11957. }
  11958. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11959. {
  11960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11962. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11963. {
  11964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11965. }
  11966. else
  11967. {
  11968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11969. }
  11970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11971. isKnowKey = TRUE;
  11972. }
  11973. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11974. {
  11975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11977. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11978. {
  11979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11980. }
  11981. else
  11982. {
  11983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11984. }
  11985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11986. isKnowKey = TRUE;
  11987. }
  11988. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11989. {
  11990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11992. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11993. {
  11994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11995. }
  11996. else
  11997. {
  11998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11999. }
  12000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12001. isKnowKey = TRUE;
  12002. }
  12003. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12004. {
  12005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12007. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12008. {
  12009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12010. }
  12011. else
  12012. {
  12013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12014. }
  12015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12016. isKnowKey = TRUE;
  12017. }
  12018. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12019. {
  12020. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12022. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12023. {
  12024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12025. }
  12026. else
  12027. {
  12028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12029. }
  12030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12031. isKnowKey = TRUE;
  12032. }
  12033. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12034. {
  12035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12037. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12038. {
  12039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12040. }
  12041. else
  12042. {
  12043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12044. }
  12045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12046. isKnowKey = TRUE;
  12047. }
  12048. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12049. {
  12050. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12052. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12053. {
  12054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12055. }
  12056. else
  12057. {
  12058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12059. }
  12060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12061. isKnowKey = TRUE;
  12062. }
  12063. //=========================================================
  12064. if(!isEmpty && !isKnowKey)
  12065. {
  12066. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12067. strcpy(unknownkey[UnknownKeynum], keyReq);
  12068. UnknownKeynum = UnknownKeynum + 1;
  12069. }
  12070. }
  12071. void processUnkownKey(void)
  12072. {
  12073. DEBUG_INFO("processUnkownKey\n");
  12074. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12075. for(int index=0; index < UnknownKeynum; index++)
  12076. {
  12077. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12078. {
  12079. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12080. }
  12081. }
  12082. }
  12083. int setKeyValue(char *key, char *value)
  12084. {
  12085. int isSuccess = NotSupported;
  12086. int check_ascii=0;
  12087. char str[10]={0};
  12088. #ifdef Debug
  12089. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  12090. #endif
  12091. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12092. {
  12093. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12095. {
  12096. strcpy(str, (const char*)value);
  12097. for(int i = 0; str[i]; i++){
  12098. str[i] = tolower(str[i]);
  12099. }
  12100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12101. isSuccess = ConfigurationStatus_Accepted;
  12102. }
  12103. else
  12104. {
  12105. isSuccess = ConfigurationStatus_Rejected;
  12106. }
  12107. }
  12108. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12109. {
  12110. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12112. {
  12113. strcpy(str, (const char*)value);
  12114. for(int i = 0; str[i]; i++){
  12115. str[i] = tolower(str[i]);
  12116. }
  12117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12118. isSuccess = ConfigurationStatus_Accepted;
  12119. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  12120. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12121. }
  12122. else
  12123. {
  12124. isSuccess = ConfigurationStatus_Rejected;
  12125. }
  12126. }
  12127. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12128. {
  12129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12130. {
  12131. strcpy(str, (const char*)value);
  12132. for(int i = 0; str[i]; i++)
  12133. {
  12134. str[i] = tolower(str[i]);
  12135. }
  12136. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12138. isSuccess = ConfigurationStatus_Accepted;
  12139. }
  12140. else
  12141. {
  12142. isSuccess = ConfigurationStatus_Rejected;
  12143. }
  12144. }
  12145. if(strcmp(key, "BlinkRepeat") == 0)
  12146. {
  12147. //Charger.BlinkRepeat = Integer.parseInt(value);
  12148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12149. {
  12150. check_ascii = value[0];
  12151. if( (check_ascii < 48) || (check_ascii > 57) )
  12152. {
  12153. isSuccess = ConfigurationStatus_Rejected;
  12154. }
  12155. else
  12156. {
  12157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12158. isSuccess = ConfigurationStatus_Accepted;
  12159. }
  12160. }
  12161. else
  12162. {
  12163. isSuccess = ConfigurationStatus_Rejected;
  12164. }
  12165. }
  12166. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12167. {
  12168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12169. {
  12170. check_ascii = value[0];
  12171. if( (check_ascii < 48) || (check_ascii > 57) )
  12172. {
  12173. isSuccess = ConfigurationStatus_Rejected;
  12174. }
  12175. else
  12176. {
  12177. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12179. isSuccess = ConfigurationStatus_Accepted;
  12180. }
  12181. }
  12182. else
  12183. {
  12184. isSuccess = ConfigurationStatus_Rejected;
  12185. }
  12186. }
  12187. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12188. {
  12189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12190. {
  12191. check_ascii = value[0];
  12192. if( (check_ascii < 48) || (check_ascii > 57) )
  12193. {
  12194. isSuccess = ConfigurationStatus_Rejected;
  12195. }
  12196. else
  12197. {
  12198. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12200. isSuccess = ConfigurationStatus_Accepted;
  12201. }
  12202. }
  12203. else
  12204. {
  12205. isSuccess = ConfigurationStatus_Rejected;
  12206. }
  12207. }
  12208. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12209. {
  12210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12211. {
  12212. check_ascii = value[0];
  12213. if( (check_ascii < 48) || (check_ascii > 57) )
  12214. {
  12215. isSuccess = ConfigurationStatus_Rejected;
  12216. }
  12217. else
  12218. {
  12219. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12221. isSuccess = ConfigurationStatus_Accepted;
  12222. }
  12223. }
  12224. else
  12225. {
  12226. isSuccess = ConfigurationStatus_Rejected;
  12227. }
  12228. }
  12229. if(strcmp(key, "HeartbeatInterval") == 0)
  12230. {
  12231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12232. {
  12233. check_ascii = value[0];
  12234. if( (check_ascii < 48) || (check_ascii > 57) )
  12235. {
  12236. isSuccess = ConfigurationStatus_Rejected;
  12237. }
  12238. else
  12239. {
  12240. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12242. HeartBeatWaitTime = atoi(value);
  12243. isSuccess = ConfigurationStatus_Accepted;
  12244. }
  12245. }
  12246. else
  12247. {
  12248. isSuccess = ConfigurationStatus_Rejected;
  12249. }
  12250. }
  12251. if(strcmp(key, "LightIntensity") == 0)
  12252. {
  12253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12254. {
  12255. check_ascii = value[0];
  12256. if( (check_ascii < 48) || (check_ascii > 57) )
  12257. {
  12258. isSuccess = ConfigurationStatus_Rejected;
  12259. }
  12260. else
  12261. {
  12262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12263. isSuccess = ConfigurationStatus_Accepted;
  12264. }
  12265. }
  12266. else
  12267. {
  12268. isSuccess = ConfigurationStatus_Rejected;
  12269. }
  12270. }
  12271. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12272. {
  12273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12274. {
  12275. strcpy(str, (const char*)value);
  12276. for(int i = 0; str[i]; i++)
  12277. {
  12278. str[i] = tolower(str[i]);
  12279. }
  12280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12281. isSuccess = ConfigurationStatus_Accepted;
  12282. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12283. }
  12284. else
  12285. {
  12286. isSuccess = ConfigurationStatus_Rejected;
  12287. }
  12288. }
  12289. if(strcmp(key, "LocalPreAuthorize") == 0)
  12290. {
  12291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12292. {
  12293. strcpy(str, (const char*)value);
  12294. for(int i = 0; str[i]; i++)
  12295. {
  12296. str[i] = tolower(str[i]);
  12297. }
  12298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12299. isSuccess = ConfigurationStatus_Accepted;
  12300. }
  12301. else
  12302. {
  12303. isSuccess = ConfigurationStatus_Rejected;
  12304. }
  12305. }
  12306. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12307. {
  12308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12309. {
  12310. check_ascii = value[0];
  12311. if( (check_ascii < 48) || (check_ascii > 57) )
  12312. {
  12313. isSuccess = ConfigurationStatus_Rejected;
  12314. }
  12315. else
  12316. {
  12317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12318. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12319. isSuccess = ConfigurationStatus_Accepted;
  12320. }
  12321. }
  12322. else
  12323. {
  12324. isSuccess = ConfigurationStatus_Rejected;
  12325. }
  12326. }
  12327. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12328. {
  12329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12330. {
  12331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12332. isSuccess = ConfigurationStatus_Accepted;
  12333. }
  12334. else
  12335. {
  12336. isSuccess = ConfigurationStatus_Rejected;
  12337. }
  12338. }
  12339. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12340. {
  12341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12342. {
  12343. check_ascii = value[0];
  12344. if( (check_ascii < 48) || (check_ascii > 57) )
  12345. {
  12346. isSuccess = ConfigurationStatus_Rejected;
  12347. }
  12348. else
  12349. {
  12350. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12352. isSuccess = ConfigurationStatus_Accepted;
  12353. }
  12354. }
  12355. else
  12356. {
  12357. isSuccess = ConfigurationStatus_Rejected;
  12358. }
  12359. }
  12360. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12361. {
  12362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12363. {
  12364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12365. isSuccess = ConfigurationStatus_Accepted;
  12366. }
  12367. else
  12368. {
  12369. isSuccess = ConfigurationStatus_Rejected;
  12370. }
  12371. }
  12372. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12373. {
  12374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12375. {
  12376. check_ascii = value[0];
  12377. if( (check_ascii < 48) || (check_ascii > 57) )
  12378. {
  12379. isSuccess = ConfigurationStatus_Rejected;
  12380. }
  12381. else
  12382. {
  12383. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12385. isSuccess = ConfigurationStatus_Accepted;
  12386. }
  12387. }
  12388. else
  12389. {
  12390. isSuccess = ConfigurationStatus_Rejected;
  12391. }
  12392. }
  12393. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12394. {
  12395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12396. {
  12397. check_ascii = value[0];
  12398. if( (check_ascii < 48) || (check_ascii > 57) )
  12399. {
  12400. isSuccess = ConfigurationStatus_Rejected;
  12401. }
  12402. else
  12403. {
  12404. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12406. isSuccess = ConfigurationStatus_Accepted;
  12407. }
  12408. }
  12409. else
  12410. {
  12411. isSuccess = ConfigurationStatus_Rejected;
  12412. }
  12413. }
  12414. if(strcmp(key, "MinimumStatusDuration") == 0)
  12415. {
  12416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12417. {
  12418. check_ascii = value[0];
  12419. if( (check_ascii < 48) || (check_ascii > 57) )
  12420. {
  12421. isSuccess = ConfigurationStatus_Rejected;
  12422. }
  12423. else
  12424. {
  12425. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12426. {
  12427. isSuccess = ConfigurationStatus_Rejected;
  12428. }
  12429. else
  12430. {
  12431. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12433. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12434. isSuccess = ConfigurationStatus_Accepted;
  12435. }
  12436. }
  12437. }
  12438. else
  12439. {
  12440. isSuccess = ConfigurationStatus_Rejected;
  12441. }
  12442. }
  12443. if(strcmp(key, "NumberOfConnectors") == 0)
  12444. {
  12445. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12446. {
  12447. check_ascii = value[0];
  12448. if( (check_ascii < 48) || (check_ascii > 57) )
  12449. {
  12450. isSuccess = ConfigurationStatus_Rejected;
  12451. }
  12452. else
  12453. {
  12454. //Charger.ResetRetries = Integer.parseInt(value);
  12455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12456. isSuccess = ConfigurationStatus_Accepted;
  12457. }
  12458. }
  12459. else
  12460. {
  12461. isSuccess = ConfigurationStatus_Rejected;
  12462. }
  12463. }
  12464. if(strcmp(key, "ResetRetries") == 0)
  12465. {
  12466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12467. {
  12468. check_ascii = value[0];
  12469. if( (check_ascii < 48) || (check_ascii > 57) )
  12470. {
  12471. isSuccess = ConfigurationStatus_Rejected;
  12472. }
  12473. else
  12474. {
  12475. //Charger.ResetRetries = Integer.parseInt(value);
  12476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12477. isSuccess = ConfigurationStatus_Accepted;
  12478. }
  12479. }
  12480. else
  12481. {
  12482. isSuccess = ConfigurationStatus_Rejected;
  12483. }
  12484. }
  12485. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12486. {
  12487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12488. {
  12489. strcpy(str, (const char*)value);
  12490. for(int i = 0; str[i]; i++)
  12491. {
  12492. str[i] = tolower(str[i]);
  12493. }
  12494. if(strcmp(str, "notapplicable")== 0)
  12495. {
  12496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12497. isSuccess = ConfigurationStatus_Accepted;
  12498. }
  12499. else if(strcmp(str, "unknown")== 0)
  12500. {
  12501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12502. isSuccess = ConfigurationStatus_Accepted;
  12503. }
  12504. else if(strcmp(str, "rst")== 0)
  12505. {
  12506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12507. isSuccess = ConfigurationStatus_Accepted;
  12508. }
  12509. else if(strcmp(str, "rts")== 0)
  12510. {
  12511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12512. isSuccess = ConfigurationStatus_Accepted;
  12513. }
  12514. else if(strcmp(str, "srt")== 0)
  12515. {
  12516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12517. isSuccess = ConfigurationStatus_Accepted;
  12518. }
  12519. else if(strcmp(str, "str")== 0)
  12520. {
  12521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12522. isSuccess = ConfigurationStatus_Accepted;
  12523. }
  12524. else if(strcmp(str, "trs")== 0)
  12525. {
  12526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12527. isSuccess = ConfigurationStatus_Accepted;
  12528. }
  12529. else if(strcmp(str, "tsr")== 0)
  12530. {
  12531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12532. isSuccess = ConfigurationStatus_Accepted;
  12533. }
  12534. else
  12535. {
  12536. isSuccess = ConfigurationStatus_Rejected;
  12537. }
  12538. }
  12539. else
  12540. {
  12541. isSuccess = ConfigurationStatus_Rejected;
  12542. }
  12543. }
  12544. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12545. {
  12546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12547. {
  12548. check_ascii = value[0];
  12549. if( (check_ascii < 48) || (check_ascii > 57) )
  12550. {
  12551. isSuccess = ConfigurationStatus_Rejected;
  12552. }
  12553. else
  12554. {
  12555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12556. isSuccess = ConfigurationStatus_Accepted;
  12557. }
  12558. }
  12559. else
  12560. {
  12561. isSuccess = ConfigurationStatus_Rejected;
  12562. }
  12563. }
  12564. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12565. {
  12566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12567. {
  12568. strcpy(str, (const char*)value);
  12569. for(int i = 0; str[i]; i++)
  12570. {
  12571. str[i] = tolower(str[i]);
  12572. }
  12573. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12575. isSuccess = ConfigurationStatus_Accepted;
  12576. }
  12577. else
  12578. {
  12579. isSuccess = ConfigurationStatus_Rejected;
  12580. }
  12581. }
  12582. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12583. {
  12584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12585. {
  12586. strcpy(str, (const char*)value);
  12587. for(int i = 0; str[i]; i++)
  12588. {
  12589. str[i] = tolower(str[i]);
  12590. }
  12591. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12593. isSuccess = ConfigurationStatus_Accepted;
  12594. }
  12595. else
  12596. {
  12597. isSuccess = ConfigurationStatus_Rejected;
  12598. }
  12599. }
  12600. if(strcmp(key, "StopTxnAlignedData") == 0)
  12601. {
  12602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12603. {
  12604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12605. isSuccess = ConfigurationStatus_Accepted;
  12606. }
  12607. else
  12608. {
  12609. isSuccess = ConfigurationStatus_Rejected;
  12610. }
  12611. }
  12612. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12613. {
  12614. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12615. {
  12616. check_ascii = value[0];
  12617. if( (check_ascii < 48) || (check_ascii > 57) )
  12618. {
  12619. isSuccess = ConfigurationStatus_Rejected;
  12620. }
  12621. else
  12622. {
  12623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12624. isSuccess = ConfigurationStatus_Accepted;
  12625. }
  12626. }
  12627. else
  12628. {
  12629. isSuccess = ConfigurationStatus_Rejected;
  12630. }
  12631. }
  12632. if(strcmp(key, "StopTxnSampledData") == 0)
  12633. {
  12634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12635. {
  12636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12637. isSuccess = ConfigurationStatus_Accepted;
  12638. }
  12639. else
  12640. {
  12641. isSuccess = ConfigurationStatus_Rejected;
  12642. }
  12643. }
  12644. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12645. {
  12646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12647. {
  12648. check_ascii = value[0];
  12649. if( (check_ascii < 48) || (check_ascii > 57) )
  12650. {
  12651. isSuccess = ConfigurationStatus_Rejected;
  12652. }
  12653. else
  12654. {
  12655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12656. isSuccess = ConfigurationStatus_Accepted;
  12657. }
  12658. }
  12659. else
  12660. {
  12661. isSuccess = ConfigurationStatus_Rejected;
  12662. }
  12663. }
  12664. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12665. {
  12666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12667. {
  12668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12669. isSuccess = ConfigurationStatus_Accepted;
  12670. }
  12671. else
  12672. {
  12673. isSuccess = ConfigurationStatus_Rejected;
  12674. }
  12675. }
  12676. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12677. {
  12678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12679. {
  12680. check_ascii = value[0];
  12681. if( (check_ascii < 48) || (check_ascii > 57) )
  12682. {
  12683. isSuccess = ConfigurationStatus_Rejected;
  12684. }
  12685. else
  12686. {
  12687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12688. isSuccess = ConfigurationStatus_Accepted;
  12689. }
  12690. }
  12691. else
  12692. {
  12693. isSuccess = ConfigurationStatus_Rejected;
  12694. }
  12695. }
  12696. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12697. {
  12698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12699. {
  12700. check_ascii = value[0];
  12701. if( (check_ascii < 48) || (check_ascii > 57) )
  12702. {
  12703. isSuccess = ConfigurationStatus_Rejected;
  12704. }
  12705. else
  12706. {
  12707. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12709. TransactionMessageAttemptsValue = atoi(value);
  12710. isSuccess = ConfigurationStatus_Accepted;
  12711. }
  12712. }
  12713. else
  12714. {
  12715. isSuccess = ConfigurationStatus_Rejected;
  12716. }
  12717. }
  12718. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12719. {
  12720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12721. {
  12722. check_ascii = value[0];
  12723. if( (check_ascii < 48) || (check_ascii > 57) )
  12724. {
  12725. isSuccess = ConfigurationStatus_Rejected;
  12726. }
  12727. else
  12728. {
  12729. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12731. TransactionMessageRetryIntervalValue = atoi(value);
  12732. isSuccess = ConfigurationStatus_Accepted;
  12733. }
  12734. }
  12735. else
  12736. {
  12737. isSuccess = ConfigurationStatus_Rejected;
  12738. }
  12739. }
  12740. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12741. {
  12742. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12743. {
  12744. strcpy(str, (const char*)value);
  12745. for(int i = 0; str[i]; i++)
  12746. {
  12747. str[i] = tolower(str[i]);
  12748. }
  12749. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12751. isSuccess = ConfigurationStatus_Accepted;
  12752. }
  12753. else
  12754. {
  12755. isSuccess = ConfigurationStatus_Rejected;
  12756. }
  12757. }
  12758. if(strcmp(key, "WebSocketPingInterval") == 0)
  12759. {
  12760. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12761. {
  12762. check_ascii = value[0];
  12763. if( (check_ascii < 48) || (check_ascii > 57) )
  12764. {
  12765. isSuccess = ConfigurationStatus_Rejected;
  12766. }
  12767. else
  12768. {
  12769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12770. isSuccess = ConfigurationStatus_Accepted;
  12771. }
  12772. }
  12773. else
  12774. {
  12775. isSuccess = ConfigurationStatus_Rejected;
  12776. }
  12777. }
  12778. #if 0
  12779. //For OCPP Test Case
  12780. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12781. {
  12782. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12783. {
  12784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12785. isSuccess = ConfigurationStatus_Accepted;
  12786. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12787. }
  12788. else
  12789. {
  12790. isSuccess = ConfigurationStatus_Rejected;
  12791. }
  12792. }
  12793. #endif
  12794. #if 1
  12795. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12796. {
  12797. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12798. {
  12799. strcpy(str, (const char*)value);
  12800. for(int i = 0; str[i]; i++)
  12801. {
  12802. str[i] = tolower(str[i]);
  12803. }
  12804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12805. isSuccess = ConfigurationStatus_Accepted;
  12806. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12807. }
  12808. else
  12809. {
  12810. isSuccess = ConfigurationStatus_Rejected;
  12811. }
  12812. }
  12813. #endif
  12814. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12815. {
  12816. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12817. {
  12818. check_ascii = value[0];
  12819. if( (check_ascii < 48) || (check_ascii > 57) )
  12820. {
  12821. isSuccess = ConfigurationStatus_Rejected;
  12822. }
  12823. else
  12824. {
  12825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12826. isSuccess = ConfigurationStatus_Accepted;
  12827. }
  12828. }
  12829. else
  12830. {
  12831. isSuccess = ConfigurationStatus_Rejected;
  12832. }
  12833. }
  12834. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12835. {
  12836. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12837. {
  12838. check_ascii = value[0];
  12839. if( (check_ascii < 48) || (check_ascii > 57) )
  12840. {
  12841. isSuccess = ConfigurationStatus_Rejected;
  12842. }
  12843. else
  12844. {
  12845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12846. isSuccess = ConfigurationStatus_Accepted;
  12847. }
  12848. }
  12849. else
  12850. {
  12851. isSuccess = ConfigurationStatus_Rejected;
  12852. }
  12853. }
  12854. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12855. {
  12856. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12857. {
  12858. strcpy(str, (const char*)value);
  12859. for(int i = 0; str[i]; i++)
  12860. {
  12861. str[i] = tolower(str[i]);
  12862. }
  12863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12864. isSuccess = ConfigurationStatus_Accepted;
  12865. }
  12866. else
  12867. {
  12868. isSuccess = ConfigurationStatus_Rejected;
  12869. }
  12870. }
  12871. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12872. {
  12873. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12874. {
  12875. check_ascii = value[0];
  12876. if( (check_ascii < 48) || (check_ascii > 57) )
  12877. {
  12878. isSuccess = ConfigurationStatus_Rejected;
  12879. }
  12880. else
  12881. {
  12882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12883. isSuccess = ConfigurationStatus_Accepted;
  12884. }
  12885. }
  12886. else
  12887. {
  12888. isSuccess = ConfigurationStatus_Rejected;
  12889. }
  12890. }
  12891. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12892. {
  12893. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12894. {
  12895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12896. isSuccess = ConfigurationStatus_Accepted;
  12897. }
  12898. else
  12899. {
  12900. isSuccess = ConfigurationStatus_Rejected;
  12901. }
  12902. }
  12903. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12904. {
  12905. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12906. {
  12907. check_ascii = value[0];
  12908. if( (check_ascii < 48) || (check_ascii > 57) )
  12909. {
  12910. isSuccess = ConfigurationStatus_Rejected;
  12911. }
  12912. else
  12913. {
  12914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12915. isSuccess = ConfigurationStatus_Accepted;
  12916. }
  12917. }
  12918. else
  12919. {
  12920. isSuccess = ConfigurationStatus_Rejected;
  12921. }
  12922. }
  12923. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12924. {
  12925. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12926. {
  12927. strcpy(str, (const char*)value);
  12928. for(int i = 0; str[i]; i++)
  12929. {
  12930. str[i] = tolower(str[i]);
  12931. }
  12932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12933. isSuccess = ConfigurationStatus_Accepted;
  12934. }
  12935. else
  12936. {
  12937. isSuccess = ConfigurationStatus_Rejected;
  12938. }
  12939. }
  12940. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12941. {
  12942. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12943. {
  12944. check_ascii = value[0];
  12945. if( (check_ascii < 48) || (check_ascii > 57) )
  12946. {
  12947. isSuccess = ConfigurationStatus_Rejected;
  12948. }
  12949. else
  12950. {
  12951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12952. isSuccess = ConfigurationStatus_Accepted;
  12953. }
  12954. }
  12955. else
  12956. {
  12957. isSuccess = ConfigurationStatus_Rejected;
  12958. }
  12959. }
  12960. return isSuccess;
  12961. }
  12962. int updateSetting(char *key, char *value)
  12963. {
  12964. mtrace();
  12965. int isSuccess = FALSE;
  12966. char string[1000]={0}, buffer[1000]={0};
  12967. char strtemp[50]={0};
  12968. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12969. int pos, c = 0;
  12970. char *loc;
  12971. int pos1=0;
  12972. FILE *f = fopen("/var/www/settings1", "r");
  12973. if(f == NULL)
  12974. {
  12975. #ifdef Debug
  12976. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12977. #endif
  12978. return isSuccess;
  12979. }
  12980. fseek(f, 0, SEEK_END);
  12981. long fsize = ftell(f);
  12982. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12983. fread(string, 1, fsize, f);
  12984. fclose(f);
  12985. string[fsize] = 0;
  12986. loc = strstr(string, key);
  12987. if(loc != NULL)
  12988. {
  12989. DEBUG_INFO("key exist!\n");
  12990. pos = loc - string-1;
  12991. f = fopen("/var/www/settings1", "w");
  12992. strncpy(buffer, string, pos);
  12993. fprintf(f, "%s", buffer);
  12994. memset(sstr ,0, sizeof(sstr) );
  12995. c = 0;
  12996. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12997. {
  12998. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12999. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13000. c++;
  13001. }
  13002. sstr[c] = '\0';
  13003. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  13004. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  13005. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  13006. memset(buffer ,0, sizeof(buffer) );
  13007. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  13008. //printf("buffer=%s",buffer);
  13009. fprintf(f, "%s", buffer);
  13010. fclose(f);
  13011. }
  13012. else
  13013. {
  13014. printf("key not exist!\n");
  13015. f = fopen("/var/www/settings1", "w+");
  13016. fputs(string, f);
  13017. fseek(f, -1, SEEK_CUR);
  13018. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  13019. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  13020. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  13021. fclose(f);
  13022. }
  13023. isSuccess = TRUE;
  13024. return isSuccess;
  13025. }
  13026. int TransactionMessageAttemptsGet(void)
  13027. {
  13028. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13029. }
  13030. int FirstHeartBeatResponse(void)
  13031. {
  13032. return FirstHeartBeat;
  13033. }
  13034. int TransactionMessageRetryIntervalGet(void)
  13035. {
  13036. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13037. }
  13038. #define SA struct sockaddr
  13039. #define MAXBUF 1024
  13040. //static int m_socket_data;
  13041. //static int sockfd;
  13042. int ReadHttpStatus(int sock){
  13043. //char c;
  13044. char buff[1024]="",*ptr=buff+1;
  13045. int bytes_received, status;
  13046. DEBUG_INFO("Begin Response ..\n");
  13047. while((bytes_received = recv(sock, ptr, 1, 0))){
  13048. if(bytes_received==-1){
  13049. perror("ReadHttpStatus");
  13050. exit(1);
  13051. }
  13052. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13053. ptr++;
  13054. }
  13055. *ptr=0;
  13056. ptr=buff+1;
  13057. sscanf(ptr,"%*s %d ", &status);
  13058. DEBUG_INFO("%s\n",ptr);
  13059. DEBUG_INFO("status=%d\n",status);
  13060. DEBUG_INFO("End Response ..\n");
  13061. return (bytes_received>0)?status:0;
  13062. }
  13063. //the only filed that it parsed is 'Content-Length'
  13064. int ParseHeader(int sock){
  13065. //char c;
  13066. char buff[1024]="",*ptr=buff+4;
  13067. int bytes_received;
  13068. DEBUG_INFO("Begin HEADER ..\n");
  13069. while((bytes_received = recv(sock, ptr, 1, 0))){
  13070. if(bytes_received==-1){
  13071. perror("Parse Header");
  13072. exit(1);
  13073. }
  13074. if(
  13075. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13076. (ptr[-1]=='\r') && (*ptr=='\n' )
  13077. ) break;
  13078. ptr++;
  13079. }
  13080. *ptr=0;
  13081. ptr=buff+4;
  13082. //printf("%s",ptr);
  13083. if(bytes_received){
  13084. ptr=strstr(ptr,"Content-Length:");
  13085. if(ptr){
  13086. sscanf(ptr,"%*s %d",&bytes_received);
  13087. }else
  13088. bytes_received=-1; //unknown size
  13089. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13090. }
  13091. DEBUG_INFO("End HEADER ..\n");
  13092. return bytes_received ;
  13093. }
  13094. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13095. {
  13096. char rmFileCmd[100]={0};
  13097. char FilePath[100]={0};
  13098. char ftpbuf[200];
  13099. int systemresult;
  13100. //DEBUG_INFO("filename=%s\n",filename);
  13101. //DEBUG_INFO("url=%s\n",url);
  13102. sprintf(FilePath,"/mnt/%s",filename);
  13103. if((access(FilePath,F_OK))!=-1)
  13104. {
  13105. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13106. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13107. system(rmFileCmd);
  13108. }
  13109. memset(ftpbuf, 0, sizeof(ftpbuf));
  13110. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13111. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13112. systemresult = system(ftpbuf);
  13113. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13114. if(systemresult != 0)
  13115. {
  13116. DEBUG_INFO("http DownLoad error!\n");
  13117. return FALSE;
  13118. }
  13119. return TRUE;
  13120. }
  13121. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13122. {
  13123. char rmFileCmd[100]={0};
  13124. char FilePath[100]={0};
  13125. char ftpbuf[200];
  13126. int systemresult;
  13127. //char temp[100];
  13128. #if 0
  13129. struct hostent* server;
  13130. char *IPbuffer;
  13131. server = gethostbyname(location);
  13132. // To convert an Internet network
  13133. // address into ASCII string
  13134. IPbuffer = inet_ntoa(*((struct in_addr*)
  13135. server->h_addr_list[0]));
  13136. #endif
  13137. sprintf(FilePath,"/mnt/%s",filename);
  13138. if((access(FilePath,F_OK))!=-1)
  13139. {
  13140. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13141. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13142. system(rmFileCmd);
  13143. }
  13144. memset(ftpbuf, 0, sizeof(ftpbuf));
  13145. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13146. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13147. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13148. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13149. systemresult = system(ftpbuf);
  13150. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13151. if(systemresult != 0)
  13152. {
  13153. printf("wget error!\n");
  13154. return FALSE;
  13155. }
  13156. return TRUE;
  13157. }
  13158. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13159. {
  13160. char rmFileCmd[100]={0};
  13161. char FilePath[100]={0};
  13162. char ftpbuf[200];
  13163. char filenametemp[60]={0};
  13164. int systemresult;
  13165. //DEBUG_INFO("filename=%s\n",filename);
  13166. //DEBUG_INFO("url=%s\n",url);
  13167. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13168. if((access(FilePath,F_OK))!=-1)
  13169. {
  13170. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13171. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13172. system(rmFileCmd);
  13173. }
  13174. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13175. if(fp == NULL)
  13176. {
  13177. DEBUG_INFO("log is NULL\n");
  13178. return FALSE;
  13179. }
  13180. else
  13181. {
  13182. fprintf(fp, "%s\n", url);
  13183. sscanf(filename, "%*2[.]%s", filenametemp);
  13184. fprintf(fp, "%s\n", filenametemp);
  13185. fclose(fp);
  13186. }
  13187. memset(ftpbuf, 0, sizeof(ftpbuf));
  13188. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13189. systemresult = system(ftpbuf);
  13190. DEBUG_INFO("systemresult=%d\n",systemresult);
  13191. if(systemresult != 0)
  13192. {
  13193. DEBUG_INFO("http upload error!\n");
  13194. return FALSE;
  13195. }
  13196. return TRUE;
  13197. }
  13198. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13199. {
  13200. struct hostent* server;
  13201. char *IPbuffer;
  13202. char ftpbuf[200];
  13203. int systemresult;
  13204. // To retrieve host information
  13205. server = gethostbyname(location);
  13206. // To convert an Internet network
  13207. // address into ASCII string
  13208. IPbuffer = inet_ntoa(*((struct in_addr*)
  13209. server->h_addr_list[0]));
  13210. memset(ftpbuf, 0, sizeof(ftpbuf));
  13211. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13212. /* format : ftpput -u username -p passwd IP target source*/
  13213. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13214. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13215. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13216. systemresult = system(ftpbuf);
  13217. DEBUG_INFO("systemresult=%d\n",systemresult);
  13218. if(systemresult != 0)
  13219. {
  13220. DEBUG_INFO("ftpput error!\n");
  13221. return FALSE;
  13222. }
  13223. return TRUE;
  13224. }
  13225. int SettingChargingRecord(int target, int transactionId)
  13226. {
  13227. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13228. {
  13229. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13230. {
  13231. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13232. {
  13233. addBuff(target, transactionId, 0);
  13234. return TRUE;
  13235. }
  13236. }
  13237. for (int index = 0; index < CCS_QUANTITY; index++)
  13238. {
  13239. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13240. {
  13241. addBuff(target, transactionId, 0);
  13242. return TRUE;
  13243. }
  13244. }
  13245. for (int index = 0; index < GB_QUANTITY; index++)
  13246. {
  13247. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13248. {
  13249. addBuff(target, transactionId, 0);
  13250. return TRUE;
  13251. }
  13252. }
  13253. }
  13254. else
  13255. {
  13256. for (int index = 0; index < AC_QUANTITY; index++)
  13257. {
  13258. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13259. {
  13260. addBuff(target, transactionId, 0);
  13261. return TRUE;
  13262. }
  13263. }
  13264. }
  13265. return FALSE;
  13266. }
  13267. int addBuff(int gun_idx, int user_id, int cmd_sn)
  13268. {
  13269. int isSuccess = FALSE;
  13270. //char *query = NULL;
  13271. sqlite3_stmt *stmt;
  13272. int rc; // return code
  13273. char str[20];
  13274. sprintf(str,"%d",user_id);
  13275. 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 */
  13276. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  13277. rc = sqlite3_step(stmt); /* 3 */
  13278. if (rc != SQLITE_DONE) {
  13279. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  13280. goto out;
  13281. }
  13282. sqlite3_finalize(stmt);
  13283. // free(query);
  13284. out:
  13285. //----------------------
  13286. // close SQLite database
  13287. //----------------------
  13288. sqlite3_close(db);
  13289. printf("database closed.\n");
  13290. return isSuccess;
  13291. }
  13292. /**
  13293. * Place the contents of the specified file into a memory buffer
  13294. *
  13295. * @param[in] filename The path and name of the file to read
  13296. * @param[out] filebuffer A pointer to the contents in memory
  13297. * @return status 0 success, 1 on failure
  13298. */
  13299. int get_file_contents(const char* filename, char** outbuffer) {
  13300. FILE* file = NULL;
  13301. long filesize;
  13302. const int blocksize = 1;
  13303. size_t readsize;
  13304. char* filebuffer;
  13305. // Open the file
  13306. file = fopen(filename, "r");
  13307. if (NULL == file)
  13308. {
  13309. printf("'%s' not opened\n", filename);
  13310. exit(EXIT_FAILURE);
  13311. }
  13312. // Determine the file size
  13313. fseek(file, 0, SEEK_END);
  13314. filesize = ftell(file);
  13315. rewind (file);
  13316. // Allocate memory for the file contents
  13317. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13318. *outbuffer = filebuffer;
  13319. if (filebuffer == NULL)
  13320. {
  13321. fputs ("malloc out-of-memory", stderr);
  13322. exit(EXIT_FAILURE);
  13323. }
  13324. // Read in the file
  13325. readsize = fread(filebuffer, blocksize, filesize, file);
  13326. if (readsize != filesize)
  13327. {
  13328. fputs ("didn't read file completely",stderr);
  13329. exit(EXIT_FAILURE);
  13330. }
  13331. // Clean exit
  13332. fclose(file);
  13333. return EXIT_SUCCESS;
  13334. }
  13335. static int selectSqlCount = 0;
  13336. static int callback(void *data, int argc, char **argv, char **azColName){
  13337. int i;
  13338. //printf("%s: ", (const char*)data);
  13339. selectSqlCount = argc;
  13340. for(i = 0; i<argc; i++){
  13341. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13342. }
  13343. //printf("\n");
  13344. return 0;
  13345. }
  13346. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13347. //int i;
  13348. //printf("%s:\n", (const char*)data);
  13349. localversion = argv[5] ? atoi(argv[5]) : 0;
  13350. //printf("localversion=%d\n", localversion);
  13351. return 0;
  13352. }
  13353. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13354. //int i;
  13355. //printf("%s:\n", (const char*)data);
  13356. //idTag
  13357. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13358. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13359. //parentIdTag
  13360. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13361. //expir_date
  13362. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13363. //status
  13364. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13365. //version
  13366. idTagQuery.listVersionInt = atoi(argv[5]);
  13367. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13368. return 0;
  13369. }
  13370. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  13371. #if 0
  13372. int i;
  13373. //printf("%s:\n", (const char*)data);
  13374. for(i=0; i<argc; i++){
  13375. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  13376. }
  13377. //printf("");
  13378. #endif
  13379. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13380. // printf("localversion=%d\n", localversion);
  13381. return 0;
  13382. }
  13383. /** sqlite3_exec的回调。
  13384. *
  13385. * 向控制台打印查询的结果。
  13386. *
  13387. * @param in data 传递给回调函数的数据。
  13388. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  13389. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  13390. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  13391. * @return 状态码。
  13392. */
  13393. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13394. {
  13395. for (int i = 0; i < n_columns; i++)
  13396. {
  13397. DEBUG_INFO("%s/t", col_values[i]);
  13398. }
  13399. DEBUG_INFO("/n");
  13400. return 0;
  13401. }
  13402. void OCPP_getListVerion()
  13403. {
  13404. int rc = 0;
  13405. // const char* data = "Callback function called";
  13406. char sql[100];
  13407. char zErrMsg[100];
  13408. memset(sql, 0, 100);
  13409. memset(zErrMsg, 0, 100);
  13410. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  13411. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13412. /* Execute SQL statement */
  13413. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13414. DEBUG_INFO("rc=%d\n",rc);
  13415. if( rc != SQLITE_OK ){
  13416. DEBUG_INFO("SQL error: %s", zErrMsg);
  13417. //sqlite3_free(zErrMsg);
  13418. }
  13419. }
  13420. void OCPP_getIdTag(char idTag[])
  13421. {
  13422. int rc = 0;
  13423. // const char* data = "Callback function called";
  13424. char sql[100];
  13425. char zErrMsg[100];
  13426. memset(sql, 0, 100);
  13427. memset(zErrMsg, 0, 100);
  13428. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  13429. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13430. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13431. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13432. /* Execute SQL statement */
  13433. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13434. if( rc != SQLITE_OK ){
  13435. DEBUG_INFO("SQL error: %s", zErrMsg);
  13436. //sqlite3_free(zErrMsg);
  13437. }
  13438. //return ver;
  13439. }
  13440. void OCPP_get_TableAuthlocalAllData(void)
  13441. {
  13442. int rc = 0;
  13443. // const char* data = "Callback function called";
  13444. char sql[100];
  13445. char zErrMsg[100];
  13446. memset(sql, 0, 100);
  13447. memset(zErrMsg, 0, 100);
  13448. sprintf(sql,"select * from ocpp_auth_local ");
  13449. /* Execute SQL statement */
  13450. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13451. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  13452. if( rc != SQLITE_OK ){
  13453. DEBUG_INFO("SQL error: %s", zErrMsg);
  13454. //sqlite3_free(zErrMsg);
  13455. }
  13456. //return ver;
  13457. }
  13458. int OCPP_cleanLocalList()
  13459. {
  13460. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13461. char *errMsg = 0;
  13462. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13463. if (SQLITE_OK != rc)
  13464. {
  13465. DEBUG_INFO("%s\n",errMsg);
  13466. return FALSE;
  13467. }
  13468. else
  13469. {
  13470. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  13471. }
  13472. return TRUE;
  13473. }
  13474. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13475. {
  13476. int isSuccess = FALSE;
  13477. int ret = 0;
  13478. //const char* data = "Callback function called";
  13479. char sql[300];
  13480. char zErrMsg[200];
  13481. memset(sql, 0, 300);
  13482. memset(zErrMsg, 0, 200);
  13483. 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);
  13484. //* Execute SQL statement */
  13485. //zErrMsg = 0;
  13486. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13487. if( ret != SQLITE_OK ){
  13488. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13489. // free(zErrMsg);
  13490. // free(sql);
  13491. return isSuccess;
  13492. }
  13493. memset(sql, 0, 300);
  13494. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13495. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13496. if( ret != SQLITE_OK ){
  13497. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13498. // free(zErrMsg);
  13499. // free(sql);
  13500. return isSuccess;
  13501. }
  13502. // DEBUG_INFO("successfully Insert records created\n");
  13503. isSuccess = TRUE;
  13504. return isSuccess;
  13505. }
  13506. void OCPP_deleteIdTag(char idTag[])
  13507. {
  13508. //int ver = 0;
  13509. //int isSuccess = FALSE;
  13510. int rc = 0;
  13511. char sql[100];
  13512. char zErrMsg[100];
  13513. memset(sql, 0, 100);
  13514. memset(zErrMsg, 0, 100);
  13515. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13516. //* Execute SQL statement */
  13517. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13518. if( rc != SQLITE_OK ){
  13519. DEBUG_INFO("SQL error: %s", zErrMsg);
  13520. //sqlite3_free(zErrMsg);
  13521. }
  13522. }
  13523. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13524. {
  13525. int isSuccess = FALSE;
  13526. int ret = 0;
  13527. const char* data = "Callback function called";
  13528. char sql[200];
  13529. char zErrMsg[100];
  13530. memset(sql, 0, 200);
  13531. memset(zErrMsg, 0, 100);
  13532. //* selectFromTable */
  13533. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  13534. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13535. //* Execute SQL statement */
  13536. selectSqlCount = 0;
  13537. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13538. if( ret != SQLITE_OK ){
  13539. printf("Error SQL: %s\n", zErrMsg);
  13540. }
  13541. printf("successfully select operation done\n");
  13542. memset(sql, 0, 200);
  13543. memset(zErrMsg, 0, 100);
  13544. if(selectSqlCount == 0)
  13545. {
  13546. //Insert
  13547. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  13548. 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);
  13549. DEBUG_INFO("sql:%s\n", sql);
  13550. //* Execute SQL statement */
  13551. //zErrMsg = 0;
  13552. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  13553. if( ret != SQLITE_OK ){
  13554. printf("SQL error: %s\n", zErrMsg);
  13555. return isSuccess;
  13556. }
  13557. DEBUG_INFO("successfully Insert records created\n");
  13558. isSuccess = TRUE;
  13559. }
  13560. else
  13561. {
  13562. //Update
  13563. //* Create merged SQL statement */
  13564. 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);
  13565. /* Execute SQL statement */
  13566. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13567. if( ret != SQLITE_OK ){
  13568. printf("SQL error: %s\n", zErrMsg);
  13569. //sqlite3_free(zErrMsg);
  13570. //sqlite3_free(sql);
  13571. return isSuccess;
  13572. }
  13573. DEBUG_INFO("Successfully operation done \n");
  13574. isSuccess = TRUE;
  13575. }
  13576. return isSuccess;
  13577. }
  13578. int GetOcppServerURL()
  13579. {
  13580. int result = FALSE;
  13581. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  13582. memset(OcppHost, 0, sizeof(OcppHost));
  13583. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  13584. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13585. {
  13586. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  13587. #if 1
  13588. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13589. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13590. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13591. #endif
  13592. #if 0
  13593. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13594. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  13595. OcppProtocol, OcppHost, OcppTempPath);
  13596. OcppPort = 443;
  13597. #endif
  13598. result = TRUE;
  13599. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13600. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13601. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13602. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13603. goto End;
  13604. }
  13605. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13606. {
  13607. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  13608. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13609. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13610. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13611. result = TRUE;
  13612. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13613. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13614. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13615. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13616. goto End;
  13617. }
  13618. else
  13619. {
  13620. strcpy(OcppHost,"");
  13621. }
  13622. End:
  13623. return result;
  13624. }
  13625. int GetOcppPath()
  13626. {
  13627. int result = FALSE;
  13628. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13629. {
  13630. if(OcppTempPath == NULL)
  13631. {
  13632. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13633. }
  13634. else
  13635. {
  13636. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13637. }
  13638. result = TRUE;
  13639. goto End;
  13640. }
  13641. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13642. {
  13643. if(OcppTempPath == NULL)
  13644. {
  13645. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13646. }
  13647. else
  13648. {
  13649. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13650. }
  13651. result = TRUE;
  13652. goto End;
  13653. }
  13654. else
  13655. {
  13656. strcpy(OcppPath,"");
  13657. }
  13658. End:
  13659. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  13660. return result;
  13661. }
  13662. int GetOcppPort()
  13663. {
  13664. return OcppPort;
  13665. }
  13666. int GetOcppConnStatus(void)
  13667. {
  13668. return ShmOCPP16Data->OcppConnStatus;
  13669. }
  13670. void SetOcppConnStatus(uint8_t status)
  13671. {
  13672. ShmOCPP16Data->OcppConnStatus = status;
  13673. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13674. }
  13675. int GetHeartBeatWithNOResponse(void)
  13676. {
  13677. return HeartBeatWithNOResponse;
  13678. }
  13679. void SetHeartBeatWithNOResponse(void)
  13680. {
  13681. HeartBeatWithNOResponse = 0;
  13682. }
  13683. void splitstring(char *src,const char *separator,char **dest,int *num) {
  13684. /*
  13685. src 源字串的首地址(buf的地址)
  13686. separator 指定的分割字元
  13687. dest 接收子字串的陣列
  13688. num 分割後子字串的個數
  13689. */
  13690. char *pNext;
  13691. int count = 0;
  13692. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  13693. return;
  13694. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  13695. return;
  13696. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  13697. while(pNext != NULL) {
  13698. *dest++ = pNext;
  13699. ++count;
  13700. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  13701. }
  13702. *num = count;
  13703. }
  13704. int GetTransactionId(int gunindex, unsigned char idTag[])
  13705. {
  13706. char ch;
  13707. FILE *fptr1;
  13708. int temptransactionId;
  13709. char str[100]={0};
  13710. temptransactionId = 0;
  13711. /*------ Read the file ----------------*/
  13712. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13713. if (!fptr1)
  13714. {
  13715. //printf(" File not found or unable to open the input file!!\n");
  13716. return temptransactionId;
  13717. }
  13718. ch=fgetc(fptr1);
  13719. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13720. rewind(fptr1);
  13721. if(ch!=EOF)
  13722. {
  13723. // printf("%c",ch);
  13724. while (fgets(str, 100, fptr1) != NULL)
  13725. {
  13726. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13727. if(str[0]=='\0')
  13728. {
  13729. break;
  13730. }
  13731. char *revbuf[8] = {0}; //存放分割後的子字串
  13732. int num = 0;//分割後子字串的個數
  13733. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13734. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13735. {
  13736. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13737. {
  13738. temptransactionId = atoi(revbuf[2]);
  13739. break;
  13740. }
  13741. }
  13742. }
  13743. }
  13744. fclose(fptr1);
  13745. /*------- End of reading ---------------*/
  13746. return temptransactionId;
  13747. }
  13748. void SetTransactionIdZero(int transactionId)
  13749. {
  13750. //TransactionId[gunindex] = 0;
  13751. char ch;
  13752. FILE *fptr1, *fptr2;
  13753. int temptransactionId = 0;
  13754. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13755. printf("\n Delete a specific line from a file :\n");
  13756. printf("-----------------------------------------\n");
  13757. //scanf("%s",fname);
  13758. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13759. if (!fptr1)
  13760. {
  13761. //printf(" File not found or unable to open the input file!!\n");
  13762. return ;
  13763. }
  13764. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13765. if (!fptr2)
  13766. {
  13767. printf("Unable to open a temporary file to write!!\n");
  13768. fclose(fptr1);
  13769. return ;
  13770. }
  13771. ch=fgetc(fptr1);
  13772. //printf(" Now the content of the file %s is : \n",fname);
  13773. rewind(fptr1);
  13774. if(ch!=EOF)
  13775. {
  13776. // copy all contents to the temporary file except the specific line
  13777. while (fgets(str, 100, fptr1) != NULL)
  13778. {
  13779. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13780. if(str[0]=='\0')
  13781. {
  13782. break;
  13783. }
  13784. char *revbuf[8] = {0}; //存放分割後的子字串
  13785. int num = 0;//分割後子字串的個數
  13786. strcpy(strtemp, str);
  13787. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13788. if(revbuf[2][0] != '\0')
  13789. {
  13790. temptransactionId = atoi(revbuf[2]);
  13791. if(transactionId != temptransactionId)
  13792. {
  13793. fprintf(fptr2, "%s\n", strtemp);
  13794. }
  13795. }
  13796. }
  13797. }
  13798. fclose(fptr1);
  13799. fclose(fptr2);
  13800. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13801. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13802. printf("\n Delete a specific line from a file End\n");
  13803. printf("-----------------------------------------\n");
  13804. /*------ Read the file ----------------*/
  13805. }
  13806. int InternetDisconnect(void)
  13807. {
  13808. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13809. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13810. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13811. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13812. }
  13813. void GetChargingProfileRequest(int gunindex)
  13814. {
  13815. mtrace();
  13816. //int connectorIdInt, durationInt;
  13817. //char chargingRateUnitStr[4]={0};
  13818. int tempdurationInt = 0;
  13819. int tempchargingProfileId = 0;
  13820. int tempstackLevel = 0;
  13821. int temptransactionId = 0;
  13822. float tempminChargingRateFloat = 0.0;
  13823. char tempchargingProfilePurposeStr[24]={0};
  13824. char tempchargingProfileKindStr[12]={0};
  13825. char temprecurrencyKindStr[8]={0};
  13826. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13827. char tempvalidToStr[28]={0};
  13828. int tempStartPeriodInt = 0;
  13829. float tempLimitInt = 0.0;//0.1;
  13830. int tempNumberPhasesInt=0;
  13831. char fname[200];
  13832. //char comfirmstr[20];
  13833. float MinChargingRate =0.0;
  13834. double diff_t;
  13835. struct tm tp;
  13836. FILE *fptr1;//, *fptr2;
  13837. int c = 0;
  13838. char * pch;
  13839. char *loc;
  13840. char sstr[200]={ 0 };
  13841. int n_chargingProfile = 0;
  13842. int n_SchedulePeriods = 0;
  13843. char SchedulePeriodList[10][200]={0};
  13844. char sLineWord[1600]={0};
  13845. char word[1000]={0};
  13846. int confirmPeriods = 0;
  13847. struct StructProfile ChargePointMaxProfile;
  13848. struct StructProfile TxDefaultProfile;
  13849. struct StructProfile TxProfile;
  13850. struct StructProfile TxDefaultProfiletemp[2]={0};
  13851. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13852. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13853. struct StructChargingProfile TxProfile_TEMP={0};
  13854. int TxDefaultProfileFileIsNull=FALSE;
  13855. int ChargePointMaxProfileIsNull=FALSE;
  13856. int TxProfileIsNull=FALSE;
  13857. // int CompositeSceduleIndex = 0;
  13858. char ChargePointMaxProfileScheduleStr[30]={0};
  13859. char TxDefaultProfileScheduleStr[30]={0};
  13860. char TxProfileScheduleStr[30]={0};
  13861. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13862. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13863. memset(&TxProfile,0,sizeof(struct StructProfile));
  13864. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13865. DEBUG_INFO("GetChargingProfileRequest\n");
  13866. //*****************************ChargePointMaxProfile******************************************/
  13867. strcpy(fname, ChargePointMaxProfile_JSON);
  13868. ChargePointMaxProfileIsNull=TRUE;
  13869. DEBUG_INFO("test 1\n");
  13870. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13871. {
  13872. fptr1 = fopen(fname, "r");
  13873. int c;
  13874. c = fgetc(fptr1);
  13875. //DEBUG_INFO("c:%d\n",c);
  13876. rewind(fptr1);
  13877. if(c == EOF)
  13878. {
  13879. DEBUG_INFO("\n End of file reached.");
  13880. ChargePointMaxProfileIsNull=TRUE;
  13881. fclose(fptr1);
  13882. }
  13883. else
  13884. {
  13885. DEBUG_INFO("test 2\n");
  13886. ChargePointMaxProfileIsNull=FALSE;
  13887. while(fscanf(fptr1, "%s", word) != EOF)
  13888. {
  13889. if(strcmp(word, "chargingProfileId") == 0)
  13890. {
  13891. n_chargingProfile = n_chargingProfile + 1;
  13892. }
  13893. }
  13894. rewind(fptr1);
  13895. //search Charging Profile Element
  13896. int i = 0;
  13897. int j = 0;
  13898. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13899. //***********chargingProfileId**************/
  13900. c = 0;
  13901. loc = strstr(sLineWord, "chargingProfileId");
  13902. //DEBUG_INFO("loc=%s\n",loc);
  13903. memset(sstr ,0, sizeof(sstr) );
  13904. if(loc != NULL)
  13905. {
  13906. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13907. {
  13908. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13909. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13910. c++;
  13911. }
  13912. sstr[c] = '\0';
  13913. tempchargingProfileId = atoi(sstr);
  13914. }
  13915. else
  13916. {
  13917. tempchargingProfileId = 0;
  13918. }
  13919. //***********stackLevel**************/
  13920. c = 0;
  13921. loc = strstr(sLineWord, "stackLevel");
  13922. //DEBUG_INFO("loc=%s\n",loc);
  13923. memset(sstr ,0, sizeof(sstr) );
  13924. if(loc != NULL)
  13925. {
  13926. while (loc[2+strlen("stackLevel")+c] != '\"')
  13927. {
  13928. sstr[c] = loc[2+strlen("stackLevel")+c];
  13929. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13930. c++;
  13931. }
  13932. sstr[c] = '\0';
  13933. tempstackLevel = atoi(sstr);
  13934. }
  13935. else
  13936. {
  13937. tempstackLevel = 0;
  13938. }
  13939. //***********chargingProfilePurpose **************/
  13940. c = 0;
  13941. loc = strstr(sLineWord, "chargingProfilePurpose");
  13942. //DEBUG_INFO("loc=%s\n",loc);
  13943. memset(sstr ,0, sizeof(sstr) );
  13944. if(loc != NULL)
  13945. {
  13946. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13947. {
  13948. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13949. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13950. c++;
  13951. }
  13952. sstr[c] = '\0';
  13953. strcpy(tempchargingProfilePurposeStr,sstr);
  13954. }
  13955. else
  13956. {
  13957. strcpy(tempchargingProfilePurposeStr,"");
  13958. }
  13959. //***********chargingProfileKind **************/
  13960. c = 0;
  13961. loc = strstr(sLineWord, "chargingProfileKind");
  13962. //DEBUG_INFO("loc=%s\n",loc);
  13963. memset(sstr ,0, sizeof(sstr) );
  13964. if(loc != NULL)
  13965. {
  13966. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13967. {
  13968. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13969. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13970. c++;
  13971. }
  13972. sstr[c] = '\0';
  13973. strcpy(tempchargingProfileKindStr,sstr);
  13974. }
  13975. else
  13976. {
  13977. strcpy(tempchargingProfileKindStr,"");
  13978. }
  13979. //***********recurrencyKind **************/
  13980. c = 0;
  13981. loc = strstr(sLineWord, "recurrencyKind");
  13982. //DEBUG_INFO("loc=%s\n",loc);
  13983. memset(sstr ,0, sizeof(sstr) );
  13984. if(loc != NULL)
  13985. {
  13986. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13987. {
  13988. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13990. c++;
  13991. }
  13992. sstr[c] = '\0';
  13993. strcpy(temprecurrencyKindStr,sstr);
  13994. }
  13995. else
  13996. {
  13997. strcpy(temprecurrencyKindStr,"");
  13998. }
  13999. //***********validFrom**************/
  14000. c = 0;
  14001. loc = strstr(sLineWord, "validFrom");
  14002. //DEBUG_INFO("loc=%s\n",loc);
  14003. memset(sstr ,0, sizeof(sstr) );
  14004. if(loc != NULL)
  14005. {
  14006. while (loc[3+strlen("validFrom")+c] != '\"')
  14007. {
  14008. sstr[c] = loc[3+strlen("validFrom")+c];
  14009. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14010. c++;
  14011. }
  14012. sstr[c] = '\0';
  14013. strcpy(tempvalidFromStr,sstr);
  14014. }
  14015. else
  14016. {
  14017. strcpy(tempvalidFromStr,"");
  14018. }
  14019. //***********validTo **************/
  14020. c = 0;
  14021. loc = strstr(sLineWord, "validTo");
  14022. //DEBUG_INFO("loc=%s\n",loc);
  14023. memset(sstr ,0, sizeof(sstr) );
  14024. if(loc != NULL)
  14025. {
  14026. while (loc[3+strlen("validTo")+c] != '\"')
  14027. {
  14028. sstr[c] = loc[3+strlen("validTo")+c];
  14029. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14030. c++;
  14031. }
  14032. sstr[c] = '\0';
  14033. strcpy(tempvalidToStr,sstr);
  14034. }
  14035. else
  14036. {
  14037. strcpy(tempvalidToStr,"");
  14038. }
  14039. //***********validFrom**************/
  14040. c = 0;
  14041. loc = strstr(sLineWord, "validFrom");
  14042. if(loc != NULL)
  14043. {
  14044. memset(sstr ,0, sizeof(sstr) );
  14045. while (loc[3+strlen("validFrom")+c] != '\"')
  14046. {
  14047. sstr[c] = loc[3+strlen("validFrom")+c];
  14048. c++;
  14049. }
  14050. sstr[c] = '\0';
  14051. strcpy(tempvalidFromStr,sstr);
  14052. }
  14053. else
  14054. {
  14055. strcpy(tempvalidFromStr,"");
  14056. }
  14057. //***********validTo **************/
  14058. c = 0;
  14059. loc = strstr(sLineWord, "validTo");
  14060. if(loc != NULL)
  14061. {
  14062. memset(sstr ,0, sizeof(sstr) );
  14063. while (loc[3+strlen("validTo")+c] != '\"')
  14064. {
  14065. sstr[c] = loc[3+strlen("validTo")+c];
  14066. c++;
  14067. }
  14068. sstr[c] = '\0';
  14069. strcpy(tempvalidToStr,sstr);
  14070. }
  14071. else
  14072. {
  14073. strcpy(tempvalidToStr,"");
  14074. }
  14075. //***********duration**************/
  14076. c = 0;
  14077. loc = strstr(sLineWord, "duration");
  14078. if(loc != NULL)
  14079. {
  14080. memset(sstr ,0, sizeof(sstr) );
  14081. while (loc[2+strlen("duration")+c] != ',')
  14082. {
  14083. sstr[c] = loc[2+strlen("duration")+c];
  14084. c++;
  14085. }
  14086. sstr[c] = '\0';
  14087. tempdurationInt = atoi(sstr);
  14088. }
  14089. else
  14090. {
  14091. tempdurationInt = 0;
  14092. }
  14093. //**********startSchedule**********/
  14094. c = 0;
  14095. loc = strstr(sLineWord, "startSchedule");
  14096. if(loc != NULL)
  14097. {
  14098. memset(sstr ,0, sizeof(sstr) );
  14099. while (loc[3+strlen("startSchedule")+c] != '\"')
  14100. {
  14101. sstr[c] = loc[3+strlen("startSchedule")+c];
  14102. c++;
  14103. }
  14104. sstr[c] = '\0';
  14105. strcpy(tempstartScheduleStr, sstr);
  14106. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  14107. }
  14108. else
  14109. {
  14110. strcpy(tempstartScheduleStr, "");
  14111. strcpy(ChargePointMaxProfileScheduleStr, "");
  14112. }
  14113. //**********chargingRateUnit**********/
  14114. c = 0;
  14115. loc = strstr(sLineWord, "chargingRateUnit");
  14116. memset(sstr ,0, sizeof(sstr) );
  14117. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14118. {
  14119. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14120. c++;
  14121. }
  14122. sstr[c] = '\0';
  14123. strcpy(tempchargingRateUnitStr, sstr);
  14124. //**********minChargingRate*******/
  14125. c = 0;
  14126. loc = strstr(sLineWord, "minChargingRate");
  14127. if(loc != NULL)
  14128. {
  14129. memset(sstr ,0, sizeof(sstr) );
  14130. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14131. {
  14132. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14133. c++;
  14134. }
  14135. sstr[c] = '\0';
  14136. tempminChargingRateFloat = atof(sstr);
  14137. }
  14138. else
  14139. {
  14140. tempminChargingRateFloat = 0.0;
  14141. }
  14142. //
  14143. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14144. tp.tm_isdst = -1;
  14145. time_t utc = mktime(&tp);
  14146. time_t t = time(NULL);
  14147. diff_t = difftime(t, utc);
  14148. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14149. //parsing strings to words
  14150. i = 0;
  14151. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14152. loc = loc+3+strlen("chargingSchedulePeriod");
  14153. pch = strtok(loc ,"{");
  14154. while (pch != NULL)
  14155. {
  14156. strcpy(SchedulePeriodList[i], pch);
  14157. pch = strtok (NULL, "{");
  14158. i = i + 1;
  14159. }
  14160. n_SchedulePeriods = i;
  14161. for(int i=0;i<n_SchedulePeriods;i++)
  14162. {
  14163. //*************startPeriod****************/
  14164. c = 0;
  14165. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14166. memset(sstr ,0, sizeof(sstr) );
  14167. while (loc[strlen("startPeriod")+2+c] != ',')
  14168. {
  14169. sstr[c] = loc[strlen("startPeriod")+2+c];
  14170. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14171. c++;
  14172. }
  14173. sstr[c] = '\0';
  14174. tempStartPeriodInt = atoi(sstr);
  14175. //*************limit****************/
  14176. c = 0;
  14177. loc = strstr(SchedulePeriodList[i], "limit");
  14178. memset(sstr ,0, sizeof(sstr) );
  14179. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14180. {
  14181. sstr[c] = loc[strlen("limit")+2+c];
  14182. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14183. c++;
  14184. }
  14185. sstr[c] = '\0';
  14186. tempLimitInt = atof(sstr);
  14187. //*************numberPhases****************/
  14188. c = 0;
  14189. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14190. memset(sstr ,0, sizeof(sstr) );
  14191. if(loc != NULL)
  14192. {
  14193. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14194. {
  14195. sstr[c] = loc[strlen("numberPhases")+2+c];
  14196. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14197. c++;
  14198. }
  14199. sstr[c] = '\0';
  14200. tempNumberPhasesInt = atoi(sstr);
  14201. }
  14202. else
  14203. {
  14204. tempNumberPhasesInt = 0;
  14205. }
  14206. if(j == 0)
  14207. {
  14208. ChargePointMaxProfile.Duration = tempdurationInt;
  14209. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  14210. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  14211. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14212. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14213. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14214. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  14215. ChargePointMaxProfile_TEMP.TransactionId = 0;
  14216. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14217. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14218. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14219. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14220. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14221. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14222. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14223. }
  14224. }
  14225. if(MinChargingRate < tempminChargingRateFloat)
  14226. {
  14227. MinChargingRate = tempminChargingRateFloat;
  14228. }
  14229. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14230. if(confirmPeriods < n_SchedulePeriods)
  14231. {
  14232. confirmPeriods = n_SchedulePeriods;
  14233. }
  14234. j = j + 1;
  14235. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14236. fclose(fptr1);
  14237. }// end else
  14238. }// the end of access file ChargePointMaxProfile
  14239. DEBUG_INFO("test 3\n");
  14240. //****************************TxDefaultProfile************************************************/
  14241. memset(fname, 0, sizeof fname);
  14242. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  14243. TxDefaultProfileFileIsNull=TRUE;
  14244. if((access(fname,F_OK))!=-1)
  14245. {
  14246. fptr1 = fopen(fname, "r");
  14247. c = 0;
  14248. c = fgetc(fptr1);
  14249. //DEBUG_INFO("c:%d\n",c);
  14250. rewind(fptr1);
  14251. if(c == EOF)
  14252. {
  14253. DEBUG_INFO("\n End of file reached.");
  14254. TxDefaultProfileFileIsNull=TRUE;
  14255. fclose(fptr1);
  14256. }
  14257. else
  14258. {
  14259. TxDefaultProfileFileIsNull=FALSE;
  14260. while(fscanf(fptr1, "%s", word) != EOF)
  14261. {
  14262. if(strcmp(word, "chargingProfileId") == 0)
  14263. {
  14264. n_chargingProfile = n_chargingProfile + 1;
  14265. }
  14266. }
  14267. rewind(fptr1);
  14268. //search Charging Profile Element
  14269. int i = 0;
  14270. int j = 0;
  14271. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14272. {
  14273. #if 0
  14274. //***********connectorId****************/
  14275. c = 0;
  14276. loc = strstr(sLineWord, "connectorId");
  14277. memset(sstr ,0, sizeof(sstr) );
  14278. while (loc[strlen("connectorId")+2+c] != ',')
  14279. {
  14280. sstr[c] = loc[strlen("connectorId")+2+c];
  14281. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14282. c++;
  14283. }
  14284. sstr[c] = '\0';
  14285. tempconnectorIdInt = atoi(sstr);
  14286. #endif
  14287. //***********chargingProfileId**************/
  14288. c = 0;
  14289. loc = strstr(sLineWord, "chargingProfileId");
  14290. //DEBUG_INFO("loc=%s\n",loc);
  14291. memset(sstr ,0, sizeof(sstr) );
  14292. if(loc != NULL)
  14293. {
  14294. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14295. {
  14296. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14297. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14298. c++;
  14299. }
  14300. sstr[c] = '\0';
  14301. tempchargingProfileId = atoi(sstr);
  14302. }
  14303. else
  14304. {
  14305. tempchargingProfileId = 0;
  14306. }
  14307. //***********stackLevel**************/
  14308. c = 0;
  14309. loc = strstr(sLineWord, "stackLevel");
  14310. //DEBUG_INFO("loc=%s\n",loc);
  14311. memset(sstr ,0, sizeof(sstr) );
  14312. if(loc != NULL)
  14313. {
  14314. while (loc[2+strlen("stackLevel")+c] != '\"')
  14315. {
  14316. sstr[c] = loc[2+strlen("stackLevel")+c];
  14317. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14318. c++;
  14319. }
  14320. sstr[c] = '\0';
  14321. tempstackLevel = atoi(sstr);
  14322. }
  14323. else
  14324. {
  14325. tempstackLevel = 0;
  14326. }
  14327. //***********chargingProfilePurpose **************/
  14328. c = 0;
  14329. loc = strstr(sLineWord, "chargingProfilePurpose");
  14330. //DEBUG_INFO("loc=%s\n",loc);
  14331. memset(sstr ,0, sizeof(sstr) );
  14332. if(loc != NULL)
  14333. {
  14334. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14335. {
  14336. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14337. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14338. c++;
  14339. }
  14340. sstr[c] = '\0';
  14341. strcpy(tempchargingProfilePurposeStr,sstr);
  14342. }
  14343. else
  14344. {
  14345. strcpy(tempchargingProfilePurposeStr,"");
  14346. }
  14347. //***********chargingProfileKind **************/
  14348. c = 0;
  14349. loc = strstr(sLineWord, "chargingProfileKind");
  14350. //DEBUG_INFO("loc=%s\n",loc);
  14351. memset(sstr ,0, sizeof(sstr) );
  14352. if(loc != NULL)
  14353. {
  14354. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14355. {
  14356. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14357. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14358. c++;
  14359. }
  14360. sstr[c] = '\0';
  14361. strcpy(tempchargingProfileKindStr,sstr);
  14362. }
  14363. else
  14364. {
  14365. strcpy(tempchargingProfileKindStr,"");
  14366. }
  14367. //***********recurrencyKind **************/
  14368. c = 0;
  14369. loc = strstr(sLineWord, "recurrencyKind");
  14370. //DEBUG_INFO("loc=%s\n",loc);
  14371. memset(sstr ,0, sizeof(sstr) );
  14372. if(loc != NULL)
  14373. {
  14374. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14375. {
  14376. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14377. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14378. c++;
  14379. }
  14380. sstr[c] = '\0';
  14381. strcpy(temprecurrencyKindStr,sstr);
  14382. }
  14383. else
  14384. {
  14385. strcpy(temprecurrencyKindStr,"");
  14386. }
  14387. //***********validFrom**************/
  14388. c = 0;
  14389. loc = strstr(sLineWord, "validFrom");
  14390. if(loc != NULL)
  14391. {
  14392. memset(sstr ,0, sizeof(sstr) );
  14393. while (loc[3+strlen("validFrom")+c] != '\"')
  14394. {
  14395. sstr[c] = loc[3+strlen("validFrom")+c];
  14396. c++;
  14397. }
  14398. sstr[c] = '\0';
  14399. strcpy(tempvalidFromStr,sstr);
  14400. }
  14401. else
  14402. {
  14403. strcpy(tempvalidFromStr,"");
  14404. }
  14405. //***********validTo **************/
  14406. c = 0;
  14407. loc = strstr(sLineWord, "validTo");
  14408. if(loc != NULL)
  14409. {
  14410. memset(sstr ,0, sizeof(sstr) );
  14411. while (loc[3+strlen("validTo")+c] != '\"')
  14412. {
  14413. sstr[c] = loc[3+strlen("validTo")+c];
  14414. c++;
  14415. }
  14416. sstr[c] = '\0';
  14417. strcpy(tempvalidToStr,sstr);
  14418. }
  14419. else
  14420. {
  14421. strcpy(tempvalidToStr,"");
  14422. }
  14423. //***********duration**************/
  14424. c = 0;
  14425. loc = strstr(sLineWord, "duration");
  14426. if(loc != NULL)
  14427. {
  14428. memset(sstr ,0, sizeof(sstr) );
  14429. while (loc[2+strlen("duration")+c] != ',')
  14430. {
  14431. sstr[c] = loc[2+strlen("duration")+c];
  14432. c++;
  14433. }
  14434. sstr[c] = '\0';
  14435. tempdurationInt = atoi(sstr);
  14436. }
  14437. else
  14438. {
  14439. tempdurationInt = 0;
  14440. }
  14441. //**********startSchedule**********/
  14442. c = 0;
  14443. loc = strstr(sLineWord, "startSchedule");
  14444. if(loc != NULL)
  14445. {
  14446. memset(sstr ,0, sizeof(sstr) );
  14447. while (loc[3+strlen("startSchedule")+c] != '\"')
  14448. {
  14449. sstr[c] = loc[3+strlen("startSchedule")+c];
  14450. c++;
  14451. }
  14452. sstr[c] = '\0';
  14453. strcpy(tempstartScheduleStr, sstr);
  14454. strcpy(TxDefaultProfileScheduleStr, sstr);
  14455. }
  14456. else
  14457. {
  14458. strcpy(tempstartScheduleStr, "");
  14459. strcpy(TxDefaultProfileScheduleStr, "");
  14460. }
  14461. //**********chargingRateUnit**********/
  14462. c = 0;
  14463. loc = strstr(sLineWord, "chargingRateUnit");
  14464. memset(sstr ,0, sizeof(sstr) );
  14465. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14466. {
  14467. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14468. c++;
  14469. }
  14470. sstr[c] = '\0';
  14471. strcpy(tempchargingRateUnitStr, sstr);
  14472. //**********minChargingRate*******/
  14473. c = 0;
  14474. loc = strstr(sLineWord, "minChargingRate");
  14475. if(loc != NULL)
  14476. {
  14477. memset(sstr ,0, sizeof(sstr) );
  14478. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14479. {
  14480. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14481. c++;
  14482. }
  14483. sstr[c] = '\0';
  14484. tempminChargingRateFloat = atof(sstr);
  14485. }
  14486. else
  14487. {
  14488. tempminChargingRateFloat = 0.0;
  14489. }
  14490. //
  14491. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14492. tp.tm_isdst = -1;
  14493. time_t utc = mktime(&tp);
  14494. time_t t = time(NULL);
  14495. diff_t = difftime(t, utc);
  14496. printf("diff between startScheduleStr and now =%f\n",diff_t);
  14497. //parsing strings to words
  14498. i = 0;
  14499. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14500. loc = loc+3+strlen("chargingSchedulePeriod");
  14501. pch = strtok(loc ,"{");
  14502. while (pch != NULL)
  14503. {
  14504. strcpy(SchedulePeriodList[i], pch);
  14505. pch = strtok (NULL, "{");
  14506. i = i + 1;
  14507. }
  14508. n_SchedulePeriods = i;
  14509. for(int i=0;i<n_SchedulePeriods;i++)
  14510. {
  14511. //*************startPeriod****************/
  14512. c = 0;
  14513. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14514. memset(sstr ,0, sizeof(sstr) );
  14515. while (loc[strlen("startPeriod")+2+c] != ',')
  14516. {
  14517. sstr[c] = loc[strlen("startPeriod")+2+c];
  14518. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14519. c++;
  14520. }
  14521. sstr[c] = '\0';
  14522. tempStartPeriodInt = atoi(sstr);
  14523. //*************limit****************/
  14524. c = 0;
  14525. loc = strstr(SchedulePeriodList[i], "limit");
  14526. memset(sstr ,0, sizeof(sstr) );
  14527. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14528. {
  14529. sstr[c] = loc[strlen("limit")+2+c];
  14530. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14531. c++;
  14532. }
  14533. sstr[c] = '\0';
  14534. tempLimitInt = atof(sstr);
  14535. //*************numberPhases****************/
  14536. c = 0;
  14537. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14538. memset(sstr ,0, sizeof(sstr) );
  14539. if(loc != NULL)
  14540. {
  14541. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14542. {
  14543. sstr[c] = loc[strlen("numberPhases")+2+c];
  14544. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14545. c++;
  14546. }
  14547. sstr[c] = '\0';
  14548. tempNumberPhasesInt = atoi(sstr);
  14549. }
  14550. else
  14551. {
  14552. tempNumberPhasesInt = 0;
  14553. }
  14554. if(j == 0)
  14555. {
  14556. TxDefaultProfile.Duration = tempdurationInt;
  14557. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  14558. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  14559. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14560. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14561. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14562. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  14563. TxDefaultProfile_TEMP.TransactionId = 0;
  14564. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14565. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14566. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14567. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14568. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14569. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14570. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14571. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14572. }
  14573. else
  14574. {
  14575. //other stack level charging Profile
  14576. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  14577. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  14578. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  14579. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  14580. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  14581. }
  14582. }
  14583. if(MinChargingRate < tempminChargingRateFloat)
  14584. {
  14585. MinChargingRate = tempminChargingRateFloat;
  14586. }
  14587. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14588. if(confirmPeriods < n_SchedulePeriods)
  14589. confirmPeriods = n_SchedulePeriods;
  14590. j = j + 1;
  14591. }
  14592. fclose(fptr1);
  14593. //Stacking Charging Profiles
  14594. for(int l=0; l <(j-1) ;l++)
  14595. {
  14596. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  14597. {
  14598. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  14599. {
  14600. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  14601. {
  14602. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  14603. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  14604. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  14605. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14606. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14607. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14608. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14609. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14610. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14611. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14612. }
  14613. else
  14614. {
  14615. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14616. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14617. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14618. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14619. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14620. }
  14621. }
  14622. }
  14623. }//end of Stacking Charging Profiles
  14624. }// end else
  14625. }// the end of ACCESS TxDefaultProfile
  14626. //****************************TxProfile************************************************/
  14627. memset(fname, 0, sizeof fname);
  14628. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  14629. TxProfileIsNull=TRUE;
  14630. if((access(fname,F_OK))!=-1)
  14631. {
  14632. fptr1 = fopen(fname, "r");
  14633. c = 0;
  14634. c = fgetc(fptr1);
  14635. //DEBUG_INFO("c:%d\n",c);
  14636. rewind(fptr1);
  14637. if(c == EOF)
  14638. {
  14639. DEBUG_INFO("\n End of file reached.");
  14640. TxProfileIsNull=TRUE;
  14641. fclose(fptr1);
  14642. }
  14643. else
  14644. {
  14645. TxProfileIsNull=FALSE;
  14646. while(fscanf(fptr1, "%s", word) != EOF)
  14647. {
  14648. if(strcmp(word, "chargingProfileId") == 0)
  14649. {
  14650. n_chargingProfile = n_chargingProfile + 1;
  14651. }
  14652. }
  14653. rewind(fptr1);
  14654. //search Charging Profile Element
  14655. int i= 0;
  14656. int j= 0;
  14657. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14658. #if 0
  14659. /***********connectorId****************/
  14660. c = 0;
  14661. loc = strstr(sLineWord, "connectorId");
  14662. memset(sstr ,0, sizeof(sstr) );
  14663. while (loc[strlen("connectorId")+2+c] != ',')
  14664. {
  14665. sstr[c] = loc[strlen("connectorId")+2+c];
  14666. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14667. c++;
  14668. }
  14669. sstr[c] = '\0';
  14670. tempconnectorIdInt = atoi(sstr);
  14671. #endif
  14672. //***********chargingProfileId**************/
  14673. c = 0;
  14674. loc = strstr(sLineWord, "chargingProfileId");
  14675. memset(sstr ,0, sizeof(sstr) );
  14676. if(loc != NULL)
  14677. {
  14678. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14679. {
  14680. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14681. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14682. c++;
  14683. }
  14684. sstr[c] = '\0';
  14685. tempchargingProfileId = atoi(sstr);
  14686. }
  14687. else
  14688. {
  14689. tempchargingProfileId = 0;
  14690. }
  14691. //***********transactionId **************/
  14692. c = 0;
  14693. loc = strstr(sLineWord, "transactionId");
  14694. //DEBUG_INFO("loc=%s\n",loc);
  14695. memset(sstr ,0, sizeof(sstr) );
  14696. if(loc != NULL)
  14697. {
  14698. while (loc[2+strlen("transactionId")+c] != '\"')
  14699. {
  14700. sstr[c] = loc[2+strlen("transactionId")+c];
  14701. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14702. c++;
  14703. }
  14704. sstr[c] = '\0';
  14705. temptransactionId = atoi(sstr);
  14706. }
  14707. else
  14708. {
  14709. temptransactionId = 0;
  14710. }
  14711. //***********stackLevel**************/
  14712. c = 0;
  14713. loc = strstr(sLineWord, "stackLevel");
  14714. //DEBUG_INFO("loc=%s\n",loc);
  14715. memset(sstr ,0, sizeof(sstr) );
  14716. if(loc != NULL)
  14717. {
  14718. while (loc[2+strlen("stackLevel")+c] != '\"')
  14719. {
  14720. sstr[c] = loc[2+strlen("stackLevel")+c];
  14721. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14722. c++;
  14723. }
  14724. sstr[c] = '\0';
  14725. tempstackLevel = atoi(sstr);
  14726. }
  14727. else
  14728. {
  14729. tempstackLevel = 0;
  14730. }
  14731. //***********chargingProfilePurpose **************/
  14732. c = 0;
  14733. loc = strstr(sLineWord, "chargingProfilePurpose");
  14734. //DEBUG_INFO("loc=%s\n",loc);
  14735. memset(sstr ,0, sizeof(sstr) );
  14736. if(loc != NULL)
  14737. {
  14738. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14739. {
  14740. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14741. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14742. c++;
  14743. }
  14744. sstr[c] = '\0';
  14745. strcpy(tempchargingProfilePurposeStr,sstr);
  14746. }
  14747. else
  14748. {
  14749. strcpy(tempchargingProfilePurposeStr,"");
  14750. }
  14751. //***********chargingProfileKind **************/
  14752. c = 0;
  14753. loc = strstr(sLineWord, "chargingProfileKind");
  14754. //DEBUG_INFO("loc=%s\n",loc);
  14755. memset(sstr ,0, sizeof(sstr) );
  14756. if(loc != NULL)
  14757. {
  14758. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14759. {
  14760. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14761. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14762. c++;
  14763. }
  14764. sstr[c] = '\0';
  14765. strcpy(tempchargingProfileKindStr,sstr);
  14766. }
  14767. else
  14768. {
  14769. strcpy(tempchargingProfileKindStr,"");
  14770. }
  14771. //***********recurrencyKind **************/
  14772. c = 0;
  14773. loc = strstr(sLineWord, "recurrencyKind");
  14774. //DEBUG_INFO("loc=%s\n",loc);
  14775. memset(sstr ,0, sizeof(sstr) );
  14776. if(loc != NULL)
  14777. {
  14778. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14779. {
  14780. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14781. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14782. c++;
  14783. }
  14784. sstr[c] = '\0';
  14785. strcpy(temprecurrencyKindStr,sstr);
  14786. }
  14787. else
  14788. {
  14789. strcpy(temprecurrencyKindStr,"");
  14790. }
  14791. //***********validFrom**************/
  14792. c = 0;
  14793. loc = strstr(sLineWord, "validFrom");
  14794. if(loc != NULL)
  14795. {
  14796. memset(sstr ,0, sizeof(sstr) );
  14797. while (loc[3+strlen("validFrom")+c] != '\"')
  14798. {
  14799. sstr[c] = loc[3+strlen("validFrom")+c];
  14800. c++;
  14801. }
  14802. sstr[c] = '\0';
  14803. strcpy(tempvalidFromStr,sstr);
  14804. }
  14805. else
  14806. {
  14807. strcpy(tempvalidFromStr,"");
  14808. }
  14809. //***********validTo**************/
  14810. c = 0;
  14811. loc = strstr(sLineWord, "validTo");
  14812. if(loc != NULL)
  14813. {
  14814. memset(sstr ,0, sizeof(sstr) );
  14815. while (loc[3+strlen("validTo")+c] != '\"')
  14816. {
  14817. sstr[c] = loc[3+strlen("validTo")+c];
  14818. c++;
  14819. }
  14820. sstr[c] = '\0';
  14821. strcpy(tempvalidToStr,sstr);
  14822. }
  14823. else
  14824. {
  14825. strcpy(tempvalidToStr,"");
  14826. }
  14827. //***********duration**************/
  14828. c = 0;
  14829. loc = strstr(sLineWord, "duration");
  14830. //DEBUG_INFO("loc=%s\n",loc);
  14831. memset(sstr ,0, sizeof(sstr) );
  14832. if(loc != NULL)
  14833. {
  14834. while (loc[2+strlen("duration")+c] != '\"')
  14835. {
  14836. sstr[c] = loc[2+strlen("duration")+c];
  14837. c++;
  14838. }
  14839. sstr[c] = '\0';
  14840. tempdurationInt = atoi(sstr);
  14841. }
  14842. else
  14843. {
  14844. tempdurationInt = 0;
  14845. }
  14846. //**********startSchedule**********/
  14847. c = 0;
  14848. loc = strstr(sLineWord, "startSchedule");
  14849. if(loc != NULL)
  14850. {
  14851. memset(sstr ,0, sizeof(sstr) );
  14852. while (loc[3+strlen("startSchedule")+c] != '\"')
  14853. {
  14854. sstr[c] = loc[3+strlen("startSchedule")+c];
  14855. c++;
  14856. }
  14857. sstr[c] = '\0';
  14858. strcpy(tempstartScheduleStr, sstr);
  14859. strcpy(TxProfileScheduleStr, sstr);
  14860. }
  14861. else
  14862. {
  14863. strcpy(tempstartScheduleStr, "");
  14864. strcpy(TxProfileScheduleStr, "");
  14865. }
  14866. //**********chargingRateUnit**********/
  14867. c = 0;
  14868. loc = strstr(sLineWord, "chargingRateUnit");
  14869. memset(sstr ,0, sizeof(sstr) );
  14870. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14871. {
  14872. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14873. c++;
  14874. }
  14875. sstr[c] = '\0';
  14876. strcpy(tempchargingRateUnitStr, sstr);
  14877. //**********minChargingRate*******/
  14878. c = 0;
  14879. loc = strstr(sLineWord, "minChargingRate");
  14880. if(loc != NULL)
  14881. {
  14882. memset(sstr ,0, sizeof(sstr) );
  14883. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14884. {
  14885. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14886. c++;
  14887. }
  14888. sstr[c] = '\0';
  14889. tempminChargingRateFloat = atof(sstr);
  14890. }
  14891. else
  14892. {
  14893. tempminChargingRateFloat = 0.0;
  14894. }
  14895. //
  14896. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14897. tp.tm_isdst = -1;
  14898. time_t utc = mktime(&tp);
  14899. time_t t = time(NULL);
  14900. diff_t = difftime(t, utc);
  14901. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14902. //parsing strings to words
  14903. i = 0;
  14904. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14905. loc = loc+3+strlen("chargingSchedulePeriod");
  14906. pch = strtok(loc ,"{");
  14907. while (pch != NULL)
  14908. {
  14909. strcpy(SchedulePeriodList[i], pch);
  14910. pch = strtok (NULL, "{");
  14911. i = i + 1;
  14912. }
  14913. n_SchedulePeriods = i;
  14914. for(int i=0;i<n_SchedulePeriods;i++)
  14915. {
  14916. //*************startPeriod****************/
  14917. c = 0;
  14918. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14919. memset(sstr ,0, sizeof(sstr) );
  14920. while (loc[strlen("startPeriod")+2+c] != ',')
  14921. {
  14922. sstr[c] = loc[strlen("startPeriod")+2+c];
  14923. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14924. c++;
  14925. }
  14926. sstr[c] = '\0';
  14927. tempStartPeriodInt = atoi(sstr);
  14928. //*************limit****************/
  14929. c = 0;
  14930. loc = strstr(SchedulePeriodList[i], "limit");
  14931. memset(sstr ,0, sizeof(sstr) );
  14932. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14933. {
  14934. sstr[c] = loc[strlen("limit")+2+c];
  14935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14936. c++;
  14937. }
  14938. sstr[c] = '\0';
  14939. tempLimitInt = atof(sstr);
  14940. //*************numberPhases****************/
  14941. c = 0;
  14942. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14943. memset(sstr ,0, sizeof(sstr) );
  14944. if(loc != NULL)
  14945. {
  14946. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14947. {
  14948. sstr[c] = loc[strlen("numberPhases")+2+c];
  14949. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14950. c++;
  14951. }
  14952. sstr[c] = '\0';
  14953. tempNumberPhasesInt = atoi(sstr);
  14954. }
  14955. else
  14956. {
  14957. tempNumberPhasesInt = 0;
  14958. }
  14959. //TxProfile.Duration = durationInt;
  14960. TxProfile.TotalPeriod = n_SchedulePeriods;
  14961. TxProfile.Period[i].Limit = tempLimitInt;
  14962. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14963. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14964. }
  14965. if(MinChargingRate < tempminChargingRateFloat)
  14966. {
  14967. MinChargingRate = tempminChargingRateFloat;
  14968. }
  14969. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14970. if(confirmPeriods < n_SchedulePeriods)
  14971. confirmPeriods = n_SchedulePeriods;
  14972. if(j == 0)
  14973. {
  14974. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14975. TxProfile_TEMP.StackLevel = tempstackLevel;
  14976. TxProfile_TEMP.TransactionId = 0;
  14977. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14978. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14979. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14980. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14981. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14982. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14983. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14984. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14985. }
  14986. }
  14987. fclose(fptr1);
  14988. }
  14989. }// the end of ACCESS TxProfile
  14990. //-----------------------------------------------CompositeSchedule--------------------------//
  14991. int period=0;
  14992. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14993. {
  14994. //TxProfile
  14995. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14996. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14997. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14998. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14999. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15000. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15001. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15002. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15003. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15004. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15005. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15006. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15007. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15008. for(int k=0; k < TxProfile.TotalPeriod;k++)
  15009. {
  15010. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  15011. {
  15012. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15013. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15014. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15015. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15016. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15017. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15018. period = period + 1;
  15019. }
  15020. else
  15021. {
  15022. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  15023. {
  15024. }
  15025. else
  15026. {
  15027. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15028. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15029. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15030. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15031. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15032. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15033. period = period + 1;
  15034. }
  15035. }
  15036. }
  15037. struct tm tp;
  15038. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15039. tp.tm_isdst = -1;
  15040. time_t utc = mktime(&tp);
  15041. time_t t = time(NULL);
  15042. double diff_f = difftime(t, utc);
  15043. int diff_i;// = (int)diff_f;
  15044. int quotient; // = diff_i / 86400;//86400 seconds/day
  15045. if(diff_f >= 0)
  15046. {
  15047. diff_i = (int)diff_f;
  15048. quotient = diff_i / 86400;//86400 seconds/day
  15049. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15050. {
  15051. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  15052. {
  15053. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15054. {
  15055. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15056. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15057. }
  15058. else
  15059. {
  15060. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15061. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15062. }
  15063. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15064. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15065. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15066. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15067. period = period + 1;
  15068. }
  15069. }
  15070. }// end of if(diff_f >= 0)
  15071. }
  15072. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15073. {
  15074. //TxDefaultProfile
  15075. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15076. struct tm tp;
  15077. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15078. tp.tm_isdst = -1;
  15079. time_t utc = mktime(&tp);
  15080. time_t t = time(NULL);
  15081. double diff_f = difftime(t, utc);
  15082. int diff_i;// = (int)diff_f;
  15083. int quotient; // = diff_i / 86400;//86400 seconds/day
  15084. int remainder;
  15085. //---- Define StartSchedule----/
  15086. struct tm *gtime;
  15087. time_t now;
  15088. char buf[28];
  15089. //---Read the current system time---/
  15090. time(&now);
  15091. //---Convert the system time to GMT (now UTC)---/
  15092. gtime = gmtime(&now);
  15093. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15094. if(diff_f >= 0)
  15095. {
  15096. diff_i = (int)diff_f;
  15097. quotient = diff_i / 86400;//86400 seconds/day
  15098. remainder = diff_i % 86400;
  15099. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15100. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15101. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15102. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  15103. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15104. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15105. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15106. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15107. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15108. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15109. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15110. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15111. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  15112. {
  15113. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15114. {
  15115. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15116. {
  15117. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15118. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15119. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15120. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15121. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15122. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15123. period = period + 1;
  15124. }
  15125. else
  15126. {
  15127. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15128. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15129. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15130. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  15131. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15132. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15133. period = period + 1;
  15134. }
  15135. }
  15136. }
  15137. } // end of diff_f >= 0
  15138. }
  15139. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  15140. {
  15141. //TxDefaultProfile
  15142. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15143. struct tm tp;
  15144. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15145. tp.tm_isdst = -1;
  15146. time_t utc = mktime(&tp);
  15147. time_t t = time(NULL);
  15148. double diff_f = difftime(t, utc);
  15149. int diff_i;// = (int)diff_f;
  15150. int quotient; // = diff_i / 86400;//86400 seconds/day
  15151. int remainder;
  15152. //---- Define StartSchedule----/
  15153. struct tm *gtime;
  15154. time_t now;
  15155. char buf[28];
  15156. //---Read the current system time---/
  15157. time(&now);
  15158. //---Convert the system time to GMT (now UTC)---/
  15159. gtime = gmtime(&now);
  15160. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15161. if(diff_f >= 0)
  15162. {
  15163. diff_i = (int)diff_f;
  15164. quotient = diff_i / 86400;//86400 seconds/day
  15165. remainder = diff_i % 86400;
  15166. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15167. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15168. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15169. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  15170. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15171. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15172. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15173. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15174. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15175. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  15176. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15177. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15178. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15179. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15180. {
  15181. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15182. {
  15183. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15184. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15185. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15186. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15187. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15188. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15189. period = period + 1;
  15190. }
  15191. }
  15192. } //end of diff_f >= 0
  15193. }
  15194. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15195. {
  15196. //ChargePointMaxProfile
  15197. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  15198. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  15199. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15200. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  15201. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  15202. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15203. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15204. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  15205. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  15206. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  15207. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  15208. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  15209. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  15210. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  15211. {
  15212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  15213. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  15214. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  15215. period = period + 1;
  15216. }
  15217. }
  15218. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  15219. {
  15220. //TxProfile Daily
  15221. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  15222. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  15223. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  15224. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  15225. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15226. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15227. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15228. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15229. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15230. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15231. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15232. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15233. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15234. for(int l=0; l< TxProfile.TotalPeriod; l++)
  15235. {
  15236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  15237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  15238. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  15239. }
  15240. }
  15241. confirmPeriods = period;
  15242. if(confirmPeriods != 0)
  15243. {
  15244. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  15245. 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,"
  15246. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  15247. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  15248. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  15249. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  15250. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  15251. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  15252. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  15253. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  15254. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  15255. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  15256. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  15257. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  15258. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  15259. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  15260. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  15261. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  15262. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  15263. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  15264. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  15265. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  15266. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  15267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  15268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  15269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  15270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  15271. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  15272. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  15273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  15274. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  15275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  15276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  15277. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  15278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  15279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  15280. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  15281. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  15282. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  15283. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  15284. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  15285. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  15286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  15287. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  15288. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  15289. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  15290. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  15291. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  15292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  15293. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  15294. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  15295. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  15296. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  15297. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  15298. }
  15299. }
  15300. void storeTempStopTransaction(int gun_index)
  15301. {
  15302. //int result = FAIL;
  15303. //char message[1500]={0};
  15304. char guid[37]={0};
  15305. int tempIndex = 0;
  15306. //char tempdata[65]={0};
  15307. //int idx_sample=0;
  15308. DEBUG_ERROR("sendStopTransactionRequest \n");
  15309. memset(queuedata, 0, sizeof(queuedata));
  15310. //ENERGY_ACTIVE_IMPORT_REGISTER
  15311. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15312. if(gunType[gun_index] == 'J')
  15313. {
  15314. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15315. {
  15316. tempIndex = ((gun_index==2) ? 1: 0);
  15317. }
  15318. else
  15319. {
  15320. tempIndex = gun_index;
  15321. }
  15322. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15323. {
  15324. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15325. {
  15326. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  15327. }
  15328. }// END OF CHAdeMO_QUANTITY
  15329. }
  15330. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15331. {
  15332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15333. {
  15334. tempIndex = ((gun_index==2) ? 1: 0);
  15335. }
  15336. else
  15337. {
  15338. tempIndex = gun_index;
  15339. }
  15340. for (int index = 0; index < CCS_QUANTITY; index++)
  15341. {
  15342. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15343. {
  15344. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  15345. }
  15346. }// END OF CCS_QUANTITY
  15347. }
  15348. else if(gunType[gun_index] == 'G')
  15349. {
  15350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15351. {
  15352. tempIndex = ((gun_index==2) ? 1: 0);
  15353. }
  15354. else
  15355. {
  15356. tempIndex = gun_index;
  15357. }
  15358. for (int index = 0; index < GB_QUANTITY; index++)
  15359. {
  15360. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15361. {
  15362. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  15363. }
  15364. }// END OF GB_QUANTITY
  15365. }
  15366. else
  15367. {
  15368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15369. {
  15370. tempIndex = 2;
  15371. }
  15372. else
  15373. {
  15374. tempIndex = gun_index;
  15375. }
  15376. for (int index = 0; index < AC_QUANTITY; index++)
  15377. {
  15378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15379. {
  15380. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  15381. }
  15382. }// END OF AC_QUANTITY
  15383. }
  15384. //Stop Transaction Time
  15385. struct timeval tmnow;
  15386. struct tm *tm;
  15387. char buf[28];//, usec_buf[6];
  15388. gettimeofday(&tmnow, NULL);
  15389. time_t t;
  15390. t = time(NULL);
  15391. /*UTC time and date*/
  15392. tm = gmtime(&t);
  15393. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15395. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15396. random_uuid(guid);
  15397. /***********************************transactionData******************************************************/
  15398. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  15399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15400. //=================================
  15401. // Transaction_Begin
  15402. //=================================
  15403. // Energy.Active.Export.Interval
  15404. //idx_sample=0;
  15405. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  15406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15408. 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*/]);
  15409. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15410. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15411. {
  15412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15413. }
  15414. else
  15415. {
  15416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15417. }
  15418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15420. //=================================
  15421. // Transaction_End
  15422. //=================================
  15423. //Current.Export
  15424. //idx_sample=1;
  15425. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15426. if(gunType[gun_index] == 'J')
  15427. {
  15428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15429. {
  15430. tempIndex = ((gun_index==2) ? 1: 0);
  15431. }
  15432. else
  15433. {
  15434. tempIndex = gun_index;
  15435. }
  15436. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15437. {
  15438. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15439. {
  15440. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15441. }
  15442. }// End of for CHAdeMO_QUANTITY
  15443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15444. }
  15445. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15446. {
  15447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15448. {
  15449. tempIndex = ((gun_index==2) ? 1: 0);
  15450. }
  15451. else
  15452. {
  15453. tempIndex = gun_index;
  15454. }
  15455. for (int index = 0; index < CCS_QUANTITY; index++)
  15456. {
  15457. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15458. {
  15459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15460. }
  15461. }// End of for CCS_QUANTITY
  15462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15463. }
  15464. else if(gunType[gun_index] == 'G')
  15465. {
  15466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15467. {
  15468. tempIndex = ((gun_index==2) ? 1: 0);
  15469. }
  15470. else
  15471. {
  15472. tempIndex = gun_index;
  15473. }
  15474. for (int index = 0; index < GB_QUANTITY; index++)
  15475. {
  15476. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15477. {
  15478. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15479. }
  15480. }// End of for GB_QUANTITY
  15481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15482. }
  15483. else
  15484. {
  15485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15486. {
  15487. tempIndex = 2;
  15488. }
  15489. else
  15490. {
  15491. tempIndex = gun_index;
  15492. }
  15493. for (int index = 0; index < AC_QUANTITY; index++)
  15494. {
  15495. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15496. {
  15497. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15498. }
  15499. }// End of for AC_QUANTITY
  15500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15501. }
  15502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15505. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15508. //Energy.Active.Export.Interval
  15509. //idx_sample=2;
  15510. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15511. if(gunType[gun_index] == 'J')
  15512. {
  15513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15514. {
  15515. tempIndex = ((gun_index==2) ? 1: 0);
  15516. }
  15517. else
  15518. {
  15519. tempIndex = gun_index;
  15520. }
  15521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15522. {
  15523. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15524. {
  15525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15526. }
  15527. }// END OF CHAdeMO_QUANTITY
  15528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15529. }
  15530. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15531. {
  15532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15533. {
  15534. tempIndex = ((gun_index==2) ? 1: 0);
  15535. }
  15536. else
  15537. {
  15538. tempIndex = gun_index;
  15539. }
  15540. for (int index = 0; index < CCS_QUANTITY; index++)
  15541. {
  15542. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15543. {
  15544. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15545. }
  15546. }// END OF CCS_QUANTITY
  15547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15548. }
  15549. else if(gunType[gun_index] == 'G')
  15550. {
  15551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15552. {
  15553. tempIndex = ((gun_index==2) ? 1: 0);
  15554. }
  15555. else
  15556. {
  15557. tempIndex = gun_index;
  15558. }
  15559. for (int index = 0; index < GB_QUANTITY; index++)
  15560. {
  15561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15562. {
  15563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15564. }
  15565. }// END OF GB_QUANTITY
  15566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15567. }
  15568. else
  15569. {
  15570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15571. {
  15572. tempIndex = 2;
  15573. }
  15574. else
  15575. {
  15576. tempIndex = gun_index;
  15577. }
  15578. for (int index = 0; index < AC_QUANTITY; index++)
  15579. {
  15580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15581. {
  15582. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15583. }
  15584. }// END OF AC_QUANTITY
  15585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15586. }
  15587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15590. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15593. //Power.Active.Export
  15594. //idx_sample=3;
  15595. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15596. if(gunType[gun_index] == 'J')
  15597. {
  15598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15599. {
  15600. tempIndex = ((gun_index==2) ? 1: 0);
  15601. }
  15602. else
  15603. {
  15604. tempIndex = gun_index;
  15605. }
  15606. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15607. {
  15608. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15609. {
  15610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15611. }
  15612. } // End for CHAdeMO_QUANTITY
  15613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15614. }
  15615. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15616. {
  15617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15618. {
  15619. tempIndex = ((gun_index==2) ? 1: 0);
  15620. }
  15621. else
  15622. {
  15623. tempIndex = gun_index;
  15624. }
  15625. for (int index = 0; index < CCS_QUANTITY; index++)
  15626. {
  15627. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15628. {
  15629. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15630. }
  15631. } // END for CCS_QUANTITY
  15632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15633. }
  15634. else if(gunType[gun_index] == 'G')
  15635. {
  15636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15637. {
  15638. tempIndex = ((gun_index==2) ? 1: 0);
  15639. }
  15640. else
  15641. {
  15642. tempIndex = gun_index;
  15643. }
  15644. for (int index = 0; index < GB_QUANTITY; index++)
  15645. {
  15646. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15647. {
  15648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15649. }
  15650. }// END for GB_QUANTITY
  15651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15652. }
  15653. else
  15654. {
  15655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15656. {
  15657. tempIndex = 2;
  15658. }
  15659. else
  15660. {
  15661. tempIndex = gun_index;
  15662. }
  15663. for (int index = 0; index < AC_QUANTITY; index++)
  15664. {
  15665. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15666. {
  15667. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15668. }
  15669. } // END for AC_QUANTITY
  15670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15671. }
  15672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15675. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15678. //Voltage
  15679. //idx_sample=4;
  15680. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15681. if(gunType[gun_index] == 'J')
  15682. {
  15683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15684. {
  15685. tempIndex = ((gun_index==2) ? 1: 0);
  15686. }
  15687. else
  15688. {
  15689. tempIndex = gun_index;
  15690. }
  15691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15692. {
  15693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15694. {
  15695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15696. }
  15697. } // END OF FOR CHAdeMO_QUANTITY
  15698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15699. }
  15700. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15701. {
  15702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15703. {
  15704. tempIndex = ((gun_index==2) ? 1: 0);
  15705. }
  15706. else
  15707. {
  15708. tempIndex = gun_index;
  15709. }
  15710. for (int index = 0; index < CCS_QUANTITY; index++)
  15711. {
  15712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15713. {
  15714. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15715. }
  15716. } // END OF FOR CCS_QUANTITY
  15717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15718. }
  15719. else if(gunType[gun_index] == 'G')
  15720. {
  15721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15722. {
  15723. tempIndex = ((gun_index==2) ? 1: 0);
  15724. }
  15725. else
  15726. {
  15727. tempIndex = gun_index;
  15728. }
  15729. for (int index = 0; index < GB_QUANTITY; index++)
  15730. {
  15731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15732. {
  15733. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15734. }
  15735. } // END OF FOR GB_QUANTITY
  15736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15737. }
  15738. else
  15739. {
  15740. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15741. {
  15742. tempIndex = 2;
  15743. }
  15744. else
  15745. {
  15746. tempIndex = gun_index;
  15747. }
  15748. for (int index = 0; index < AC_QUANTITY; index++)
  15749. {
  15750. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15751. {
  15752. 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
  15753. }
  15754. } // END OF FOR AC_QUANTITY
  15755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15756. }
  15757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15759. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15760. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15763. //SoC
  15764. //idx_sample=5;
  15765. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15766. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15767. {
  15768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15769. {
  15770. tempIndex = ((gun_index==2) ? 1: 0);
  15771. }
  15772. else
  15773. {
  15774. tempIndex = gun_index;
  15775. }
  15776. if(gunType[gun_index] == 'J')
  15777. {
  15778. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15779. {
  15780. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15781. {
  15782. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15783. }
  15784. }
  15785. }
  15786. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15787. {
  15788. for (int index = 0; index < CCS_QUANTITY; index++)
  15789. {
  15790. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15791. {
  15792. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15793. }
  15794. }
  15795. }
  15796. else if(gunType[gun_index] == 'G')
  15797. {
  15798. for (int index = 0; index < GB_QUANTITY; index++)
  15799. {
  15800. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15801. {
  15802. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15803. }
  15804. }
  15805. }
  15806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  15811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15812. } // END FOR DC CASE
  15813. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15814. {
  15815. 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\"}]}]}]"
  15816. ,MESSAGE_TYPE_CALL
  15817. ,guid
  15818. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15819. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15820. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15822. ,"PowerLoss"
  15823. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  15860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  15861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  15862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  15863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  15864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  15865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  15866. );
  15867. }
  15868. else
  15869. {
  15870. 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\"}]}]}]"
  15871. ,MESSAGE_TYPE_CALL
  15872. ,guid
  15873. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15874. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15875. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15877. ,"PowerLoss"
  15878. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15914. );
  15915. }
  15916. // Check File "TempStopTransaction" Exist
  15917. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  15918. {
  15919. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15920. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  15921. }
  15922. else
  15923. {
  15924. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15925. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  15926. if(log == NULL)
  15927. {
  15928. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15929. return ;
  15930. }
  15931. else
  15932. {
  15933. fclose(log);
  15934. }
  15935. }
  15936. //Add TempStopTransaction | Update TempStopTransaction
  15937. // open file for writing
  15938. FILE *outfile;
  15939. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  15940. DEBUG_INFO("data=%s\n",queuedata);
  15941. fputs(queuedata, outfile);
  15942. fputs("\n", outfile);
  15943. fclose (outfile);
  15944. }
  15945. void checkTempStopTransaction(int gun_index)
  15946. {
  15947. FILE *fptr1;
  15948. char ch;
  15949. char str[1200]={0};
  15950. char guid[37]={0};
  15951. char tempdata[65]={0};
  15952. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  15953. if (!fptr1)
  15954. {
  15955. //printf(" File not found or unable to open the input file!!\n");
  15956. return ;
  15957. }
  15958. ch=fgetc(fptr1);
  15959. //printf(" Now the content of the file %s is : \n",fname);
  15960. rewind(fptr1);
  15961. if(ch!=EOF)
  15962. {
  15963. // copy all contents to the temporary file except the specific line
  15964. while (fgets(str, 1200, fptr1) != NULL)
  15965. {
  15966. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15967. if(str[0]=='\0')
  15968. {
  15969. break;
  15970. }
  15971. random_uuid(guid);
  15972. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15973. if(hashmap_operation(0, guid, tempdata) == 1)
  15974. {
  15975. DEBUG_INFO("StopTransaction mapitem pass\n");
  15976. }
  15977. queue_operation(4, guid, str );//addq(guid, queuedata); ---> remove temporally
  15978. memset(str,0,sizeof str);
  15979. }
  15980. }
  15981. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15982. fclose(fptr1);
  15983. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  15984. }
  15985. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15986. {
  15987. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15988. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15989. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15990. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15991. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15992. }
  15993. int GetWebSocketPingInterval(void)
  15994. {
  15995. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15996. }
  15997. int GetServerSign(void)
  15998. {
  15999. return server_sign;
  16000. }
  16001. void SetServerSign(int value)
  16002. {
  16003. server_sign = value;
  16004. }
  16005. int GetBootNotificationInterval(void)
  16006. {
  16007. return BootNotificationInterval;
  16008. }
  16009. int GetInternetConn(void)
  16010. {
  16011. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16012. }
  16013. void InitialSystemValue(void)
  16014. {
  16015. int connectorIndex = 0;
  16016. //int valueASCII = 0;
  16017. server_cycle_Status = 120;
  16018. gunTotalNumber=0;
  16019. SystemInitial = 0;
  16020. localversion=0;
  16021. BootNotificationInterval = 0;
  16022. authorizeRetryTimes = 0;
  16023. GunStatusInterval = 10;
  16024. TransactionMessageAttemptsValue = 0;
  16025. TransactionMessageRetryIntervalValue = 0;
  16026. //Hear Beat
  16027. HeartBeatWithNOResponse = 0;
  16028. HeartBeatCountPerHour = 0;
  16029. HeartBeatWaitTime = 10;
  16030. FirstHeartBeat = 0;
  16031. FirmwareStatusNotificationStatus = 3; // Idle
  16032. DiagnosticsStatusNotificationStatus = 0; // Idle
  16033. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  16034. memset(statusModeChage, 0, sizeof(statusModeChage));
  16035. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  16036. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  16037. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  16038. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  16039. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  16040. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  16041. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  16042. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  16043. memset(gunType, 0, sizeof(gunType));
  16044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16045. {
  16046. //check connector / socket type (index: 8, 9, 10)
  16047. for(int index=7; index <10 ; index++)
  16048. {
  16049. if(index != 8)
  16050. {
  16051. // DC Connector
  16052. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  16053. {
  16054. SystemInitial = SystemInitial + 1;
  16055. gunTotalNumber = gunTotalNumber + 1;
  16056. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16057. connectorIndex = connectorIndex + 1;
  16058. }
  16059. }
  16060. else
  16061. {
  16062. // AC Connector
  16063. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16064. {
  16065. SystemInitial = SystemInitial + 1;
  16066. gunTotalNumber = gunTotalNumber + 1;
  16067. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16068. connectorIndex = connectorIndex + 1;
  16069. }
  16070. }
  16071. }
  16072. //DEBUG_INFO("DC ...\n");
  16073. }
  16074. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16075. {
  16076. //check connector / socket type (index: 8, 9, 10)
  16077. for(int index=7; index <10 ; index++)
  16078. {
  16079. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16080. {
  16081. SystemInitial = SystemInitial + 1;
  16082. gunTotalNumber = gunTotalNumber + 1;
  16083. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16084. connectorIndex = connectorIndex + 1;
  16085. DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16086. }
  16087. }
  16088. DEBUG_INFO("gunTotalNumber: %d\n", gunTotalNumber);
  16089. DEBUG_INFO("connectorIndex: %d\n", connectorIndex);
  16090. DEBUG_INFO("SystemInitial: %d\n", SystemInitial);
  16091. //DEBUG_INFO("AC ...\n");
  16092. }
  16093. //Status && ConnectorPlugIn Setting
  16094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16095. {
  16096. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16097. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16098. }
  16099. for (int index = 0; index < CCS_QUANTITY; index++)
  16100. {
  16101. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16102. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16103. }
  16104. for (int index = 0; index < GB_QUANTITY; index++)
  16105. {
  16106. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16107. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16108. }
  16109. for (int index = 0; index < AC_QUANTITY; index++)
  16110. {
  16111. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16112. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16113. }
  16114. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16115. {
  16116. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16117. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16118. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16119. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  16120. }
  16121. // Charger PRE_SYS_MODE
  16122. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  16123. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16124. clientTime.Heartbeat=time((time_t*)NULL);
  16125. sleep(1);
  16126. }
  16127. void LWS_Send(char * str)
  16128. {
  16129. //=====================================================
  16130. // Check InternetConn 0: disconnected, 1: connected
  16131. //====================================================
  16132. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  16133. {
  16134. DEBUG_INFO("\n offline now !!!\n");
  16135. return;
  16136. }
  16137. pthread_mutex_lock(&lock);
  16138. memset(SendBuffer,0,SendBufLen);
  16139. sprintf((char *)SendBuffer, "%s", str);
  16140. pthread_mutex_unlock(&lock);
  16141. lws_callback_on_writable(wsi_client);
  16142. lws_service(context, 10000);//timeout_ms
  16143. }